Subtrees hinzugefügt
This commit is contained in:
parent
07bf15b97b
commit
193803e06c
89 changed files with 20136 additions and 0 deletions
5
Software/iud_key_angriffe_vigenere/.gitignore
vendored
Normal file
5
Software/iud_key_angriffe_vigenere/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
*.class
|
||||
*.ctxt
|
||||
*.sh
|
||||
repo.adoc
|
||||
*.~lock
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
import java.awt.*;
|
||||
import java.awt.geom.Line2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import javax.swing.*;
|
||||
|
||||
public class Balkendiagramm extends JPanel {
|
||||
|
||||
private double gesamt;
|
||||
private double haeufigkeit[];
|
||||
private double maxwert;
|
||||
private int verschiebung = 0;
|
||||
private double haeufigkeit_de[] = { 0.0651, 0.0189, 0.0306, 0.0508, 0.174, 0.0166, 0.0301, 0.0476,0.0755, 0.0027, 0.0121,0.0344,0.0252,0.0978,0.0251,0.0079,0.0002,0.07,0.0727,0.0615,0.0435,0.067,0.0189,0.0003,0.0004,0.0113};
|
||||
|
||||
|
||||
public void setHaeufigkeit(double haeufigkeit[]) {
|
||||
|
||||
this.haeufigkeit = haeufigkeit;
|
||||
gesamt = 0;
|
||||
for (int i = 0; i < 26; i++) {
|
||||
gesamt += haeufigkeit[i];
|
||||
}
|
||||
for (int i = 0; i < 26; i++) {
|
||||
haeufigkeit[i] /= gesamt;
|
||||
}
|
||||
maxwert = 0.20;
|
||||
|
||||
}
|
||||
|
||||
public void setVerschiebung(int verschiebung) {
|
||||
if (verschiebung >= 0 && verschiebung < 26) {
|
||||
this.verschiebung = verschiebung;
|
||||
|
||||
} else {
|
||||
this.verschiebung = 0;
|
||||
} // end of if-else
|
||||
}
|
||||
|
||||
public void paintComponent(Graphics g) {
|
||||
Graphics2D g2 = (Graphics2D) g;
|
||||
super.paintComponent(g2);
|
||||
Dimension d = getSize(null);
|
||||
//Skalieren auf 100x100 mit y-Invertierung
|
||||
g2.scale(d.getWidth() / 120.0, -d.getHeight() / 100.0);
|
||||
// Ursprung verschieben nach (15,-90)
|
||||
g2.translate(5, -90);
|
||||
// Linien etwas breiter
|
||||
g2.setStroke(new BasicStroke(1.5f));
|
||||
// x-Achse zeichnen
|
||||
g2.draw(new Line2D.Double(0, 0, 104, 0));
|
||||
// Linien etwas dünner
|
||||
g2.setStroke(new BasicStroke(0.5f));
|
||||
// Deutsche Häufigkeit grau
|
||||
g2.setColor(Color.darkGray);
|
||||
// Säulen zeichnen
|
||||
for (int i = 0; i < 26; i++) {
|
||||
g2.fill(new Rectangle2D.Double(4 * i+1, 0, 2, haeufigkeit_de[i] / maxwert *100));
|
||||
}
|
||||
// Texthäufigkeit blau
|
||||
g2.setColor(Color.blue);
|
||||
// Säulen zeichnen
|
||||
for (int i = 0; i < 26; i++) {
|
||||
g2.fill(new Rectangle2D.Double(4 * i, 0, 2, haeufigkeit[(i+verschiebung)%26] / maxwert *100));
|
||||
}
|
||||
// y-Invertierung rückgängig machen
|
||||
g2.scale(1, -1);
|
||||
// Beschriftung x-Achse
|
||||
String xAchse = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
// Fontgröße für Beschriftung ändern
|
||||
g2.setColor(Color.black);
|
||||
g2.setFont(g2.getFont().deriveFont(5f));
|
||||
for (int i = 0; i < 26; i++) {
|
||||
g2.drawString(xAchse.substring(i, i + 1),
|
||||
i * 4, +6);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
public class Baustein implements Comparable<Baustein>{
|
||||
|
||||
// Anfang Attribute
|
||||
private String zeichen;
|
||||
private int anzahl;
|
||||
// Ende Attribute
|
||||
|
||||
public Baustein(String zeichen) {
|
||||
super();
|
||||
anzahl = 1;
|
||||
this.zeichen = zeichen;
|
||||
}
|
||||
// Anfang Methoden
|
||||
|
||||
|
||||
|
||||
public int compareTo(Baustein c) {
|
||||
|
||||
int anz = c.getAnzahl();
|
||||
|
||||
//ascending order
|
||||
return anz - this.anzahl;
|
||||
|
||||
//descending order
|
||||
//return compareQuantity - this.quantity;
|
||||
|
||||
}
|
||||
public String getZeichen() {
|
||||
return zeichen;
|
||||
}
|
||||
|
||||
public int getAnzahl() {
|
||||
return anzahl;
|
||||
}
|
||||
|
||||
public void incAnzahl() {
|
||||
anzahl++;
|
||||
}
|
||||
|
||||
|
||||
// Ende Methoden
|
||||
}
|
||||
Binary file not shown.
|
|
@ -0,0 +1,365 @@
|
|||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
import javax.swing.table.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import javax.swing.text.DefaultHighlighter;
|
||||
import javax.swing.text.Highlighter;
|
||||
import javax.swing.text.Highlighter.HighlightPainter;
|
||||
import javax.swing.text.BadLocationException;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Programm zur Kryptoanalyse
|
||||
* von monoalphabetischen Substitutionen
|
||||
*
|
||||
* @version 1.0 from 23.11.2016
|
||||
* @author Thomas Schaller
|
||||
*/
|
||||
|
||||
public class BreakVigenere extends JFrame {
|
||||
// Anfang Attribute
|
||||
private JTextField[] buchstabe;
|
||||
|
||||
private JButton jButton1 = new JButton();
|
||||
private JButton jBBuchstabe = new JButton();
|
||||
private Balkendiagramm bdText = new Balkendiagramm();
|
||||
|
||||
private JTextArea jTAKrypto = new JTextArea("");
|
||||
private JScrollPane jTAKryptoScrollPane = new JScrollPane(jTAKrypto);
|
||||
private JTextArea jTAKlartext = new JTextArea("");
|
||||
private JScrollPane jTAKlartextScrollPane = new JScrollPane(jTAKlartext);
|
||||
private JLabel jLKryptotext = new JLabel();
|
||||
private JLabel jLKlartext = new JLabel();
|
||||
private JLabel jLCopyright = new JLabel();
|
||||
private JTextArea jTAKorrelation = new JTextArea("");
|
||||
private JScrollPane jTAKorrelationScrollPane = new JScrollPane(jTAKorrelation);
|
||||
private JSpinner jSpVerschiebung = new JSpinner();
|
||||
private SpinnerNumberModel jSpVerschiebungModel = new SpinnerNumberModel(0, 0, 99, 1);
|
||||
private JNumberField jNFAnzahlTreffer = new JNumberField();
|
||||
private JLabel lVerschiebung = new JLabel();
|
||||
private JLabel lAnzahlgleicherBuchstaben = new JLabel();
|
||||
// Ende Attribute
|
||||
|
||||
public BreakVigenere (String title) {
|
||||
super (title);
|
||||
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
|
||||
int frameWidth = 707;
|
||||
int frameHeight = 649;
|
||||
setSize(frameWidth, frameHeight);
|
||||
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
int x = (d.width - getSize().width) / 2;
|
||||
int y = (d.height - getSize().height) / 2;
|
||||
setLocation(x, y);
|
||||
Container cp = getContentPane();
|
||||
cp.setLayout(null);
|
||||
// Anfang Komponenten
|
||||
|
||||
jTAKryptoScrollPane.setBounds(16, 24, 665, 105);
|
||||
jTAKrypto.setLineWrap(true);
|
||||
jTAKrypto.setFont(new Font("Courier New", Font.BOLD, 16));
|
||||
jTAKrypto.setText("JMLQMFNSKIOQNXGYZOQEBJLUKXHFCXGVLGBMREAJZCAEKVIFOWJLMFGJLPQZJIYHQQHYJLAFGFLRLQYESTPMHIAWQZFIPPMZMIZGPDOIIIVGTHIIQVKHLVHQOPLNMIKMSWCYKMUIVBREADEQOXLVVMILSMVWYZLVAONSIIVIKVKIVPOIZIEGXHLHCDILKIVPKYAWKTKRIIVQJMRXQZKVHFBVULHRVQYXYMBTKQPYAUSNHLZUSJUJBQTFHRLEKMUIAUTPHXMUTMZGPQXWWVIONINIAONVPIJQTIUWMONWIRLUMIUAMDQIZTWXEKYEXTOELPQNXMZIFEKGOWJONIYDCDVSSCODGTOMMMTKLKMNKRPRLQSRHGPEKMUIUFUHLZMDLJLRBXOGOXMZHYJLAONPBKMDBSYRIONNLHMYKMUDMXTIUOTMXXLBBNAGOWBMHIUDCYTGOWBQTESTPMHIAMVEKMUIZFGFBPINKVGYOQNIUYVPYSHPTQBIYJONGVLRIXVLHFMFKEBWHGTYADMZJETMBQXJHRLQXHPIXDUKYIAEOZLTWXEESTPMHIAMAONIJLQRLVPIZGTKHFMDKWDEZZUGOIQZLIZXMEBIYJITXIUSPZKWJLTEYISHQQYIYACDJIPQRMNVCSUUZESMMZOWJLMZQVFTBARSNIVSOSCEVNGXAMAFGFLPTMYSJEQZLSYQMUTIZZWYBIYWKTRWZPMDLVLMHGCLSIVPKRRIVZCSYXAAJIYIQZKWRIVZYEADMEBSYKMEILSEOQTKLVVQARKOZKVXVKZMVLPWKTYGOAIONHHPMUILADCQXVHXMZCYYHMZJETETEREAIQZOWJLMEORUWXDILLFMZAXGXEUKFLMABOISWEQOWLZQDZZAMWYTMHTIDKRAETXKWNIPAXGOXLQXXJLBUMOLMBPOIIYKTYXHFMZJIZOMZTWHXHQYFLWBUSQLRLUKVLMPQTJVPOQORKIZPOICIZEILPILQTIUETBNEIIBQGYZHMDZEIYTMGYZKMINPAA\nMDJIUQAEKRZMVPGPSIDQXFYECONXHPAAKMUQIXHIUYBLZAVVLQTLPIZZGGOOTMXXLBBNAGOWBMHIUWWNKKPRVFSEUAQQJIYZWZBSYRMENEUHMXZWPGPEUQPXCYKMUIXQXMVHQEILLTWXEESTPMHIAMAONIZYJEZMAYBUURTMBUSFLMABOISIQZKVWIZUUHLZWZCLYIVPZVPXPQSMBWAUILHYNHKVZGPAHIUIAFGRKEZPGPWLINKXLFMEILYRSFKESWWPOINIEANRAIIXVLHFMFOWJLMDKMOIVRUPNILQXFBGPEZEIIVHKVDIVPKXLFMXREZSJQXIPXAHKVDVNQRXLETBNEIIBQJMLIZMRPLVLUTKZMVHUPBXWDOWJLETRXLFMUJIUQWZUESTPMHIAMAONIUWCNYXPXCFOSUWUQZLVHMZCEYHQQYWJLWZYIPXTMTKLQJXOGOKZGTHZXHXOGOLIFZIKMMEHIYIQFYMTNITXESWWXGRNIDAXXYMBTKQPYAGTHIITXGWVHMDOXHPQQTMZGPQMISIPDZISIWZHEAXQEZEHPJQXXPIUBLSOPMZKVZGPXAKCSZPOIHPXTGFLXMZGGONMIKMSWLDKMVHMDBMLVEDZIYRHGCIJLAQRRHPAYKGOEVUYGOIATOPMWUUZXLPPMZXLIZTOIYDCPOIUEKTOLTFMZGRUXMMRFLVBUYGOIQNKIYJCZJIUIQZKGOMNRXMLVAONIPFMNKWAIPQTHGYUQOWAECEFALMZGTHLRUQZESPAONIPFMZJMLECRKMUIZSKQLMVEGQLRIONWLWQFFIUYVPYSCIZNARKIVEORKHIEYWPGPPOIRPMUTIYIIGLHLVODKVLRLDKLLRSMTRUEPQFYLMVVGLYLCZJIYXABZIYMUVGLYZMDGPSKMYKMUIZFKHLVVQGTVPQFGRPWKTKKLPMTXXLKQABEURQNGXAMAFGHLPTMVSYXIMRFLVBUYZLVEDLISXMMRTOEJQZIBRLNKPSEAAYOLRVIUVAYVPYGOYNPOI\nWSTKGPWLINKXPWKTKGOMNRXMLVCZMQPXDQXAYJMXZITETBNEIIBGTHZGPXYWLPPUKVGYEGXHLETNKVAMAEILLMJQHIUYBLZHPIVMILQILQSFBGPEZEIIVLAHYIPQTAHVQYPEOVODOJMHMDLVHRHAYIIPIUYIKIDUMIUVMBUVAEAUJILECRARKWKTRYNZWDYXHXBPKVHPJQXXPWKTKMIILUKXHFCXGVLGBMJIZXZUZLLQQGYDBZMDCIUHMZJEIIQMHIYEVPKVZETEOQVVQSORHPDQXAYJMXZIHPXTGFLXMQORGYBDGKLRLUKWLVSDETASODGTOMAONWAEZWKZVVAONPHKDUMIUVMEMIYMMFORKIVRUPNIVPKRQEPDNYUHMDZIUMVHKVNIAEKROIQFARKHQQAVZTZZMPPGPHURAVQFNITMCEBSYKMEILSEOQTITIBTUHLACDJIBRBQXHLQVMSIUZQSKRYIKTOJMVMNKOHRVF");
|
||||
jTAKrypto.addKeyListener(new KeyAdapter() {
|
||||
public void keyTyped(KeyEvent evt) {
|
||||
jTAKrypto_KeyTyped(evt);
|
||||
}
|
||||
});
|
||||
cp.add(jTAKryptoScrollPane);
|
||||
|
||||
jTAKlartextScrollPane.setBounds(16, 480, 665, 105);
|
||||
jTAKlartext.setLineWrap(true);
|
||||
jTAKlartext.setFont(new Font("Courier New", Font.BOLD, 16));
|
||||
cp.add(jTAKlartextScrollPane);
|
||||
jLKryptotext.setText("Kryptotext");
|
||||
jLKryptotext.setBounds(16, 3, 110, 20);
|
||||
cp.add(jLKryptotext);
|
||||
jLKlartext.setText("Klartext");
|
||||
jLKlartext.setBounds(16, 456, 110, 20);
|
||||
cp.add(jLKlartext);
|
||||
jLCopyright.setText("(cc) Schaller (ZPG Informatik) - V1.0 (2017)");
|
||||
jLCopyright.setBounds(128, 584, 419, 33);
|
||||
jLCopyright.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
jLCopyright.setFont(new Font("Dialog", Font.PLAIN, 12));
|
||||
cp.add(jLCopyright);
|
||||
|
||||
// -------------------------------- Tab 1 ---------------------------------------------
|
||||
JPanel tab1 = new JPanel();
|
||||
tab1.setLayout(null);
|
||||
|
||||
jTAKorrelationScrollPane.setBounds(16, 144, 665, 57);
|
||||
jTAKorrelationScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
|
||||
jTAKorrelation.setText("");
|
||||
jTAKorrelation.setEditable(false);
|
||||
jTAKorrelation.setEnabled(true);
|
||||
jTAKorrelation.setFont(new Font("Courier New", Font.BOLD, 16));
|
||||
tab1.add(jTAKorrelationScrollPane);
|
||||
jSpVerschiebung.setBounds(192, 110, 41, 25);
|
||||
jSpVerschiebung.setValue(1);
|
||||
jSpVerschiebung.setModel(jSpVerschiebungModel);
|
||||
jSpVerschiebung.addChangeListener(new ChangeListener() {
|
||||
public void stateChanged(ChangeEvent evt) {
|
||||
jSpVerschiebung_StateChanged(evt);
|
||||
}
|
||||
});
|
||||
tab1.add(jSpVerschiebung);
|
||||
|
||||
jNFAnzahlTreffer.setBounds(192, 140, 41, 25);
|
||||
jNFAnzahlTreffer.setText("");
|
||||
jNFAnzahlTreffer.setEditable(false);
|
||||
tab1.add(jNFAnzahlTreffer);
|
||||
lVerschiebung.setBounds(16, 10, 310, 20);
|
||||
lVerschiebung.setText("Angriff auf die Schlüssellänge mit Autokorrelation");
|
||||
tab1.add(lVerschiebung);
|
||||
JLabel l = new JLabel();
|
||||
l.setBounds(14, 165, 640, 40);
|
||||
l.setText("<html>Suche nach der Verschiebung, bei der möglichst viele Buchstaben übereinstimmen.<br> Das ist vermutlich die Schlüssellänge.</html>");
|
||||
tab1.add(l);
|
||||
l = new JLabel();
|
||||
l.setBounds(16, 112, 162, 20);
|
||||
l.setText("Verschiebung");
|
||||
tab1.add(l);
|
||||
lAnzahlgleicherBuchstaben.setBounds(16, 142, 162, 20);
|
||||
lAnzahlgleicherBuchstaben.setText("Anzahl gleicher Buchstaben");
|
||||
tab1.add(lAnzahlgleicherBuchstaben);
|
||||
|
||||
// ---------------------------------- Tab 2 -------------------------------
|
||||
JPanel tab2 = new JPanel();
|
||||
tab2.setLayout(null);
|
||||
|
||||
l = new JLabel();
|
||||
l.setBounds(16, 10, 310, 20);
|
||||
l.setText("Angriff auf die Teiltexte mit Häufigkeitsanalyse");
|
||||
tab2.add(l);
|
||||
|
||||
l = new JLabel();
|
||||
l.setBounds(380, 10, 300, 25);
|
||||
l.setText("Buchstabenhäufigkeit Deutsch");
|
||||
tab2.add(l);
|
||||
|
||||
l = new JLabel();
|
||||
l.setBounds(16, 40, 300, 25);
|
||||
l.setText("Schlüssel");
|
||||
tab2.add(l);
|
||||
|
||||
l = new JLabel();
|
||||
l.setBounds(16, 100, 300, 100);
|
||||
l.setText("<html>Versuche den Schlüssel zu knacken, indem du in jedem Teiltext die Häufigkeitsverteilung der Buchstaben mit der üblichen Häufigkeitsverteilung in deutschen Texten in Einklang bringst.</html>");
|
||||
tab2.add(l);
|
||||
|
||||
double[] h = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
|
||||
bdText.setBounds(380,40,300,180);
|
||||
bdText.setHaeufigkeit(h);
|
||||
tab2.add(bdText);
|
||||
|
||||
jButton1.setBounds(16, 210, 193, 25);
|
||||
jButton1.setText("Entschlüsselung versuchen");
|
||||
jButton1.setMargin(new Insets(2, 2, 2, 2));
|
||||
jButton1.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent evt) {
|
||||
jButton1_ActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
tab2.add(jButton1);
|
||||
|
||||
|
||||
|
||||
// Ende Komponenten
|
||||
buchstabe = new JTextField[26];
|
||||
for (int i = 0; i<26 ;i++ ) {
|
||||
buchstabe[i] = new JTextField();
|
||||
buchstabe[i].setBounds(16+i*25, 65, 25, 25);
|
||||
buchstabe[i].setText("A");
|
||||
buchstabe[i].setHorizontalAlignment(SwingConstants.CENTER);
|
||||
buchstabe[i].setVisible(false);
|
||||
buchstabe[i].addFocusListener(new FocusAdapter() {
|
||||
public void focusGained(FocusEvent evt) {
|
||||
highlightKryptotext(evt);
|
||||
}
|
||||
});
|
||||
buchstabe[i].addKeyListener(new KeyAdapter() {
|
||||
public void keyReleased(KeyEvent e) {
|
||||
e.consume();
|
||||
}
|
||||
|
||||
public void keyTyped(KeyEvent e) {
|
||||
e.consume();
|
||||
}
|
||||
|
||||
public void keyPressed(KeyEvent e) {
|
||||
JTextField textField = (JTextField) e.getSource();
|
||||
String text = textField.getText();
|
||||
if ((e.getKeyChar()>='a' && e.getKeyChar()<='z') ||(e.getKeyChar()>='A' && e.getKeyChar()<='Z')) {
|
||||
text = ""+e.getKeyChar();
|
||||
}
|
||||
if (e.getKeyChar()==' ' || e.getKeyChar() == KeyEvent.VK_BACK_SPACE || e.getKeyChar() == KeyEvent.VK_DELETE) {
|
||||
text = "";
|
||||
|
||||
} // end of if
|
||||
textField.setText(text.toUpperCase());
|
||||
e.consume();
|
||||
if (textField.getText().length()>0) {
|
||||
bdText.setVerschiebung((int) textField.getText().charAt(0)-65);
|
||||
|
||||
} else {
|
||||
bdText.setVerschiebung(0);
|
||||
} // end of if-else
|
||||
bdText.repaint();
|
||||
|
||||
} // end of if
|
||||
|
||||
});
|
||||
|
||||
tab2.add(buchstabe[i]);
|
||||
} // end of for
|
||||
|
||||
JTabbedPane tabpane = new JTabbedPane
|
||||
(JTabbedPane.TOP,JTabbedPane.SCROLL_TAB_LAYOUT );
|
||||
tabpane.setBounds(10,140,672,290);
|
||||
|
||||
tabpane.addTab("Schritt 1", tab1);
|
||||
tabpane.addTab("Schritt 2", tab2);
|
||||
cp.add(tabpane);
|
||||
|
||||
setResizable(false);
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Anfang Methoden
|
||||
public void jButton1_ActionPerformed(ActionEvent evt) {
|
||||
String krypttext = jTAKrypto.getText().toUpperCase();
|
||||
String klartext="";
|
||||
int c = 0;
|
||||
int diff = (Integer) jSpVerschiebung.getValue();
|
||||
for (int i=0;i<krypttext.length() ;i++ ) {
|
||||
int asc = krypttext.charAt(i);
|
||||
if (asc != 10) {
|
||||
String z = buchstabe[c%diff].getText().toUpperCase();
|
||||
if (z.equals("")) {
|
||||
klartext += "*";
|
||||
} else {
|
||||
int v = (int) z.charAt(0)-65;
|
||||
asc = (asc-65-v+26)%26+65;
|
||||
klartext += (char) asc;
|
||||
} // end of if
|
||||
c++;
|
||||
}
|
||||
|
||||
} // end of for
|
||||
jTAKlartext.setText(klartext);
|
||||
} // end of jButton1_ActionPerformed
|
||||
|
||||
|
||||
|
||||
|
||||
public void highlightKryptotext(FocusEvent evt) {
|
||||
int start, diff;
|
||||
for (start = 0; start < 26 ; start++) {
|
||||
if (buchstabe[start] == evt.getSource()) {
|
||||
break;
|
||||
} // end of if-else
|
||||
} // end of for
|
||||
jBBuchstabe.setText("Buchstabenhäufigkeit Deutsch");
|
||||
|
||||
diff = (Integer) jSpVerschiebung.getValue();
|
||||
Highlighter h1 = jTAKrypto.getHighlighter();
|
||||
h1.removeAllHighlights();
|
||||
int c = 0;
|
||||
String krypto = jTAKrypto.getText().toUpperCase();
|
||||
double[] h = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
|
||||
try{
|
||||
for (int i=0;i<krypto.length() ;i++) {
|
||||
int asc = (int)krypto.charAt(i);
|
||||
if (asc!=10) {
|
||||
|
||||
if (c%diff == start) {
|
||||
h1.addHighlight(i, i+1,
|
||||
new DefaultHighlighter.DefaultHighlightPainter(new Color(100,100,255)));
|
||||
if (asc>=65 && asc<=90) {
|
||||
h[asc-65]++;
|
||||
}
|
||||
} // end of if
|
||||
c++;
|
||||
} // end of if
|
||||
}
|
||||
bdText.setHaeufigkeit(h);
|
||||
if (buchstabe[start].getText().length()>0) {
|
||||
bdText.setVerschiebung((int) buchstabe[start].getText().charAt(0)-65);
|
||||
|
||||
} else {
|
||||
bdText.setVerschiebung(0);
|
||||
} // end of if-else
|
||||
bdText.repaint();
|
||||
} catch(BadLocationException e) {}
|
||||
}
|
||||
|
||||
|
||||
public void jSpVerschiebung_StateChanged(ChangeEvent evt) {
|
||||
String krypto = jTAKrypto.getText().toUpperCase();
|
||||
String krypto2="";
|
||||
|
||||
for (int i=0; i<krypto.length() ; i++) {
|
||||
if ((int) krypto.charAt(i) != 10) {
|
||||
krypto2 += krypto.charAt(i);
|
||||
} else krypto2 += " "; // end of if
|
||||
} // end of for
|
||||
jTAKorrelation.setText(krypto2);
|
||||
int v = (Integer) (jSpVerschiebung.getValue());
|
||||
String praefix = "\n";
|
||||
for (int i=0;i<v ; i++ ) {
|
||||
praefix = praefix + " ";
|
||||
} // end of for
|
||||
jTAKorrelation.append(praefix+krypto2);
|
||||
|
||||
Highlighter h1 = jTAKorrelation.getHighlighter();
|
||||
h1.removeAllHighlights();
|
||||
int anzahlTreffer=0;
|
||||
try{
|
||||
for (int i=v;i<krypto.length() ;i++ ) {
|
||||
if (krypto.charAt(i)==krypto.charAt(i-v)) {
|
||||
anzahlTreffer++;
|
||||
h1.addHighlight(i, i+1,
|
||||
new DefaultHighlighter.DefaultHighlightPainter(Color.yellow));
|
||||
h1.addHighlight(krypto.length()+i+1,krypto.length()+i+2,
|
||||
new DefaultHighlighter.DefaultHighlightPainter(Color.yellow));
|
||||
}
|
||||
} // end of for
|
||||
|
||||
}catch(BadLocationException e) {}
|
||||
jNFAnzahlTreffer.setInt(anzahlTreffer);
|
||||
for (int i=0; i<buchstabe.length ;i++ ) {
|
||||
if (i<v) {
|
||||
buchstabe[i].setVisible(true);
|
||||
} else {
|
||||
buchstabe[i].setVisible(false);
|
||||
|
||||
} // end of if-else
|
||||
} // end of for
|
||||
|
||||
} // end of jSpVerschiebung_StateChanged
|
||||
|
||||
public void jTAKrypto_KeyTyped(KeyEvent evt) {
|
||||
//jSpVerschiebung_StateChanged(null);
|
||||
|
||||
} // end of jTAKrypto_KeyTyped
|
||||
|
||||
public void jTAKrypto_InputMethodTextChanged(InputMethodEvent evt) {
|
||||
jSpVerschiebung_StateChanged(null);
|
||||
|
||||
} // end of jTAKrypto_InputMethodTextChanged
|
||||
|
||||
public void jTAKrypto_FocusGained(FocusEvent evt) {
|
||||
// TODO hier Quelltext einfügen
|
||||
|
||||
} // end of jTAKrypto_FocusGained
|
||||
|
||||
// Ende Methoden
|
||||
|
||||
public static void main(String[] args) {
|
||||
new BreakVigenere("BreakVigenere");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,577 @@
|
|||
object breakVigenere: TFGUIForm
|
||||
Left = 876
|
||||
Top = 1
|
||||
BorderIcons = [biSystemMenu]
|
||||
Caption = 'BreakVigenere'
|
||||
ClientHeight = 611
|
||||
ClientWidth = 691
|
||||
Color = clBtnFace
|
||||
Font.Charset = DEFAULT_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -10
|
||||
Font.Name = 'MS Sans Serif'
|
||||
Font.Style = []
|
||||
FormStyle = fsStayOnTop
|
||||
OldCreateOrder = True
|
||||
Position = poDesigned
|
||||
ShowHint = True
|
||||
Visible = True
|
||||
OnClose = FormClose
|
||||
OnCloseQuery = FormCloseQuery
|
||||
OnResize = FormResize
|
||||
FrameType = 5
|
||||
Resizable = False
|
||||
Undecorated = False
|
||||
Background = clBtnFace
|
||||
PixelsPerInch = 96
|
||||
TextHeight = 13
|
||||
object jButton1: TJButton
|
||||
Tag = 4
|
||||
Left = 216
|
||||
Top = 440
|
||||
Width = 241
|
||||
Height = 25
|
||||
Hint = 'jButton1'
|
||||
Foreground = 3355443
|
||||
Background = 15658734
|
||||
Font.Charset = DEFAULT_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -12
|
||||
Font.Name = 'Dialog'
|
||||
Font.Style = [fsBold]
|
||||
actionPerformed = 'jButton1_ActionPerformed'
|
||||
Text = 'Entschl'#252'sselung versuchen'
|
||||
Mnemonic = 0
|
||||
DisplayedMnemonicIndex = 0
|
||||
Selected = False
|
||||
BorderPainted = True
|
||||
FocusPainted = False
|
||||
ContentAreaFilled = True
|
||||
HorizontalAlignment = CENTER
|
||||
VerticalAlignment = CENTER
|
||||
HorizontalTextPosition = RIGHT
|
||||
VerticalTextPosition = CENTER
|
||||
IconTextGap = 4
|
||||
RolloverEnabled = False
|
||||
Border.BorderType = NoBorder
|
||||
Border.LineColor = clBlack
|
||||
Border.LineThickness = 0
|
||||
Border.LineRounded = False
|
||||
Border.EtchHighlightColor = clBlack
|
||||
Border.EtchShadowColor = clBlack
|
||||
Border.Etchtype = 0
|
||||
Border.BevelHighlightColor = clBlack
|
||||
Border.BevelShadowColor = clBlack
|
||||
Border.Beveltype = 0
|
||||
Border.MatteColor = clBlack
|
||||
Border.MatteTop = 0
|
||||
Border.MatteLeft = 0
|
||||
Border.MatteBottom = 0
|
||||
Border.MatteRight = 0
|
||||
end
|
||||
object jTable1: TJTable
|
||||
Tag = 19
|
||||
Left = 656
|
||||
Top = 408
|
||||
Width = 193
|
||||
Height = 89
|
||||
Hint = 'jTable1'
|
||||
Foreground = clWindowText
|
||||
Background = clWhite
|
||||
Font.Charset = GB2312_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -12
|
||||
Font.Name = '@Fixedsys'
|
||||
Font.Style = []
|
||||
RowHeight = 16
|
||||
ShowHorizontalLines = True
|
||||
ShowVerticalLines = True
|
||||
ShowGrid = True
|
||||
Columns.Strings = (
|
||||
'Title 1'
|
||||
'Title 2'
|
||||
'Title 3'
|
||||
'Title 4'
|
||||
'Title 5')
|
||||
ColCount = 5
|
||||
RowCount = 5
|
||||
FillsViewportHeight = False
|
||||
AutoCreateRowSorter = False
|
||||
RowSelectionAllowed = True
|
||||
ColumnSelectionAllowed = False
|
||||
CellSelectionEnabled = False
|
||||
DragEnabled = False
|
||||
HorizontalScrollBarPolicy = AS_NEEDED
|
||||
VerticalScrollBarPolicy = AS_NEEDED
|
||||
end
|
||||
object jTable2: TJTable
|
||||
Tag = 19
|
||||
Left = 656
|
||||
Top = 336
|
||||
Width = 201
|
||||
Height = 81
|
||||
Hint = 'jTable2'
|
||||
Foreground = 3355443
|
||||
Background = clWhite
|
||||
Font.Charset = DEFAULT_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -12
|
||||
Font.Name = 'Dialog'
|
||||
Font.Style = []
|
||||
RowHeight = 16
|
||||
ShowHorizontalLines = True
|
||||
ShowVerticalLines = True
|
||||
ShowGrid = True
|
||||
Columns.Strings = (
|
||||
'Title 1'
|
||||
'Title 2'
|
||||
'Title 3'
|
||||
'Title 4'
|
||||
'Title 5')
|
||||
ColCount = 5
|
||||
RowCount = 5
|
||||
FillsViewportHeight = False
|
||||
AutoCreateRowSorter = False
|
||||
RowSelectionAllowed = True
|
||||
ColumnSelectionAllowed = False
|
||||
CellSelectionEnabled = False
|
||||
DragEnabled = False
|
||||
HorizontalScrollBarPolicy = AS_NEEDED
|
||||
VerticalScrollBarPolicy = AS_NEEDED
|
||||
end
|
||||
object jTable3: TJTable
|
||||
Tag = 19
|
||||
Left = 648
|
||||
Top = 320
|
||||
Width = 193
|
||||
Height = 57
|
||||
Hint = 'jTable3'
|
||||
Foreground = 3355443
|
||||
Background = clWhite
|
||||
Font.Charset = DEFAULT_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -12
|
||||
Font.Name = 'Dialog'
|
||||
Font.Style = []
|
||||
RowHeight = 16
|
||||
ShowHorizontalLines = True
|
||||
ShowVerticalLines = True
|
||||
ShowGrid = True
|
||||
Columns.Strings = (
|
||||
'Title 1'
|
||||
'Title 2'
|
||||
'Title 3'
|
||||
'Title 4'
|
||||
'Title 5')
|
||||
ColCount = 5
|
||||
RowCount = 5
|
||||
FillsViewportHeight = False
|
||||
AutoCreateRowSorter = False
|
||||
RowSelectionAllowed = True
|
||||
ColumnSelectionAllowed = False
|
||||
CellSelectionEnabled = False
|
||||
DragEnabled = False
|
||||
HorizontalScrollBarPolicy = AS_NEEDED
|
||||
VerticalScrollBarPolicy = AS_NEEDED
|
||||
end
|
||||
object jBBuchstabe: TJButton
|
||||
Tag = 4
|
||||
Left = 248
|
||||
Top = 232
|
||||
Width = 193
|
||||
Height = 25
|
||||
Hint = 'jButton2'
|
||||
Foreground = 3355443
|
||||
Background = 15658734
|
||||
Font.Charset = DEFAULT_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -12
|
||||
Font.Name = 'Dialog'
|
||||
Font.Style = [fsBold]
|
||||
actionPerformed = 'jBBuchstabe_ActionPerformed'
|
||||
Text = 'Buchstabenh'#228'ufigkeit'
|
||||
Mnemonic = 0
|
||||
DisplayedMnemonicIndex = 0
|
||||
Selected = False
|
||||
BorderPainted = True
|
||||
FocusPainted = False
|
||||
ContentAreaFilled = True
|
||||
HorizontalAlignment = CENTER
|
||||
VerticalAlignment = CENTER
|
||||
HorizontalTextPosition = RIGHT
|
||||
VerticalTextPosition = CENTER
|
||||
IconTextGap = 4
|
||||
RolloverEnabled = False
|
||||
Border.BorderType = NoBorder
|
||||
Border.LineColor = clBlack
|
||||
Border.LineThickness = 0
|
||||
Border.LineRounded = False
|
||||
Border.EtchHighlightColor = clBlack
|
||||
Border.EtchShadowColor = clBlack
|
||||
Border.Etchtype = 0
|
||||
Border.BevelHighlightColor = clBlack
|
||||
Border.BevelShadowColor = clBlack
|
||||
Border.Beveltype = 0
|
||||
Border.MatteColor = clBlack
|
||||
Border.MatteTop = 0
|
||||
Border.MatteLeft = 0
|
||||
Border.MatteBottom = 0
|
||||
Border.MatteRight = 0
|
||||
end
|
||||
object jBBigramm: TJButton
|
||||
Tag = 4
|
||||
Left = 632
|
||||
Top = 296
|
||||
Width = 201
|
||||
Height = 25
|
||||
Hint = 'jButton3'
|
||||
Foreground = 3355443
|
||||
Background = 15658734
|
||||
Font.Charset = DEFAULT_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -12
|
||||
Font.Name = 'Dialog'
|
||||
Font.Style = [fsBold]
|
||||
actionPerformed = 'jBBigramm_ActionPerformed'
|
||||
Text = 'Bigramm-H'#228'ufigkeit'
|
||||
Mnemonic = 0
|
||||
DisplayedMnemonicIndex = 0
|
||||
Selected = False
|
||||
BorderPainted = True
|
||||
FocusPainted = False
|
||||
ContentAreaFilled = True
|
||||
HorizontalAlignment = CENTER
|
||||
VerticalAlignment = CENTER
|
||||
HorizontalTextPosition = RIGHT
|
||||
VerticalTextPosition = CENTER
|
||||
IconTextGap = 4
|
||||
RolloverEnabled = False
|
||||
Border.BorderType = NoBorder
|
||||
Border.LineColor = clBlack
|
||||
Border.LineThickness = 0
|
||||
Border.LineRounded = False
|
||||
Border.EtchHighlightColor = clBlack
|
||||
Border.EtchShadowColor = clBlack
|
||||
Border.Etchtype = 0
|
||||
Border.BevelHighlightColor = clBlack
|
||||
Border.BevelShadowColor = clBlack
|
||||
Border.Beveltype = 0
|
||||
Border.MatteColor = clBlack
|
||||
Border.MatteTop = 0
|
||||
Border.MatteLeft = 0
|
||||
Border.MatteBottom = 0
|
||||
Border.MatteRight = 0
|
||||
end
|
||||
object jBDoppel: TJButton
|
||||
Tag = 4
|
||||
Left = 656
|
||||
Top = 280
|
||||
Width = 193
|
||||
Height = 25
|
||||
Hint = 'jButton4'
|
||||
Foreground = 3355443
|
||||
Background = 15658734
|
||||
Font.Charset = DEFAULT_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -12
|
||||
Font.Name = 'Dialog'
|
||||
Font.Style = [fsBold]
|
||||
actionPerformed = 'jBDoppel_ActionPerformed'
|
||||
Text = 'Doppelbuchstaben-H'#228'ufigkeit'
|
||||
Mnemonic = 0
|
||||
DisplayedMnemonicIndex = 0
|
||||
Selected = False
|
||||
BorderPainted = True
|
||||
FocusPainted = False
|
||||
ContentAreaFilled = True
|
||||
HorizontalAlignment = CENTER
|
||||
VerticalAlignment = CENTER
|
||||
HorizontalTextPosition = RIGHT
|
||||
VerticalTextPosition = CENTER
|
||||
IconTextGap = 4
|
||||
RolloverEnabled = False
|
||||
Border.BorderType = NoBorder
|
||||
Border.LineColor = clBlack
|
||||
Border.LineThickness = 0
|
||||
Border.LineRounded = False
|
||||
Border.EtchHighlightColor = clBlack
|
||||
Border.EtchShadowColor = clBlack
|
||||
Border.Etchtype = 0
|
||||
Border.BevelHighlightColor = clBlack
|
||||
Border.BevelShadowColor = clBlack
|
||||
Border.Beveltype = 0
|
||||
Border.MatteColor = clBlack
|
||||
Border.MatteTop = 0
|
||||
Border.MatteLeft = 0
|
||||
Border.MatteBottom = 0
|
||||
Border.MatteRight = 0
|
||||
end
|
||||
object jTAKrypto: TJTextArea
|
||||
Tag = 3
|
||||
Left = 16
|
||||
Top = 24
|
||||
Width = 665
|
||||
Height = 105
|
||||
Cursor = crIBeam
|
||||
Hint = 'jTextArea1'
|
||||
Foreground = clWindowText
|
||||
Background = clWhite
|
||||
Font.Charset = ANSI_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -16
|
||||
Font.Name = 'Courier New'
|
||||
Font.Style = [fsBold]
|
||||
focusGained = 'jTAKrypto_FocusGained'
|
||||
inputMethodTextChanged = 'jTextArea1_InputMethodTextChanged'
|
||||
keyTyped = 'jTextArea1_KeyTyped'
|
||||
LineWrap = True
|
||||
HorizontalScrollBarPolicy = AS_NEEDED
|
||||
VerticalScrollBarPolicy = AS_NEEDED
|
||||
WrapStyleWord = False
|
||||
TabSize = 8
|
||||
Text.Strings = (
|
||||
|
||||
'JMLQMFNSKIOQNXGYZOQEBJLUKXHFCXGVLGBMREAJZCAEKVIFOWJLMFGJLPQZJIYH' +
|
||||
'QQHYJLAFGFLRLQYESTPMHIAWQZFIPPMZMIZGPDOIIIVGTHIIQVKHLVHQOPLNMIKM' +
|
||||
'SWCYKMUIVBREADEQOXLVVMILSMVWYZLVAONSIIVIKVKIVPOIZIEGXHLHCDILKIVP' +
|
||||
'KYAWKTKRIIVQJMRXQZKVHFBVULHRVQYXYMBTKQPYAUSNHLZUSJUJBQTFHRLEKMUI' +
|
||||
'AUTPHXMUTMZGPQXWWVIONINIAONVPIJQTIUWMONWIRLUMIUAMDQIZTWXEKYEXTOE' +
|
||||
'LPQNXMZIFEKGOWJONIYDCDVSSCODGTOMMMTKLKMNKRPRLQSRHGPEKMUIUFUHLZMD' +
|
||||
'LJLRBXOGOXMZHYJLAONPBKMDBSYRIONNLHMYKMUDMXTIUOTMXXLBBNAGOWBMHIUD' +
|
||||
'CYTGOWBQTESTPMHIAMVEKMUIZFGFBPINKVGYOQNIUYVPYSHPTQBIYJONGVLRIXVL' +
|
||||
'HFMFKEBWHGTYADMZJETMBQXJHRLQXHPIXDUKYIAEOZLTWXEESTPMHIAMAONIJLQR' +
|
||||
'LVPIZGTKHFMDKWDEZZUGOIQZLIZXMEBIYJITXIUSPZKWJLTEYISHQQYIYACDJIPQ' +
|
||||
'RMNVCSUUZESMMZOWJLMZQVFTBARSNIVSOSCEVNGXAMAFGFLPTMYSJEQZLSYQMUTI' +
|
||||
'ZZWYBIYWKTRWZPMDLVLMHGCLSIVPKRRIVZCSYXAAJIYIQZKWRIVZYEADMEBSYKME' +
|
||||
'ILSEOQTKLVVQARKOZKVXVKZMVLPWKTYGOAIONHHPMUILADCQXVHXMZCYYHMZJETE' +
|
||||
'TEREAIQZOWJLMEORUWXDILLFMZAXGXEUKFLMABOISWEQOWLZQDZZAMWYTMHTIDKR' +
|
||||
'AETXKWNIPAXGOXLQXXJLBUMOLMBPOIIYKTYXHFMZJIZOMZTWHXHQYFLWBUSQLRLU' +
|
||||
'KVLMPQTJVPOQORKIZPOICIZEILPILQTIUETBNEIIBQGYZHMDZEIYTMGYZKMINPAA'
|
||||
|
||||
'MDJIUQAEKRZMVPGPSIDQXFYECONXHPAAKMUQIXHIUYBLZAVVLQTLPIZZGGOOTMXX' +
|
||||
'LBBNAGOWBMHIUWWNKKPRVFSEUAQQJIYZWZBSYRMENEUHMXZWPGPEUQPXCYKMUIXQ' +
|
||||
'XMVHQEILLTWXEESTPMHIAMAONIZYJEZMAYBUURTMBUSFLMABOISIQZKVWIZUUHLZ' +
|
||||
'WZCLYIVPZVPXPQSMBWAUILHYNHKVZGPAHIUIAFGRKEZPGPWLINKXLFMEILYRSFKE' +
|
||||
'SWWPOINIEANRAIIXVLHFMFOWJLMDKMOIVRUPNILQXFBGPEZEIIVHKVDIVPKXLFMX' +
|
||||
'REZSJQXIPXAHKVDVNQRXLETBNEIIBQJMLIZMRPLVLUTKZMVHUPBXWDOWJLETRXLF' +
|
||||
'MUJIUQWZUESTPMHIAMAONIUWCNYXPXCFOSUWUQZLVHMZCEYHQQYWJLWZYIPXTMTK' +
|
||||
'LQJXOGOKZGTHZXHXOGOLIFZIKMMEHIYIQFYMTNITXESWWXGRNIDAXXYMBTKQPYAG' +
|
||||
'THIITXGWVHMDOXHPQQTMZGPQMISIPDZISIWZHEAXQEZEHPJQXXPIUBLSOPMZKVZG' +
|
||||
'PXAKCSZPOIHPXTGFLXMZGGONMIKMSWLDKMVHMDBMLVEDZIYRHGCIJLAQRRHPAYKG' +
|
||||
'OEVUYGOIATOPMWUUZXLPPMZXLIZTOIYDCPOIUEKTOLTFMZGRUXMMRFLVBUYGOIQN' +
|
||||
'KIYJCZJIUIQZKGOMNRXMLVAONIPFMNKWAIPQTHGYUQOWAECEFALMZGTHLRUQZESP' +
|
||||
'AONIPFMZJMLECRKMUIZSKQLMVEGQLRIONWLWQFFIUYVPYSCIZNARKIVEORKHIEYW' +
|
||||
'PGPPOIRPMUTIYIIGLHLVODKVLRLDKLLRSMTRUEPQFYLMVVGLYLCZJIYXABZIYMUV' +
|
||||
'GLYZMDGPSKMYKMUIZFKHLVVQGTVPQFGRPWKTKKLPMTXXLKQABEURQNGXAMAFGHLP' +
|
||||
'TMVSYXIMRFLVBUYZLVEDLISXMMRTOEJQZIBRLNKPSEAAYOLRVIUVAYVPYGOYNPOI'
|
||||
|
||||
'WSTKGPWLINKXPWKTKGOMNRXMLVCZMQPXDQXAYJMXZITETBNEIIBGTHZGPXYWLPPU' +
|
||||
'KVGYEGXHLETNKVAMAEILLMJQHIUYBLZHPIVMILQILQSFBGPEZEIIVLAHYIPQTAHV' +
|
||||
'QYPEOVODOJMHMDLVHRHAYIIPIUYIKIDUMIUVMBUVAEAUJILECRARKWKTRYNZWDYX' +
|
||||
'HXBPKVHPJQXXPWKTKMIILUKXHFCXGVLGBMJIZXZUZLLQQGYDBZMDCIUHMZJEIIQM' +
|
||||
'HIYEVPKVZETEOQVVQSORHPDQXAYJMXZIHPXTGFLXMQORGYBDGKLRLUKWLVSDETAS' +
|
||||
'ODGTOMAONWAEZWKZVVAONPHKDUMIUVMEMIYMMFORKIVRUPNIVPKRQEPDNYUHMDZI' +
|
||||
'UMVHKVNIAEKROIQFARKHQQAVZTZZMPPGPHURAVQFNITMCEBSYKMEILSEOQTITIBT' +
|
||||
'UHLACDJIBRBQXHLQVMSIUZQSKRYIKTOJMVMNKOHRVF')
|
||||
Editable = True
|
||||
end
|
||||
object jTextArea2: TJTextArea
|
||||
Tag = 3
|
||||
Left = 8
|
||||
Top = 480
|
||||
Width = 673
|
||||
Height = 105
|
||||
Cursor = crIBeam
|
||||
Hint = 'jTextArea2'
|
||||
Foreground = clWindowText
|
||||
Background = clWhite
|
||||
Font.Charset = ANSI_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -16
|
||||
Font.Name = 'Courier New'
|
||||
Font.Style = [fsBold]
|
||||
LineWrap = True
|
||||
HorizontalScrollBarPolicy = AS_NEEDED
|
||||
VerticalScrollBarPolicy = AS_NEEDED
|
||||
WrapStyleWord = False
|
||||
TabSize = 8
|
||||
Editable = True
|
||||
end
|
||||
object jLabel1: TJLabel
|
||||
Tag = 1
|
||||
Left = 16
|
||||
Top = 8
|
||||
Width = 110
|
||||
Height = 20
|
||||
Hint = 'jLabel1'
|
||||
Foreground = 3355443
|
||||
Background = clBtnFace
|
||||
Font.Charset = DEFAULT_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -12
|
||||
Font.Name = 'Dialog'
|
||||
Font.Style = [fsBold]
|
||||
Text = 'Kryptotext'
|
||||
HorizontalAlignment = LEFT
|
||||
VerticalAlignment = CENTER
|
||||
HorizontalTextPosition = RIGHT
|
||||
VerticalTextPosition = CENTER
|
||||
IconTextGap = 4
|
||||
DisplayedMnemonic = 0
|
||||
DisplayedMnemonicIndex = 0
|
||||
end
|
||||
object jLabel2: TJLabel
|
||||
Tag = 1
|
||||
Left = 8
|
||||
Top = 456
|
||||
Width = 110
|
||||
Height = 20
|
||||
Hint = 'jLabel1'
|
||||
Foreground = 3355443
|
||||
Background = clBtnFace
|
||||
Font.Charset = DEFAULT_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -12
|
||||
Font.Name = 'Dialog'
|
||||
Font.Style = [fsBold]
|
||||
Text = 'Klartext'
|
||||
HorizontalAlignment = LEFT
|
||||
VerticalAlignment = CENTER
|
||||
HorizontalTextPosition = RIGHT
|
||||
VerticalTextPosition = CENTER
|
||||
IconTextGap = 4
|
||||
DisplayedMnemonic = 0
|
||||
DisplayedMnemonicIndex = 0
|
||||
end
|
||||
object jLabel4: TJLabel
|
||||
Tag = 1
|
||||
Left = 128
|
||||
Top = 584
|
||||
Width = 419
|
||||
Height = 33
|
||||
Hint = 'jLabel4'
|
||||
Foreground = clWindowText
|
||||
Background = clBtnFace
|
||||
Font.Charset = DEFAULT_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -12
|
||||
Font.Name = 'Dialog'
|
||||
Font.Style = []
|
||||
Text = '(cc) Schaller (ZPG Informatik) - V1.0 (2017)'
|
||||
HorizontalAlignment = CENTER
|
||||
VerticalAlignment = CENTER
|
||||
HorizontalTextPosition = RIGHT
|
||||
VerticalTextPosition = CENTER
|
||||
IconTextGap = 4
|
||||
DisplayedMnemonic = 0
|
||||
DisplayedMnemonicIndex = 0
|
||||
end
|
||||
object jTAKorrelation: TJTextArea
|
||||
Tag = 3
|
||||
Left = 16
|
||||
Top = 144
|
||||
Width = 665
|
||||
Height = 57
|
||||
Cursor = crIBeam
|
||||
Hint = 'jTextArea3'
|
||||
Foreground = clWindowText
|
||||
Background = clWhite
|
||||
Font.Charset = ANSI_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -12
|
||||
Font.Name = 'Courier New'
|
||||
Font.Style = [fsBold]
|
||||
LineWrap = False
|
||||
HorizontalScrollBarPolicy = ALWAYS
|
||||
VerticalScrollBarPolicy = AS_NEEDED
|
||||
WrapStyleWord = False
|
||||
TabSize = 8
|
||||
Text.Strings = (
|
||||
'')
|
||||
Editable = False
|
||||
end
|
||||
object jSpVerschiebung: TJSpinner
|
||||
Tag = 22
|
||||
Left = 192
|
||||
Top = 232
|
||||
Width = 41
|
||||
Height = 25
|
||||
Hint = 'jSpinner1'
|
||||
Foreground = 3355443
|
||||
Background = clWhite
|
||||
Font.Charset = DEFAULT_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -12
|
||||
Font.Name = 'Dialog'
|
||||
Font.Style = [fsBold]
|
||||
stateChanged = 'jSpVerschiebung_StateChanged'
|
||||
Maximum = 99
|
||||
Minimum = 0
|
||||
StepSize = 1
|
||||
Value = '0'
|
||||
end
|
||||
object jNFAnzahlTreffer: TJNumberField
|
||||
Tag = 21
|
||||
Left = 192
|
||||
Top = 264
|
||||
Width = 41
|
||||
Height = 25
|
||||
Cursor = crIBeam
|
||||
Hint = 'jNumberField1'
|
||||
Foreground = 3355443
|
||||
Background = clWhite
|
||||
Font.Charset = DEFAULT_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -12
|
||||
Font.Name = 'Dialog'
|
||||
Font.Style = []
|
||||
HorizontalAlignment = LEFT
|
||||
Editable = False
|
||||
end
|
||||
object lVerschiebung: TJLabel
|
||||
Tag = 1
|
||||
Left = 16
|
||||
Top = 232
|
||||
Width = 110
|
||||
Height = 20
|
||||
Hint = 'jLabel3'
|
||||
Foreground = 3355443
|
||||
Background = clBtnFace
|
||||
Font.Charset = DEFAULT_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -12
|
||||
Font.Name = 'Dialog'
|
||||
Font.Style = [fsBold]
|
||||
Text = 'Verschiebung'
|
||||
HorizontalAlignment = LEFT
|
||||
VerticalAlignment = CENTER
|
||||
HorizontalTextPosition = RIGHT
|
||||
VerticalTextPosition = CENTER
|
||||
IconTextGap = 4
|
||||
DisplayedMnemonic = 0
|
||||
DisplayedMnemonicIndex = 0
|
||||
end
|
||||
object lAnzahlgleicherBuchstaben: TJLabel
|
||||
Tag = 1
|
||||
Left = 16
|
||||
Top = 264
|
||||
Width = 162
|
||||
Height = 20
|
||||
Hint = 'jLabel3'
|
||||
Foreground = 3355443
|
||||
Background = clBtnFace
|
||||
Font.Charset = DEFAULT_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -12
|
||||
Font.Name = 'Dialog'
|
||||
Font.Style = [fsBold]
|
||||
Text = 'Anzahl gleicher Buchstaben'
|
||||
HorizontalAlignment = LEFT
|
||||
VerticalAlignment = CENTER
|
||||
HorizontalTextPosition = RIGHT
|
||||
VerticalTextPosition = CENTER
|
||||
IconTextGap = 4
|
||||
DisplayedMnemonic = 0
|
||||
DisplayedMnemonicIndex = 0
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,210 @@
|
|||
// LineRenderer.java
|
||||
|
||||
// Copyright 2002 Regula Hoefer-Isenegger
|
||||
//
|
||||
// This file is part of The Java Turtle (TJT) package
|
||||
//
|
||||
// TJT 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
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// TJT 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 The Java Turtle Package; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package ch.aplu.turtle;
|
||||
|
||||
import ch.aplu.turtle.*;
|
||||
import java.awt.geom.*;
|
||||
/** This class is responsible for drawing the turtle's lines.
|
||||
|
||||
@author <a href="mailto:regula@hoefer.ch">Regula Hoefer-Isenegger</a>
|
||||
@version 0.1
|
||||
*/
|
||||
public class LineRenderer {
|
||||
private Point2D.Double point;
|
||||
private Turtle turtle;
|
||||
|
||||
LineRenderer(Turtle turtle) {
|
||||
this.point = new Point2D.Double();
|
||||
this.turtle = turtle;
|
||||
}
|
||||
|
||||
/** Initialisation with coordinates <code>x</code> and
|
||||
<code>y</code>.
|
||||
*/
|
||||
public void init(double x, double y) {
|
||||
this.point.setLocation(x, y);
|
||||
}
|
||||
/** Same as init(double x, double y), but with a Point2D.Double
|
||||
argument for convenience
|
||||
*/
|
||||
public void init(Point2D.Double p) {
|
||||
this.init(p.x, p.y);
|
||||
}
|
||||
/** Get the current x-coordinate in screen coordinates.*/
|
||||
private double getX(){
|
||||
return (toScreenCoords(point)).getX();
|
||||
}
|
||||
/** Get the current x-coordinate in screen coordinates.*/
|
||||
private double getY(){
|
||||
return toScreenCoords(point).getY();
|
||||
}
|
||||
/** Calls the clipLineTo and wrapLineTo methods, according
|
||||
to the turtle's edge behavior.
|
||||
|
||||
Only overwrite this method when working with another
|
||||
(one that you have defined) edge behaviour. <br>
|
||||
If you mean to change the manner of drawing lines, do this in
|
||||
the methods clipLineTo() and wrapLineTo().
|
||||
@see #clipLineTo
|
||||
@see #wrapLineTo
|
||||
*/
|
||||
protected void internalLineTo(double x, double y){
|
||||
Point2D.Double screenPos = toScreenCoords(x, y);
|
||||
if(turtle.isClip()){
|
||||
clipLineTo(screenPos.getX(), screenPos.getY());
|
||||
}
|
||||
if (turtle.isWrap()){
|
||||
wrapLineTo(screenPos.getX(), screenPos.getY());
|
||||
}
|
||||
init(x,y);
|
||||
}
|
||||
/** Calls the internalLineTo(x,y), which does the actual painting.
|
||||
*/
|
||||
public void lineTo(double x, double y) {
|
||||
internalLineTo(x, y);
|
||||
}
|
||||
/** Calls the internalLineTo(x,y), which does the actual painting.
|
||||
|
||||
This method works the same way as lineTo(double x, double y), but
|
||||
is added for convenience.
|
||||
*/
|
||||
public void lineTo(Point2D.Double p) {
|
||||
internalLineTo(p.getX(), p.getY());
|
||||
}
|
||||
/** Does the actual painting for clip mode.
|
||||
|
||||
It works already with ScreenCoords!
|
||||
For further comments cf. internalLineTo(double x, double y).
|
||||
@see #internalLineTo
|
||||
*/
|
||||
protected void clipLineTo(double x, double y){
|
||||
turtle.getPlayground().lineTo(getX(), getY(), x, y, turtle.getPen());
|
||||
}
|
||||
/** Does the actual painting for wrap mode.
|
||||
|
||||
It works already with ScreenCoords!
|
||||
For further comments cf. internalLineTo(double x, double y).
|
||||
@see #internalLineTo
|
||||
*/
|
||||
protected void wrapLineTo(double x, double y){
|
||||
double dx = getX() - x;
|
||||
double dy = getY() - y;
|
||||
Point2D.Double start = new Point2D.Double(x, y);
|
||||
Point2D.Double end = new Point2D.Double(start.x+dx, start.y+dy);
|
||||
|
||||
intoPanel(start, end);
|
||||
Point2D.Double tmp;
|
||||
while ((tmp = calcIntersection(start.x, start.y, end.x, end.y)) != null){
|
||||
turtle.getPlayground().lineTo(start.x, start.y, tmp.getX(), tmp.getY(), turtle.getPen());
|
||||
start = tmp;
|
||||
intoPanel(start, end);
|
||||
dx = end.x - start.x;
|
||||
dy = end.y - start.y;
|
||||
}
|
||||
|
||||
turtle.getPlayground().lineTo(start.x, start.y, end.x, end.y, turtle.getPen());
|
||||
}
|
||||
/** Makes the coordinates fit into the Panel.
|
||||
|
||||
Well, this is some sort of modulus calculation.
|
||||
*/
|
||||
private void intoPanel(Point2D.Double start, Point2D.Double end){
|
||||
int pWidth = turtle.getPlayground().getWidth();
|
||||
int pHeight = turtle.getPlayground().getHeight();
|
||||
while(start.x < 0){
|
||||
start.x += pWidth;
|
||||
end.x += pWidth;
|
||||
}
|
||||
while (start.x > pWidth){
|
||||
start.x -= pWidth;
|
||||
end.x -= pWidth;
|
||||
}
|
||||
if(start.x == 0 && end.x < start.x){
|
||||
start.x += pWidth;
|
||||
end.x += pWidth;
|
||||
}
|
||||
if(start.x == pWidth && end.x > start.x){
|
||||
start.x -= pWidth;
|
||||
end.x -= pWidth;
|
||||
}
|
||||
while(start.y < 0){
|
||||
start.y += pHeight;
|
||||
end.y += pHeight;
|
||||
}
|
||||
while (start.y > pHeight){
|
||||
start.y -= pHeight;
|
||||
end.y -= pHeight;
|
||||
}
|
||||
if(start.y == 0 && end.y < start.y){
|
||||
start.y += pHeight;
|
||||
end.y += pHeight;
|
||||
}
|
||||
if(start.y == pHeight && end.y > start.y){
|
||||
start.y -= pHeight;
|
||||
end.y -= pHeight;
|
||||
}
|
||||
|
||||
}
|
||||
/** Intersection line with playground-edges
|
||||
(startX / startY) MUST lie in the playground!
|
||||
*/
|
||||
private Point2D.Double calcIntersection(double startX, double startY, double endX, double endY){
|
||||
double dx = endX - startX;
|
||||
double dy = endY - startY;
|
||||
double W = turtle.getPlayground().getWidth();
|
||||
double H = turtle.getPlayground().getHeight();
|
||||
if(endX < 0){
|
||||
if((dy/dx <= startY/startX) && (dy/dx >= -(H-startY)/startX)){ // links
|
||||
return new Point2D.Double(0, startY-startX*dy/dx);
|
||||
}
|
||||
}
|
||||
else if(endX > W){
|
||||
if((dy/dx >= -startY/(W-startX)) && (dy/dx <= (H-startY)/(W-startX))){// rechts
|
||||
return new Point2D.Double(W, startY+(W-startX)*dy/dx);
|
||||
}
|
||||
}
|
||||
if(endY < 0){ // oben
|
||||
return new Point2D.Double(startX-startY*dx/dy, 0);
|
||||
}
|
||||
else if(endY > H){ // unten
|
||||
return new Point2D.Double(startX+(H-startY)*dx/dy, H);
|
||||
}
|
||||
else{
|
||||
return null; // Endpoint lies in the window
|
||||
}
|
||||
}
|
||||
/** Calculates the screen coordinates of the turtle's actual
|
||||
position according to the interpretation of the playground.
|
||||
*/
|
||||
private Point2D.Double toScreenCoords(double x, double y){
|
||||
return turtle.getPlayground().toScreenCoords(x, y);
|
||||
}
|
||||
/** Calculates the screen coordinates of the turtle's actual
|
||||
position according to the interpretation of the playground.
|
||||
|
||||
Added for convenience.
|
||||
@see #toScreenCoords(double, double)
|
||||
*/
|
||||
private Point2D.Double toScreenCoords(Point2D.Double p){
|
||||
return turtle.getPlayground().toScreenCoords(p.x, p.y);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,268 @@
|
|||
// Pen.java
|
||||
|
||||
// Copyright 2002 Regula Hoefer-Isenegger
|
||||
//
|
||||
// This file is part of The Java Turtle package (TJT)
|
||||
//
|
||||
// TJT 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
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// TJT 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 The Java Turtle Package; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package ch.aplu.turtle;
|
||||
|
||||
import ch.aplu.turtle.*;
|
||||
import java.awt.Color;
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Stroke;
|
||||
import java.awt.Font;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
|
||||
/** The Pen class provides anything used for drawing the lines, such as line width,
|
||||
pen color, end caps, dashed lines, etc.
|
||||
|
||||
@see java.awt.BasicStroke
|
||||
|
||||
@author <a href="mailto:regula@hoefer.ch">Regula Hoefer-Isenegger</a>
|
||||
@version 0.1.1
|
||||
*/
|
||||
public class Pen
|
||||
{
|
||||
/* Attributes *********************************************/
|
||||
|
||||
/** The default font that is used when drawing Text.
|
||||
|
||||
First argument must be one of "Serif", "SansSerif", "Monotyped", "Dialog" or "DialogInput"
|
||||
to guarantee that this font exists on all systems.
|
||||
|
||||
@see java.awt.Font for more information, e.g. on font styles.
|
||||
|
||||
*/
|
||||
public static Font DEFAULT_FONT = new Font("SansSerif", Font.PLAIN, 24);
|
||||
private Color color;
|
||||
private Color fillColor;
|
||||
private BasicStroke stroke;
|
||||
private Font font;
|
||||
|
||||
/* Constructors *******************************************/
|
||||
/** Constructor with standard Color and standard Stroke.
|
||||
|
||||
@see java.awt.BasicStroke
|
||||
*/
|
||||
public Pen(){
|
||||
color = Color.black;
|
||||
setFillColor(Color.black);
|
||||
stroke = new BasicStroke();
|
||||
font = DEFAULT_FONT;
|
||||
}
|
||||
/** Constructor with Color <code>color</code> and standard Stroke.
|
||||
|
||||
@see java.awt.BasicStroke
|
||||
*/
|
||||
public Pen(Color color){
|
||||
this.color = color;
|
||||
setFillColor(color);
|
||||
stroke = new BasicStroke();
|
||||
font = DEFAULT_FONT;
|
||||
}
|
||||
/* Methods ************************************************/
|
||||
/** Query the <code>Pen</code>s color.*/
|
||||
public Color getColor(){
|
||||
return color;
|
||||
}
|
||||
/** Set the <code>Pen</code>s color.*/
|
||||
public void setColor(Color color){
|
||||
this.color = color;
|
||||
}
|
||||
/** Set the <code>Pen</code>s fill color.
|
||||
*/
|
||||
public void setFillColor(Color color){
|
||||
this.fillColor = color;
|
||||
}
|
||||
/** Query the <code>Pen</code>s fill color.*/
|
||||
public Color getFillColor(){
|
||||
return this.fillColor;
|
||||
}
|
||||
/** Get the <code>Pen</code>s <code>Stroke</code>
|
||||
|
||||
@see BasicStroke
|
||||
@see Stroke
|
||||
*/
|
||||
public Stroke getStroke(){
|
||||
return stroke;
|
||||
}
|
||||
/** Query the <code>Pen</code>s line width*/
|
||||
public float getLineWidth(){
|
||||
return stroke.getLineWidth();
|
||||
}
|
||||
/** Query the <code>Pen</code>s end cap style.
|
||||
|
||||
@see java.awt.BasicStroke
|
||||
*/
|
||||
public int getEndCap(){
|
||||
return stroke.getEndCap();
|
||||
}
|
||||
/** Query the <code>Pen</code>s line join style.
|
||||
|
||||
@see java.awt.BasicStroke
|
||||
*/
|
||||
public int getLineJoin(){
|
||||
return stroke.getLineJoin();
|
||||
}
|
||||
/** Query the <code>Pen</code>s miter limit style.
|
||||
|
||||
@see java.awt.BasicStroke
|
||||
*/
|
||||
public float getMiterLimit(){
|
||||
return stroke.getMiterLimit();
|
||||
}
|
||||
/** Query the <code>Pen</code>s dash array.
|
||||
|
||||
@see java.awt.BasicStroke
|
||||
*/
|
||||
public float[] getDashArray(){
|
||||
return stroke.getDashArray();
|
||||
}
|
||||
/** Query the <code>Pen</code>s dash phase.
|
||||
|
||||
@see java.awt.BasicStroke
|
||||
*/
|
||||
public float getDashPhase(){
|
||||
return stroke.getDashPhase();
|
||||
}
|
||||
|
||||
/** Set the <code>Pen</code>s line width. */
|
||||
public void setLineWidth(float width){
|
||||
stroke = new BasicStroke((float)width,
|
||||
stroke.getEndCap(),
|
||||
stroke.getLineJoin(),
|
||||
stroke.getMiterLimit(),
|
||||
stroke.getDashArray(),
|
||||
stroke.getDashPhase());
|
||||
}
|
||||
/** Set the <code>Pen</code>s end cap style.
|
||||
|
||||
@see java.awt.BasicStroke
|
||||
*/
|
||||
public void setEndCap(int endCap){
|
||||
stroke = new BasicStroke(stroke.getLineWidth(),
|
||||
endCap,
|
||||
stroke.getLineJoin(),
|
||||
stroke.getMiterLimit(),
|
||||
stroke.getDashArray(),
|
||||
stroke.getDashPhase());
|
||||
}
|
||||
/** Set the <code>Pen</code>s line join style.
|
||||
|
||||
@see java.awt.BasicStroke
|
||||
*/
|
||||
public void setLineJoin(int join){
|
||||
stroke = new BasicStroke(stroke.getLineWidth(),
|
||||
stroke.getEndCap(),
|
||||
join,
|
||||
stroke.getMiterLimit(),
|
||||
stroke.getDashArray(),
|
||||
stroke.getDashPhase());
|
||||
}
|
||||
/** Set the <code>Pen</code>s miter limit.
|
||||
|
||||
@see java.awt.BasicStroke
|
||||
*/
|
||||
public void setMiterLimit(float miterlimit){
|
||||
stroke = new BasicStroke(stroke.getLineWidth(),
|
||||
stroke.getEndCap(),
|
||||
stroke.getLineJoin(),
|
||||
miterlimit,
|
||||
stroke.getDashArray(),
|
||||
stroke.getDashPhase());
|
||||
}
|
||||
/** Set the <code>Pen</code>s dash array.
|
||||
|
||||
@see java.awt.BasicStroke
|
||||
*/
|
||||
public void setDash(float[] dashArray){
|
||||
stroke = new BasicStroke(stroke.getLineWidth(),
|
||||
stroke.getEndCap(),
|
||||
stroke.getLineJoin(),
|
||||
stroke.getMiterLimit(),
|
||||
dashArray,
|
||||
stroke.getDashPhase());
|
||||
}
|
||||
/** Set the <code>Pen</code>s dash phase.
|
||||
|
||||
@see java.awt.BasicStroke
|
||||
*/
|
||||
public void setDashPhase(float dashPhase){
|
||||
stroke = new BasicStroke(stroke.getLineWidth(),
|
||||
stroke.getEndCap(),
|
||||
stroke.getLineJoin(),
|
||||
stroke.getMiterLimit(),
|
||||
stroke.getDashArray(),
|
||||
dashPhase);
|
||||
}
|
||||
/** Provides information about the currently available font families (e.g. "Roman").
|
||||
Each font name is a string packed into a array of strings.
|
||||
@see java.awt.Font for more information about font attributes etc.
|
||||
*/
|
||||
public static String[] getAvailableFontFamilies(){
|
||||
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
String s[] = ge.getAvailableFontFamilyNames();
|
||||
return s;
|
||||
}
|
||||
/** Change the font style.
|
||||
|
||||
@see java.awt.Font for possible styles.
|
||||
*/
|
||||
public void setFontStyle(int style){
|
||||
font = font.deriveFont(style);
|
||||
}
|
||||
/** Change the font size (in points).
|
||||
*/
|
||||
public void setFontSize(int size){
|
||||
font = font.deriveFont((float)size);
|
||||
}
|
||||
/** Change the font size (in points).
|
||||
You will probably only need the int version <a href="#setFontSize(int)">setFontSize(int)</a>.
|
||||
*/
|
||||
public void setFontSize(float size){
|
||||
font = font.deriveFont(size);
|
||||
}
|
||||
/** Query the size (in points, rounded to int) of the current font.
|
||||
*/
|
||||
public int getFontSize(){
|
||||
return font.getSize() ;
|
||||
}
|
||||
/** Change the font to the given one.
|
||||
*/
|
||||
public void setFont(Font f){
|
||||
font = f;
|
||||
}
|
||||
/** Query the current font.
|
||||
*/
|
||||
public Font getFont(){
|
||||
return font;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,789 @@
|
|||
// Playground.java
|
||||
|
||||
// Copyright 2002 Regula Hoefer-Isenegger
|
||||
// Major code modifications by Aegidius Pluess
|
||||
// Adaption for the Java-Editor by Gerhard Röhner
|
||||
//
|
||||
// This file is part of The Java Turtle package (TJT)
|
||||
//
|
||||
// TJT 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
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// TJT 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 The Java Turtle Package; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package ch.aplu.turtle;
|
||||
|
||||
import ch.aplu.turtle.*;
|
||||
import java.util.*;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.print.*;
|
||||
import java.awt.geom.*;
|
||||
import java.awt.image.*;
|
||||
import java.awt.font.*;
|
||||
|
||||
/**
|
||||
A <code>Playground</code> is the <code>Turtle</code>'s home, i.e. the <code>Turtle</code> lives
|
||||
and moves in the <code>Playground</code>.
|
||||
|
||||
The<code>Playground</code> is responsible for interpreting angle and position of the
|
||||
<code>Turtle</code> and for choosing the correct turtle image and putting it on the right
|
||||
spot of the Playground. This means: e.g. whenever you wish to switch the x- and y-axis, you
|
||||
should do it in this class, and not in the <code>Turtle</code> class.
|
||||
|
||||
@author <a href="mailto:regula@hoefer.ch">Regula Hoefer-Isenegger</a>
|
||||
@version 0.1.1
|
||||
*/
|
||||
|
||||
public class Playground extends JPanel implements Printable {
|
||||
|
||||
/** Hold the <code>Turtle</code>s of this Playground. */
|
||||
private Vector<Turtle> turtles;
|
||||
|
||||
/** Hold the offscreen buffer and graphics context
|
||||
* where Turtle traces are drawn.
|
||||
*/
|
||||
private BufferedImage traceBuffer = null;
|
||||
protected Graphics2D traceG2D = null;
|
||||
private Dimension playgroundSize;
|
||||
|
||||
/** Hold the offscreen buffer and graphics context
|
||||
* of the Turtles images.
|
||||
*/
|
||||
private BufferedImage turtleBuffer = null;
|
||||
protected Graphics2D turtleG2D = null;
|
||||
|
||||
/** Flag to tell whether we have at least one Turtle shown. */
|
||||
private boolean isTurtleVisible = false;
|
||||
|
||||
/** Flag to tell whether we use automatic repainting */
|
||||
private boolean isRepainting = true;
|
||||
|
||||
/** The default background color.
|
||||
*/
|
||||
protected static Color DEFAULT_BACKGROUND_COLOR = Color.white;
|
||||
|
||||
private double printerScale = 1; // Default printer scaling
|
||||
private TPrintable traceCanvas; // Store ref to user class
|
||||
private Graphics2D printerG2D = null;
|
||||
private boolean isPrintScreen = false; // Indicate we are printing the playground
|
||||
private double printerScaleFactor = 1.1; // Magnification factor for printer
|
||||
|
||||
/**
|
||||
* originX is the x-position of the cartesian coodinate system within the playground.
|
||||
*/
|
||||
public int originX;
|
||||
|
||||
/**
|
||||
* originY is the y-position of the cartesian coodinate system within the playground.
|
||||
*/
|
||||
public int originY;
|
||||
|
||||
private static Color[] ColorArray = {Color.cyan, Color.red, Color.green, Color.blue, Color.yellow,
|
||||
Color.lightGray, Color.magenta, Color.orange, Color.pink, Color.black, Color.gray
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a Playground with default background color.
|
||||
* e.g. creates a new vector (which holds the
|
||||
* <code>Turtle</code>s),
|
||||
*/
|
||||
public Playground() {
|
||||
turtles = new Vector<Turtle>();
|
||||
setDoubleBuffered(false);
|
||||
setBackground(DEFAULT_BACKGROUND_COLOR);
|
||||
initBuffers(new Dimension(100, 100));
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the offscreen buffers and sets the size.
|
||||
*/
|
||||
protected void initBuffers(Dimension size) {
|
||||
Color bkColor = getBackground();
|
||||
playgroundSize = size;
|
||||
traceBuffer = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_ARGB);
|
||||
traceG2D = traceBuffer.createGraphics();
|
||||
traceG2D.setColor(bkColor);
|
||||
traceG2D.fillRect(0, 0, size.width, size.height);
|
||||
traceG2D.setBackground(bkColor);
|
||||
|
||||
turtleBuffer = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_ARGB);
|
||||
turtleG2D = turtleBuffer.createGraphics();
|
||||
turtleG2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
originX = size.width/2;
|
||||
originY = size.height/2;
|
||||
}
|
||||
|
||||
/** Add a new <code>Turtle</code> to the Playground.
|
||||
*/
|
||||
public void add(Turtle turtle) {
|
||||
turtles.add(turtle);
|
||||
turtle.setPlayground(this);
|
||||
int i = turtles.size();
|
||||
while (i > 10) {
|
||||
i = i - 10;
|
||||
} // end of while
|
||||
turtle.init(ColorArray[i-1]);
|
||||
toTop(turtle);
|
||||
}
|
||||
|
||||
public void setBounds(int x, int y, int width, int height) {
|
||||
super.setBounds(x, y, width, height);
|
||||
initBuffers(new Dimension(width, height));
|
||||
}
|
||||
|
||||
/** Remove a <code>Turtle</code> from the Playground.
|
||||
*/
|
||||
public void remove(Turtle turtle) {
|
||||
turtles.remove(turtle);
|
||||
}
|
||||
|
||||
/** Tell current number of <code>Turtle</code>s in this Playground.
|
||||
*/
|
||||
public int countTurtles() {
|
||||
return turtles.size();
|
||||
}
|
||||
|
||||
/** Return the <code>Turtle</code> at index <code>index</code>.
|
||||
*/
|
||||
public Turtle getTurtle(int index) {
|
||||
return turtles.elementAt(index);
|
||||
}
|
||||
|
||||
/** Move the given <code>Turtle</code> above all the others, then
|
||||
paints all turtles.
|
||||
@see #toTop
|
||||
*/
|
||||
public void paintTurtles(Turtle turtle) {
|
||||
toTop(turtle);
|
||||
paintTurtles();
|
||||
}
|
||||
|
||||
/** Paint all turtles (calling paintComponent())
|
||||
*/
|
||||
public void paintTurtles() {
|
||||
isTurtleVisible = false;
|
||||
Graphics2D g2D = getTurtleG2D();
|
||||
for (int i = 0; i < countTurtles(); i++) {
|
||||
Turtle aTurtle = getTurtle(i);
|
||||
if (!aTurtle.isHidden()) {
|
||||
paintTurtle(aTurtle);
|
||||
}
|
||||
}
|
||||
|
||||
// This is the main repaint call, when the turtle is
|
||||
// moving (even when all turtles are hidden).
|
||||
// Strange behaviour an slow Mac machines (pre J2SE 1.4 version):
|
||||
// It happens that some turtle images are not completely redrawn.
|
||||
// This is probably due to an improper handling of fast multiple repaint requests.
|
||||
// Workaround: we wait a small amount of time (and give the thread away)
|
||||
// (No visible slow down on new machines.)
|
||||
|
||||
paintPlayground();
|
||||
if (printerG2D == null) {
|
||||
//if (isRepainting)
|
||||
//repaint();
|
||||
//paintPlayground();
|
||||
}
|
||||
|
||||
if (isTurtleVisible) {
|
||||
try {
|
||||
Thread.currentThread().sleep(10);
|
||||
}
|
||||
catch (Exception e) {}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Paint the given <code>Turtle</code>.
|
||||
* ( no repaint() )
|
||||
*/
|
||||
public void paintTurtle(Turtle turtle) {
|
||||
if (turtleBuffer == null){
|
||||
turtleBuffer = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
|
||||
turtleG2D = turtleBuffer.createGraphics();
|
||||
}
|
||||
Graphics2D turtleGraphics = getTurtleG2D();
|
||||
turtle.getTurtleRenderer().paint(turtle._getX(), turtle._getY(), turtleGraphics);
|
||||
isTurtleVisible = true;
|
||||
}
|
||||
|
||||
/** Put an image of the given <code>Turtle</code> in turtle buffer.
|
||||
*/
|
||||
protected void stampTurtle(Turtle turtle) {
|
||||
turtle.clone();
|
||||
isTurtleVisible = true;
|
||||
if (printerG2D == null)
|
||||
repaint();
|
||||
}
|
||||
|
||||
/** Draw a line from the point <code>(x0, y0)</code> to <code>(x1, y1)</code>
|
||||
with the color of the given <code>Pen</code>.
|
||||
*/
|
||||
protected void lineTo(double x0, double y0, double x1, double y1, Pen pen) {
|
||||
int ix0 = (int)Math.round(x0);
|
||||
int iy0 = (int)Math.round(y0);
|
||||
int ix1 = (int)Math.round(x1);
|
||||
int iy1 = (int)Math.round(y1);
|
||||
Color color = pen.getColor();
|
||||
|
||||
if (traceBuffer == null) {
|
||||
traceBuffer = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
|
||||
traceG2D = traceBuffer.createGraphics();
|
||||
}
|
||||
Graphics2D traceG2D = getTraceG2D();
|
||||
traceG2D.setColor(color);
|
||||
traceG2D.setStroke(pen.getStroke());
|
||||
traceG2D.drawLine(ix0, iy0, ix1, iy1);
|
||||
if (printerG2D != null)
|
||||
printerG2D.drawLine(ix0, iy0, ix1, iy1);
|
||||
}
|
||||
|
||||
/** A class for convenience. */
|
||||
protected class Point extends java.awt.Point {
|
||||
Point(int x, int y) {
|
||||
super(x, y);
|
||||
}
|
||||
Point() {
|
||||
super();
|
||||
}
|
||||
Point(Point p) {
|
||||
super(p.x, p.y);
|
||||
}
|
||||
|
||||
/** Get a new Point with coordinates (this.x+p.x, this.y+p.y).
|
||||
*/
|
||||
protected Point add(Point p) {
|
||||
return new Point(this.x+p.x, this.y+p.y);
|
||||
}
|
||||
|
||||
/** Translate by the amounts dx = p.x, dy = p.y. */
|
||||
protected void translate(Point p) {
|
||||
translate(p.x, p.y);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "(" + x + "," + y + ")";
|
||||
}
|
||||
}
|
||||
|
||||
/** Fill a region.
|
||||
The region is defined by the <code>Turtle</code>s actual position and
|
||||
is bounded by any other color than the give background color.
|
||||
*/
|
||||
public void fill(Turtle t, Color bgColor) {
|
||||
final Point[] diff = { new Point(0,-1), new Point(-1,0), new Point(1,0), new Point(0,1)};
|
||||
final int N=0;
|
||||
final int W=1;
|
||||
final int E=2;
|
||||
final int S=3;
|
||||
|
||||
int bgcolor = bgColor.getRGB();
|
||||
int fillColor = t.getPen().getFillColor().getRGB();
|
||||
Vector list = new Vector();
|
||||
Point2D.Double p1 = toScreenCoords(t.getPos());
|
||||
int startX = (int)Math.round(p1.getX());
|
||||
int startY = (int)Math.round(p1.getY());
|
||||
Point p = new Point(startX, startY);
|
||||
if (traceBuffer.getRGB(startX, startY) == bgcolor) {
|
||||
traceBuffer.setRGB(startX, startY, fillColor);
|
||||
list.addElement(new Point(startX, startY));
|
||||
int d = N;
|
||||
int back;
|
||||
while (list.size() > 0) {
|
||||
while (d <= S) { // forward
|
||||
Point tmp = p.add(diff[d]);
|
||||
try {
|
||||
if (traceBuffer.getRGB(tmp.x, tmp.y) == bgcolor) {
|
||||
p.translate(diff[d]);
|
||||
traceBuffer.setRGB(p.x, p.y, fillColor);
|
||||
if (printerG2D != null)
|
||||
{
|
||||
printerG2D.setColor(t.getPen().getFillColor());
|
||||
// printerG2D.drawLine(p.x,p.y, p.x, p.y);
|
||||
BasicStroke stroke = new BasicStroke(2);
|
||||
printerG2D.setStroke(stroke);
|
||||
Line2D line = new Line2D.Double(p.x, p.y, p.x, p.y);
|
||||
printerG2D.draw(line);
|
||||
}
|
||||
list.addElement(new Integer(d));
|
||||
d=N;
|
||||
}
|
||||
else {
|
||||
d++;
|
||||
}
|
||||
}
|
||||
catch (ArrayIndexOutOfBoundsException e) {
|
||||
d++;
|
||||
}
|
||||
}
|
||||
Object obj = list.remove(list.size()-1);
|
||||
try {
|
||||
d=((Integer)obj).intValue(); // last element
|
||||
back = S - d;
|
||||
p.translate(diff[back]);
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
// the first (zeroest) element in list is the start-point
|
||||
// just do nothing with it
|
||||
}
|
||||
}
|
||||
}
|
||||
traceG2D.drawLine(0, 0, 0, 0); // Workaround because on Mac the trace buffer is not drawn without this
|
||||
if (printerG2D == null)
|
||||
repaint();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the playground with given color.
|
||||
*/
|
||||
public void clear(Color color) {
|
||||
traceG2D.setColor(color);
|
||||
traceG2D.fillRect(0, 0, getWidth(), getHeight());
|
||||
turtleG2D.setColor(color);
|
||||
turtleG2D.fillRect(0, 0, getWidth(), getHeight());
|
||||
isTurtleVisible = true;
|
||||
if (printerG2D == null)
|
||||
repaint();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear playground.
|
||||
*/
|
||||
public void clear() {
|
||||
clear(getBackground());
|
||||
}
|
||||
|
||||
/** Paint the Playground.
|
||||
just a method for convenience.
|
||||
*/
|
||||
public void paintComponent() {
|
||||
paintComponent(getGraphics());
|
||||
}
|
||||
|
||||
/** Draw the trace and turtle buffers.
|
||||
*/
|
||||
public void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
Graphics2D g2D = (Graphics2D)g;
|
||||
g2D.drawImage(traceBuffer, 0, 0, this);
|
||||
if (isTurtleVisible)
|
||||
g2D.drawImage(turtleBuffer, 0, 0, this);
|
||||
}
|
||||
|
||||
public void paintPlayground() {
|
||||
Graphics g = getGraphics();
|
||||
if (g != null) {
|
||||
super.paintComponent(g);
|
||||
Graphics2D g2D = (Graphics2D)g;
|
||||
g2D.drawImage(traceBuffer, 0, 0, this);
|
||||
if (isTurtleVisible)
|
||||
g2D.drawImage(turtleBuffer, 0, 0, this);
|
||||
|
||||
} // end of if
|
||||
}
|
||||
|
||||
/** Remove all turtles from the turtle buffer.
|
||||
*/
|
||||
public void clearTurtles() {
|
||||
for (int i = 0; i < countTurtles(); i++) {
|
||||
Turtle turtle = getTurtle(i);
|
||||
clearTurtle(turtle);
|
||||
}
|
||||
}
|
||||
|
||||
/** Remove the given turtle from the turtle buffer.
|
||||
Override this method if you have added a new behaviour (like
|
||||
wrap or clip) to the turtle.
|
||||
*/
|
||||
public void clearTurtle(Turtle turtle) {
|
||||
if(turtle != null){
|
||||
if (!turtle.isHidden()) {
|
||||
if(turtle.isClip()){
|
||||
clearClipTurtle(turtle);
|
||||
}
|
||||
else if(turtle.isWrap()){
|
||||
clearWrapTurtle(turtle);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** This method is called when the given <code>Turtle</code> is in wrap mode.
|
||||
|
||||
@see ch.aplu.turtle.Turtle#wrap
|
||||
*/
|
||||
protected void clearWrapTurtle(Turtle turtle){
|
||||
clearWrapTurtle(turtle, turtleBuffer);
|
||||
}
|
||||
|
||||
/** Here the actual clearing of a <code>Turtle</code> in wrap mode from the
|
||||
given image is performed.
|
||||
*/
|
||||
protected void clearWrapTurtle(Turtle turtle, Image im){
|
||||
Rectangle bounds = getBounds(turtle);
|
||||
int pWidth = getWidth();
|
||||
int pHeight = getHeight();
|
||||
int x = bounds.x;
|
||||
int y = bounds.y;
|
||||
while (x > pWidth){
|
||||
x -= pWidth;
|
||||
}
|
||||
while (x < 0){
|
||||
x += pWidth;
|
||||
}
|
||||
while (y > pHeight){
|
||||
y -= pHeight;
|
||||
}
|
||||
while (y < 0){
|
||||
y += pHeight;
|
||||
}
|
||||
x = x % pWidth;
|
||||
y = y % pHeight;
|
||||
toAlphaNull(im, new Rectangle(x, y, bounds.width, bounds.height)); // OK
|
||||
boolean right = (x + bounds.width > getWidth());
|
||||
boolean bottom = (y + bounds.height > getHeight());
|
||||
if (right) {
|
||||
toAlphaNull(im, new Rectangle(x-pWidth, y, bounds.width, bounds.height));
|
||||
}
|
||||
if (bottom) {
|
||||
toAlphaNull(im, new Rectangle(x, y-pHeight, bounds.width, bounds.height));
|
||||
}
|
||||
if (right && bottom) {
|
||||
toAlphaNull(im, new Rectangle(x-pWidth, y-pHeight, bounds.width, bounds.height));
|
||||
}
|
||||
}
|
||||
|
||||
/** Copy and translate a given Rectangle.
|
||||
*/
|
||||
private Rectangle copyAndTranslate(Rectangle rect, int dx, int dy) {
|
||||
return new Rectangle(rect.x+dx, rect.y+dy,
|
||||
rect.width, rect.height);
|
||||
}
|
||||
|
||||
/** This method is called when the given <code>Turtle</code> is in clip mode.
|
||||
|
||||
@see ch.aplu.turtle.Turtle#clip
|
||||
*/
|
||||
protected void clearClipTurtle(Turtle turtle) {
|
||||
clearClipTurtle(turtle, turtleBuffer);
|
||||
}
|
||||
|
||||
/** Here the actual clearing of a <code>Turtle</code> in clip mode from the
|
||||
given image is performed.
|
||||
*/
|
||||
protected void clearClipTurtle(Turtle turtle, Image im) {
|
||||
Rectangle bounds = getBounds(turtle);
|
||||
toAlphaNull(im, bounds);
|
||||
}
|
||||
|
||||
/** Set the alpha channel of all pixels in the given image
|
||||
in the given Rectangle to zero (i.e. totally transparent).
|
||||
|
||||
This method is used byte the clearXXXTurtle methods.
|
||||
*/
|
||||
private void toAlphaNull(Image im, Rectangle rect) {
|
||||
Rectangle rim = new Rectangle(0, 0, im.getWidth(this), im.getHeight(this));
|
||||
Rectangle r = new Rectangle();
|
||||
if (rect.intersects(rim)) {
|
||||
r=rect.intersection(rim);
|
||||
}
|
||||
int size = r.width*r.height;
|
||||
float[] alphachannel = new float[r.width*r.height];
|
||||
((BufferedImage)im).getAlphaRaster().setPixels(r.x, r.y, r.width, r.height, alphachannel);
|
||||
}
|
||||
|
||||
/** Puts a Turtle above all others.
|
||||
*/
|
||||
public Turtle toTop(Turtle turtle) {
|
||||
if (turtles.removeElement(turtle)) {
|
||||
turtles.add(turtle);
|
||||
}
|
||||
return turtle;
|
||||
}
|
||||
/** Put a Turtle below all others.
|
||||
*/
|
||||
public Turtle toBottom(Turtle turtle) {
|
||||
if (turtles.removeElement(turtle)) {
|
||||
turtles.add(0,turtle);
|
||||
}
|
||||
return turtle;
|
||||
}
|
||||
|
||||
/** Calculate the screen coordinates of the given point.
|
||||
*/
|
||||
public Point2D.Double toScreenCoords(Point2D.Double p) {
|
||||
return internalToScreenCoords(p.x, p.y);
|
||||
}
|
||||
|
||||
/** Calculate the screen coordinates of the given point coordinates.
|
||||
*/
|
||||
public Point2D.Double toScreenCoords(double x, double y) {
|
||||
return internalToScreenCoords(x, y);
|
||||
}
|
||||
|
||||
protected Point2D.Double internalToScreenCoords(double x, double y) {
|
||||
// reflect at x-axis, then translate to center of Playground
|
||||
// pixel coordinates coorespond to turtle coordinates, only translation needed
|
||||
double newX = originX + x;
|
||||
double newY = originY - y;
|
||||
return new Point2D.Double(newX, newY);
|
||||
}
|
||||
|
||||
/** Calculate the turtle coordinates of the given screen coordinates.
|
||||
*/
|
||||
public Point2D.Double toTurtleCoords(double x, double y) {
|
||||
// pixel coordinates coorespond to turtle coordinates, only translation needed
|
||||
double newX = x - originX;
|
||||
double newY = originY - y;
|
||||
return new Point2D.Double(newX, newY);
|
||||
}
|
||||
|
||||
/** Calculate the turtle coordinates of the given screen point.
|
||||
*/
|
||||
public Point2D.Double toTurtleCoords(Point2D.Double p) {
|
||||
return toTurtleCoords(p.x, p.y);
|
||||
}
|
||||
|
||||
/** Calculate the screen angle.
|
||||
I.e. the interpretation of angle.
|
||||
@param radians The angle in radians.
|
||||
*/
|
||||
double toScreenAngle(double radians) {
|
||||
double sa = radians;
|
||||
if (sa < Math.PI/2){
|
||||
sa += 2*Math.PI;
|
||||
}
|
||||
sa -= Math.PI/2;
|
||||
if (sa != 0) {
|
||||
sa = Math.PI*2 - sa;
|
||||
}
|
||||
return sa;
|
||||
}
|
||||
|
||||
/** Calculate the bounds of the <code>Turtle</code>s picture on the screen.
|
||||
*/
|
||||
protected Rectangle getBounds(Turtle turtle) {
|
||||
Rectangle bounds = turtle.getBounds();
|
||||
Point2D.Double tmp = toScreenCoords(new Point2D.Double(bounds.getX(), bounds.getY()));
|
||||
bounds.setRect(tmp.x-2, tmp.y-2, bounds.width+4, bounds.height+4);
|
||||
return bounds;
|
||||
}
|
||||
|
||||
/** Return the graphics context of the turtle buffer.
|
||||
*/
|
||||
public Graphics2D getTurtleG2D() {
|
||||
return turtleG2D;
|
||||
}
|
||||
|
||||
/** Return the image of the turtle buffer.
|
||||
*/
|
||||
public BufferedImage getTurtleBuffer() {
|
||||
return turtleBuffer;
|
||||
}
|
||||
|
||||
/** Return the graphics context of the trace buffer.
|
||||
*/
|
||||
public Graphics2D getTraceG2D() {
|
||||
return traceG2D;
|
||||
}
|
||||
|
||||
/** Return the graphics context of the printer.
|
||||
*/
|
||||
public Graphics2D getPrinterG2D() {
|
||||
return printerG2D;
|
||||
}
|
||||
|
||||
/** Return the image of the trace buffer.
|
||||
*/
|
||||
public BufferedImage getTraceBuffer() {
|
||||
return traceBuffer;
|
||||
}
|
||||
|
||||
/** Clean the traces.
|
||||
All turtles stay how and where they are, only lines, text and stamps will be removed.
|
||||
*/
|
||||
void clean() {
|
||||
Graphics2D g = getTraceG2D();
|
||||
g.setColor(getBackground());
|
||||
g.fillRect(0,0,getWidth(), getHeight());
|
||||
if (printerG2D == null)
|
||||
repaint();
|
||||
}
|
||||
|
||||
/** Draw the <code>text</code> at the current position of the Turtle <code>t</code>.
|
||||
Drawing a text at some coordinates <code>(x,y)</code> we mean that the bottom left corner of
|
||||
the text will be at these coordinates.
|
||||
Font and colour are specified by the Turtle's Pen.
|
||||
*/
|
||||
public void label(String text, Turtle t) {
|
||||
Point2D.Double sc = toScreenCoords(t.getPos());
|
||||
int x = (int)Math.round(sc.x);
|
||||
int y = (int)Math.round(sc.y);
|
||||
Graphics2D traceG2D = getTraceG2D();
|
||||
FontRenderContext frc = traceG2D.getFontRenderContext();
|
||||
Font f = t.getFont();
|
||||
TextLayout tl = new TextLayout(text, f, frc);
|
||||
traceG2D.setColor(t.getPen().getColor());
|
||||
tl.draw(traceG2D, x, y);
|
||||
if (printerG2D != null)
|
||||
{
|
||||
printerG2D.setColor(t.getPen().getColor());
|
||||
tl.draw(printerG2D, x, y);
|
||||
}
|
||||
|
||||
if (printerG2D == null)
|
||||
repaint();
|
||||
}
|
||||
|
||||
/** Set antialiasing on or off for the turtle trace buffer
|
||||
* This may result in an better trace quality.
|
||||
*/
|
||||
public void setAntiAliasing(boolean on) {
|
||||
if (on)
|
||||
traceG2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
else
|
||||
traceG2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_OFF);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the given TPrintable (implementing draw()),
|
||||
* open a printer dialog and start printing with given scale.
|
||||
* Return false, if printer dialog is aborted,
|
||||
* otherwise return true.<br>
|
||||
* If tp == null, the current playground is printed.
|
||||
*
|
||||
*/
|
||||
protected boolean print(TPrintable tp, double scale) {
|
||||
if (tp == null)
|
||||
isPrintScreen = true;
|
||||
else
|
||||
isPrintScreen = false;
|
||||
printerScale = scale;
|
||||
PrinterJob pj = PrinterJob.getPrinterJob();
|
||||
pj.setPrintable(this);
|
||||
traceCanvas = tp;
|
||||
if (pj.printDialog()) {
|
||||
try {
|
||||
pj.print();
|
||||
}
|
||||
catch (PrinterException ex) {
|
||||
System.out.println(ex);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* For internal use only. Implementation of Printable.
|
||||
* (Callback method called by printing system.)
|
||||
*/
|
||||
public int print(Graphics g, PageFormat pf, int pageIndex) {
|
||||
if (pageIndex != 0)
|
||||
return NO_SUCH_PAGE;
|
||||
Graphics2D g2D = (Graphics2D)g;
|
||||
double printerWidth = pf.getImageableWidth();
|
||||
double printerHeight = pf.getImageableHeight();
|
||||
double printerSize = printerWidth > printerHeight ? printerWidth :
|
||||
printerHeight;
|
||||
double xZero = pf.getImageableX();
|
||||
double yZero = pf.getImageableY();
|
||||
|
||||
printerG2D = g2D; // Indicate also, we are printing now
|
||||
|
||||
// Needed for fill operations: the trace canvas must be empty in order to
|
||||
// perform the fill algoritm (searching for outline of figure)
|
||||
if (!isPrintScreen)
|
||||
clean();
|
||||
|
||||
g2D.scale(printerScaleFactor * printerScale, printerScaleFactor * printerScale);
|
||||
g2D.translate(xZero/printerScale, yZero/printerScale);
|
||||
|
||||
if (isPrintScreen)
|
||||
{
|
||||
print(g);
|
||||
}
|
||||
else // Printing the traceCanvas
|
||||
{
|
||||
// Hide all turtles
|
||||
boolean[] turtleState = new boolean[countTurtles()];
|
||||
for (int i = 0; i < countTurtles(); i++) {
|
||||
Turtle aTurtle = getTurtle(i);
|
||||
turtleState[i] = aTurtle.isHidden();
|
||||
aTurtle.ht();
|
||||
}
|
||||
traceCanvas.draw();
|
||||
|
||||
// Restore old context
|
||||
for (int i = 0; i < countTurtles(); i++) {
|
||||
Turtle aTurtle = getTurtle(i);
|
||||
if (!turtleState[i])
|
||||
aTurtle.st();
|
||||
}
|
||||
}
|
||||
|
||||
printerG2D = null;
|
||||
return PAGE_EXISTS;
|
||||
}
|
||||
|
||||
/** Return the color of the pixel at the current turtle position.
|
||||
*/
|
||||
public Color getPixelColor(Turtle t) {
|
||||
Point2D.Double p1 = toScreenCoords(t.getPos());
|
||||
int x = (int)Math.round(p1.getX());
|
||||
int y = (int)Math.round(p1.getY());
|
||||
return new Color(traceBuffer.getRGB(x, y));
|
||||
}
|
||||
|
||||
public void enableRepaint(boolean b) {
|
||||
isRepainting = b;
|
||||
}
|
||||
|
||||
/** set the background color of the playground
|
||||
*/
|
||||
public void setBackground(Color color) {
|
||||
super.setBackground(color);
|
||||
if (traceG2D != null) {
|
||||
clear(color);
|
||||
} // end of if
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the origin of the cartesian coordinate system within the playground
|
||||
*/
|
||||
public void setOrigin(int x, int y) {
|
||||
for (int i = 0; i < countTurtles(); i++) {
|
||||
Turtle turtle = getTurtle(i);
|
||||
Point2D.Double p1 = toScreenCoords(turtle.getPos());
|
||||
double newX = p1.getX() - x;
|
||||
double newY = y - p1.getY();
|
||||
turtle.internalSetPos(newX, newY);
|
||||
}
|
||||
originX = x;
|
||||
originY = y;
|
||||
}
|
||||
|
||||
public int getOriginX() {
|
||||
return originX;
|
||||
}
|
||||
|
||||
public int getOriginY() {
|
||||
return originY;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Binary file not shown.
|
|
@ -0,0 +1,84 @@
|
|||
// SharedConstants.java
|
||||
|
||||
// Copyright 2002 Regula Hoefer-Isenegger
|
||||
//
|
||||
// This file is part of The Java Turtle (TJT) package
|
||||
//
|
||||
// TJT 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
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// TJT 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 The Java Turtle Package; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
/* History;
|
||||
V1.36 - Sep 2004: First official release
|
||||
V1.37 - Nov 2004: Unchanged, modifications in ch.aplu.util
|
||||
V1.38 - Dec 2004: Unchanged, modifications in ch.aplu.util
|
||||
V1.39 - Jan 2005: Unchanged, modifications in ch.aplu.util
|
||||
V1.40 - Mar 2005: Add background color, TurtleKeyAdapter, TurtleArea
|
||||
V1.41 - May 2005: User defined turtle shape, minor changes in doc and code style
|
||||
V1.42 - Dec 2005: Unchanged, modifications in ch.aplu.util
|
||||
V1.43 - Feb 2006: Bug removed: Turtle.turtleFrame was not initialized in all ctors of class Turtle
|
||||
V1.44 - Mar 2007: Bug removed: stampTurtle did not work properly in wrap mode
|
||||
V1.45 - Aug 2007: TurtleKeyAdapter: use wait/notify to reduce CPU time (from 100% to 2%)
|
||||
V1.46 - Aug 2007: synchronize(playground) for forward and rotate animation,
|
||||
new method bong() using StreamingPlayer
|
||||
V1.47 - Sept 2007: Unchanged, modifications in ch.aplu.util
|
||||
V1.48 - Sept 2007: Unchanged, modifications in ch.aplu.util
|
||||
V1.49 - Oct 2007: Unchanged, modifications in ch.aplu.util
|
||||
V1.50 - Oct 2007: Unchanged, modifications in ch.aplu.util
|
||||
V1.51 - Nov 2007: Fixed: correct position of label, when wrapping is on
|
||||
Fixed: getPos() returns now the wrapped coordinates
|
||||
Added: _getPos() returns unwrapped coordinates
|
||||
V1.52 - Nov 2007: Added bean classes in order to use turtles with a Gui builder
|
||||
V1.53 - Nov 2007: Added TurtlePane visual information when used in Gui builder design mode
|
||||
V1.54 - Nov 2007: Minor changes to documentation
|
||||
V1.55 - Dec 2007: Added property enableFocus to GPane, default: setFocusable(false)
|
||||
V1.56 - Mar 2008: Unchanged, modifications in ch.aplu.util
|
||||
V1.57 - Mar 2008: Unchanged, modifications in ch.aplu.util
|
||||
V1.58 - Mar 2008: Modification to fill() (fill(x, y)):
|
||||
region is defined with pixel color at current position
|
||||
as opposed to background color
|
||||
V1.59 - Oct 2008: Added ctors TurtleFrame with window position (ulx, uly)
|
||||
Added Turtle.getPixelColor()
|
||||
V2.00 - Nov 2008: Unchanged, modifications in ch.aplu.util
|
||||
J2SE V1.4 no longer supported
|
||||
V2.01 - Jan 2009: Unchanged, modifications in ch.aplu.util
|
||||
V2.02 - Feb 2009 Turtle constructors run in EDT now
|
||||
V2.03 - Feb 2009 Unchanged, modifications in ch.aplu.util
|
||||
V2.04 - Feb 2009 Unchanged, modifications in ch.aplu.util
|
||||
V2.05 - Feb 2009 Unchanged, modifications in ch.aplu.util
|
||||
V2.06 - Mar 2009 Unchanged, modifications in ch.aplu.util
|
||||
V2.07 - Mar 2009 All except print methods synchronized, so Turtle package is
|
||||
now thread-safe
|
||||
V2.08 - Apr 2009 Unchanged, modifications in ch.aplu.util
|
||||
V2.09 - Jun 2009 Unchanged, modifications in ch.aplu.util
|
||||
V2.10 - Jun 2010 Version for the Java-Editor
|
||||
*/
|
||||
|
||||
package ch.aplu.turtle;
|
||||
|
||||
interface SharedConstants
|
||||
{
|
||||
int DEBUG_LEVEL_OFF = 0;
|
||||
int DEBUG_LEVEL_LOW = 1;
|
||||
int DEBUG_LEVEL_MEDIUM = 2;
|
||||
int DEBUG_LEVEL_HIGH = 3;
|
||||
|
||||
int DEBUG = DEBUG_LEVEL_OFF;
|
||||
|
||||
String ABOUT =
|
||||
"Copyright © 2002-2009\nRegula Hoefer-Isenegger, Aegidius Pluess\n, Gerhard Roehner\n" +
|
||||
"under GNU General Public License\n" +
|
||||
"http://www.aplu.ch\n" +
|
||||
"All rights reserved";
|
||||
String VERSION = "2.10 - June 2015";
|
||||
}
|
||||
|
|
@ -0,0 +1,84 @@
|
|||
// StreamingPlayer.java
|
||||
|
||||
package ch.aplu.turtle;
|
||||
|
||||
|
||||
import javax.sound.sampled.*;
|
||||
import java.io.*;
|
||||
|
||||
class StreamingPlayer
|
||||
{
|
||||
private class PlayerThread extends Thread
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
byte buf[] = new byte[20000];
|
||||
try
|
||||
{
|
||||
int cnt;
|
||||
while ((cnt = audioInputStream.read(buf, 0, buf.length)) != -1)
|
||||
{
|
||||
if (cnt > 0)
|
||||
sourceDataLine.write(buf, 0, cnt);
|
||||
}
|
||||
sourceDataLine.drain();
|
||||
sourceDataLine.close();
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
System.out.println(ex);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private AudioFormat audioFormat;
|
||||
private AudioInputStream audioInputStream;
|
||||
private SourceDataLine sourceDataLine;
|
||||
private PlayerThread playerThread;
|
||||
|
||||
StreamingPlayer(InputStream is)
|
||||
{
|
||||
try
|
||||
{
|
||||
audioInputStream =
|
||||
AudioSystem.getAudioInputStream(is);
|
||||
audioFormat = audioInputStream.getFormat();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{}
|
||||
}
|
||||
|
||||
void start(boolean doFinish)
|
||||
throws LineUnavailableException
|
||||
{
|
||||
DataLine.Info dataLineInfo =
|
||||
new DataLine.Info(SourceDataLine.class, audioFormat);
|
||||
sourceDataLine =
|
||||
(SourceDataLine)AudioSystem.getLine(dataLineInfo);
|
||||
sourceDataLine.open(audioFormat);
|
||||
sourceDataLine.start();
|
||||
playerThread = new PlayerThread();
|
||||
playerThread.start();
|
||||
if (doFinish)
|
||||
waitToFinish();
|
||||
}
|
||||
|
||||
boolean isPlaying()
|
||||
{
|
||||
if (playerThread == null)
|
||||
return false;
|
||||
return (playerThread.isAlive());
|
||||
}
|
||||
|
||||
void waitToFinish()
|
||||
{
|
||||
if (playerThread == null)
|
||||
return;
|
||||
try
|
||||
{
|
||||
playerThread.join();
|
||||
}
|
||||
catch (InterruptedException ex) {}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
// TPrintable.java
|
||||
|
||||
// Copyright 2002 Regula Hoefer-Isenegger
|
||||
|
||||
// This file is part of The Java Turtle (TJT) package
|
||||
//
|
||||
// TJT 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
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// TJT 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 The Java Turtle Package; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
// Added by Aegidius Pluess
|
||||
|
||||
package ch.aplu.turtle;
|
||||
|
||||
/**
|
||||
* Interface for printing on an attached printer.
|
||||
* Normally an application uses a Turtle and implements this interface.
|
||||
* draw() should contain all drawing operations into the
|
||||
* Turtle's Playground. The printing occures, when Turtle's print() is
|
||||
* called.<br><br>
|
||||
*/
|
||||
|
||||
|
||||
public interface TPrintable
|
||||
{
|
||||
/**
|
||||
* This method must perform all drawing operations.
|
||||
* Be aware that for some undocumented reason
|
||||
* draw() is called twice. So be sure you initialize it correctly.
|
||||
*/
|
||||
|
||||
public void draw();
|
||||
}
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -0,0 +1,66 @@
|
|||
// TurtleFactory.java
|
||||
|
||||
// Copyright 2002 Regula Hoefer-Isenegger
|
||||
//
|
||||
// This file is part of The Java Turtle (TJT) package
|
||||
//
|
||||
// TJT 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
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// TJT 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 The Java Turtle Package; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package ch.aplu.turtle;
|
||||
|
||||
import java.awt.image.*;
|
||||
import java.awt.*;
|
||||
|
||||
class TurtleFactory
|
||||
{
|
||||
/** Generates the shape of the turtle with <code>color</code>,
|
||||
* angle <code>angle</code>, width <code>w</code>
|
||||
* and height <code>h</code>.
|
||||
*/
|
||||
protected Image turtleImage(Color color, double angle, int w, int h)
|
||||
{
|
||||
BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_4BYTE_ABGR);
|
||||
Graphics2D g = (Graphics2D)bi.getGraphics();
|
||||
// Origin in center
|
||||
g.translate(w/2, h/2);
|
||||
// angle = 0 is direction east (as usual in mathematics)
|
||||
g.rotate(Math.PI/2 - angle);
|
||||
g.setColor(color);
|
||||
|
||||
// Body
|
||||
g.fillOval((int)( -0.35 * w), (int)( -0.35 * h),
|
||||
(int)(0.7 * w), (int)(0.7 * h));
|
||||
|
||||
// Head
|
||||
g.fillOval((int)( -0.1 * w), (int)( -0.5 * h),
|
||||
(int)(0.2 * w), (int)(0.2 * h));
|
||||
|
||||
// Tail
|
||||
int[] xcoords =
|
||||
{(int)( -0.05 * w), 0, (int)(0.05 * w)};
|
||||
int[] ycoords =
|
||||
{(int)(0.35 * h), (int)(0.45 * h), (int)(0.35 * h)};
|
||||
g.fillPolygon(xcoords, ycoords, 3);
|
||||
|
||||
// Feet
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
g.rotate(Math.PI / 2);
|
||||
g.fillOval((int)( -0.35 * w), (int)( -0.35 * h),
|
||||
(int)(0.125 * w), (int)(0.125 * h));
|
||||
}
|
||||
return (Image)bi;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,312 @@
|
|||
// TurtleRenderer.java
|
||||
|
||||
// Copyright 2002 Regula Hoefer-Isenegger
|
||||
// Some modifications by Aegidius Pluess
|
||||
|
||||
// This file is part of The Java Turtle (TJT) package
|
||||
//
|
||||
// TJT 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
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// TJT 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 The Java Turtle Package; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package ch.aplu.turtle;
|
||||
|
||||
import ch.aplu.turtle.*;
|
||||
import java.awt.image.*;
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import java.awt.geom.*;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
/** This class is responsible for creating and choosing the correct Turtle picture.
|
||||
@author <a href="mailto:regula@hoefer.ch">Regula Hoefer-Isenegger</a>
|
||||
@version 0.1
|
||||
*/
|
||||
public class TurtleRenderer implements ImageObserver {
|
||||
/** Holds the current image */
|
||||
private Image currentImage;
|
||||
/** Holds all images */
|
||||
private Vector images;
|
||||
/** Tells how many pictures are needed*/
|
||||
private int resolution;
|
||||
/** A reference to the <code>Turtle</code> */
|
||||
private Turtle turtle;
|
||||
/** Holds the current Angle */
|
||||
private double currentAngle;
|
||||
|
||||
private final int turtleSize = 29;
|
||||
|
||||
/***/
|
||||
public TurtleRenderer(Turtle turtle) {
|
||||
this.currentImage = null;
|
||||
this.images = new Vector();
|
||||
this.turtle = turtle;
|
||||
currentAngle = 0;
|
||||
}
|
||||
|
||||
/** As an image stays unchanged, there's no need to ever update it. So this method returns always false.
|
||||
|
||||
For further information cf. <code>java.awt.image.ImageObserver</code>.
|
||||
@see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
|
||||
*/
|
||||
public boolean imageUpdate(Image img, int infoflags,
|
||||
int x, int y, int width, int height) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Return the current image.
|
||||
*/
|
||||
public Image currentImage() {
|
||||
return this.currentImage;
|
||||
}
|
||||
|
||||
/** Tell whether the image has changed.
|
||||
*/
|
||||
public boolean imageChanged(double angle) {
|
||||
return (this.currentImage != getImage(angle));
|
||||
}
|
||||
|
||||
/** Set the current image to the specified one. */
|
||||
private void setCurrentImage(Image image) {
|
||||
currentImage = image;
|
||||
}
|
||||
|
||||
/** Choose the image for the angle <code>angle</code>.
|
||||
*/
|
||||
private Image getImage(double angle) {
|
||||
while (angle < 0) {
|
||||
angle += 2*Math.PI;
|
||||
}
|
||||
while (angle >= 2*Math.PI) {
|
||||
angle -= 2*Math.PI;
|
||||
}
|
||||
double res = 2*Math.PI/(double)this.resolution;
|
||||
int index = (int)(angle/res);
|
||||
return image(index);
|
||||
}
|
||||
|
||||
/** Set the current image to the one corresponding to the angle <code>angle</code>.
|
||||
*/
|
||||
public void setAngle(double angle) {
|
||||
currentAngle = angle;
|
||||
setCurrentImage(getImage(angle));
|
||||
}
|
||||
|
||||
/** @return the current angle. */
|
||||
protected double getAngle(){
|
||||
return currentAngle;
|
||||
}
|
||||
|
||||
/** Create the images. There are <code>resolution</code> images (i.e. two subsequent
|
||||
images contain an angle of 2π/<resolution> or 360/resolution degrees).
|
||||
*/
|
||||
public void init(TurtleFactory factory, int resolution) {
|
||||
this.resolution = resolution;
|
||||
Integer res = new Integer(resolution);
|
||||
double incRes = Math.PI*2/res.doubleValue();
|
||||
double angle = 0;
|
||||
images = new Vector();
|
||||
for (int i = 0; i < resolution; i++) {
|
||||
images.add(factory.turtleImage(turtle.getColor(),
|
||||
turtle.getPlayground().toScreenAngle(angle),
|
||||
turtleSize, turtleSize));
|
||||
angle += incRes;
|
||||
}
|
||||
setCurrentImage(getImage(currentAngle));
|
||||
}
|
||||
|
||||
/** Tell how many images this <code>TurtleRenderer</code> holds */
|
||||
private int countImages() {
|
||||
return this.images.size();
|
||||
}
|
||||
|
||||
/** Get the image at <code>index</code> */
|
||||
private Image image(int index) {
|
||||
return (Image)this.images.elementAt(index);
|
||||
}
|
||||
|
||||
/** This method is responsible for painting the turtle onto the
|
||||
playground at (<code>x, y</code>).
|
||||
*/
|
||||
public final void paint(double x, double y) {
|
||||
internalPaint(x, y, turtle.getPlayground().getGraphics());
|
||||
}
|
||||
|
||||
/** This method is responsible for painting the turtle onto the
|
||||
playground at <code>p</code>.
|
||||
*/
|
||||
public final void paint(Point2D.Double p) {
|
||||
internalPaint(p.x, p.y, turtle.getPlayground().getGraphics());
|
||||
}
|
||||
|
||||
/** This method is responsible for painting the <code>Turtle</code>
|
||||
at (<code>x, y</code>).<br>
|
||||
The Graphics argument tells where to paint.
|
||||
*/
|
||||
public final void paint(double x, double y, Graphics g) {
|
||||
internalPaint(x, y, g);
|
||||
}
|
||||
|
||||
/** This method is responsible for painting the <code>Turtle</code>
|
||||
at <code>p</code>.<br>
|
||||
The Graphics argument tells where to paint.
|
||||
*/
|
||||
public void paint(Point2D.Double p, Graphics g){
|
||||
internalPaint(p.x, p.y, g);
|
||||
}
|
||||
|
||||
/** Call clipPaint and wrapPaint().
|
||||
|
||||
You should override this method only, if you add a new (edge)
|
||||
behaviour to the turtle. I recommend to you then to first call this
|
||||
method from the overriding one.
|
||||
<br>
|
||||
If you want to change anything about the real painting, override
|
||||
clipPaint or wrapPaint.
|
||||
|
||||
@see #clipPaint(int, int, Graphics2D)
|
||||
@see #wrapPaint(int, int, Graphics2D)
|
||||
*/
|
||||
protected void internalPaint(double x, double y, Graphics g) {
|
||||
if(turtle.isClip()){
|
||||
Point2D.Double p =
|
||||
calcTopLeftCorner(turtle.getPlayground().toScreenCoords(x, y));
|
||||
clipPaint((int)p.x, (int)p.y, (Graphics2D)g);
|
||||
}
|
||||
else if(turtle.isWrap()){
|
||||
Point2D.Double p =
|
||||
calcTopLeftCorner(turtle.getPlayground().toScreenCoords(x, y));
|
||||
wrapPaint((int)p.x, (int)p.y, (Graphics2D)g);
|
||||
}
|
||||
}
|
||||
|
||||
/** Define how to paint in clip mode and do it */
|
||||
protected void clipPaint(int x, int y, Graphics2D g2D) {
|
||||
g2D.drawImage(currentImage, x, y, this);
|
||||
}
|
||||
|
||||
/** Define how to paint in wrap mode and do it */
|
||||
protected void wrapPaint(int x, int y, Graphics2D g2D) {
|
||||
int pWidth = turtle.getPlayground().getWidth();
|
||||
int pHeight = turtle.getPlayground().getHeight();
|
||||
int paintX = x;
|
||||
while (paintX > pWidth) {
|
||||
paintX -= pWidth;
|
||||
}
|
||||
while (paintX < 0) {
|
||||
paintX += pWidth;
|
||||
}
|
||||
int paintY = y;
|
||||
while (paintY > pHeight) {
|
||||
paintY -= pHeight;
|
||||
}
|
||||
while (paintY < 0) {
|
||||
paintY += pHeight;
|
||||
}
|
||||
g2D.drawImage(currentImage, paintX, paintY, this);
|
||||
int nWidth = currentImage.getWidth(this);
|
||||
int nHeight = currentImage.getHeight(this);
|
||||
boolean right = (paintX+nWidth > pWidth);
|
||||
boolean bottom = (paintY+nHeight > pHeight);
|
||||
if(right) {
|
||||
g2D.drawImage(currentImage,
|
||||
paintX-pWidth,
|
||||
paintY,
|
||||
this);
|
||||
}
|
||||
if(bottom) {
|
||||
g2D.drawImage(currentImage,
|
||||
paintX,
|
||||
paintY-pHeight,
|
||||
this);
|
||||
}
|
||||
if(right && bottom) {
|
||||
g2D.drawImage(currentImage,
|
||||
paintX-pWidth,
|
||||
paintY-pHeight,
|
||||
this);
|
||||
}
|
||||
}
|
||||
|
||||
/** Compute the x-coordinate of the top left corner of the Turtle image
|
||||
(it depends on the specified x-coordinate and the image width).
|
||||
*/
|
||||
protected int calcTopLeftCornerX(double x) {
|
||||
int intX = (int)x;
|
||||
int nWidth;
|
||||
if(currentImage == null) {
|
||||
setCurrentImage(new TurtleFactory().
|
||||
turtleImage(turtle.getColor(), getAngle(), turtleSize, turtleSize));
|
||||
}
|
||||
nWidth = this.currentImage.getWidth(this);
|
||||
// the center of the turtle lies on the turtle's location:
|
||||
intX -= nWidth/2;
|
||||
return intX; // top left corner of the Turtle's image
|
||||
}
|
||||
|
||||
/** Compute the y-coordinate of the top left corner of the Turtle image
|
||||
(it depends on the specified y-coordinate and the image height).
|
||||
*/
|
||||
protected int calcTopLeftCornerY(double y) {
|
||||
int intY = (int)y;
|
||||
if(currentImage == null) {
|
||||
setCurrentImage(new TurtleFactory().
|
||||
turtleImage(turtle.getColor(), getAngle(), turtleSize, turtleSize));
|
||||
}
|
||||
int nHeight = currentImage.getHeight(this);
|
||||
// the center of the turtle lies on the turtle's location:
|
||||
intY -= nHeight/2;
|
||||
|
||||
return intY; // top left corner of the Turtle's image
|
||||
}
|
||||
/** Compute the top left corner of the Turtle image
|
||||
(dependent on the specified x- and y-coordinate and the image
|
||||
width and height.
|
||||
*/
|
||||
protected Point2D.Double calcTopLeftCorner(double x, double y) {
|
||||
if(currentImage == null) {
|
||||
setCurrentImage(new TurtleFactory().
|
||||
turtleImage(turtle.getColor(), getAngle(), turtleSize, turtleSize));
|
||||
}
|
||||
int w = currentImage.getWidth(this);
|
||||
int h = currentImage.getHeight(this);
|
||||
return new Point2D.Double(x-w/2, y-h/2);
|
||||
}
|
||||
|
||||
/** Compute the top left corner of the Turtle image
|
||||
(dependent on the specified point <code>p</code> and the image
|
||||
width and height.
|
||||
*/
|
||||
protected Point2D.Double calcTopLeftCorner(Point2D.Double p) {
|
||||
return calcTopLeftCorner(p.x, p.y);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
public class Eval {
|
||||
|
||||
public static Wrap getOb(Object o) {
|
||||
return new Wrap(o);
|
||||
}
|
||||
|
||||
protected static Object getOb(final String s) {
|
||||
return new Object() {public String result = s;};
|
||||
}
|
||||
|
||||
protected static Object getOb(final boolean b) {
|
||||
return new Object() {public boolean result = b;};
|
||||
}
|
||||
|
||||
protected static Object getOb(final byte b) {
|
||||
return new Object() {public byte result = b;};
|
||||
}
|
||||
|
||||
protected static Object getOb(final char c) {
|
||||
return new Object() {public char result = c;};
|
||||
}
|
||||
|
||||
protected static Object getOb(final double d) {
|
||||
return new Object() {public double result = d;};
|
||||
}
|
||||
|
||||
protected static Object getOb(final float f) {
|
||||
return new Object() {public float result = f;};
|
||||
}
|
||||
|
||||
protected static Object getOb(final int i) {
|
||||
return new Object() {public int result = i;};
|
||||
}
|
||||
|
||||
protected static Object getOb(final long l) {
|
||||
return new Object() {public long result = l;};
|
||||
}
|
||||
protected static Object getOb(final short s) {
|
||||
return new Object() {public short result = s;};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Wrap {
|
||||
public Object result;
|
||||
|
||||
Wrap(Object result) {
|
||||
this.result = result;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,98 @@
|
|||
import java.io.*;
|
||||
|
||||
/**
|
||||
Support class for console input and output of numeric values.<br><br>
|
||||
|
||||
Example for input:<br>
|
||||
int age = InOut.readInt("Your age: ");<br><br>
|
||||
|
||||
Example for output:<br>
|
||||
System.out.println("price: " + InOut.format2(prize) + "Euro");<br>
|
||||
System.out.println("percent: " + InOut.formatN(percent, 1) + " %");
|
||||
*/
|
||||
|
||||
|
||||
public class InOut {
|
||||
|
||||
/** Formats a double-value with 2 decimal digits. */
|
||||
public static String format2(double d) {
|
||||
return String.format("%.2f", d);
|
||||
}
|
||||
|
||||
/** Formats a double-value with N decimal digits. */
|
||||
public static String formatN(double d, int N) {
|
||||
return String.format("%." + N + "f", d);
|
||||
}
|
||||
|
||||
/** Reads a boolean-value from console. */
|
||||
public static boolean readBoolean(String prompt) {
|
||||
final String[] trueValues =
|
||||
{ "1", "y", "t", "j", "w", "yes", "true", "ja", "wahr", "ok" };
|
||||
System.out.print(prompt);
|
||||
String input = readln().toLowerCase();
|
||||
for (int i = 0; i < trueValues.length; ++i)
|
||||
if (trueValues[i].equals(input))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Reads a char-value from console. */
|
||||
public static char readChar(String prompt) {
|
||||
System.out.print(prompt);
|
||||
return readln().charAt(0);
|
||||
}
|
||||
|
||||
/** Reads a double-value from console. */
|
||||
public static double readDouble(String prompt) {
|
||||
System.out.print(prompt);
|
||||
return Double.parseDouble(readln());
|
||||
}
|
||||
|
||||
/** Reads a float-value from console. */
|
||||
public static float readFloat(String prompt) {
|
||||
System.out.print(prompt);
|
||||
return Float.parseFloat(readln());
|
||||
}
|
||||
|
||||
/** Reads an int-value from console. */
|
||||
public static int readInt(String prompt) {
|
||||
System.out.print(prompt);
|
||||
return Integer.parseInt(readln());
|
||||
}
|
||||
|
||||
/** Reads a long-value from console. */
|
||||
public static long readLong(String prompt) {
|
||||
System.out.print(prompt);
|
||||
return Long.parseLong(readln());
|
||||
}
|
||||
|
||||
/** Reads a string-value from console. */
|
||||
public static String readString(String prompt) {
|
||||
System.out.print(prompt);
|
||||
return readln();
|
||||
}
|
||||
|
||||
/** Reads a string-value from console without prompt.
|
||||
For use at the end of a console program. */
|
||||
public static String readln() {
|
||||
try {
|
||||
return Input.readLine();
|
||||
} catch(Exception e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
private static BufferedReader Input;
|
||||
|
||||
static {
|
||||
try {
|
||||
Input = new BufferedReader(new InputStreamReader(System.in));
|
||||
}
|
||||
catch (Exception e) {
|
||||
System.out.println("console input not possible.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,311 @@
|
|||
package je.util;
|
||||
/*
|
||||
* Class : Turtle
|
||||
* Copyright: (c) Gerhard Röhner
|
||||
*
|
||||
* History
|
||||
* --------
|
||||
* 3.00 2000.10.10 first version as java class
|
||||
* 3.01 2002.10.22 DrawDynamic
|
||||
* 3.02 2010.10.11 sleepTime for paint delay
|
||||
* 3.03 2012.03.20 cartesian coordinate system, used with originX, originY, setOrigin
|
||||
* 3.04 2015.01.24 english version, integrated component
|
||||
*/
|
||||
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.image.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
/**
|
||||
* This class is a turtle component for simple graphic programming.
|
||||
*
|
||||
* @see <a href="http://www.javaeditor.org">
|
||||
* @author Gerhard Röhner
|
||||
* @version 3.03 20/03/2012
|
||||
*/
|
||||
|
||||
|
||||
public class Turtle extends Canvas {
|
||||
|
||||
// -- private Attribute ------------------------------------------------------
|
||||
|
||||
private BufferedImage myBufferedImage;
|
||||
private Graphics myBufferedGraphics;
|
||||
private Color foreground;
|
||||
private Color background;
|
||||
private static final double piDurch180 = Math.PI / 180;
|
||||
|
||||
// -- public attributes -----------------------------------------------------
|
||||
|
||||
/**
|
||||
* turtleX is the x-coordinate of the turtle
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.turtleX = 100;</PRE>
|
||||
*/
|
||||
public double turtleX;
|
||||
|
||||
/**
|
||||
* turtleY is the y-coordinate of the turtle.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.turtleY = 200;</PRE>
|
||||
*/
|
||||
public double turtleY;
|
||||
|
||||
/**
|
||||
* turtleW is the current angle of the turtle in the range form 0 to 360 degrees.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.turtleW = 180;</PRE>
|
||||
*/
|
||||
public double turtleW;
|
||||
|
||||
/**
|
||||
* originX is the x-position of the cartesian coodinate system within the turtle canvas.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.originX = 0;</PRE>
|
||||
*/
|
||||
public double originX;
|
||||
|
||||
/**
|
||||
* originY is the y-position of the cartesian coodinate system within the turtle canvas.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.originY = 100;</PRE>
|
||||
*/
|
||||
public double originY;
|
||||
|
||||
/**
|
||||
* If drawDynamic is true you can watch the drawing of the turtle.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.drawDynamic = true;</PRE>
|
||||
*/
|
||||
public boolean drawDynamic;
|
||||
|
||||
/**
|
||||
* For drawDynamic = true you set the delay in milliseconds for drawing.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.sleepTime = 500;</PRE>
|
||||
*/
|
||||
public int sleepTime = 0;
|
||||
|
||||
// --- constructor -----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Creates a Turtle with a canvas.
|
||||
* At the beginning the Turtle is placed in the middle of it's canvas.
|
||||
* The start angle is 0 degree, which means the Turtle looks to the right.
|
||||
* The background color is white, the drawing color black.
|
||||
* <P>
|
||||
* The turtle position can easily be changed by clicking into the canvas.
|
||||
* <P>
|
||||
* The size of the canvas can easily be changed with the mouse.
|
||||
* <P>
|
||||
* Example: <PRE>Turtle myTurtle = new Turtle();</PRE>
|
||||
*/
|
||||
|
||||
public Turtle() {
|
||||
myBufferedImage = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
|
||||
myBufferedGraphics = myBufferedImage.getGraphics();
|
||||
|
||||
setForeground(Color.black);
|
||||
setBackground(Color.white);
|
||||
drawDynamic = true;
|
||||
|
||||
addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent evt) {
|
||||
turtleMouseClicked(evt);}});
|
||||
addComponentListener(new ComponentAdapter() {
|
||||
public void componentResized(ComponentEvent evt) {
|
||||
turtleResized(evt);}});
|
||||
setOrigin(50, 50);
|
||||
}
|
||||
|
||||
private void turtleMouseClicked(MouseEvent evt) {
|
||||
turtleX = evt.getX() - originX;
|
||||
turtleY = originY - evt.getY();
|
||||
turtleW = 0;
|
||||
}
|
||||
|
||||
private void turtleResized(ComponentEvent evt) {
|
||||
int width = getWidth();
|
||||
int height = getHeight();
|
||||
|
||||
BufferedImage newBufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
|
||||
Graphics newGraphics = newBufferedImage.getGraphics();
|
||||
newGraphics.setColor(background);
|
||||
newGraphics.fillRect(0, 0, width, height);
|
||||
newGraphics.setColor(foreground);
|
||||
newGraphics.drawImage(myBufferedImage, 0, 0, this);
|
||||
|
||||
turtleX = 0;
|
||||
turtleY = 0;
|
||||
turtleW = 0;
|
||||
setOrigin(width / 2, height / 2);
|
||||
|
||||
myBufferedImage = newBufferedImage;
|
||||
myBufferedGraphics = newGraphics;
|
||||
}
|
||||
|
||||
public boolean isDoubleBuffered() {
|
||||
return true;
|
||||
}
|
||||
|
||||
private void wTurtleMod360() {
|
||||
while (turtleW >= 360)
|
||||
turtleW = turtleW - 360;
|
||||
while (turtleW < 0)
|
||||
turtleW = turtleW + 360;
|
||||
}
|
||||
|
||||
// --- angle and turns -------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Turns the angle of the turtle relativ by the parameter angle.
|
||||
* Positive values means a turn right, negative a turn left.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.turn(-90);</PRE>
|
||||
*/
|
||||
public void turn(double angle) {
|
||||
turtleW = turtleW + angle;
|
||||
wTurtleMod360();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the angle of the turtle absolute by the parameter angle.
|
||||
* The angle increases counterclockwise, therefore
|
||||
* right = 0, top = 90, left = 180, bottom = 270.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.turnto(270);</PRE>
|
||||
*/
|
||||
public void turnto(double angle) {
|
||||
turtleW = angle;
|
||||
wTurtleMod360();
|
||||
}
|
||||
|
||||
// --- Drawing ---------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* The Turtle draws a line of the length specified in the current direction.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.draw(100);</PRE>
|
||||
*/
|
||||
public void draw(double length) {
|
||||
drawto(turtleX + length * Math.cos(turtleW * piDurch180),
|
||||
turtleY + length * Math.sin(turtleW * piDurch180));
|
||||
}
|
||||
|
||||
/**
|
||||
* The Turtle draws a line form the current position (turtleX, turtleY) to the
|
||||
* position (x, y) relativ to the cartesian coordinate system.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.drawto(200, 300);</PRE>
|
||||
*/
|
||||
public void drawto(double x, double y) {
|
||||
int x1 = (int) (originX + turtleX);
|
||||
int x2 = (int) (originX + x);
|
||||
int y1 = (int) (originY - turtleY);
|
||||
int y2 = (int) (originY - y);
|
||||
|
||||
myBufferedGraphics.drawLine(x1, y1, x2, y2);
|
||||
if (drawDynamic){
|
||||
getGraphics().drawLine(x1, y1, x2, y2);
|
||||
try {
|
||||
Thread.currentThread().sleep(sleepTime);
|
||||
} catch(InterruptedException e) {
|
||||
}
|
||||
} else
|
||||
repaint();
|
||||
|
||||
turtleX = x;
|
||||
turtleY = y;
|
||||
}
|
||||
|
||||
// --- Moving ----------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* The Turtle moves without drawing the length specified in the current
|
||||
* direction.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.move(100);</PRE>
|
||||
*/
|
||||
public void move(double length) {
|
||||
turtleX = turtleX + length * Math.cos (turtleW * piDurch180);
|
||||
turtleY = turtleY + length * Math.sin (turtleW * piDurch180);
|
||||
}
|
||||
|
||||
/**
|
||||
* The Turtle moves without drawing to position (x, y) relativ to the
|
||||
* cartesian coordinate system.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.moveto(100, 200);</PRE>
|
||||
*/
|
||||
public void moveto(double x, double y) {
|
||||
turtleX = x;
|
||||
turtleY = y;
|
||||
}
|
||||
|
||||
// --- set origin -----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Sets the origin of the cartesian coordinate system within the turtle's canvas.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.setOrigin(100, 200);</PRE>
|
||||
*/
|
||||
public void setOrigin(double x, double y) {
|
||||
originX = x;
|
||||
originY = y;
|
||||
}
|
||||
|
||||
// --- fore- and background color --------------------------------------------
|
||||
|
||||
/**
|
||||
* Sets the drawing color of the Turtle to color c.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.setForeground(Color.red);</PRE>
|
||||
*/
|
||||
public void setForeground(Color c) {
|
||||
foreground = c;
|
||||
myBufferedGraphics.setColor(foreground);
|
||||
super.setForeground(foreground);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the canvas color of the Turtle to color c.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.setBackground(Color.blue); </PRE>
|
||||
*/
|
||||
public void setBackground(Color c) {
|
||||
background = c;
|
||||
myBufferedGraphics.setColor(background);
|
||||
myBufferedGraphics.fillRect(0, 0, getWidth(), getHeight());
|
||||
myBufferedGraphics.setColor(foreground);
|
||||
repaint();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the Turtle's canvas with the background color.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.clear();</PRE>
|
||||
*/
|
||||
public void clear() {
|
||||
setBackground(background);
|
||||
getGraphics().drawImage(myBufferedImage, 0, 0, this);
|
||||
repaint();
|
||||
}
|
||||
|
||||
// --- Showing --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Shows the Turtle's canvas.
|
||||
*/
|
||||
public void paint(Graphics g) {
|
||||
g.drawImage(myBufferedImage, 0, 0, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the Turtle's canvas.
|
||||
*/
|
||||
public void update(Graphics g) {
|
||||
paint(g);
|
||||
}
|
||||
|
||||
}
|
||||
Binary file not shown.
|
|
@ -0,0 +1,210 @@
|
|||
// LineRenderer.java
|
||||
|
||||
// Copyright 2002 Regula Hoefer-Isenegger
|
||||
//
|
||||
// This file is part of The Java Turtle (TJT) package
|
||||
//
|
||||
// TJT 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
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// TJT 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 The Java Turtle Package; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package ch.aplu.turtle;
|
||||
|
||||
import ch.aplu.turtle.*;
|
||||
import java.awt.geom.*;
|
||||
/** This class is responsible for drawing the turtle's lines.
|
||||
|
||||
@author <a href="mailto:regula@hoefer.ch">Regula Hoefer-Isenegger</a>
|
||||
@version 0.1
|
||||
*/
|
||||
public class LineRenderer {
|
||||
private Point2D.Double point;
|
||||
private Turtle turtle;
|
||||
|
||||
LineRenderer(Turtle turtle) {
|
||||
this.point = new Point2D.Double();
|
||||
this.turtle = turtle;
|
||||
}
|
||||
|
||||
/** Initialisation with coordinates <code>x</code> and
|
||||
<code>y</code>.
|
||||
*/
|
||||
public void init(double x, double y) {
|
||||
this.point.setLocation(x, y);
|
||||
}
|
||||
/** Same as init(double x, double y), but with a Point2D.Double
|
||||
argument for convenience
|
||||
*/
|
||||
public void init(Point2D.Double p) {
|
||||
this.init(p.x, p.y);
|
||||
}
|
||||
/** Get the current x-coordinate in screen coordinates.*/
|
||||
private double getX(){
|
||||
return (toScreenCoords(point)).getX();
|
||||
}
|
||||
/** Get the current x-coordinate in screen coordinates.*/
|
||||
private double getY(){
|
||||
return toScreenCoords(point).getY();
|
||||
}
|
||||
/** Calls the clipLineTo and wrapLineTo methods, according
|
||||
to the turtle's edge behavior.
|
||||
|
||||
Only overwrite this method when working with another
|
||||
(one that you have defined) edge behaviour. <br>
|
||||
If you mean to change the manner of drawing lines, do this in
|
||||
the methods clipLineTo() and wrapLineTo().
|
||||
@see #clipLineTo
|
||||
@see #wrapLineTo
|
||||
*/
|
||||
protected void internalLineTo(double x, double y){
|
||||
Point2D.Double screenPos = toScreenCoords(x, y);
|
||||
if(turtle.isClip()){
|
||||
clipLineTo(screenPos.getX(), screenPos.getY());
|
||||
}
|
||||
if (turtle.isWrap()){
|
||||
wrapLineTo(screenPos.getX(), screenPos.getY());
|
||||
}
|
||||
init(x,y);
|
||||
}
|
||||
/** Calls the internalLineTo(x,y), which does the actual painting.
|
||||
*/
|
||||
public void lineTo(double x, double y) {
|
||||
internalLineTo(x, y);
|
||||
}
|
||||
/** Calls the internalLineTo(x,y), which does the actual painting.
|
||||
|
||||
This method works the same way as lineTo(double x, double y), but
|
||||
is added for convenience.
|
||||
*/
|
||||
public void lineTo(Point2D.Double p) {
|
||||
internalLineTo(p.getX(), p.getY());
|
||||
}
|
||||
/** Does the actual painting for clip mode.
|
||||
|
||||
It works already with ScreenCoords!
|
||||
For further comments cf. internalLineTo(double x, double y).
|
||||
@see #internalLineTo
|
||||
*/
|
||||
protected void clipLineTo(double x, double y){
|
||||
turtle.getPlayground().lineTo(getX(), getY(), x, y, turtle.getPen());
|
||||
}
|
||||
/** Does the actual painting for wrap mode.
|
||||
|
||||
It works already with ScreenCoords!
|
||||
For further comments cf. internalLineTo(double x, double y).
|
||||
@see #internalLineTo
|
||||
*/
|
||||
protected void wrapLineTo(double x, double y){
|
||||
double dx = getX() - x;
|
||||
double dy = getY() - y;
|
||||
Point2D.Double start = new Point2D.Double(x, y);
|
||||
Point2D.Double end = new Point2D.Double(start.x+dx, start.y+dy);
|
||||
|
||||
intoPanel(start, end);
|
||||
Point2D.Double tmp;
|
||||
while ((tmp = calcIntersection(start.x, start.y, end.x, end.y)) != null){
|
||||
turtle.getPlayground().lineTo(start.x, start.y, tmp.getX(), tmp.getY(), turtle.getPen());
|
||||
start = tmp;
|
||||
intoPanel(start, end);
|
||||
dx = end.x - start.x;
|
||||
dy = end.y - start.y;
|
||||
}
|
||||
|
||||
turtle.getPlayground().lineTo(start.x, start.y, end.x, end.y, turtle.getPen());
|
||||
}
|
||||
/** Makes the coordinates fit into the Panel.
|
||||
|
||||
Well, this is some sort of modulus calculation.
|
||||
*/
|
||||
private void intoPanel(Point2D.Double start, Point2D.Double end){
|
||||
int pWidth = turtle.getPlayground().getWidth();
|
||||
int pHeight = turtle.getPlayground().getHeight();
|
||||
while(start.x < 0){
|
||||
start.x += pWidth;
|
||||
end.x += pWidth;
|
||||
}
|
||||
while (start.x > pWidth){
|
||||
start.x -= pWidth;
|
||||
end.x -= pWidth;
|
||||
}
|
||||
if(start.x == 0 && end.x < start.x){
|
||||
start.x += pWidth;
|
||||
end.x += pWidth;
|
||||
}
|
||||
if(start.x == pWidth && end.x > start.x){
|
||||
start.x -= pWidth;
|
||||
end.x -= pWidth;
|
||||
}
|
||||
while(start.y < 0){
|
||||
start.y += pHeight;
|
||||
end.y += pHeight;
|
||||
}
|
||||
while (start.y > pHeight){
|
||||
start.y -= pHeight;
|
||||
end.y -= pHeight;
|
||||
}
|
||||
if(start.y == 0 && end.y < start.y){
|
||||
start.y += pHeight;
|
||||
end.y += pHeight;
|
||||
}
|
||||
if(start.y == pHeight && end.y > start.y){
|
||||
start.y -= pHeight;
|
||||
end.y -= pHeight;
|
||||
}
|
||||
|
||||
}
|
||||
/** Intersection line with playground-edges
|
||||
(startX / startY) MUST lie in the playground!
|
||||
*/
|
||||
private Point2D.Double calcIntersection(double startX, double startY, double endX, double endY){
|
||||
double dx = endX - startX;
|
||||
double dy = endY - startY;
|
||||
double W = turtle.getPlayground().getWidth();
|
||||
double H = turtle.getPlayground().getHeight();
|
||||
if(endX < 0){
|
||||
if((dy/dx <= startY/startX) && (dy/dx >= -(H-startY)/startX)){ // links
|
||||
return new Point2D.Double(0, startY-startX*dy/dx);
|
||||
}
|
||||
}
|
||||
else if(endX > W){
|
||||
if((dy/dx >= -startY/(W-startX)) && (dy/dx <= (H-startY)/(W-startX))){// rechts
|
||||
return new Point2D.Double(W, startY+(W-startX)*dy/dx);
|
||||
}
|
||||
}
|
||||
if(endY < 0){ // oben
|
||||
return new Point2D.Double(startX-startY*dx/dy, 0);
|
||||
}
|
||||
else if(endY > H){ // unten
|
||||
return new Point2D.Double(startX+(H-startY)*dx/dy, H);
|
||||
}
|
||||
else{
|
||||
return null; // Endpoint lies in the window
|
||||
}
|
||||
}
|
||||
/** Calculates the screen coordinates of the turtle's actual
|
||||
position according to the interpretation of the playground.
|
||||
*/
|
||||
private Point2D.Double toScreenCoords(double x, double y){
|
||||
return turtle.getPlayground().toScreenCoords(x, y);
|
||||
}
|
||||
/** Calculates the screen coordinates of the turtle's actual
|
||||
position according to the interpretation of the playground.
|
||||
|
||||
Added for convenience.
|
||||
@see #toScreenCoords(double, double)
|
||||
*/
|
||||
private Point2D.Double toScreenCoords(Point2D.Double p){
|
||||
return turtle.getPlayground().toScreenCoords(p.x, p.y);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,268 @@
|
|||
// Pen.java
|
||||
|
||||
// Copyright 2002 Regula Hoefer-Isenegger
|
||||
//
|
||||
// This file is part of The Java Turtle package (TJT)
|
||||
//
|
||||
// TJT 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
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// TJT 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 The Java Turtle Package; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package ch.aplu.turtle;
|
||||
|
||||
import ch.aplu.turtle.*;
|
||||
import java.awt.Color;
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Stroke;
|
||||
import java.awt.Font;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
|
||||
/** The Pen class provides anything used for drawing the lines, such as line width,
|
||||
pen color, end caps, dashed lines, etc.
|
||||
|
||||
@see java.awt.BasicStroke
|
||||
|
||||
@author <a href="mailto:regula@hoefer.ch">Regula Hoefer-Isenegger</a>
|
||||
@version 0.1.1
|
||||
*/
|
||||
public class Pen
|
||||
{
|
||||
/* Attributes *********************************************/
|
||||
|
||||
/** The default font that is used when drawing Text.
|
||||
|
||||
First argument must be one of "Serif", "SansSerif", "Monotyped", "Dialog" or "DialogInput"
|
||||
to guarantee that this font exists on all systems.
|
||||
|
||||
@see java.awt.Font for more information, e.g. on font styles.
|
||||
|
||||
*/
|
||||
public static Font DEFAULT_FONT = new Font("SansSerif", Font.PLAIN, 24);
|
||||
private Color color;
|
||||
private Color fillColor;
|
||||
private BasicStroke stroke;
|
||||
private Font font;
|
||||
|
||||
/* Constructors *******************************************/
|
||||
/** Constructor with standard Color and standard Stroke.
|
||||
|
||||
@see java.awt.BasicStroke
|
||||
*/
|
||||
public Pen(){
|
||||
color = Color.black;
|
||||
setFillColor(Color.black);
|
||||
stroke = new BasicStroke();
|
||||
font = DEFAULT_FONT;
|
||||
}
|
||||
/** Constructor with Color <code>color</code> and standard Stroke.
|
||||
|
||||
@see java.awt.BasicStroke
|
||||
*/
|
||||
public Pen(Color color){
|
||||
this.color = color;
|
||||
setFillColor(color);
|
||||
stroke = new BasicStroke();
|
||||
font = DEFAULT_FONT;
|
||||
}
|
||||
/* Methods ************************************************/
|
||||
/** Query the <code>Pen</code>s color.*/
|
||||
public Color getColor(){
|
||||
return color;
|
||||
}
|
||||
/** Set the <code>Pen</code>s color.*/
|
||||
public void setColor(Color color){
|
||||
this.color = color;
|
||||
}
|
||||
/** Set the <code>Pen</code>s fill color.
|
||||
*/
|
||||
public void setFillColor(Color color){
|
||||
this.fillColor = color;
|
||||
}
|
||||
/** Query the <code>Pen</code>s fill color.*/
|
||||
public Color getFillColor(){
|
||||
return this.fillColor;
|
||||
}
|
||||
/** Get the <code>Pen</code>s <code>Stroke</code>
|
||||
|
||||
@see BasicStroke
|
||||
@see Stroke
|
||||
*/
|
||||
public Stroke getStroke(){
|
||||
return stroke;
|
||||
}
|
||||
/** Query the <code>Pen</code>s line width*/
|
||||
public float getLineWidth(){
|
||||
return stroke.getLineWidth();
|
||||
}
|
||||
/** Query the <code>Pen</code>s end cap style.
|
||||
|
||||
@see java.awt.BasicStroke
|
||||
*/
|
||||
public int getEndCap(){
|
||||
return stroke.getEndCap();
|
||||
}
|
||||
/** Query the <code>Pen</code>s line join style.
|
||||
|
||||
@see java.awt.BasicStroke
|
||||
*/
|
||||
public int getLineJoin(){
|
||||
return stroke.getLineJoin();
|
||||
}
|
||||
/** Query the <code>Pen</code>s miter limit style.
|
||||
|
||||
@see java.awt.BasicStroke
|
||||
*/
|
||||
public float getMiterLimit(){
|
||||
return stroke.getMiterLimit();
|
||||
}
|
||||
/** Query the <code>Pen</code>s dash array.
|
||||
|
||||
@see java.awt.BasicStroke
|
||||
*/
|
||||
public float[] getDashArray(){
|
||||
return stroke.getDashArray();
|
||||
}
|
||||
/** Query the <code>Pen</code>s dash phase.
|
||||
|
||||
@see java.awt.BasicStroke
|
||||
*/
|
||||
public float getDashPhase(){
|
||||
return stroke.getDashPhase();
|
||||
}
|
||||
|
||||
/** Set the <code>Pen</code>s line width. */
|
||||
public void setLineWidth(float width){
|
||||
stroke = new BasicStroke((float)width,
|
||||
stroke.getEndCap(),
|
||||
stroke.getLineJoin(),
|
||||
stroke.getMiterLimit(),
|
||||
stroke.getDashArray(),
|
||||
stroke.getDashPhase());
|
||||
}
|
||||
/** Set the <code>Pen</code>s end cap style.
|
||||
|
||||
@see java.awt.BasicStroke
|
||||
*/
|
||||
public void setEndCap(int endCap){
|
||||
stroke = new BasicStroke(stroke.getLineWidth(),
|
||||
endCap,
|
||||
stroke.getLineJoin(),
|
||||
stroke.getMiterLimit(),
|
||||
stroke.getDashArray(),
|
||||
stroke.getDashPhase());
|
||||
}
|
||||
/** Set the <code>Pen</code>s line join style.
|
||||
|
||||
@see java.awt.BasicStroke
|
||||
*/
|
||||
public void setLineJoin(int join){
|
||||
stroke = new BasicStroke(stroke.getLineWidth(),
|
||||
stroke.getEndCap(),
|
||||
join,
|
||||
stroke.getMiterLimit(),
|
||||
stroke.getDashArray(),
|
||||
stroke.getDashPhase());
|
||||
}
|
||||
/** Set the <code>Pen</code>s miter limit.
|
||||
|
||||
@see java.awt.BasicStroke
|
||||
*/
|
||||
public void setMiterLimit(float miterlimit){
|
||||
stroke = new BasicStroke(stroke.getLineWidth(),
|
||||
stroke.getEndCap(),
|
||||
stroke.getLineJoin(),
|
||||
miterlimit,
|
||||
stroke.getDashArray(),
|
||||
stroke.getDashPhase());
|
||||
}
|
||||
/** Set the <code>Pen</code>s dash array.
|
||||
|
||||
@see java.awt.BasicStroke
|
||||
*/
|
||||
public void setDash(float[] dashArray){
|
||||
stroke = new BasicStroke(stroke.getLineWidth(),
|
||||
stroke.getEndCap(),
|
||||
stroke.getLineJoin(),
|
||||
stroke.getMiterLimit(),
|
||||
dashArray,
|
||||
stroke.getDashPhase());
|
||||
}
|
||||
/** Set the <code>Pen</code>s dash phase.
|
||||
|
||||
@see java.awt.BasicStroke
|
||||
*/
|
||||
public void setDashPhase(float dashPhase){
|
||||
stroke = new BasicStroke(stroke.getLineWidth(),
|
||||
stroke.getEndCap(),
|
||||
stroke.getLineJoin(),
|
||||
stroke.getMiterLimit(),
|
||||
stroke.getDashArray(),
|
||||
dashPhase);
|
||||
}
|
||||
/** Provides information about the currently available font families (e.g. "Roman").
|
||||
Each font name is a string packed into a array of strings.
|
||||
@see java.awt.Font for more information about font attributes etc.
|
||||
*/
|
||||
public static String[] getAvailableFontFamilies(){
|
||||
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
String s[] = ge.getAvailableFontFamilyNames();
|
||||
return s;
|
||||
}
|
||||
/** Change the font style.
|
||||
|
||||
@see java.awt.Font for possible styles.
|
||||
*/
|
||||
public void setFontStyle(int style){
|
||||
font = font.deriveFont(style);
|
||||
}
|
||||
/** Change the font size (in points).
|
||||
*/
|
||||
public void setFontSize(int size){
|
||||
font = font.deriveFont((float)size);
|
||||
}
|
||||
/** Change the font size (in points).
|
||||
You will probably only need the int version <a href="#setFontSize(int)">setFontSize(int)</a>.
|
||||
*/
|
||||
public void setFontSize(float size){
|
||||
font = font.deriveFont(size);
|
||||
}
|
||||
/** Query the size (in points, rounded to int) of the current font.
|
||||
*/
|
||||
public int getFontSize(){
|
||||
return font.getSize() ;
|
||||
}
|
||||
/** Change the font to the given one.
|
||||
*/
|
||||
public void setFont(Font f){
|
||||
font = f;
|
||||
}
|
||||
/** Query the current font.
|
||||
*/
|
||||
public Font getFont(){
|
||||
return font;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,789 @@
|
|||
// Playground.java
|
||||
|
||||
// Copyright 2002 Regula Hoefer-Isenegger
|
||||
// Major code modifications by Aegidius Pluess
|
||||
// Adaption for the Java-Editor by Gerhard Röhner
|
||||
//
|
||||
// This file is part of The Java Turtle package (TJT)
|
||||
//
|
||||
// TJT 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
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// TJT 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 The Java Turtle Package; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package ch.aplu.turtle;
|
||||
|
||||
import ch.aplu.turtle.*;
|
||||
import java.util.*;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.print.*;
|
||||
import java.awt.geom.*;
|
||||
import java.awt.image.*;
|
||||
import java.awt.font.*;
|
||||
|
||||
/**
|
||||
A <code>Playground</code> is the <code>Turtle</code>'s home, i.e. the <code>Turtle</code> lives
|
||||
and moves in the <code>Playground</code>.
|
||||
|
||||
The<code>Playground</code> is responsible for interpreting angle and position of the
|
||||
<code>Turtle</code> and for choosing the correct turtle image and putting it on the right
|
||||
spot of the Playground. This means: e.g. whenever you wish to switch the x- and y-axis, you
|
||||
should do it in this class, and not in the <code>Turtle</code> class.
|
||||
|
||||
@author <a href="mailto:regula@hoefer.ch">Regula Hoefer-Isenegger</a>
|
||||
@version 0.1.1
|
||||
*/
|
||||
|
||||
public class Playground extends JPanel implements Printable {
|
||||
|
||||
/** Hold the <code>Turtle</code>s of this Playground. */
|
||||
private Vector<Turtle> turtles;
|
||||
|
||||
/** Hold the offscreen buffer and graphics context
|
||||
* where Turtle traces are drawn.
|
||||
*/
|
||||
private BufferedImage traceBuffer = null;
|
||||
protected Graphics2D traceG2D = null;
|
||||
private Dimension playgroundSize;
|
||||
|
||||
/** Hold the offscreen buffer and graphics context
|
||||
* of the Turtles images.
|
||||
*/
|
||||
private BufferedImage turtleBuffer = null;
|
||||
protected Graphics2D turtleG2D = null;
|
||||
|
||||
/** Flag to tell whether we have at least one Turtle shown. */
|
||||
private boolean isTurtleVisible = false;
|
||||
|
||||
/** Flag to tell whether we use automatic repainting */
|
||||
private boolean isRepainting = true;
|
||||
|
||||
/** The default background color.
|
||||
*/
|
||||
protected static Color DEFAULT_BACKGROUND_COLOR = Color.white;
|
||||
|
||||
private double printerScale = 1; // Default printer scaling
|
||||
private TPrintable traceCanvas; // Store ref to user class
|
||||
private Graphics2D printerG2D = null;
|
||||
private boolean isPrintScreen = false; // Indicate we are printing the playground
|
||||
private double printerScaleFactor = 1.1; // Magnification factor for printer
|
||||
|
||||
/**
|
||||
* originX is the x-position of the cartesian coodinate system within the playground.
|
||||
*/
|
||||
public int originX;
|
||||
|
||||
/**
|
||||
* originY is the y-position of the cartesian coodinate system within the playground.
|
||||
*/
|
||||
public int originY;
|
||||
|
||||
private static Color[] ColorArray = {Color.cyan, Color.red, Color.green, Color.blue, Color.yellow,
|
||||
Color.lightGray, Color.magenta, Color.orange, Color.pink, Color.black, Color.gray
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a Playground with default background color.
|
||||
* e.g. creates a new vector (which holds the
|
||||
* <code>Turtle</code>s),
|
||||
*/
|
||||
public Playground() {
|
||||
turtles = new Vector<Turtle>();
|
||||
setDoubleBuffered(false);
|
||||
setBackground(DEFAULT_BACKGROUND_COLOR);
|
||||
initBuffers(new Dimension(100, 100));
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the offscreen buffers and sets the size.
|
||||
*/
|
||||
protected void initBuffers(Dimension size) {
|
||||
Color bkColor = getBackground();
|
||||
playgroundSize = size;
|
||||
traceBuffer = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_ARGB);
|
||||
traceG2D = traceBuffer.createGraphics();
|
||||
traceG2D.setColor(bkColor);
|
||||
traceG2D.fillRect(0, 0, size.width, size.height);
|
||||
traceG2D.setBackground(bkColor);
|
||||
|
||||
turtleBuffer = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_ARGB);
|
||||
turtleG2D = turtleBuffer.createGraphics();
|
||||
turtleG2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
originX = size.width/2;
|
||||
originY = size.height/2;
|
||||
}
|
||||
|
||||
/** Add a new <code>Turtle</code> to the Playground.
|
||||
*/
|
||||
public void add(Turtle turtle) {
|
||||
turtles.add(turtle);
|
||||
turtle.setPlayground(this);
|
||||
int i = turtles.size();
|
||||
while (i > 10) {
|
||||
i = i - 10;
|
||||
} // end of while
|
||||
turtle.init(ColorArray[i-1]);
|
||||
toTop(turtle);
|
||||
}
|
||||
|
||||
public void setBounds(int x, int y, int width, int height) {
|
||||
super.setBounds(x, y, width, height);
|
||||
initBuffers(new Dimension(width, height));
|
||||
}
|
||||
|
||||
/** Remove a <code>Turtle</code> from the Playground.
|
||||
*/
|
||||
public void remove(Turtle turtle) {
|
||||
turtles.remove(turtle);
|
||||
}
|
||||
|
||||
/** Tell current number of <code>Turtle</code>s in this Playground.
|
||||
*/
|
||||
public int countTurtles() {
|
||||
return turtles.size();
|
||||
}
|
||||
|
||||
/** Return the <code>Turtle</code> at index <code>index</code>.
|
||||
*/
|
||||
public Turtle getTurtle(int index) {
|
||||
return turtles.elementAt(index);
|
||||
}
|
||||
|
||||
/** Move the given <code>Turtle</code> above all the others, then
|
||||
paints all turtles.
|
||||
@see #toTop
|
||||
*/
|
||||
public void paintTurtles(Turtle turtle) {
|
||||
toTop(turtle);
|
||||
paintTurtles();
|
||||
}
|
||||
|
||||
/** Paint all turtles (calling paintComponent())
|
||||
*/
|
||||
public void paintTurtles() {
|
||||
isTurtleVisible = false;
|
||||
Graphics2D g2D = getTurtleG2D();
|
||||
for (int i = 0; i < countTurtles(); i++) {
|
||||
Turtle aTurtle = getTurtle(i);
|
||||
if (!aTurtle.isHidden()) {
|
||||
paintTurtle(aTurtle);
|
||||
}
|
||||
}
|
||||
|
||||
// This is the main repaint call, when the turtle is
|
||||
// moving (even when all turtles are hidden).
|
||||
// Strange behaviour an slow Mac machines (pre J2SE 1.4 version):
|
||||
// It happens that some turtle images are not completely redrawn.
|
||||
// This is probably due to an improper handling of fast multiple repaint requests.
|
||||
// Workaround: we wait a small amount of time (and give the thread away)
|
||||
// (No visible slow down on new machines.)
|
||||
|
||||
paintPlayground();
|
||||
if (printerG2D == null) {
|
||||
//if (isRepainting)
|
||||
//repaint();
|
||||
//paintPlayground();
|
||||
}
|
||||
|
||||
if (isTurtleVisible) {
|
||||
try {
|
||||
Thread.currentThread().sleep(10);
|
||||
}
|
||||
catch (Exception e) {}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Paint the given <code>Turtle</code>.
|
||||
* ( no repaint() )
|
||||
*/
|
||||
public void paintTurtle(Turtle turtle) {
|
||||
if (turtleBuffer == null){
|
||||
turtleBuffer = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
|
||||
turtleG2D = turtleBuffer.createGraphics();
|
||||
}
|
||||
Graphics2D turtleGraphics = getTurtleG2D();
|
||||
turtle.getTurtleRenderer().paint(turtle._getX(), turtle._getY(), turtleGraphics);
|
||||
isTurtleVisible = true;
|
||||
}
|
||||
|
||||
/** Put an image of the given <code>Turtle</code> in turtle buffer.
|
||||
*/
|
||||
protected void stampTurtle(Turtle turtle) {
|
||||
turtle.clone();
|
||||
isTurtleVisible = true;
|
||||
if (printerG2D == null)
|
||||
repaint();
|
||||
}
|
||||
|
||||
/** Draw a line from the point <code>(x0, y0)</code> to <code>(x1, y1)</code>
|
||||
with the color of the given <code>Pen</code>.
|
||||
*/
|
||||
protected void lineTo(double x0, double y0, double x1, double y1, Pen pen) {
|
||||
int ix0 = (int)Math.round(x0);
|
||||
int iy0 = (int)Math.round(y0);
|
||||
int ix1 = (int)Math.round(x1);
|
||||
int iy1 = (int)Math.round(y1);
|
||||
Color color = pen.getColor();
|
||||
|
||||
if (traceBuffer == null) {
|
||||
traceBuffer = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
|
||||
traceG2D = traceBuffer.createGraphics();
|
||||
}
|
||||
Graphics2D traceG2D = getTraceG2D();
|
||||
traceG2D.setColor(color);
|
||||
traceG2D.setStroke(pen.getStroke());
|
||||
traceG2D.drawLine(ix0, iy0, ix1, iy1);
|
||||
if (printerG2D != null)
|
||||
printerG2D.drawLine(ix0, iy0, ix1, iy1);
|
||||
}
|
||||
|
||||
/** A class for convenience. */
|
||||
protected class Point extends java.awt.Point {
|
||||
Point(int x, int y) {
|
||||
super(x, y);
|
||||
}
|
||||
Point() {
|
||||
super();
|
||||
}
|
||||
Point(Point p) {
|
||||
super(p.x, p.y);
|
||||
}
|
||||
|
||||
/** Get a new Point with coordinates (this.x+p.x, this.y+p.y).
|
||||
*/
|
||||
protected Point add(Point p) {
|
||||
return new Point(this.x+p.x, this.y+p.y);
|
||||
}
|
||||
|
||||
/** Translate by the amounts dx = p.x, dy = p.y. */
|
||||
protected void translate(Point p) {
|
||||
translate(p.x, p.y);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "(" + x + "," + y + ")";
|
||||
}
|
||||
}
|
||||
|
||||
/** Fill a region.
|
||||
The region is defined by the <code>Turtle</code>s actual position and
|
||||
is bounded by any other color than the give background color.
|
||||
*/
|
||||
public void fill(Turtle t, Color bgColor) {
|
||||
final Point[] diff = { new Point(0,-1), new Point(-1,0), new Point(1,0), new Point(0,1)};
|
||||
final int N=0;
|
||||
final int W=1;
|
||||
final int E=2;
|
||||
final int S=3;
|
||||
|
||||
int bgcolor = bgColor.getRGB();
|
||||
int fillColor = t.getPen().getFillColor().getRGB();
|
||||
Vector list = new Vector();
|
||||
Point2D.Double p1 = toScreenCoords(t.getPos());
|
||||
int startX = (int)Math.round(p1.getX());
|
||||
int startY = (int)Math.round(p1.getY());
|
||||
Point p = new Point(startX, startY);
|
||||
if (traceBuffer.getRGB(startX, startY) == bgcolor) {
|
||||
traceBuffer.setRGB(startX, startY, fillColor);
|
||||
list.addElement(new Point(startX, startY));
|
||||
int d = N;
|
||||
int back;
|
||||
while (list.size() > 0) {
|
||||
while (d <= S) { // forward
|
||||
Point tmp = p.add(diff[d]);
|
||||
try {
|
||||
if (traceBuffer.getRGB(tmp.x, tmp.y) == bgcolor) {
|
||||
p.translate(diff[d]);
|
||||
traceBuffer.setRGB(p.x, p.y, fillColor);
|
||||
if (printerG2D != null)
|
||||
{
|
||||
printerG2D.setColor(t.getPen().getFillColor());
|
||||
// printerG2D.drawLine(p.x,p.y, p.x, p.y);
|
||||
BasicStroke stroke = new BasicStroke(2);
|
||||
printerG2D.setStroke(stroke);
|
||||
Line2D line = new Line2D.Double(p.x, p.y, p.x, p.y);
|
||||
printerG2D.draw(line);
|
||||
}
|
||||
list.addElement(new Integer(d));
|
||||
d=N;
|
||||
}
|
||||
else {
|
||||
d++;
|
||||
}
|
||||
}
|
||||
catch (ArrayIndexOutOfBoundsException e) {
|
||||
d++;
|
||||
}
|
||||
}
|
||||
Object obj = list.remove(list.size()-1);
|
||||
try {
|
||||
d=((Integer)obj).intValue(); // last element
|
||||
back = S - d;
|
||||
p.translate(diff[back]);
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
// the first (zeroest) element in list is the start-point
|
||||
// just do nothing with it
|
||||
}
|
||||
}
|
||||
}
|
||||
traceG2D.drawLine(0, 0, 0, 0); // Workaround because on Mac the trace buffer is not drawn without this
|
||||
if (printerG2D == null)
|
||||
repaint();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the playground with given color.
|
||||
*/
|
||||
public void clear(Color color) {
|
||||
traceG2D.setColor(color);
|
||||
traceG2D.fillRect(0, 0, getWidth(), getHeight());
|
||||
turtleG2D.setColor(color);
|
||||
turtleG2D.fillRect(0, 0, getWidth(), getHeight());
|
||||
isTurtleVisible = true;
|
||||
if (printerG2D == null)
|
||||
repaint();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear playground.
|
||||
*/
|
||||
public void clear() {
|
||||
clear(getBackground());
|
||||
}
|
||||
|
||||
/** Paint the Playground.
|
||||
just a method for convenience.
|
||||
*/
|
||||
public void paintComponent() {
|
||||
paintComponent(getGraphics());
|
||||
}
|
||||
|
||||
/** Draw the trace and turtle buffers.
|
||||
*/
|
||||
public void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
Graphics2D g2D = (Graphics2D)g;
|
||||
g2D.drawImage(traceBuffer, 0, 0, this);
|
||||
if (isTurtleVisible)
|
||||
g2D.drawImage(turtleBuffer, 0, 0, this);
|
||||
}
|
||||
|
||||
public void paintPlayground() {
|
||||
Graphics g = getGraphics();
|
||||
if (g != null) {
|
||||
super.paintComponent(g);
|
||||
Graphics2D g2D = (Graphics2D)g;
|
||||
g2D.drawImage(traceBuffer, 0, 0, this);
|
||||
if (isTurtleVisible)
|
||||
g2D.drawImage(turtleBuffer, 0, 0, this);
|
||||
|
||||
} // end of if
|
||||
}
|
||||
|
||||
/** Remove all turtles from the turtle buffer.
|
||||
*/
|
||||
public void clearTurtles() {
|
||||
for (int i = 0; i < countTurtles(); i++) {
|
||||
Turtle turtle = getTurtle(i);
|
||||
clearTurtle(turtle);
|
||||
}
|
||||
}
|
||||
|
||||
/** Remove the given turtle from the turtle buffer.
|
||||
Override this method if you have added a new behaviour (like
|
||||
wrap or clip) to the turtle.
|
||||
*/
|
||||
public void clearTurtle(Turtle turtle) {
|
||||
if(turtle != null){
|
||||
if (!turtle.isHidden()) {
|
||||
if(turtle.isClip()){
|
||||
clearClipTurtle(turtle);
|
||||
}
|
||||
else if(turtle.isWrap()){
|
||||
clearWrapTurtle(turtle);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** This method is called when the given <code>Turtle</code> is in wrap mode.
|
||||
|
||||
@see ch.aplu.turtle.Turtle#wrap
|
||||
*/
|
||||
protected void clearWrapTurtle(Turtle turtle){
|
||||
clearWrapTurtle(turtle, turtleBuffer);
|
||||
}
|
||||
|
||||
/** Here the actual clearing of a <code>Turtle</code> in wrap mode from the
|
||||
given image is performed.
|
||||
*/
|
||||
protected void clearWrapTurtle(Turtle turtle, Image im){
|
||||
Rectangle bounds = getBounds(turtle);
|
||||
int pWidth = getWidth();
|
||||
int pHeight = getHeight();
|
||||
int x = bounds.x;
|
||||
int y = bounds.y;
|
||||
while (x > pWidth){
|
||||
x -= pWidth;
|
||||
}
|
||||
while (x < 0){
|
||||
x += pWidth;
|
||||
}
|
||||
while (y > pHeight){
|
||||
y -= pHeight;
|
||||
}
|
||||
while (y < 0){
|
||||
y += pHeight;
|
||||
}
|
||||
x = x % pWidth;
|
||||
y = y % pHeight;
|
||||
toAlphaNull(im, new Rectangle(x, y, bounds.width, bounds.height)); // OK
|
||||
boolean right = (x + bounds.width > getWidth());
|
||||
boolean bottom = (y + bounds.height > getHeight());
|
||||
if (right) {
|
||||
toAlphaNull(im, new Rectangle(x-pWidth, y, bounds.width, bounds.height));
|
||||
}
|
||||
if (bottom) {
|
||||
toAlphaNull(im, new Rectangle(x, y-pHeight, bounds.width, bounds.height));
|
||||
}
|
||||
if (right && bottom) {
|
||||
toAlphaNull(im, new Rectangle(x-pWidth, y-pHeight, bounds.width, bounds.height));
|
||||
}
|
||||
}
|
||||
|
||||
/** Copy and translate a given Rectangle.
|
||||
*/
|
||||
private Rectangle copyAndTranslate(Rectangle rect, int dx, int dy) {
|
||||
return new Rectangle(rect.x+dx, rect.y+dy,
|
||||
rect.width, rect.height);
|
||||
}
|
||||
|
||||
/** This method is called when the given <code>Turtle</code> is in clip mode.
|
||||
|
||||
@see ch.aplu.turtle.Turtle#clip
|
||||
*/
|
||||
protected void clearClipTurtle(Turtle turtle) {
|
||||
clearClipTurtle(turtle, turtleBuffer);
|
||||
}
|
||||
|
||||
/** Here the actual clearing of a <code>Turtle</code> in clip mode from the
|
||||
given image is performed.
|
||||
*/
|
||||
protected void clearClipTurtle(Turtle turtle, Image im) {
|
||||
Rectangle bounds = getBounds(turtle);
|
||||
toAlphaNull(im, bounds);
|
||||
}
|
||||
|
||||
/** Set the alpha channel of all pixels in the given image
|
||||
in the given Rectangle to zero (i.e. totally transparent).
|
||||
|
||||
This method is used byte the clearXXXTurtle methods.
|
||||
*/
|
||||
private void toAlphaNull(Image im, Rectangle rect) {
|
||||
Rectangle rim = new Rectangle(0, 0, im.getWidth(this), im.getHeight(this));
|
||||
Rectangle r = new Rectangle();
|
||||
if (rect.intersects(rim)) {
|
||||
r=rect.intersection(rim);
|
||||
}
|
||||
int size = r.width*r.height;
|
||||
float[] alphachannel = new float[r.width*r.height];
|
||||
((BufferedImage)im).getAlphaRaster().setPixels(r.x, r.y, r.width, r.height, alphachannel);
|
||||
}
|
||||
|
||||
/** Puts a Turtle above all others.
|
||||
*/
|
||||
public Turtle toTop(Turtle turtle) {
|
||||
if (turtles.removeElement(turtle)) {
|
||||
turtles.add(turtle);
|
||||
}
|
||||
return turtle;
|
||||
}
|
||||
/** Put a Turtle below all others.
|
||||
*/
|
||||
public Turtle toBottom(Turtle turtle) {
|
||||
if (turtles.removeElement(turtle)) {
|
||||
turtles.add(0,turtle);
|
||||
}
|
||||
return turtle;
|
||||
}
|
||||
|
||||
/** Calculate the screen coordinates of the given point.
|
||||
*/
|
||||
public Point2D.Double toScreenCoords(Point2D.Double p) {
|
||||
return internalToScreenCoords(p.x, p.y);
|
||||
}
|
||||
|
||||
/** Calculate the screen coordinates of the given point coordinates.
|
||||
*/
|
||||
public Point2D.Double toScreenCoords(double x, double y) {
|
||||
return internalToScreenCoords(x, y);
|
||||
}
|
||||
|
||||
protected Point2D.Double internalToScreenCoords(double x, double y) {
|
||||
// reflect at x-axis, then translate to center of Playground
|
||||
// pixel coordinates coorespond to turtle coordinates, only translation needed
|
||||
double newX = originX + x;
|
||||
double newY = originY - y;
|
||||
return new Point2D.Double(newX, newY);
|
||||
}
|
||||
|
||||
/** Calculate the turtle coordinates of the given screen coordinates.
|
||||
*/
|
||||
public Point2D.Double toTurtleCoords(double x, double y) {
|
||||
// pixel coordinates coorespond to turtle coordinates, only translation needed
|
||||
double newX = x - originX;
|
||||
double newY = originY - y;
|
||||
return new Point2D.Double(newX, newY);
|
||||
}
|
||||
|
||||
/** Calculate the turtle coordinates of the given screen point.
|
||||
*/
|
||||
public Point2D.Double toTurtleCoords(Point2D.Double p) {
|
||||
return toTurtleCoords(p.x, p.y);
|
||||
}
|
||||
|
||||
/** Calculate the screen angle.
|
||||
I.e. the interpretation of angle.
|
||||
@param radians The angle in radians.
|
||||
*/
|
||||
double toScreenAngle(double radians) {
|
||||
double sa = radians;
|
||||
if (sa < Math.PI/2){
|
||||
sa += 2*Math.PI;
|
||||
}
|
||||
sa -= Math.PI/2;
|
||||
if (sa != 0) {
|
||||
sa = Math.PI*2 - sa;
|
||||
}
|
||||
return sa;
|
||||
}
|
||||
|
||||
/** Calculate the bounds of the <code>Turtle</code>s picture on the screen.
|
||||
*/
|
||||
protected Rectangle getBounds(Turtle turtle) {
|
||||
Rectangle bounds = turtle.getBounds();
|
||||
Point2D.Double tmp = toScreenCoords(new Point2D.Double(bounds.getX(), bounds.getY()));
|
||||
bounds.setRect(tmp.x-2, tmp.y-2, bounds.width+4, bounds.height+4);
|
||||
return bounds;
|
||||
}
|
||||
|
||||
/** Return the graphics context of the turtle buffer.
|
||||
*/
|
||||
public Graphics2D getTurtleG2D() {
|
||||
return turtleG2D;
|
||||
}
|
||||
|
||||
/** Return the image of the turtle buffer.
|
||||
*/
|
||||
public BufferedImage getTurtleBuffer() {
|
||||
return turtleBuffer;
|
||||
}
|
||||
|
||||
/** Return the graphics context of the trace buffer.
|
||||
*/
|
||||
public Graphics2D getTraceG2D() {
|
||||
return traceG2D;
|
||||
}
|
||||
|
||||
/** Return the graphics context of the printer.
|
||||
*/
|
||||
public Graphics2D getPrinterG2D() {
|
||||
return printerG2D;
|
||||
}
|
||||
|
||||
/** Return the image of the trace buffer.
|
||||
*/
|
||||
public BufferedImage getTraceBuffer() {
|
||||
return traceBuffer;
|
||||
}
|
||||
|
||||
/** Clean the traces.
|
||||
All turtles stay how and where they are, only lines, text and stamps will be removed.
|
||||
*/
|
||||
void clean() {
|
||||
Graphics2D g = getTraceG2D();
|
||||
g.setColor(getBackground());
|
||||
g.fillRect(0,0,getWidth(), getHeight());
|
||||
if (printerG2D == null)
|
||||
repaint();
|
||||
}
|
||||
|
||||
/** Draw the <code>text</code> at the current position of the Turtle <code>t</code>.
|
||||
Drawing a text at some coordinates <code>(x,y)</code> we mean that the bottom left corner of
|
||||
the text will be at these coordinates.
|
||||
Font and colour are specified by the Turtle's Pen.
|
||||
*/
|
||||
public void label(String text, Turtle t) {
|
||||
Point2D.Double sc = toScreenCoords(t.getPos());
|
||||
int x = (int)Math.round(sc.x);
|
||||
int y = (int)Math.round(sc.y);
|
||||
Graphics2D traceG2D = getTraceG2D();
|
||||
FontRenderContext frc = traceG2D.getFontRenderContext();
|
||||
Font f = t.getFont();
|
||||
TextLayout tl = new TextLayout(text, f, frc);
|
||||
traceG2D.setColor(t.getPen().getColor());
|
||||
tl.draw(traceG2D, x, y);
|
||||
if (printerG2D != null)
|
||||
{
|
||||
printerG2D.setColor(t.getPen().getColor());
|
||||
tl.draw(printerG2D, x, y);
|
||||
}
|
||||
|
||||
if (printerG2D == null)
|
||||
repaint();
|
||||
}
|
||||
|
||||
/** Set antialiasing on or off for the turtle trace buffer
|
||||
* This may result in an better trace quality.
|
||||
*/
|
||||
public void setAntiAliasing(boolean on) {
|
||||
if (on)
|
||||
traceG2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
else
|
||||
traceG2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_OFF);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the given TPrintable (implementing draw()),
|
||||
* open a printer dialog and start printing with given scale.
|
||||
* Return false, if printer dialog is aborted,
|
||||
* otherwise return true.<br>
|
||||
* If tp == null, the current playground is printed.
|
||||
*
|
||||
*/
|
||||
protected boolean print(TPrintable tp, double scale) {
|
||||
if (tp == null)
|
||||
isPrintScreen = true;
|
||||
else
|
||||
isPrintScreen = false;
|
||||
printerScale = scale;
|
||||
PrinterJob pj = PrinterJob.getPrinterJob();
|
||||
pj.setPrintable(this);
|
||||
traceCanvas = tp;
|
||||
if (pj.printDialog()) {
|
||||
try {
|
||||
pj.print();
|
||||
}
|
||||
catch (PrinterException ex) {
|
||||
System.out.println(ex);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* For internal use only. Implementation of Printable.
|
||||
* (Callback method called by printing system.)
|
||||
*/
|
||||
public int print(Graphics g, PageFormat pf, int pageIndex) {
|
||||
if (pageIndex != 0)
|
||||
return NO_SUCH_PAGE;
|
||||
Graphics2D g2D = (Graphics2D)g;
|
||||
double printerWidth = pf.getImageableWidth();
|
||||
double printerHeight = pf.getImageableHeight();
|
||||
double printerSize = printerWidth > printerHeight ? printerWidth :
|
||||
printerHeight;
|
||||
double xZero = pf.getImageableX();
|
||||
double yZero = pf.getImageableY();
|
||||
|
||||
printerG2D = g2D; // Indicate also, we are printing now
|
||||
|
||||
// Needed for fill operations: the trace canvas must be empty in order to
|
||||
// perform the fill algoritm (searching for outline of figure)
|
||||
if (!isPrintScreen)
|
||||
clean();
|
||||
|
||||
g2D.scale(printerScaleFactor * printerScale, printerScaleFactor * printerScale);
|
||||
g2D.translate(xZero/printerScale, yZero/printerScale);
|
||||
|
||||
if (isPrintScreen)
|
||||
{
|
||||
print(g);
|
||||
}
|
||||
else // Printing the traceCanvas
|
||||
{
|
||||
// Hide all turtles
|
||||
boolean[] turtleState = new boolean[countTurtles()];
|
||||
for (int i = 0; i < countTurtles(); i++) {
|
||||
Turtle aTurtle = getTurtle(i);
|
||||
turtleState[i] = aTurtle.isHidden();
|
||||
aTurtle.ht();
|
||||
}
|
||||
traceCanvas.draw();
|
||||
|
||||
// Restore old context
|
||||
for (int i = 0; i < countTurtles(); i++) {
|
||||
Turtle aTurtle = getTurtle(i);
|
||||
if (!turtleState[i])
|
||||
aTurtle.st();
|
||||
}
|
||||
}
|
||||
|
||||
printerG2D = null;
|
||||
return PAGE_EXISTS;
|
||||
}
|
||||
|
||||
/** Return the color of the pixel at the current turtle position.
|
||||
*/
|
||||
public Color getPixelColor(Turtle t) {
|
||||
Point2D.Double p1 = toScreenCoords(t.getPos());
|
||||
int x = (int)Math.round(p1.getX());
|
||||
int y = (int)Math.round(p1.getY());
|
||||
return new Color(traceBuffer.getRGB(x, y));
|
||||
}
|
||||
|
||||
public void enableRepaint(boolean b) {
|
||||
isRepainting = b;
|
||||
}
|
||||
|
||||
/** set the background color of the playground
|
||||
*/
|
||||
public void setBackground(Color color) {
|
||||
super.setBackground(color);
|
||||
if (traceG2D != null) {
|
||||
clear(color);
|
||||
} // end of if
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the origin of the cartesian coordinate system within the playground
|
||||
*/
|
||||
public void setOrigin(int x, int y) {
|
||||
for (int i = 0; i < countTurtles(); i++) {
|
||||
Turtle turtle = getTurtle(i);
|
||||
Point2D.Double p1 = toScreenCoords(turtle.getPos());
|
||||
double newX = p1.getX() - x;
|
||||
double newY = y - p1.getY();
|
||||
turtle.internalSetPos(newX, newY);
|
||||
}
|
||||
originX = x;
|
||||
originY = y;
|
||||
}
|
||||
|
||||
public int getOriginX() {
|
||||
return originX;
|
||||
}
|
||||
|
||||
public int getOriginY() {
|
||||
return originY;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Binary file not shown.
|
|
@ -0,0 +1,84 @@
|
|||
// SharedConstants.java
|
||||
|
||||
// Copyright 2002 Regula Hoefer-Isenegger
|
||||
//
|
||||
// This file is part of The Java Turtle (TJT) package
|
||||
//
|
||||
// TJT 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
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// TJT 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 The Java Turtle Package; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
/* History;
|
||||
V1.36 - Sep 2004: First official release
|
||||
V1.37 - Nov 2004: Unchanged, modifications in ch.aplu.util
|
||||
V1.38 - Dec 2004: Unchanged, modifications in ch.aplu.util
|
||||
V1.39 - Jan 2005: Unchanged, modifications in ch.aplu.util
|
||||
V1.40 - Mar 2005: Add background color, TurtleKeyAdapter, TurtleArea
|
||||
V1.41 - May 2005: User defined turtle shape, minor changes in doc and code style
|
||||
V1.42 - Dec 2005: Unchanged, modifications in ch.aplu.util
|
||||
V1.43 - Feb 2006: Bug removed: Turtle.turtleFrame was not initialized in all ctors of class Turtle
|
||||
V1.44 - Mar 2007: Bug removed: stampTurtle did not work properly in wrap mode
|
||||
V1.45 - Aug 2007: TurtleKeyAdapter: use wait/notify to reduce CPU time (from 100% to 2%)
|
||||
V1.46 - Aug 2007: synchronize(playground) for forward and rotate animation,
|
||||
new method bong() using StreamingPlayer
|
||||
V1.47 - Sept 2007: Unchanged, modifications in ch.aplu.util
|
||||
V1.48 - Sept 2007: Unchanged, modifications in ch.aplu.util
|
||||
V1.49 - Oct 2007: Unchanged, modifications in ch.aplu.util
|
||||
V1.50 - Oct 2007: Unchanged, modifications in ch.aplu.util
|
||||
V1.51 - Nov 2007: Fixed: correct position of label, when wrapping is on
|
||||
Fixed: getPos() returns now the wrapped coordinates
|
||||
Added: _getPos() returns unwrapped coordinates
|
||||
V1.52 - Nov 2007: Added bean classes in order to use turtles with a Gui builder
|
||||
V1.53 - Nov 2007: Added TurtlePane visual information when used in Gui builder design mode
|
||||
V1.54 - Nov 2007: Minor changes to documentation
|
||||
V1.55 - Dec 2007: Added property enableFocus to GPane, default: setFocusable(false)
|
||||
V1.56 - Mar 2008: Unchanged, modifications in ch.aplu.util
|
||||
V1.57 - Mar 2008: Unchanged, modifications in ch.aplu.util
|
||||
V1.58 - Mar 2008: Modification to fill() (fill(x, y)):
|
||||
region is defined with pixel color at current position
|
||||
as opposed to background color
|
||||
V1.59 - Oct 2008: Added ctors TurtleFrame with window position (ulx, uly)
|
||||
Added Turtle.getPixelColor()
|
||||
V2.00 - Nov 2008: Unchanged, modifications in ch.aplu.util
|
||||
J2SE V1.4 no longer supported
|
||||
V2.01 - Jan 2009: Unchanged, modifications in ch.aplu.util
|
||||
V2.02 - Feb 2009 Turtle constructors run in EDT now
|
||||
V2.03 - Feb 2009 Unchanged, modifications in ch.aplu.util
|
||||
V2.04 - Feb 2009 Unchanged, modifications in ch.aplu.util
|
||||
V2.05 - Feb 2009 Unchanged, modifications in ch.aplu.util
|
||||
V2.06 - Mar 2009 Unchanged, modifications in ch.aplu.util
|
||||
V2.07 - Mar 2009 All except print methods synchronized, so Turtle package is
|
||||
now thread-safe
|
||||
V2.08 - Apr 2009 Unchanged, modifications in ch.aplu.util
|
||||
V2.09 - Jun 2009 Unchanged, modifications in ch.aplu.util
|
||||
V2.10 - Jun 2010 Version for the Java-Editor
|
||||
*/
|
||||
|
||||
package ch.aplu.turtle;
|
||||
|
||||
interface SharedConstants
|
||||
{
|
||||
int DEBUG_LEVEL_OFF = 0;
|
||||
int DEBUG_LEVEL_LOW = 1;
|
||||
int DEBUG_LEVEL_MEDIUM = 2;
|
||||
int DEBUG_LEVEL_HIGH = 3;
|
||||
|
||||
int DEBUG = DEBUG_LEVEL_OFF;
|
||||
|
||||
String ABOUT =
|
||||
"Copyright © 2002-2009\nRegula Hoefer-Isenegger, Aegidius Pluess\n, Gerhard Roehner\n" +
|
||||
"under GNU General Public License\n" +
|
||||
"http://www.aplu.ch\n" +
|
||||
"All rights reserved";
|
||||
String VERSION = "2.10 - June 2015";
|
||||
}
|
||||
|
|
@ -0,0 +1,84 @@
|
|||
// StreamingPlayer.java
|
||||
|
||||
package ch.aplu.turtle;
|
||||
|
||||
|
||||
import javax.sound.sampled.*;
|
||||
import java.io.*;
|
||||
|
||||
class StreamingPlayer
|
||||
{
|
||||
private class PlayerThread extends Thread
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
byte buf[] = new byte[20000];
|
||||
try
|
||||
{
|
||||
int cnt;
|
||||
while ((cnt = audioInputStream.read(buf, 0, buf.length)) != -1)
|
||||
{
|
||||
if (cnt > 0)
|
||||
sourceDataLine.write(buf, 0, cnt);
|
||||
}
|
||||
sourceDataLine.drain();
|
||||
sourceDataLine.close();
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
System.out.println(ex);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private AudioFormat audioFormat;
|
||||
private AudioInputStream audioInputStream;
|
||||
private SourceDataLine sourceDataLine;
|
||||
private PlayerThread playerThread;
|
||||
|
||||
StreamingPlayer(InputStream is)
|
||||
{
|
||||
try
|
||||
{
|
||||
audioInputStream =
|
||||
AudioSystem.getAudioInputStream(is);
|
||||
audioFormat = audioInputStream.getFormat();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{}
|
||||
}
|
||||
|
||||
void start(boolean doFinish)
|
||||
throws LineUnavailableException
|
||||
{
|
||||
DataLine.Info dataLineInfo =
|
||||
new DataLine.Info(SourceDataLine.class, audioFormat);
|
||||
sourceDataLine =
|
||||
(SourceDataLine)AudioSystem.getLine(dataLineInfo);
|
||||
sourceDataLine.open(audioFormat);
|
||||
sourceDataLine.start();
|
||||
playerThread = new PlayerThread();
|
||||
playerThread.start();
|
||||
if (doFinish)
|
||||
waitToFinish();
|
||||
}
|
||||
|
||||
boolean isPlaying()
|
||||
{
|
||||
if (playerThread == null)
|
||||
return false;
|
||||
return (playerThread.isAlive());
|
||||
}
|
||||
|
||||
void waitToFinish()
|
||||
{
|
||||
if (playerThread == null)
|
||||
return;
|
||||
try
|
||||
{
|
||||
playerThread.join();
|
||||
}
|
||||
catch (InterruptedException ex) {}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
// TPrintable.java
|
||||
|
||||
// Copyright 2002 Regula Hoefer-Isenegger
|
||||
|
||||
// This file is part of The Java Turtle (TJT) package
|
||||
//
|
||||
// TJT 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
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// TJT 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 The Java Turtle Package; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
// Added by Aegidius Pluess
|
||||
|
||||
package ch.aplu.turtle;
|
||||
|
||||
/**
|
||||
* Interface for printing on an attached printer.
|
||||
* Normally an application uses a Turtle and implements this interface.
|
||||
* draw() should contain all drawing operations into the
|
||||
* Turtle's Playground. The printing occures, when Turtle's print() is
|
||||
* called.<br><br>
|
||||
*/
|
||||
|
||||
|
||||
public interface TPrintable
|
||||
{
|
||||
/**
|
||||
* This method must perform all drawing operations.
|
||||
* Be aware that for some undocumented reason
|
||||
* draw() is called twice. So be sure you initialize it correctly.
|
||||
*/
|
||||
|
||||
public void draw();
|
||||
}
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -0,0 +1,66 @@
|
|||
// TurtleFactory.java
|
||||
|
||||
// Copyright 2002 Regula Hoefer-Isenegger
|
||||
//
|
||||
// This file is part of The Java Turtle (TJT) package
|
||||
//
|
||||
// TJT 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
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// TJT 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 The Java Turtle Package; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package ch.aplu.turtle;
|
||||
|
||||
import java.awt.image.*;
|
||||
import java.awt.*;
|
||||
|
||||
class TurtleFactory
|
||||
{
|
||||
/** Generates the shape of the turtle with <code>color</code>,
|
||||
* angle <code>angle</code>, width <code>w</code>
|
||||
* and height <code>h</code>.
|
||||
*/
|
||||
protected Image turtleImage(Color color, double angle, int w, int h)
|
||||
{
|
||||
BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_4BYTE_ABGR);
|
||||
Graphics2D g = (Graphics2D)bi.getGraphics();
|
||||
// Origin in center
|
||||
g.translate(w/2, h/2);
|
||||
// angle = 0 is direction east (as usual in mathematics)
|
||||
g.rotate(Math.PI/2 - angle);
|
||||
g.setColor(color);
|
||||
|
||||
// Body
|
||||
g.fillOval((int)( -0.35 * w), (int)( -0.35 * h),
|
||||
(int)(0.7 * w), (int)(0.7 * h));
|
||||
|
||||
// Head
|
||||
g.fillOval((int)( -0.1 * w), (int)( -0.5 * h),
|
||||
(int)(0.2 * w), (int)(0.2 * h));
|
||||
|
||||
// Tail
|
||||
int[] xcoords =
|
||||
{(int)( -0.05 * w), 0, (int)(0.05 * w)};
|
||||
int[] ycoords =
|
||||
{(int)(0.35 * h), (int)(0.45 * h), (int)(0.35 * h)};
|
||||
g.fillPolygon(xcoords, ycoords, 3);
|
||||
|
||||
// Feet
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
g.rotate(Math.PI / 2);
|
||||
g.fillOval((int)( -0.35 * w), (int)( -0.35 * h),
|
||||
(int)(0.125 * w), (int)(0.125 * h));
|
||||
}
|
||||
return (Image)bi;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,312 @@
|
|||
// TurtleRenderer.java
|
||||
|
||||
// Copyright 2002 Regula Hoefer-Isenegger
|
||||
// Some modifications by Aegidius Pluess
|
||||
|
||||
// This file is part of The Java Turtle (TJT) package
|
||||
//
|
||||
// TJT 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
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// TJT 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 The Java Turtle Package; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package ch.aplu.turtle;
|
||||
|
||||
import ch.aplu.turtle.*;
|
||||
import java.awt.image.*;
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import java.awt.geom.*;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
/** This class is responsible for creating and choosing the correct Turtle picture.
|
||||
@author <a href="mailto:regula@hoefer.ch">Regula Hoefer-Isenegger</a>
|
||||
@version 0.1
|
||||
*/
|
||||
public class TurtleRenderer implements ImageObserver {
|
||||
/** Holds the current image */
|
||||
private Image currentImage;
|
||||
/** Holds all images */
|
||||
private Vector images;
|
||||
/** Tells how many pictures are needed*/
|
||||
private int resolution;
|
||||
/** A reference to the <code>Turtle</code> */
|
||||
private Turtle turtle;
|
||||
/** Holds the current Angle */
|
||||
private double currentAngle;
|
||||
|
||||
private final int turtleSize = 29;
|
||||
|
||||
/***/
|
||||
public TurtleRenderer(Turtle turtle) {
|
||||
this.currentImage = null;
|
||||
this.images = new Vector();
|
||||
this.turtle = turtle;
|
||||
currentAngle = 0;
|
||||
}
|
||||
|
||||
/** As an image stays unchanged, there's no need to ever update it. So this method returns always false.
|
||||
|
||||
For further information cf. <code>java.awt.image.ImageObserver</code>.
|
||||
@see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
|
||||
*/
|
||||
public boolean imageUpdate(Image img, int infoflags,
|
||||
int x, int y, int width, int height) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Return the current image.
|
||||
*/
|
||||
public Image currentImage() {
|
||||
return this.currentImage;
|
||||
}
|
||||
|
||||
/** Tell whether the image has changed.
|
||||
*/
|
||||
public boolean imageChanged(double angle) {
|
||||
return (this.currentImage != getImage(angle));
|
||||
}
|
||||
|
||||
/** Set the current image to the specified one. */
|
||||
private void setCurrentImage(Image image) {
|
||||
currentImage = image;
|
||||
}
|
||||
|
||||
/** Choose the image for the angle <code>angle</code>.
|
||||
*/
|
||||
private Image getImage(double angle) {
|
||||
while (angle < 0) {
|
||||
angle += 2*Math.PI;
|
||||
}
|
||||
while (angle >= 2*Math.PI) {
|
||||
angle -= 2*Math.PI;
|
||||
}
|
||||
double res = 2*Math.PI/(double)this.resolution;
|
||||
int index = (int)(angle/res);
|
||||
return image(index);
|
||||
}
|
||||
|
||||
/** Set the current image to the one corresponding to the angle <code>angle</code>.
|
||||
*/
|
||||
public void setAngle(double angle) {
|
||||
currentAngle = angle;
|
||||
setCurrentImage(getImage(angle));
|
||||
}
|
||||
|
||||
/** @return the current angle. */
|
||||
protected double getAngle(){
|
||||
return currentAngle;
|
||||
}
|
||||
|
||||
/** Create the images. There are <code>resolution</code> images (i.e. two subsequent
|
||||
images contain an angle of 2π/<resolution> or 360/resolution degrees).
|
||||
*/
|
||||
public void init(TurtleFactory factory, int resolution) {
|
||||
this.resolution = resolution;
|
||||
Integer res = new Integer(resolution);
|
||||
double incRes = Math.PI*2/res.doubleValue();
|
||||
double angle = 0;
|
||||
images = new Vector();
|
||||
for (int i = 0; i < resolution; i++) {
|
||||
images.add(factory.turtleImage(turtle.getColor(),
|
||||
turtle.getPlayground().toScreenAngle(angle),
|
||||
turtleSize, turtleSize));
|
||||
angle += incRes;
|
||||
}
|
||||
setCurrentImage(getImage(currentAngle));
|
||||
}
|
||||
|
||||
/** Tell how many images this <code>TurtleRenderer</code> holds */
|
||||
private int countImages() {
|
||||
return this.images.size();
|
||||
}
|
||||
|
||||
/** Get the image at <code>index</code> */
|
||||
private Image image(int index) {
|
||||
return (Image)this.images.elementAt(index);
|
||||
}
|
||||
|
||||
/** This method is responsible for painting the turtle onto the
|
||||
playground at (<code>x, y</code>).
|
||||
*/
|
||||
public final void paint(double x, double y) {
|
||||
internalPaint(x, y, turtle.getPlayground().getGraphics());
|
||||
}
|
||||
|
||||
/** This method is responsible for painting the turtle onto the
|
||||
playground at <code>p</code>.
|
||||
*/
|
||||
public final void paint(Point2D.Double p) {
|
||||
internalPaint(p.x, p.y, turtle.getPlayground().getGraphics());
|
||||
}
|
||||
|
||||
/** This method is responsible for painting the <code>Turtle</code>
|
||||
at (<code>x, y</code>).<br>
|
||||
The Graphics argument tells where to paint.
|
||||
*/
|
||||
public final void paint(double x, double y, Graphics g) {
|
||||
internalPaint(x, y, g);
|
||||
}
|
||||
|
||||
/** This method is responsible for painting the <code>Turtle</code>
|
||||
at <code>p</code>.<br>
|
||||
The Graphics argument tells where to paint.
|
||||
*/
|
||||
public void paint(Point2D.Double p, Graphics g){
|
||||
internalPaint(p.x, p.y, g);
|
||||
}
|
||||
|
||||
/** Call clipPaint and wrapPaint().
|
||||
|
||||
You should override this method only, if you add a new (edge)
|
||||
behaviour to the turtle. I recommend to you then to first call this
|
||||
method from the overriding one.
|
||||
<br>
|
||||
If you want to change anything about the real painting, override
|
||||
clipPaint or wrapPaint.
|
||||
|
||||
@see #clipPaint(int, int, Graphics2D)
|
||||
@see #wrapPaint(int, int, Graphics2D)
|
||||
*/
|
||||
protected void internalPaint(double x, double y, Graphics g) {
|
||||
if(turtle.isClip()){
|
||||
Point2D.Double p =
|
||||
calcTopLeftCorner(turtle.getPlayground().toScreenCoords(x, y));
|
||||
clipPaint((int)p.x, (int)p.y, (Graphics2D)g);
|
||||
}
|
||||
else if(turtle.isWrap()){
|
||||
Point2D.Double p =
|
||||
calcTopLeftCorner(turtle.getPlayground().toScreenCoords(x, y));
|
||||
wrapPaint((int)p.x, (int)p.y, (Graphics2D)g);
|
||||
}
|
||||
}
|
||||
|
||||
/** Define how to paint in clip mode and do it */
|
||||
protected void clipPaint(int x, int y, Graphics2D g2D) {
|
||||
g2D.drawImage(currentImage, x, y, this);
|
||||
}
|
||||
|
||||
/** Define how to paint in wrap mode and do it */
|
||||
protected void wrapPaint(int x, int y, Graphics2D g2D) {
|
||||
int pWidth = turtle.getPlayground().getWidth();
|
||||
int pHeight = turtle.getPlayground().getHeight();
|
||||
int paintX = x;
|
||||
while (paintX > pWidth) {
|
||||
paintX -= pWidth;
|
||||
}
|
||||
while (paintX < 0) {
|
||||
paintX += pWidth;
|
||||
}
|
||||
int paintY = y;
|
||||
while (paintY > pHeight) {
|
||||
paintY -= pHeight;
|
||||
}
|
||||
while (paintY < 0) {
|
||||
paintY += pHeight;
|
||||
}
|
||||
g2D.drawImage(currentImage, paintX, paintY, this);
|
||||
int nWidth = currentImage.getWidth(this);
|
||||
int nHeight = currentImage.getHeight(this);
|
||||
boolean right = (paintX+nWidth > pWidth);
|
||||
boolean bottom = (paintY+nHeight > pHeight);
|
||||
if(right) {
|
||||
g2D.drawImage(currentImage,
|
||||
paintX-pWidth,
|
||||
paintY,
|
||||
this);
|
||||
}
|
||||
if(bottom) {
|
||||
g2D.drawImage(currentImage,
|
||||
paintX,
|
||||
paintY-pHeight,
|
||||
this);
|
||||
}
|
||||
if(right && bottom) {
|
||||
g2D.drawImage(currentImage,
|
||||
paintX-pWidth,
|
||||
paintY-pHeight,
|
||||
this);
|
||||
}
|
||||
}
|
||||
|
||||
/** Compute the x-coordinate of the top left corner of the Turtle image
|
||||
(it depends on the specified x-coordinate and the image width).
|
||||
*/
|
||||
protected int calcTopLeftCornerX(double x) {
|
||||
int intX = (int)x;
|
||||
int nWidth;
|
||||
if(currentImage == null) {
|
||||
setCurrentImage(new TurtleFactory().
|
||||
turtleImage(turtle.getColor(), getAngle(), turtleSize, turtleSize));
|
||||
}
|
||||
nWidth = this.currentImage.getWidth(this);
|
||||
// the center of the turtle lies on the turtle's location:
|
||||
intX -= nWidth/2;
|
||||
return intX; // top left corner of the Turtle's image
|
||||
}
|
||||
|
||||
/** Compute the y-coordinate of the top left corner of the Turtle image
|
||||
(it depends on the specified y-coordinate and the image height).
|
||||
*/
|
||||
protected int calcTopLeftCornerY(double y) {
|
||||
int intY = (int)y;
|
||||
if(currentImage == null) {
|
||||
setCurrentImage(new TurtleFactory().
|
||||
turtleImage(turtle.getColor(), getAngle(), turtleSize, turtleSize));
|
||||
}
|
||||
int nHeight = currentImage.getHeight(this);
|
||||
// the center of the turtle lies on the turtle's location:
|
||||
intY -= nHeight/2;
|
||||
|
||||
return intY; // top left corner of the Turtle's image
|
||||
}
|
||||
/** Compute the top left corner of the Turtle image
|
||||
(dependent on the specified x- and y-coordinate and the image
|
||||
width and height.
|
||||
*/
|
||||
protected Point2D.Double calcTopLeftCorner(double x, double y) {
|
||||
if(currentImage == null) {
|
||||
setCurrentImage(new TurtleFactory().
|
||||
turtleImage(turtle.getColor(), getAngle(), turtleSize, turtleSize));
|
||||
}
|
||||
int w = currentImage.getWidth(this);
|
||||
int h = currentImage.getHeight(this);
|
||||
return new Point2D.Double(x-w/2, y-h/2);
|
||||
}
|
||||
|
||||
/** Compute the top left corner of the Turtle image
|
||||
(dependent on the specified point <code>p</code> and the image
|
||||
width and height.
|
||||
*/
|
||||
protected Point2D.Double calcTopLeftCorner(Point2D.Double p) {
|
||||
return calcTopLeftCorner(p.x, p.y);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
#BlueJ package file
|
||||
objectbench.height=155
|
||||
objectbench.width=760
|
||||
package.divider.horizontal=0.6
|
||||
package.divider.vertical=0.6766467065868264
|
||||
package.editor.height=332
|
||||
package.editor.width=649
|
||||
package.editor.x=379
|
||||
package.editor.y=72
|
||||
package.frame.height=600
|
||||
package.frame.width=800
|
||||
package.numDependencies=0
|
||||
package.numTargets=1
|
||||
package.showExtends=true
|
||||
package.showUses=true
|
||||
readme.height=58
|
||||
readme.name=@README
|
||||
readme.width=47
|
||||
readme.x=10
|
||||
readme.y=10
|
||||
target1.height=62
|
||||
target1.name=aplu
|
||||
target1.type=PackageTarget
|
||||
target1.width=80
|
||||
target1.x=180
|
||||
target1.y=10
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
public class Eval {
|
||||
|
||||
public static Wrap getOb(Object o) {
|
||||
return new Wrap(o);
|
||||
}
|
||||
|
||||
protected static Object getOb(final String s) {
|
||||
return new Object() {public String result = s;};
|
||||
}
|
||||
|
||||
protected static Object getOb(final boolean b) {
|
||||
return new Object() {public boolean result = b;};
|
||||
}
|
||||
|
||||
protected static Object getOb(final byte b) {
|
||||
return new Object() {public byte result = b;};
|
||||
}
|
||||
|
||||
protected static Object getOb(final char c) {
|
||||
return new Object() {public char result = c;};
|
||||
}
|
||||
|
||||
protected static Object getOb(final double d) {
|
||||
return new Object() {public double result = d;};
|
||||
}
|
||||
|
||||
protected static Object getOb(final float f) {
|
||||
return new Object() {public float result = f;};
|
||||
}
|
||||
|
||||
protected static Object getOb(final int i) {
|
||||
return new Object() {public int result = i;};
|
||||
}
|
||||
|
||||
protected static Object getOb(final long l) {
|
||||
return new Object() {public long result = l;};
|
||||
}
|
||||
protected static Object getOb(final short s) {
|
||||
return new Object() {public short result = s;};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Wrap {
|
||||
public Object result;
|
||||
|
||||
Wrap(Object result) {
|
||||
this.result = result;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,98 @@
|
|||
import java.io.*;
|
||||
|
||||
/**
|
||||
Support class for console input and output of numeric values.<br><br>
|
||||
|
||||
Example for input:<br>
|
||||
int age = InOut.readInt("Your age: ");<br><br>
|
||||
|
||||
Example for output:<br>
|
||||
System.out.println("price: " + InOut.format2(prize) + "Euro");<br>
|
||||
System.out.println("percent: " + InOut.formatN(percent, 1) + " %");
|
||||
*/
|
||||
|
||||
|
||||
public class InOut {
|
||||
|
||||
/** Formats a double-value with 2 decimal digits. */
|
||||
public static String format2(double d) {
|
||||
return String.format("%.2f", d);
|
||||
}
|
||||
|
||||
/** Formats a double-value with N decimal digits. */
|
||||
public static String formatN(double d, int N) {
|
||||
return String.format("%." + N + "f", d);
|
||||
}
|
||||
|
||||
/** Reads a boolean-value from console. */
|
||||
public static boolean readBoolean(String prompt) {
|
||||
final String[] trueValues =
|
||||
{ "1", "y", "t", "j", "w", "yes", "true", "ja", "wahr", "ok" };
|
||||
System.out.print(prompt);
|
||||
String input = readln().toLowerCase();
|
||||
for (int i = 0; i < trueValues.length; ++i)
|
||||
if (trueValues[i].equals(input))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Reads a char-value from console. */
|
||||
public static char readChar(String prompt) {
|
||||
System.out.print(prompt);
|
||||
return readln().charAt(0);
|
||||
}
|
||||
|
||||
/** Reads a double-value from console. */
|
||||
public static double readDouble(String prompt) {
|
||||
System.out.print(prompt);
|
||||
return Double.parseDouble(readln());
|
||||
}
|
||||
|
||||
/** Reads a float-value from console. */
|
||||
public static float readFloat(String prompt) {
|
||||
System.out.print(prompt);
|
||||
return Float.parseFloat(readln());
|
||||
}
|
||||
|
||||
/** Reads an int-value from console. */
|
||||
public static int readInt(String prompt) {
|
||||
System.out.print(prompt);
|
||||
return Integer.parseInt(readln());
|
||||
}
|
||||
|
||||
/** Reads a long-value from console. */
|
||||
public static long readLong(String prompt) {
|
||||
System.out.print(prompt);
|
||||
return Long.parseLong(readln());
|
||||
}
|
||||
|
||||
/** Reads a string-value from console. */
|
||||
public static String readString(String prompt) {
|
||||
System.out.print(prompt);
|
||||
return readln();
|
||||
}
|
||||
|
||||
/** Reads a string-value from console without prompt.
|
||||
For use at the end of a console program. */
|
||||
public static String readln() {
|
||||
try {
|
||||
return Input.readLine();
|
||||
} catch(Exception e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
private static BufferedReader Input;
|
||||
|
||||
static {
|
||||
try {
|
||||
Input = new BufferedReader(new InputStreamReader(System.in));
|
||||
}
|
||||
catch (Exception e) {
|
||||
System.out.println("console input not possible.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
#BlueJ package file
|
||||
objectbench.height=155
|
||||
objectbench.width=760
|
||||
package.divider.horizontal=0.6
|
||||
package.divider.vertical=0.6766467065868264
|
||||
package.editor.height=332
|
||||
package.editor.width=649
|
||||
package.editor.x=379
|
||||
package.editor.y=72
|
||||
package.frame.height=600
|
||||
package.frame.width=800
|
||||
package.numDependencies=0
|
||||
package.numTargets=1
|
||||
package.showExtends=true
|
||||
package.showUses=true
|
||||
readme.height=58
|
||||
readme.name=@README
|
||||
readme.width=47
|
||||
readme.x=10
|
||||
readme.y=10
|
||||
target1.height=62
|
||||
target1.name=util
|
||||
target1.type=PackageTarget
|
||||
target1.width=80
|
||||
target1.x=180
|
||||
target1.y=10
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
#BlueJ package file
|
||||
objectbench.height=155
|
||||
objectbench.width=760
|
||||
package.divider.horizontal=0.6
|
||||
package.divider.vertical=0.6766467065868264
|
||||
package.editor.height=332
|
||||
package.editor.width=649
|
||||
package.editor.x=399
|
||||
package.editor.y=92
|
||||
package.frame.height=600
|
||||
package.frame.width=800
|
||||
package.numDependencies=0
|
||||
package.numTargets=1
|
||||
package.showExtends=true
|
||||
package.showUses=true
|
||||
readme.height=58
|
||||
readme.name=@README
|
||||
readme.width=47
|
||||
readme.x=10
|
||||
readme.y=10
|
||||
target1.height=50
|
||||
target1.name=Turtle
|
||||
target1.showInterface=false
|
||||
target1.type=ClassTarget
|
||||
target1.width=80
|
||||
target1.x=180
|
||||
target1.y=10
|
||||
|
|
@ -0,0 +1,311 @@
|
|||
package je.util;
|
||||
/*
|
||||
* Class : Turtle
|
||||
* Copyright: (c) Gerhard Röhner
|
||||
*
|
||||
* History
|
||||
* --------
|
||||
* 3.00 2000.10.10 first version as java class
|
||||
* 3.01 2002.10.22 DrawDynamic
|
||||
* 3.02 2010.10.11 sleepTime for paint delay
|
||||
* 3.03 2012.03.20 cartesian coordinate system, used with originX, originY, setOrigin
|
||||
* 3.04 2015.01.24 english version, integrated component
|
||||
*/
|
||||
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.image.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
/**
|
||||
* This class is a turtle component for simple graphic programming.
|
||||
*
|
||||
* @see <a href="http://www.javaeditor.org">
|
||||
* @author Gerhard Röhner
|
||||
* @version 3.03 20/03/2012
|
||||
*/
|
||||
|
||||
|
||||
public class Turtle extends Canvas {
|
||||
|
||||
// -- private Attribute ------------------------------------------------------
|
||||
|
||||
private BufferedImage myBufferedImage;
|
||||
private Graphics myBufferedGraphics;
|
||||
private Color foreground;
|
||||
private Color background;
|
||||
private static final double piDurch180 = Math.PI / 180;
|
||||
|
||||
// -- public attributes -----------------------------------------------------
|
||||
|
||||
/**
|
||||
* turtleX is the x-coordinate of the turtle
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.turtleX = 100;</PRE>
|
||||
*/
|
||||
public double turtleX;
|
||||
|
||||
/**
|
||||
* turtleY is the y-coordinate of the turtle.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.turtleY = 200;</PRE>
|
||||
*/
|
||||
public double turtleY;
|
||||
|
||||
/**
|
||||
* turtleW is the current angle of the turtle in the range form 0 to 360 degrees.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.turtleW = 180;</PRE>
|
||||
*/
|
||||
public double turtleW;
|
||||
|
||||
/**
|
||||
* originX is the x-position of the cartesian coodinate system within the turtle canvas.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.originX = 0;</PRE>
|
||||
*/
|
||||
public double originX;
|
||||
|
||||
/**
|
||||
* originY is the y-position of the cartesian coodinate system within the turtle canvas.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.originY = 100;</PRE>
|
||||
*/
|
||||
public double originY;
|
||||
|
||||
/**
|
||||
* If drawDynamic is true you can watch the drawing of the turtle.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.drawDynamic = true;</PRE>
|
||||
*/
|
||||
public boolean drawDynamic;
|
||||
|
||||
/**
|
||||
* For drawDynamic = true you set the delay in milliseconds for drawing.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.sleepTime = 500;</PRE>
|
||||
*/
|
||||
public int sleepTime = 0;
|
||||
|
||||
// --- constructor -----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Creates a Turtle with a canvas.
|
||||
* At the beginning the Turtle is placed in the middle of it's canvas.
|
||||
* The start angle is 0 degree, which means the Turtle looks to the right.
|
||||
* The background color is white, the drawing color black.
|
||||
* <P>
|
||||
* The turtle position can easily be changed by clicking into the canvas.
|
||||
* <P>
|
||||
* The size of the canvas can easily be changed with the mouse.
|
||||
* <P>
|
||||
* Example: <PRE>Turtle myTurtle = new Turtle();</PRE>
|
||||
*/
|
||||
|
||||
public Turtle() {
|
||||
myBufferedImage = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
|
||||
myBufferedGraphics = myBufferedImage.getGraphics();
|
||||
|
||||
setForeground(Color.black);
|
||||
setBackground(Color.white);
|
||||
drawDynamic = true;
|
||||
|
||||
addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent evt) {
|
||||
turtleMouseClicked(evt);}});
|
||||
addComponentListener(new ComponentAdapter() {
|
||||
public void componentResized(ComponentEvent evt) {
|
||||
turtleResized(evt);}});
|
||||
setOrigin(50, 50);
|
||||
}
|
||||
|
||||
private void turtleMouseClicked(MouseEvent evt) {
|
||||
turtleX = evt.getX() - originX;
|
||||
turtleY = originY - evt.getY();
|
||||
turtleW = 0;
|
||||
}
|
||||
|
||||
private void turtleResized(ComponentEvent evt) {
|
||||
int width = getWidth();
|
||||
int height = getHeight();
|
||||
|
||||
BufferedImage newBufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
|
||||
Graphics newGraphics = newBufferedImage.getGraphics();
|
||||
newGraphics.setColor(background);
|
||||
newGraphics.fillRect(0, 0, width, height);
|
||||
newGraphics.setColor(foreground);
|
||||
newGraphics.drawImage(myBufferedImage, 0, 0, this);
|
||||
|
||||
turtleX = 0;
|
||||
turtleY = 0;
|
||||
turtleW = 0;
|
||||
setOrigin(width / 2, height / 2);
|
||||
|
||||
myBufferedImage = newBufferedImage;
|
||||
myBufferedGraphics = newGraphics;
|
||||
}
|
||||
|
||||
public boolean isDoubleBuffered() {
|
||||
return true;
|
||||
}
|
||||
|
||||
private void wTurtleMod360() {
|
||||
while (turtleW >= 360)
|
||||
turtleW = turtleW - 360;
|
||||
while (turtleW < 0)
|
||||
turtleW = turtleW + 360;
|
||||
}
|
||||
|
||||
// --- angle and turns -------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Turns the angle of the turtle relativ by the parameter angle.
|
||||
* Positive values means a turn right, negative a turn left.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.turn(-90);</PRE>
|
||||
*/
|
||||
public void turn(double angle) {
|
||||
turtleW = turtleW + angle;
|
||||
wTurtleMod360();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the angle of the turtle absolute by the parameter angle.
|
||||
* The angle increases counterclockwise, therefore
|
||||
* right = 0, top = 90, left = 180, bottom = 270.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.turnto(270);</PRE>
|
||||
*/
|
||||
public void turnto(double angle) {
|
||||
turtleW = angle;
|
||||
wTurtleMod360();
|
||||
}
|
||||
|
||||
// --- Drawing ---------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* The Turtle draws a line of the length specified in the current direction.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.draw(100);</PRE>
|
||||
*/
|
||||
public void draw(double length) {
|
||||
drawto(turtleX + length * Math.cos(turtleW * piDurch180),
|
||||
turtleY + length * Math.sin(turtleW * piDurch180));
|
||||
}
|
||||
|
||||
/**
|
||||
* The Turtle draws a line form the current position (turtleX, turtleY) to the
|
||||
* position (x, y) relativ to the cartesian coordinate system.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.drawto(200, 300);</PRE>
|
||||
*/
|
||||
public void drawto(double x, double y) {
|
||||
int x1 = (int) (originX + turtleX);
|
||||
int x2 = (int) (originX + x);
|
||||
int y1 = (int) (originY - turtleY);
|
||||
int y2 = (int) (originY - y);
|
||||
|
||||
myBufferedGraphics.drawLine(x1, y1, x2, y2);
|
||||
if (drawDynamic){
|
||||
getGraphics().drawLine(x1, y1, x2, y2);
|
||||
try {
|
||||
Thread.currentThread().sleep(sleepTime);
|
||||
} catch(InterruptedException e) {
|
||||
}
|
||||
} else
|
||||
repaint();
|
||||
|
||||
turtleX = x;
|
||||
turtleY = y;
|
||||
}
|
||||
|
||||
// --- Moving ----------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* The Turtle moves without drawing the length specified in the current
|
||||
* direction.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.move(100);</PRE>
|
||||
*/
|
||||
public void move(double length) {
|
||||
turtleX = turtleX + length * Math.cos (turtleW * piDurch180);
|
||||
turtleY = turtleY + length * Math.sin (turtleW * piDurch180);
|
||||
}
|
||||
|
||||
/**
|
||||
* The Turtle moves without drawing to position (x, y) relativ to the
|
||||
* cartesian coordinate system.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.moveto(100, 200);</PRE>
|
||||
*/
|
||||
public void moveto(double x, double y) {
|
||||
turtleX = x;
|
||||
turtleY = y;
|
||||
}
|
||||
|
||||
// --- set origin -----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Sets the origin of the cartesian coordinate system within the turtle's canvas.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.setOrigin(100, 200);</PRE>
|
||||
*/
|
||||
public void setOrigin(double x, double y) {
|
||||
originX = x;
|
||||
originY = y;
|
||||
}
|
||||
|
||||
// --- fore- and background color --------------------------------------------
|
||||
|
||||
/**
|
||||
* Sets the drawing color of the Turtle to color c.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.setForeground(Color.red);</PRE>
|
||||
*/
|
||||
public void setForeground(Color c) {
|
||||
foreground = c;
|
||||
myBufferedGraphics.setColor(foreground);
|
||||
super.setForeground(foreground);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the canvas color of the Turtle to color c.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.setBackground(Color.blue); </PRE>
|
||||
*/
|
||||
public void setBackground(Color c) {
|
||||
background = c;
|
||||
myBufferedGraphics.setColor(background);
|
||||
myBufferedGraphics.fillRect(0, 0, getWidth(), getHeight());
|
||||
myBufferedGraphics.setColor(foreground);
|
||||
repaint();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the Turtle's canvas with the background color.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.clear();</PRE>
|
||||
*/
|
||||
public void clear() {
|
||||
setBackground(background);
|
||||
getGraphics().drawImage(myBufferedImage, 0, 0, this);
|
||||
repaint();
|
||||
}
|
||||
|
||||
// --- Showing --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Shows the Turtle's canvas.
|
||||
*/
|
||||
public void paint(Graphics g) {
|
||||
g.drawImage(myBufferedImage, 0, 0, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the Turtle's canvas.
|
||||
*/
|
||||
public void update(Graphics g) {
|
||||
paint(g);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,129 @@
|
|||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
Swing-component for input and output of numeric values.
|
||||
*/
|
||||
|
||||
public class JNumberField extends JTextField {
|
||||
|
||||
/** constructor for a JNumberField */
|
||||
public JNumberField() {
|
||||
enableEvents(AWTEvent.KEY_EVENT_MASK);
|
||||
}
|
||||
|
||||
/** Gets a double-value from the JNumberField. */
|
||||
public double getDouble() {
|
||||
Double d = new Double(getText());
|
||||
return d.doubleValue();
|
||||
}
|
||||
|
||||
/** Gets a float-value from the JNumberField. */
|
||||
public float getFloat() {
|
||||
Double d = new Double(getText());
|
||||
return d.floatValue();
|
||||
}
|
||||
|
||||
/** Gets an int-value from the JNumberField. */
|
||||
public int getInt() {
|
||||
Double d = new Double(getText());
|
||||
return d.intValue();
|
||||
}
|
||||
|
||||
/** Gets a long-value from the JNumberField. */
|
||||
public long getLong() {
|
||||
Double d = new Double(getText());
|
||||
return d.longValue();
|
||||
}
|
||||
|
||||
/** Checks wether the JNumberField contains a valid numeric value. */
|
||||
public boolean isNumeric() {
|
||||
final String Digits = "(\\p{Digit}+)";
|
||||
final String HexDigits = "(\\p{XDigit}+)";
|
||||
// an exponent is 'e' or 'E' followed by an optionally
|
||||
// signed decimal integer.
|
||||
final String Exp = "[eE][+-]?"+Digits;
|
||||
final String fpRegex =
|
||||
("[\\x00-\\x20]*"+ // Optional leading "whitespace"
|
||||
"[+-]?(" + // Optional sign character
|
||||
"NaN|" + // "NaN" string
|
||||
"Infinity|" + // "Infinity" string
|
||||
|
||||
// A decimal floating-point string representing a finite positive
|
||||
// number without a leading sign has at most five basic pieces:
|
||||
// Digits . Digits ExponentPart FloatTypeSuffix
|
||||
//
|
||||
// Since this method allows integer-only strings as input
|
||||
// in addition to strings of floating-point literals, the
|
||||
// two sub-patterns below are simplifications of the grammar
|
||||
// productions from the Java Language Specification, 2nd
|
||||
// edition, section 3.10.2.
|
||||
|
||||
// Digits ._opt Digits_opt ExponentPart_opt FloatTypeSuffix_opt
|
||||
"((("+Digits+"(\\.)?("+Digits+"?)("+Exp+")?)|"+
|
||||
|
||||
// . Digits ExponentPart_opt FloatTypeSuffix_opt
|
||||
"(\\.("+Digits+")("+Exp+")?)|"+
|
||||
|
||||
// Hexadecimal strings
|
||||
"((" +
|
||||
// 0[xX] HexDigits ._opt BinaryExponent FloatTypeSuffix_opt
|
||||
"(0[xX]" + HexDigits + "(\\.)?)|" +
|
||||
|
||||
// 0[xX] HexDigits_opt . HexDigits BinaryExponent FloatTypeSuffix_opt
|
||||
"(0[xX]" + HexDigits + "?(\\.)" + HexDigits + ")" +
|
||||
|
||||
")[pP][+-]?" + Digits + "))" +
|
||||
"[fFdD]?))" +
|
||||
"[\\x00-\\x20]*");// Optional trailing "whitespace"
|
||||
|
||||
return java.util.regex.Pattern.matches(fpRegex, getText());
|
||||
}
|
||||
|
||||
/** Sets a double-value into the JNumberField. */
|
||||
public void setDouble(double d) {
|
||||
setText(String.valueOf(d));
|
||||
}
|
||||
|
||||
/** Sets a double-value with N digits into the JNumberField. */
|
||||
public void setDouble(double d, int N) {
|
||||
setText(String.format(Locale.ENGLISH, "%." + N + "f", d));
|
||||
}
|
||||
|
||||
/** Sets a float-value into the JNumberField. */
|
||||
public void setFloat(float f) {
|
||||
setText(String.valueOf(f));
|
||||
}
|
||||
|
||||
/** Sets a float-value with N digits into the JNumberField. */
|
||||
public void setFloat(float f, int N) {
|
||||
setText(String.format(Locale.ENGLISH, "%." + N + "f", f));
|
||||
}
|
||||
|
||||
/** Sets an int-value into the JNumberField. */
|
||||
public void setInt(int i) {
|
||||
setText(String.valueOf(i));
|
||||
}
|
||||
|
||||
/** Sets a long-value into the JNumberField. */
|
||||
public void setLong(long l) {
|
||||
setText(String.valueOf(l));
|
||||
}
|
||||
|
||||
/** Clears the JNumberField */
|
||||
public void clear() {
|
||||
setText("");
|
||||
}
|
||||
|
||||
protected void processKeyEvent(KeyEvent e) {
|
||||
super.processKeyEvent(e);
|
||||
if (isNumeric() || getText().equals("-") ||
|
||||
getText().equals("") || getText().equals("."))
|
||||
setBackground(Color.white);
|
||||
else
|
||||
setBackground(Color.red);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,128 @@
|
|||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
AWT-component for input and output of numeric values.
|
||||
*/
|
||||
|
||||
public class NumberField extends TextField {
|
||||
|
||||
/** constructor for a NumberField */
|
||||
public NumberField() {
|
||||
enableEvents(AWTEvent.KEY_EVENT_MASK);
|
||||
}
|
||||
|
||||
/** Gets a double-value from the NumberField. */
|
||||
public double getDouble() {
|
||||
Double d = new Double(getText());
|
||||
return d.doubleValue();
|
||||
}
|
||||
|
||||
/** Gets a float-value from the NumberField. */
|
||||
public float getFloat() {
|
||||
Double d = new Double(getText());
|
||||
return d.floatValue();
|
||||
}
|
||||
|
||||
/** Gets an int-value from the NumberField. */
|
||||
public int getInt() {
|
||||
Double d = new Double(getText());
|
||||
return d.intValue();
|
||||
}
|
||||
|
||||
/** Gets a long-value from the NumberField. */
|
||||
public long getLong() {
|
||||
Double d = new Double(getText());
|
||||
return d.longValue();
|
||||
}
|
||||
|
||||
/** Checks wether the NumberField contains a valid numeric value. */
|
||||
public boolean isNumeric() {
|
||||
final String Digits = "(\\p{Digit}+)";
|
||||
final String HexDigits = "(\\p{XDigit}+)";
|
||||
// an exponent is 'e' or 'E' followed by an optionally
|
||||
// signed decimal integer.
|
||||
final String Exp = "[eE][+-]?"+Digits;
|
||||
final String fpRegex =
|
||||
("[\\x00-\\x20]*"+ // Optional leading "whitespace"
|
||||
"[+-]?(" + // Optional sign character
|
||||
"NaN|" + // "NaN" string
|
||||
"Infinity|" + // "Infinity" string
|
||||
|
||||
// A decimal floating-point string representing a finite positive
|
||||
// number without a leading sign has at most five basic pieces:
|
||||
// Digits . Digits ExponentPart FloatTypeSuffix
|
||||
//
|
||||
// Since this method allows integer-only strings as input
|
||||
// in addition to strings of floating-point literals, the
|
||||
// two sub-patterns below are simplifications of the grammar
|
||||
// productions from the Java Language Specification, 2nd
|
||||
// edition, section 3.10.2.
|
||||
|
||||
// Digits ._opt Digits_opt ExponentPart_opt FloatTypeSuffix_opt
|
||||
"((("+Digits+"(\\.)?("+Digits+"?)("+Exp+")?)|"+
|
||||
|
||||
// . Digits ExponentPart_opt FloatTypeSuffix_opt
|
||||
"(\\.("+Digits+")("+Exp+")?)|"+
|
||||
|
||||
// Hexadecimal strings
|
||||
"((" +
|
||||
// 0[xX] HexDigits ._opt BinaryExponent FloatTypeSuffix_opt
|
||||
"(0[xX]" + HexDigits + "(\\.)?)|" +
|
||||
|
||||
// 0[xX] HexDigits_opt . HexDigits BinaryExponent FloatTypeSuffix_opt
|
||||
"(0[xX]" + HexDigits + "?(\\.)" + HexDigits + ")" +
|
||||
|
||||
")[pP][+-]?" + Digits + "))" +
|
||||
"[fFdD]?))" +
|
||||
"[\\x00-\\x20]*");// Optional trailing "whitespace"
|
||||
|
||||
return java.util.regex.Pattern.matches(fpRegex, getText());
|
||||
}
|
||||
|
||||
/** Sets a double-value into the NumberField. */
|
||||
public void setDouble(double d) {
|
||||
setText(String.valueOf(d));
|
||||
}
|
||||
|
||||
/** Sets a double-value with N digits into the NumberField. */
|
||||
public void setDouble(double d, int N) {
|
||||
setText(String.format(Locale.ENGLISH, "%." + N + "f", d));
|
||||
}
|
||||
|
||||
/** Sets a float-value into the NumberField. */
|
||||
public void setFloat(float f) {
|
||||
setText(String.valueOf(f));
|
||||
}
|
||||
|
||||
/** Sets a float-value with N digits into the NumberField. */
|
||||
public void setFloat(float f, int N) {
|
||||
setText(String.format(Locale.ENGLISH, "%." + N + "f", f));
|
||||
}
|
||||
|
||||
/** Sets an int-value into the NumberField. */
|
||||
public void setInt(int i) {
|
||||
setText(String.valueOf(i));
|
||||
}
|
||||
|
||||
/** Sets a long-value into the NumberField. */
|
||||
public void setLong(long l) {
|
||||
setText(String.valueOf(l));
|
||||
}
|
||||
|
||||
/** Clears the NumberField */
|
||||
public void clear() {
|
||||
setText("");
|
||||
}
|
||||
|
||||
protected void processKeyEvent(KeyEvent e) {
|
||||
super.processKeyEvent(e);
|
||||
if (isNumeric() || getText().equals("-") ||
|
||||
getText().equals("") || getText().equals("."))
|
||||
setBackground(Color.white);
|
||||
else
|
||||
setBackground(Color.red);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
#BlueJ package file
|
||||
editor.fx.0.height=738
|
||||
editor.fx.0.width=816
|
||||
editor.fx.0.x=275
|
||||
editor.fx.0.y=0
|
||||
objectbench.height=93
|
||||
objectbench.width=760
|
||||
package.divider.horizontal=0.6
|
||||
package.divider.vertical=0.8003992015968064
|
||||
package.editor.height=394
|
||||
package.editor.width=649
|
||||
package.editor.x=359
|
||||
package.editor.y=52
|
||||
package.frame.height=600
|
||||
package.frame.width=800
|
||||
package.numDependencies=0
|
||||
package.numTargets=8
|
||||
package.showExtends=true
|
||||
package.showUses=true
|
||||
project.charset=windows-1252
|
||||
readme.height=58
|
||||
readme.name=@README
|
||||
readme.width=47
|
||||
readme.x=10
|
||||
readme.y=10
|
||||
target1.height=50
|
||||
target1.name=JEClassLoader
|
||||
target1.showInterface=false
|
||||
target1.type=ClassTarget
|
||||
target1.width=110
|
||||
target1.x=10
|
||||
target1.y=90
|
||||
target2.height=62
|
||||
target2.name=ch
|
||||
target2.type=PackageTarget
|
||||
target2.width=80
|
||||
target2.x=110
|
||||
target2.y=10
|
||||
target3.height=62
|
||||
target3.name=je
|
||||
target3.type=PackageTarget
|
||||
target3.width=80
|
||||
target3.x=200
|
||||
target3.y=10
|
||||
target4.height=50
|
||||
target4.name=JEControl
|
||||
target4.showInterface=false
|
||||
target4.type=ClassTarget
|
||||
target4.width=80
|
||||
target4.x=120
|
||||
target4.y=90
|
||||
target5.height=50
|
||||
target5.name=Eval
|
||||
target5.showInterface=false
|
||||
target5.type=ClassTarget
|
||||
target5.width=80
|
||||
target5.x=10
|
||||
target5.y=150
|
||||
target6.height=50
|
||||
target6.name=InOut
|
||||
target6.showInterface=false
|
||||
target6.type=ClassTarget
|
||||
target6.width=80
|
||||
target6.x=100
|
||||
target6.y=150
|
||||
target7.height=50
|
||||
target7.name=NumberField
|
||||
target7.showInterface=false
|
||||
target7.type=ClassTarget
|
||||
target7.width=110
|
||||
target7.x=190
|
||||
target7.y=150
|
||||
target8.height=50
|
||||
target8.name=JNumberField
|
||||
target8.showInterface=false
|
||||
target8.type=ClassTarget
|
||||
target8.width=110
|
||||
target8.x=10
|
||||
target8.y=210
|
||||
|
|
@ -0,0 +1,129 @@
|
|||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
Swing-component for input and output of numeric values.
|
||||
*/
|
||||
|
||||
public class JNumberField extends JTextField {
|
||||
|
||||
/** constructor for a JNumberField */
|
||||
public JNumberField() {
|
||||
enableEvents(AWTEvent.KEY_EVENT_MASK);
|
||||
}
|
||||
|
||||
/** Gets a double-value from the JNumberField. */
|
||||
public double getDouble() {
|
||||
Double d = new Double(getText());
|
||||
return d.doubleValue();
|
||||
}
|
||||
|
||||
/** Gets a float-value from the JNumberField. */
|
||||
public float getFloat() {
|
||||
Double d = new Double(getText());
|
||||
return d.floatValue();
|
||||
}
|
||||
|
||||
/** Gets an int-value from the JNumberField. */
|
||||
public int getInt() {
|
||||
Double d = new Double(getText());
|
||||
return d.intValue();
|
||||
}
|
||||
|
||||
/** Gets a long-value from the JNumberField. */
|
||||
public long getLong() {
|
||||
Double d = new Double(getText());
|
||||
return d.longValue();
|
||||
}
|
||||
|
||||
/** Checks wether the JNumberField contains a valid numeric value. */
|
||||
public boolean isNumeric() {
|
||||
final String Digits = "(\\p{Digit}+)";
|
||||
final String HexDigits = "(\\p{XDigit}+)";
|
||||
// an exponent is 'e' or 'E' followed by an optionally
|
||||
// signed decimal integer.
|
||||
final String Exp = "[eE][+-]?"+Digits;
|
||||
final String fpRegex =
|
||||
("[\\x00-\\x20]*"+ // Optional leading "whitespace"
|
||||
"[+-]?(" + // Optional sign character
|
||||
"NaN|" + // "NaN" string
|
||||
"Infinity|" + // "Infinity" string
|
||||
|
||||
// A decimal floating-point string representing a finite positive
|
||||
// number without a leading sign has at most five basic pieces:
|
||||
// Digits . Digits ExponentPart FloatTypeSuffix
|
||||
//
|
||||
// Since this method allows integer-only strings as input
|
||||
// in addition to strings of floating-point literals, the
|
||||
// two sub-patterns below are simplifications of the grammar
|
||||
// productions from the Java Language Specification, 2nd
|
||||
// edition, section 3.10.2.
|
||||
|
||||
// Digits ._opt Digits_opt ExponentPart_opt FloatTypeSuffix_opt
|
||||
"((("+Digits+"(\\.)?("+Digits+"?)("+Exp+")?)|"+
|
||||
|
||||
// . Digits ExponentPart_opt FloatTypeSuffix_opt
|
||||
"(\\.("+Digits+")("+Exp+")?)|"+
|
||||
|
||||
// Hexadecimal strings
|
||||
"((" +
|
||||
// 0[xX] HexDigits ._opt BinaryExponent FloatTypeSuffix_opt
|
||||
"(0[xX]" + HexDigits + "(\\.)?)|" +
|
||||
|
||||
// 0[xX] HexDigits_opt . HexDigits BinaryExponent FloatTypeSuffix_opt
|
||||
"(0[xX]" + HexDigits + "?(\\.)" + HexDigits + ")" +
|
||||
|
||||
")[pP][+-]?" + Digits + "))" +
|
||||
"[fFdD]?))" +
|
||||
"[\\x00-\\x20]*");// Optional trailing "whitespace"
|
||||
|
||||
return java.util.regex.Pattern.matches(fpRegex, getText());
|
||||
}
|
||||
|
||||
/** Sets a double-value into the JNumberField. */
|
||||
public void setDouble(double d) {
|
||||
setText(String.valueOf(d));
|
||||
}
|
||||
|
||||
/** Sets a double-value with N digits into the JNumberField. */
|
||||
public void setDouble(double d, int N) {
|
||||
setText(String.format(Locale.ENGLISH, "%." + N + "f", d));
|
||||
}
|
||||
|
||||
/** Sets a float-value into the JNumberField. */
|
||||
public void setFloat(float f) {
|
||||
setText(String.valueOf(f));
|
||||
}
|
||||
|
||||
/** Sets a float-value with N digits into the JNumberField. */
|
||||
public void setFloat(float f, int N) {
|
||||
setText(String.format(Locale.ENGLISH, "%." + N + "f", f));
|
||||
}
|
||||
|
||||
/** Sets an int-value into the JNumberField. */
|
||||
public void setInt(int i) {
|
||||
setText(String.valueOf(i));
|
||||
}
|
||||
|
||||
/** Sets a long-value into the JNumberField. */
|
||||
public void setLong(long l) {
|
||||
setText(String.valueOf(l));
|
||||
}
|
||||
|
||||
/** Clears the JNumberField */
|
||||
public void clear() {
|
||||
setText("");
|
||||
}
|
||||
|
||||
protected void processKeyEvent(KeyEvent e) {
|
||||
super.processKeyEvent(e);
|
||||
if (isNumeric() || getText().equals("-") ||
|
||||
getText().equals("") || getText().equals("."))
|
||||
setBackground(Color.white);
|
||||
else
|
||||
setBackground(Color.red);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
Manifest-Version: 1.0
|
||||
Class-Path: JEClasses.jar jdom-1.1.3.jar
|
||||
Created-By: 1.8.0_161 (Oracle Corporation)
|
||||
Main-Class: BreakVigenere
|
||||
|
||||
|
|
@ -0,0 +1,128 @@
|
|||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
AWT-component for input and output of numeric values.
|
||||
*/
|
||||
|
||||
public class NumberField extends TextField {
|
||||
|
||||
/** constructor for a NumberField */
|
||||
public NumberField() {
|
||||
enableEvents(AWTEvent.KEY_EVENT_MASK);
|
||||
}
|
||||
|
||||
/** Gets a double-value from the NumberField. */
|
||||
public double getDouble() {
|
||||
Double d = new Double(getText());
|
||||
return d.doubleValue();
|
||||
}
|
||||
|
||||
/** Gets a float-value from the NumberField. */
|
||||
public float getFloat() {
|
||||
Double d = new Double(getText());
|
||||
return d.floatValue();
|
||||
}
|
||||
|
||||
/** Gets an int-value from the NumberField. */
|
||||
public int getInt() {
|
||||
Double d = new Double(getText());
|
||||
return d.intValue();
|
||||
}
|
||||
|
||||
/** Gets a long-value from the NumberField. */
|
||||
public long getLong() {
|
||||
Double d = new Double(getText());
|
||||
return d.longValue();
|
||||
}
|
||||
|
||||
/** Checks wether the NumberField contains a valid numeric value. */
|
||||
public boolean isNumeric() {
|
||||
final String Digits = "(\\p{Digit}+)";
|
||||
final String HexDigits = "(\\p{XDigit}+)";
|
||||
// an exponent is 'e' or 'E' followed by an optionally
|
||||
// signed decimal integer.
|
||||
final String Exp = "[eE][+-]?"+Digits;
|
||||
final String fpRegex =
|
||||
("[\\x00-\\x20]*"+ // Optional leading "whitespace"
|
||||
"[+-]?(" + // Optional sign character
|
||||
"NaN|" + // "NaN" string
|
||||
"Infinity|" + // "Infinity" string
|
||||
|
||||
// A decimal floating-point string representing a finite positive
|
||||
// number without a leading sign has at most five basic pieces:
|
||||
// Digits . Digits ExponentPart FloatTypeSuffix
|
||||
//
|
||||
// Since this method allows integer-only strings as input
|
||||
// in addition to strings of floating-point literals, the
|
||||
// two sub-patterns below are simplifications of the grammar
|
||||
// productions from the Java Language Specification, 2nd
|
||||
// edition, section 3.10.2.
|
||||
|
||||
// Digits ._opt Digits_opt ExponentPart_opt FloatTypeSuffix_opt
|
||||
"((("+Digits+"(\\.)?("+Digits+"?)("+Exp+")?)|"+
|
||||
|
||||
// . Digits ExponentPart_opt FloatTypeSuffix_opt
|
||||
"(\\.("+Digits+")("+Exp+")?)|"+
|
||||
|
||||
// Hexadecimal strings
|
||||
"((" +
|
||||
// 0[xX] HexDigits ._opt BinaryExponent FloatTypeSuffix_opt
|
||||
"(0[xX]" + HexDigits + "(\\.)?)|" +
|
||||
|
||||
// 0[xX] HexDigits_opt . HexDigits BinaryExponent FloatTypeSuffix_opt
|
||||
"(0[xX]" + HexDigits + "?(\\.)" + HexDigits + ")" +
|
||||
|
||||
")[pP][+-]?" + Digits + "))" +
|
||||
"[fFdD]?))" +
|
||||
"[\\x00-\\x20]*");// Optional trailing "whitespace"
|
||||
|
||||
return java.util.regex.Pattern.matches(fpRegex, getText());
|
||||
}
|
||||
|
||||
/** Sets a double-value into the NumberField. */
|
||||
public void setDouble(double d) {
|
||||
setText(String.valueOf(d));
|
||||
}
|
||||
|
||||
/** Sets a double-value with N digits into the NumberField. */
|
||||
public void setDouble(double d, int N) {
|
||||
setText(String.format(Locale.ENGLISH, "%." + N + "f", d));
|
||||
}
|
||||
|
||||
/** Sets a float-value into the NumberField. */
|
||||
public void setFloat(float f) {
|
||||
setText(String.valueOf(f));
|
||||
}
|
||||
|
||||
/** Sets a float-value with N digits into the NumberField. */
|
||||
public void setFloat(float f, int N) {
|
||||
setText(String.format(Locale.ENGLISH, "%." + N + "f", f));
|
||||
}
|
||||
|
||||
/** Sets an int-value into the NumberField. */
|
||||
public void setInt(int i) {
|
||||
setText(String.valueOf(i));
|
||||
}
|
||||
|
||||
/** Sets a long-value into the NumberField. */
|
||||
public void setLong(long l) {
|
||||
setText(String.valueOf(l));
|
||||
}
|
||||
|
||||
/** Clears the NumberField */
|
||||
public void clear() {
|
||||
setText("");
|
||||
}
|
||||
|
||||
protected void processKeyEvent(KeyEvent e) {
|
||||
super.processKeyEvent(e);
|
||||
if (isNumeric() || getText().equals("-") ||
|
||||
getText().equals("") || getText().equals("."))
|
||||
setBackground(Color.white);
|
||||
else
|
||||
setBackground(Color.red);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
import java.awt.*;
|
||||
import java.awt.geom.Line2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import javax.swing.*;
|
||||
|
||||
public class Balkendiagramm extends JPanel {
|
||||
|
||||
private double gesamt;
|
||||
private double haeufigkeit[];
|
||||
private double maxwert;
|
||||
private int verschiebung = 0;
|
||||
private double haeufigkeit_de[] = { 0.0651, 0.0189, 0.0306, 0.0508, 0.174, 0.0166, 0.0301, 0.0476,0.0755, 0.0027, 0.0121,0.0344,0.0252,0.0978,0.0251,0.0079,0.0002,0.07,0.0727,0.0615,0.0435,0.067,0.0189,0.0003,0.0004,0.0113};
|
||||
|
||||
|
||||
public void setHaeufigkeit(double haeufigkeit[]) {
|
||||
|
||||
this.haeufigkeit = haeufigkeit;
|
||||
gesamt = 0;
|
||||
for (int i = 0; i < 26; i++) {
|
||||
gesamt += haeufigkeit[i];
|
||||
}
|
||||
for (int i = 0; i < 26; i++) {
|
||||
haeufigkeit[i] /= gesamt;
|
||||
}
|
||||
maxwert = 0.20;
|
||||
|
||||
}
|
||||
|
||||
public void setVerschiebung(int verschiebung) {
|
||||
if (verschiebung >= 0 && verschiebung < 26) {
|
||||
this.verschiebung = verschiebung;
|
||||
|
||||
} else {
|
||||
this.verschiebung = 0;
|
||||
} // end of if-else
|
||||
}
|
||||
|
||||
public void paintComponent(Graphics g) {
|
||||
Graphics2D g2 = (Graphics2D) g;
|
||||
super.paintComponent(g2);
|
||||
Dimension d = getSize(null);
|
||||
//Skalieren auf 100x100 mit y-Invertierung
|
||||
g2.scale(d.getWidth() / 120.0, -d.getHeight() / 100.0);
|
||||
// Ursprung verschieben nach (15,-90)
|
||||
g2.translate(5, -90);
|
||||
// Linien etwas breiter
|
||||
g2.setStroke(new BasicStroke(1.5f));
|
||||
// x-Achse zeichnen
|
||||
g2.draw(new Line2D.Double(0, 0, 104, 0));
|
||||
// Linien etwas dünner
|
||||
g2.setStroke(new BasicStroke(0.5f));
|
||||
// Deutsche Häufigkeit grau
|
||||
g2.setColor(Color.darkGray);
|
||||
// Säulen zeichnen
|
||||
for (int i = 0; i < 26; i++) {
|
||||
g2.fill(new Rectangle2D.Double(4 * i+1, 0, 2, haeufigkeit_de[i] / maxwert *100));
|
||||
}
|
||||
// Texthäufigkeit blau
|
||||
g2.setColor(Color.blue);
|
||||
// Säulen zeichnen
|
||||
for (int i = 0; i < 26; i++) {
|
||||
g2.fill(new Rectangle2D.Double(4 * i, 0, 2, haeufigkeit[(i+verschiebung)%26] / maxwert *100));
|
||||
}
|
||||
// y-Invertierung rückgängig machen
|
||||
g2.scale(1, -1);
|
||||
// Beschriftung x-Achse
|
||||
String xAchse = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
// Fontgröße für Beschriftung ändern
|
||||
g2.setColor(Color.black);
|
||||
g2.setFont(g2.getFont().deriveFont(5f));
|
||||
for (int i = 0; i < 26; i++) {
|
||||
g2.drawString(xAchse.substring(i, i + 1),
|
||||
i * 4, +6);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
public class Baustein implements Comparable<Baustein>{
|
||||
|
||||
// Anfang Attribute
|
||||
private String zeichen;
|
||||
private int anzahl;
|
||||
// Ende Attribute
|
||||
|
||||
public Baustein(String zeichen) {
|
||||
super();
|
||||
anzahl = 1;
|
||||
this.zeichen = zeichen;
|
||||
}
|
||||
// Anfang Methoden
|
||||
|
||||
|
||||
|
||||
public int compareTo(Baustein c) {
|
||||
|
||||
int anz = c.getAnzahl();
|
||||
|
||||
//ascending order
|
||||
return anz - this.anzahl;
|
||||
|
||||
//descending order
|
||||
//return compareQuantity - this.quantity;
|
||||
|
||||
}
|
||||
public String getZeichen() {
|
||||
return zeichen;
|
||||
}
|
||||
|
||||
public int getAnzahl() {
|
||||
return anzahl;
|
||||
}
|
||||
|
||||
public void incAnzahl() {
|
||||
anzahl++;
|
||||
}
|
||||
|
||||
|
||||
// Ende Methoden
|
||||
}
|
||||
Binary file not shown.
|
|
@ -0,0 +1,498 @@
|
|||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
import javax.swing.table.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import javax.swing.text.DefaultHighlighter;
|
||||
import javax.swing.text.Highlighter;
|
||||
import javax.swing.text.Highlighter.HighlightPainter;
|
||||
import javax.swing.text.BadLocationException;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Programm zur Kryptoanalyse
|
||||
* von monoalphabetischen Substitutionen
|
||||
*
|
||||
* @version 1.0 from 23.11.2016
|
||||
* @author Thomas Schaller
|
||||
*/
|
||||
|
||||
public class BreakVigenere extends JFrame {
|
||||
// Anfang Attribute
|
||||
private JTextField[] buchstabe;
|
||||
|
||||
private JButton jButton1 = new JButton();
|
||||
private JButton jBBuchstabe = new JButton();
|
||||
private Balkendiagramm bdText = new Balkendiagramm();
|
||||
|
||||
private JTextArea jTAKrypto = new JTextArea("");
|
||||
private JScrollPane jTAKryptoScrollPane = new JScrollPane(jTAKrypto);
|
||||
private JTextArea jTAKlartext = new JTextArea("");
|
||||
private JScrollPane jTAKlartextScrollPane = new JScrollPane(jTAKlartext);
|
||||
private JLabel jLKryptotext = new JLabel();
|
||||
private JLabel jLKlartext = new JLabel();
|
||||
private JLabel jLCopyright = new JLabel();
|
||||
private JTextArea jTAKorrelation = new JTextArea("");
|
||||
private JScrollPane jTAKorrelationScrollPane = new JScrollPane(jTAKorrelation);
|
||||
private JTextArea jTAKorrelation2 = new JTextArea("");
|
||||
private JScrollPane jTAKorrelation2ScrollPane = new JScrollPane(jTAKorrelation2);
|
||||
private JSpinner jSpVerschiebung = new JSpinner();
|
||||
private SpinnerNumberModel jSpVerschiebungModel = new SpinnerNumberModel(0, 0, 99, 1);
|
||||
private JNumberField jNFAnzahlTreffer = new JNumberField();
|
||||
private JLabel lVerschiebung = new JLabel();
|
||||
private JLabel lAnzahlgleicherBuchstaben = new JLabel();
|
||||
private JButton jButtonKas = new JButton(); // neu mkl
|
||||
private int lv, lb, rv, rb;
|
||||
// Ende Attribute
|
||||
|
||||
public BreakVigenere (String title) {
|
||||
super (title);
|
||||
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
|
||||
int frameWidth = 1013;
|
||||
int frameHeight = 662;
|
||||
setSize(frameWidth, frameHeight);
|
||||
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
int x = (d.width - getSize().width) / 2;
|
||||
int y = (d.height - getSize().height) / 2;
|
||||
setLocation(x, y);
|
||||
Container cp = getContentPane();
|
||||
cp.setLayout(null);
|
||||
// Anfang Komponenten
|
||||
|
||||
jTAKryptoScrollPane.setBounds(16, 24, 665, 105);
|
||||
jTAKryptoScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
|
||||
|
||||
jTAKrypto.setLineWrap(true);
|
||||
jTAKrypto.setFont(new Font("Courier New", Font.BOLD, 16));
|
||||
jTAKrypto.setText("JMLQMFNSKIOQNXGYZOQEBJLUKXHFCXGVLGBMREAJZCAEKVIFOWJLMFGJLPQZJIYHQQHYJLAFGFLRLQYESTPMHIAWQZFIPPMZMIZGPDOIIIVGTHIIQVKHLVHQOPLNMIKMSWCYKMUIVBREADEQOXLVVMILSMVWYZLVAONSIIVIKVKIVPOIZIEGXHLHCDILKIVPKYAWKTKRIIVQJMRXQZKVHFBVULHRVQYXYMBTKQPYAUSNHLZUSJUJBQTFHRLEKMUIAUTPHXMUTMZGPQXWWVIONINIAONVPIJQTIUWMONWIRLUMIUAMDQIZTWXEKYEXTOELPQNXMZIFEKGOWJONIYDCDVSSCODGTOMMMTKLKMNKRPRLQSRHGPEKMUIUFUHLZMDLJLRBXOGOXMZHYJLAONPBKMDBSYRIONNLHMYKMUDMXTIUOTMXXLBBNAGOWBMHIUDCYTGOWBQTESTPMHIAMVEKMUIZFGFBPINKVGYOQNIUYVPYSHPTQBIYJONGVLRIXVLHFMFKEBWHGTYADMZJETMBQXJHRLQXHPIXDUKYIAEOZLTWXEESTPMHIAMAONIJLQRLVPIZGTKHFMDKWDEZZUGOIQZLIZXMEBIYJITXIUSPZKWJLTEYISHQQYIYACDJIPQRMNVCSUUZESMMZOWJLMZQVFTBARSNIVSOSCEVNGXAMAFGFLPTMYSJEQZLSYQMUTIZZWYBIYWKTRWZPMDLVLMHGCLSIVPKRRIVZCSYXAAJIYIQZKWRIVZYEADMEBSYKMEILSEOQTKLVVQARKOZKVXVKZMVLPWKTYGOAIONHHPMUILADCQXVHXMZCYYHMZJETETEREAIQZOWJLMEORUWXDILLFMZAXGXEUKFLMABOISWEQOWLZQDZZAMWYTMHTIDKRAETXKWNIPAXGOXLQXXJLBUMOLMBPOIIYKTYXHFMZJIZOMZTWHXHQYFLWBUSQLRLUKVLMPQTJVPOQORKIZPOICIZEILPILQTIUETBNEIIBQGYZHMDZEIYTMGYZKMINPAAMDJIUQAEKRZMVPGPSIDQXFYECONXHPAAKMUQIXHIUYBLZAVVLQTLPIZZGGOOTMXXLBBNAGOWBMHIUWWNKKPRVFSEUAQQJIYZWZBSYRMENEUHMXZWPGPEUQPXCYKMUIXQXMVHQEILLTWXEESTPMHIAMAONIZYJEZMAYBUURTMBUSFLMABOISIQZKVWIZUUHLZWZCLYIVPZVPXPQSMBWAUILHYNHKVZGPAHIUIAFGRKEZPGPWLINKXLFMEILYRSFKESWWPOINIEANRAIIXVLHFMFOWJLMDKMOIVRUPNILQXFBGPEZEIIVHKVDIVPKXLFMXREZSJQXIPXAHKVDVNQRXLETBNEIIBQJMLIZMRPLVLUTKZMVHUPBXWDOWJLETRXLFMUJIUQWZUESTPMHIAMAONIUWCNYXPXCFOSUWUQZLVHMZCEYHQQYWJLWZYIPXTMTKLQJXOGOKZGTHZXHXOGOLIFZIKMMEHIYIQFYMTNITXESWWXGRNIDAXXYMBTKQPYAGTHIITXGWVHMDOXHPQQTMZGPQMISIPDZISIWZHEAXQEZEHPJQXXPIUBLSOPMZKVZGPXAKCSZPOIHPXTGFLXMZGGONMIKMSWLDKMVHMDBMLVEDZIYRHGCIJLAQRRHPAYKGOEVUYGOIATOPMWUUZXLPPMZXLIZTOIYDCPOIUEKTOLTFMZGRUXMMRFLVBUYGOIQNKIYJCZJIUIQZKGOMNRXMLVAONIPFMNKWAIPQTHGYUQOWAECEFALMZGTHLRUQZESPAONIPFMZJMLECRKMUIZSKQLMVEGQLRIONWLWQFFIUYVPYSCIZNARKIVEORKHIEYWPGPPOIRPMUTIYIIGLHLVODKVLRLDKLLRSMTRUEPQFYLMVVGLYLCZJIYXABZIYMUVGLYZMDGPSKMYKMUIZFKHLVVQGTVPQFGRPWKTKKLPMTXXLKQABEURQNGXAMAFGHLPTMVSYXIMRFLVBUYZLVEDLISXMMRTOEJQZIBRLNKPSEAAYOLRVIUVAYVPYGOYNPOIWSTKGPWLINKXPWKTKGOMNRXMLVCZMQPXDQXAYJMXZITETBNEIIBGTHZGPXYWLPPUKVGYEGXHLETNKVAMAEILLMJQHIUYBLZHPIVMILQILQSFBGPEZEIIVLAHYIPQTAHVQYPEOVODOJMHMDLVHRHAYIIPIUYIKIDUMIUVMBUVAEAUJILECRARKWKTRYNZWDYXHXBPKVHPJQXXPWKTKMIILUKXHFCXGVLGBMJIZXZUZLLQQGYDBZMDCIUHMZJEIIQMHIYEVPKVZETEOQVVQSORHPDQXAYJMXZIHPXTGFLXMQORGYBDGKLRLUKWLVSDETASODGTOMAONWAEZWKZVVAONPHKDUMIUVMEMIYMMFORKIVRUPNIVPKRQEPDNYUHMDZIUMVHKVNIAEKROIQFARKHQQAVZTZZMPPGPHURAVQFNITMCEBSYKMEILSEOQTITIBTUHLACDJIBRBQXHLQVMSIUZQSKRYIKTOJMVMNKOHRVF");
|
||||
jTAKrypto.addKeyListener(new KeyAdapter() {
|
||||
public void keyTyped(KeyEvent evt) {
|
||||
jTAKrypto_KeyTyped(evt);
|
||||
}
|
||||
});
|
||||
cp.add(jTAKryptoScrollPane);
|
||||
|
||||
jTAKlartextScrollPane.setBounds(16, 480, 665, 105);
|
||||
jTAKlartext.setLineWrap(true);
|
||||
jTAKlartext.setFont(new Font("Courier New", Font.BOLD, 16));
|
||||
cp.add(jTAKlartextScrollPane);
|
||||
jLKryptotext.setText("Kryptotext");
|
||||
jLKryptotext.setBounds(16, 3, 110, 20);
|
||||
cp.add(jLKryptotext);
|
||||
jLKlartext.setText("Klartext");
|
||||
jLKlartext.setBounds(16, 456, 110, 20);
|
||||
cp.add(jLKlartext);
|
||||
jLCopyright.setText("(cc) Schaller (ZPG Informatik) - V1.0 (2017)");
|
||||
jLCopyright.setBounds(128, 584, 419, 33);
|
||||
jLCopyright.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
jLCopyright.setFont(new Font("Dialog", Font.PLAIN, 12));
|
||||
cp.add(jLCopyright);
|
||||
|
||||
// -------------------------------- Tab 1 ---------------------------------------------
|
||||
JPanel tab1 = new JPanel();
|
||||
tab1.setLayout(null);
|
||||
lv = -1; lb = -1; rv = -1; rb=-1;
|
||||
jTAKorrelationScrollPane.setBounds(16, 40, 320, 110);
|
||||
jTAKorrelationScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
|
||||
jTAKorrelation.setText(jTAKrypto.getText());
|
||||
jTAKorrelation.setLineWrap(true);
|
||||
jTAKorrelation.setEditable(false);
|
||||
jTAKorrelation.setEnabled(true);
|
||||
jTAKorrelation.setFont(new Font("Courier New", Font.BOLD, 16));
|
||||
jTAKorrelation.addMouseListener(new MouseListener() {
|
||||
public void mousePressed(MouseEvent e) {
|
||||
removeSearchHighlight();
|
||||
}
|
||||
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
addSearchHighlight();
|
||||
}
|
||||
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
}
|
||||
|
||||
public void mouseExited(MouseEvent e) {
|
||||
}
|
||||
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
tab1.add(jTAKorrelationScrollPane);
|
||||
jTAKorrelation2ScrollPane.setBounds(340, 40, 320, 110);
|
||||
jTAKorrelation2ScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
|
||||
jTAKorrelation2.setText(jTAKrypto.getText());
|
||||
jTAKorrelation2.setLineWrap(true);
|
||||
jTAKorrelation2.setEditable(false);
|
||||
jTAKorrelation2.setEnabled(true);
|
||||
jTAKorrelation2.setFont(new Font("Courier New", Font.BOLD, 16));
|
||||
jTAKorrelation2.addMouseListener(new MouseListener() {
|
||||
public void mousePressed(MouseEvent e) {
|
||||
//removeSearchHighlight();
|
||||
}
|
||||
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
//addSearchHighlight();
|
||||
}
|
||||
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
}
|
||||
|
||||
public void mouseExited(MouseEvent e) {
|
||||
}
|
||||
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
selectHighlight();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
tab1.add(jTAKorrelation2ScrollPane);
|
||||
|
||||
|
||||
JLabel l = new JLabel();
|
||||
l.setBounds(350, 155, 162, 20);
|
||||
l.setText("Vermutete Schlüssellänge:");
|
||||
tab1.add(l);
|
||||
|
||||
jSpVerschiebung.setBounds(520, 152, 41, 25);
|
||||
jSpVerschiebung.setValue(1);
|
||||
jSpVerschiebung.setModel(jSpVerschiebungModel);
|
||||
jSpVerschiebung.addChangeListener(new ChangeListener() {
|
||||
public void stateChanged(ChangeEvent evt) {
|
||||
jSpVerschiebung_StateChanged(evt);
|
||||
}
|
||||
});
|
||||
tab1.add(jSpVerschiebung);
|
||||
|
||||
|
||||
lVerschiebung.setBounds(200, 10, 310, 20);
|
||||
lVerschiebung.setText("Angriff auf die Schlüssellänge mit Kasiski-Test");
|
||||
tab1.add(lVerschiebung);
|
||||
l = new JLabel();
|
||||
l.setBounds(14, 177, 640, 80);
|
||||
l.setText("<html>Markiere im linken Textfeld eine Buchstabenfolge. Wird diese dunkel kommt sie mehrmals im Text vor. Suche sie im rechten Textfeld und wähle ein Auftreten aus. Du siehst dann, wie weit die beiden auseinander liegen. Wiederhole dies mehrfach. Die Primfaktoren, die häufig vorkommen, stecken dann vermutlich auch in der Schlüssellänge. Stelle die Schlüssellänge entsprechend ein und gehe zu Schritt 2.</html>");
|
||||
tab1.add(l);
|
||||
lAnzahlgleicherBuchstaben.setBounds(16, 155, 300, 20);
|
||||
lAnzahlgleicherBuchstaben.setText("Abstand: ");
|
||||
lAnzahlgleicherBuchstaben.setHorizontalAlignment(JLabel.CENTER);
|
||||
tab1.add(lAnzahlgleicherBuchstaben);
|
||||
|
||||
jButtonKas.setBounds(16, 10, 150, 25); // neu mkl
|
||||
jButtonKas.setText("Text übernehmen");
|
||||
jButtonKas.setMargin(new Insets(2, 2, 2, 2));
|
||||
jButtonKas.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent evt) {
|
||||
jButtonKas_ActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
tab1.add(jButtonKas);
|
||||
// ---------------------------------- Tab 2 -------------------------------
|
||||
JPanel tab2 = new JPanel();
|
||||
tab2.setLayout(null);
|
||||
|
||||
l = new JLabel();
|
||||
l.setBounds(16, 10, 310, 20);
|
||||
l.setText("Angriff auf die Teiltexte mit Häufigkeitsanalyse");
|
||||
tab2.add(l);
|
||||
|
||||
l = new JLabel();
|
||||
l.setBounds(380, 10, 300, 25);
|
||||
l.setText("Buchstabenhäufigkeit Deutsch");
|
||||
tab2.add(l);
|
||||
|
||||
l = new JLabel();
|
||||
l.setBounds(16, 40, 300, 25);
|
||||
l.setText("Schlüssel");
|
||||
tab2.add(l);
|
||||
|
||||
l = new JLabel();
|
||||
l.setBounds(16, 100, 300, 100);
|
||||
l.setText("<html>Versuche den Schlüssel zu knacken, indem du in jedem Teiltext die Häufigkeitsverteilung der Buchstaben mit der üblichen Häufigkeitsverteilung in deutschen Texten in Einklang bringst.</html>");
|
||||
tab2.add(l);
|
||||
|
||||
double[] h = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
|
||||
bdText.setBounds(380,40,300,180);
|
||||
bdText.setHaeufigkeit(h);
|
||||
tab2.add(bdText);
|
||||
|
||||
jButton1.setBounds(16, 210, 193, 25);
|
||||
jButton1.setText("Entschlüsselung versuchen");
|
||||
jButton1.setMargin(new Insets(2, 2, 2, 2));
|
||||
jButton1.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent evt) {
|
||||
jButton1_ActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
tab2.add(jButton1);
|
||||
|
||||
|
||||
|
||||
// Ende Komponenten
|
||||
buchstabe = new JTextField[26];
|
||||
for (int i = 0; i<26 ;i++ ) {
|
||||
buchstabe[i] = new JTextField();
|
||||
buchstabe[i].setBounds(16+i*25, 65, 25, 25);
|
||||
buchstabe[i].setText("A");
|
||||
buchstabe[i].setHorizontalAlignment(SwingConstants.CENTER);
|
||||
buchstabe[i].setVisible(false);
|
||||
buchstabe[i].addFocusListener(new FocusAdapter() {
|
||||
public void focusGained(FocusEvent evt) {
|
||||
highlightKryptotext(evt);
|
||||
}
|
||||
});
|
||||
buchstabe[i].addKeyListener(new KeyAdapter() {
|
||||
public void keyReleased(KeyEvent e) {
|
||||
e.consume();
|
||||
}
|
||||
|
||||
public void keyTyped(KeyEvent e) {
|
||||
e.consume();
|
||||
}
|
||||
|
||||
public void keyPressed(KeyEvent e) {
|
||||
JTextField textField = (JTextField) e.getSource();
|
||||
String text = textField.getText();
|
||||
if ((e.getKeyChar()>='a' && e.getKeyChar()<='z') ||(e.getKeyChar()>='A' && e.getKeyChar()<='Z')) {
|
||||
text = ""+e.getKeyChar();
|
||||
}
|
||||
if (e.getKeyChar()==' ' || e.getKeyChar() == KeyEvent.VK_BACK_SPACE || e.getKeyChar() == KeyEvent.VK_DELETE) {
|
||||
text = "";
|
||||
|
||||
} // end of if
|
||||
textField.setText(text.toUpperCase());
|
||||
e.consume();
|
||||
if (textField.getText().length()>0) {
|
||||
bdText.setVerschiebung((int) textField.getText().charAt(0)-65);
|
||||
|
||||
} else {
|
||||
bdText.setVerschiebung(0);
|
||||
} // end of if-else
|
||||
bdText.repaint();
|
||||
|
||||
} // end of if
|
||||
|
||||
});
|
||||
|
||||
tab2.add(buchstabe[i]);
|
||||
} // end of for
|
||||
|
||||
JTabbedPane tabpane = new JTabbedPane
|
||||
(JTabbedPane.TOP,JTabbedPane.SCROLL_TAB_LAYOUT );
|
||||
tabpane.setBounds(10,140,672,290);
|
||||
|
||||
tabpane.addTab("Schritt 1", tab1);
|
||||
tabpane.addTab("Schritt 2", tab2);
|
||||
cp.add(tabpane);
|
||||
|
||||
setResizable(false);
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Anfang Methoden
|
||||
|
||||
public void jButtonKas_ActionPerformed(ActionEvent evt) { // neu mkl
|
||||
//String krypttext = jTAKrypto.getText().toUpperCase();
|
||||
jTAKorrelation.setText(jTAKrypto.getText().toUpperCase());
|
||||
jTAKorrelation2.setText(jTAKrypto.getText().toUpperCase());
|
||||
jTAKlartext.setText("");
|
||||
}
|
||||
|
||||
public void jButton1_ActionPerformed(ActionEvent evt) {
|
||||
String krypttext = jTAKrypto.getText().toUpperCase();
|
||||
String klartext="";
|
||||
int c = 0;
|
||||
int diff = (Integer) jSpVerschiebung.getValue();
|
||||
for (int i=0;i<krypttext.length() ;i++ ) {
|
||||
int asc = krypttext.charAt(i);
|
||||
if (asc != 10) {
|
||||
String z = buchstabe[c%diff].getText().toUpperCase();
|
||||
if (z.equals("")) {
|
||||
klartext += "*";
|
||||
} else {
|
||||
int v = (int) z.charAt(0)-65;
|
||||
asc = (asc-65-v+26)%26+65;
|
||||
klartext += (char) asc;
|
||||
} // end of if
|
||||
c++;
|
||||
}
|
||||
|
||||
} // end of for
|
||||
jTAKlartext.setText(klartext);
|
||||
} // end of jButton1_ActionPerformed
|
||||
|
||||
|
||||
|
||||
|
||||
public void highlightKryptotext(FocusEvent evt) {
|
||||
int start, diff;
|
||||
for (start = 0; start < 26 ; start++) {
|
||||
if (buchstabe[start] == evt.getSource()) {
|
||||
break;
|
||||
} // end of if-else
|
||||
} // end of for
|
||||
jBBuchstabe.setText("Buchstabenhäufigkeit Deutsch");
|
||||
|
||||
diff = (Integer) jSpVerschiebung.getValue();
|
||||
Highlighter h1 = jTAKrypto.getHighlighter();
|
||||
h1.removeAllHighlights();
|
||||
int c = 0;
|
||||
String krypto = jTAKrypto.getText().toUpperCase();
|
||||
double[] h = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
|
||||
try{
|
||||
for (int i=0;i<krypto.length() ;i++) {
|
||||
int asc = (int)krypto.charAt(i);
|
||||
if (asc!=10) {
|
||||
|
||||
if (c%diff == start) {
|
||||
h1.addHighlight(i, i+1,
|
||||
new DefaultHighlighter.DefaultHighlightPainter(new Color(100,100,255)));
|
||||
if (asc>=65 && asc<=90) {
|
||||
h[asc-65]++;
|
||||
}
|
||||
} // end of if
|
||||
c++;
|
||||
} // end of if
|
||||
}
|
||||
bdText.setHaeufigkeit(h);
|
||||
if (buchstabe[start].getText().length()>0) {
|
||||
bdText.setVerschiebung((int) buchstabe[start].getText().charAt(0)-65);
|
||||
|
||||
} else {
|
||||
bdText.setVerschiebung(0);
|
||||
} // end of if-else
|
||||
bdText.repaint();
|
||||
} catch(BadLocationException e) {}
|
||||
}
|
||||
|
||||
|
||||
public void addSearchHighlight() {
|
||||
String search = jTAKorrelation.getSelectedText();
|
||||
if (search !=null) {
|
||||
lv = jTAKorrelation.getSelectionStart();
|
||||
lb = jTAKorrelation.getSelectionEnd();
|
||||
Highlighter h2 = jTAKorrelation.getHighlighter();
|
||||
h2.removeAllHighlights();
|
||||
try{
|
||||
|
||||
search = search.toUpperCase();
|
||||
System.out.println(search);
|
||||
|
||||
Highlighter h1 = jTAKorrelation2.getHighlighter();
|
||||
h1.removeAllHighlights();
|
||||
String krypto = jTAKorrelation.getText().toUpperCase();
|
||||
|
||||
int c = krypto.indexOf(search,0);
|
||||
int anz = 0;
|
||||
while (c>=0) {
|
||||
h1.addHighlight(c, c+search.length(),
|
||||
new DefaultHighlighter.DefaultHighlightPainter(new Color(200,200,255)));
|
||||
anz++;
|
||||
c = krypto.indexOf(search, c+1);
|
||||
} // end of while
|
||||
if (anz>1){
|
||||
h2.addHighlight(lv, lv+search.length(),
|
||||
new DefaultHighlighter.DefaultHighlightPainter(new Color(100,100,255)));
|
||||
} else {
|
||||
h2.addHighlight(lv, lv+search.length(),
|
||||
new DefaultHighlighter.DefaultHighlightPainter(new Color(200,200,255)));
|
||||
} // end of if-else
|
||||
|
||||
|
||||
|
||||
} catch(BadLocationException e) {}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public ArrayList<Integer> primfaktoren(int zahl) {
|
||||
int w = 2;
|
||||
ArrayList<Integer> list = new ArrayList<Integer>();
|
||||
while (zahl != 1) {
|
||||
if(zahl % w == 0) {
|
||||
list.add(w);
|
||||
zahl /= w;
|
||||
}
|
||||
else {
|
||||
w++;
|
||||
} // end of if-else
|
||||
|
||||
|
||||
} // end of while
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
public void selectHighlight() {
|
||||
int caretpos = jTAKorrelation2.getCaretPosition();
|
||||
Highlighter h2 = jTAKorrelation2.getHighlighter();
|
||||
Highlighter.Highlight[] highlights = h2.getHighlights();
|
||||
for (Highlighter.Highlight h : highlights) {
|
||||
if(caretpos >= h.getStartOffset() && caretpos < h.getEndOffset())
|
||||
{
|
||||
int diff = Math.abs(lv - h.getStartOffset());
|
||||
if (diff == 0) {
|
||||
lAnzahlgleicherBuchstaben.setText("Abstand: "+diff);
|
||||
|
||||
} else {
|
||||
lAnzahlgleicherBuchstaben.setText("Abstand: "+diff+" => Primfaktoren "+ primfaktoren(diff).toString());
|
||||
|
||||
} // end of if-else
|
||||
|
||||
}
|
||||
|
||||
} // end of for
|
||||
}
|
||||
|
||||
|
||||
public void removeSearchHighlight() {
|
||||
Highlighter h1 = jTAKorrelation.getHighlighter();
|
||||
h1.removeAllHighlights();
|
||||
lAnzahlgleicherBuchstaben.setText("Abstand: ");
|
||||
}
|
||||
|
||||
|
||||
public void jSpVerschiebung_StateChanged(ChangeEvent evt) {
|
||||
|
||||
int v = (Integer) (jSpVerschiebung.getValue());
|
||||
|
||||
|
||||
for (int i=0; i<buchstabe.length ;i++ ) {
|
||||
if (i<v) {
|
||||
buchstabe[i].setVisible(true);
|
||||
} else {
|
||||
buchstabe[i].setVisible(false);
|
||||
|
||||
} // end of if-else
|
||||
} // end of for
|
||||
|
||||
} // end of jSpVerschiebung_StateChanged
|
||||
|
||||
public void jTAKrypto_KeyTyped(KeyEvent evt) {
|
||||
//jSpVerschiebung_StateChanged(null);
|
||||
|
||||
} // end of jTAKrypto_KeyTyped
|
||||
|
||||
public void jTAKrypto_InputMethodTextChanged(InputMethodEvent evt) {
|
||||
jSpVerschiebung_StateChanged(null);
|
||||
|
||||
} // end of jTAKrypto_InputMethodTextChanged
|
||||
|
||||
public void jTAKrypto_FocusGained(FocusEvent evt) {
|
||||
// TODO hier Quelltext einfügen
|
||||
|
||||
} // end of jTAKrypto_FocusGained
|
||||
|
||||
// Ende Methoden
|
||||
|
||||
public static void main(String[] args) {
|
||||
new BreakVigenere("BreakVigenere");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,578 @@
|
|||
object breakVigenere: TFGUIForm
|
||||
Left = 127
|
||||
Top = 0
|
||||
BorderIcons = [biSystemMenu]
|
||||
Caption = 'BreakVigenere'
|
||||
ClientHeight = 624
|
||||
ClientWidth = 997
|
||||
Color = clBtnFace
|
||||
Font.Charset = DEFAULT_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -10
|
||||
Font.Name = 'MS Sans Serif'
|
||||
Font.Style = []
|
||||
FormStyle = fsStayOnTop
|
||||
OldCreateOrder = True
|
||||
Position = poDesigned
|
||||
ShowHint = True
|
||||
Visible = True
|
||||
WindowState = wsMaximized
|
||||
OnClose = FormClose
|
||||
OnCloseQuery = FormCloseQuery
|
||||
OnResize = FormResize
|
||||
FrameType = 5
|
||||
Resizable = False
|
||||
Undecorated = False
|
||||
Background = clBtnFace
|
||||
PixelsPerInch = 96
|
||||
TextHeight = 13
|
||||
object jButton1: TJButton
|
||||
Tag = 4
|
||||
Left = 216
|
||||
Top = 440
|
||||
Width = 241
|
||||
Height = 25
|
||||
Hint = 'jButton1'
|
||||
Foreground = 3355443
|
||||
Background = 15658734
|
||||
Font.Charset = DEFAULT_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -12
|
||||
Font.Name = 'Dialog'
|
||||
Font.Style = [fsBold]
|
||||
actionPerformed = 'jButton1_ActionPerformed'
|
||||
Text = 'Entschl'#252'sselung versuchen'
|
||||
Mnemonic = 0
|
||||
DisplayedMnemonicIndex = 0
|
||||
Selected = False
|
||||
BorderPainted = True
|
||||
FocusPainted = False
|
||||
ContentAreaFilled = True
|
||||
HorizontalAlignment = CENTER
|
||||
VerticalAlignment = CENTER
|
||||
HorizontalTextPosition = RIGHT
|
||||
VerticalTextPosition = CENTER
|
||||
IconTextGap = 4
|
||||
RolloverEnabled = False
|
||||
Border.BorderType = NoBorder
|
||||
Border.LineColor = clBlack
|
||||
Border.LineThickness = 0
|
||||
Border.LineRounded = False
|
||||
Border.EtchHighlightColor = clBlack
|
||||
Border.EtchShadowColor = clBlack
|
||||
Border.Etchtype = 0
|
||||
Border.BevelHighlightColor = clBlack
|
||||
Border.BevelShadowColor = clBlack
|
||||
Border.Beveltype = 0
|
||||
Border.MatteColor = clBlack
|
||||
Border.MatteTop = 0
|
||||
Border.MatteLeft = 0
|
||||
Border.MatteBottom = 0
|
||||
Border.MatteRight = 0
|
||||
end
|
||||
object jTable1: TJTable
|
||||
Tag = 19
|
||||
Left = 656
|
||||
Top = 408
|
||||
Width = 193
|
||||
Height = 89
|
||||
Hint = 'jTable1'
|
||||
Foreground = clWindowText
|
||||
Background = clWhite
|
||||
Font.Charset = GB2312_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -12
|
||||
Font.Name = '@Fixedsys'
|
||||
Font.Style = []
|
||||
RowHeight = 16
|
||||
ShowHorizontalLines = True
|
||||
ShowVerticalLines = True
|
||||
ShowGrid = True
|
||||
Columns.Strings = (
|
||||
'Title 1'
|
||||
'Title 2'
|
||||
'Title 3'
|
||||
'Title 4'
|
||||
'Title 5')
|
||||
ColCount = 5
|
||||
RowCount = 5
|
||||
FillsViewportHeight = False
|
||||
AutoCreateRowSorter = False
|
||||
RowSelectionAllowed = True
|
||||
ColumnSelectionAllowed = False
|
||||
CellSelectionEnabled = False
|
||||
DragEnabled = False
|
||||
HorizontalScrollBarPolicy = AS_NEEDED
|
||||
VerticalScrollBarPolicy = AS_NEEDED
|
||||
end
|
||||
object jTable2: TJTable
|
||||
Tag = 19
|
||||
Left = 712
|
||||
Top = 192
|
||||
Width = 201
|
||||
Height = 81
|
||||
Hint = 'jTable2'
|
||||
Foreground = 3355443
|
||||
Background = clWhite
|
||||
Font.Charset = DEFAULT_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -12
|
||||
Font.Name = 'Dialog'
|
||||
Font.Style = []
|
||||
RowHeight = 16
|
||||
ShowHorizontalLines = True
|
||||
ShowVerticalLines = True
|
||||
ShowGrid = True
|
||||
Columns.Strings = (
|
||||
'Title 1'
|
||||
'Title 2'
|
||||
'Title 3'
|
||||
'Title 4'
|
||||
'Title 5')
|
||||
ColCount = 5
|
||||
RowCount = 5
|
||||
FillsViewportHeight = False
|
||||
AutoCreateRowSorter = False
|
||||
RowSelectionAllowed = True
|
||||
ColumnSelectionAllowed = False
|
||||
CellSelectionEnabled = False
|
||||
DragEnabled = False
|
||||
HorizontalScrollBarPolicy = AS_NEEDED
|
||||
VerticalScrollBarPolicy = AS_NEEDED
|
||||
end
|
||||
object jTable3: TJTable
|
||||
Tag = 19
|
||||
Left = 728
|
||||
Top = 88
|
||||
Width = 193
|
||||
Height = 57
|
||||
Hint = 'jTable3'
|
||||
Foreground = 3355443
|
||||
Background = clWhite
|
||||
Font.Charset = DEFAULT_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -12
|
||||
Font.Name = 'Dialog'
|
||||
Font.Style = []
|
||||
RowHeight = 16
|
||||
ShowHorizontalLines = True
|
||||
ShowVerticalLines = True
|
||||
ShowGrid = True
|
||||
Columns.Strings = (
|
||||
'Title 1'
|
||||
'Title 2'
|
||||
'Title 3'
|
||||
'Title 4'
|
||||
'Title 5')
|
||||
ColCount = 5
|
||||
RowCount = 5
|
||||
FillsViewportHeight = False
|
||||
AutoCreateRowSorter = False
|
||||
RowSelectionAllowed = True
|
||||
ColumnSelectionAllowed = False
|
||||
CellSelectionEnabled = False
|
||||
DragEnabled = False
|
||||
HorizontalScrollBarPolicy = AS_NEEDED
|
||||
VerticalScrollBarPolicy = AS_NEEDED
|
||||
end
|
||||
object jBBuchstabe: TJButton
|
||||
Tag = 4
|
||||
Left = 248
|
||||
Top = 232
|
||||
Width = 193
|
||||
Height = 25
|
||||
Hint = 'jButton2'
|
||||
Foreground = 3355443
|
||||
Background = 15658734
|
||||
Font.Charset = DEFAULT_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -12
|
||||
Font.Name = 'Dialog'
|
||||
Font.Style = [fsBold]
|
||||
actionPerformed = 'jBBuchstabe_ActionPerformed'
|
||||
Text = 'Buchstabenh'#228'ufigkeit'
|
||||
Mnemonic = 0
|
||||
DisplayedMnemonicIndex = 0
|
||||
Selected = False
|
||||
BorderPainted = True
|
||||
FocusPainted = False
|
||||
ContentAreaFilled = True
|
||||
HorizontalAlignment = CENTER
|
||||
VerticalAlignment = CENTER
|
||||
HorizontalTextPosition = RIGHT
|
||||
VerticalTextPosition = CENTER
|
||||
IconTextGap = 4
|
||||
RolloverEnabled = False
|
||||
Border.BorderType = NoBorder
|
||||
Border.LineColor = clBlack
|
||||
Border.LineThickness = 0
|
||||
Border.LineRounded = False
|
||||
Border.EtchHighlightColor = clBlack
|
||||
Border.EtchShadowColor = clBlack
|
||||
Border.Etchtype = 0
|
||||
Border.BevelHighlightColor = clBlack
|
||||
Border.BevelShadowColor = clBlack
|
||||
Border.Beveltype = 0
|
||||
Border.MatteColor = clBlack
|
||||
Border.MatteTop = 0
|
||||
Border.MatteLeft = 0
|
||||
Border.MatteBottom = 0
|
||||
Border.MatteRight = 0
|
||||
end
|
||||
object jBBigramm: TJButton
|
||||
Tag = 4
|
||||
Left = 680
|
||||
Top = 264
|
||||
Width = 201
|
||||
Height = 25
|
||||
Hint = 'jButton3'
|
||||
Foreground = 3355443
|
||||
Background = 15658734
|
||||
Font.Charset = DEFAULT_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -12
|
||||
Font.Name = 'Dialog'
|
||||
Font.Style = [fsBold]
|
||||
actionPerformed = 'jBBigramm_ActionPerformed'
|
||||
Text = 'Bigramm-H'#228'ufigkeit'
|
||||
Mnemonic = 0
|
||||
DisplayedMnemonicIndex = 0
|
||||
Selected = False
|
||||
BorderPainted = True
|
||||
FocusPainted = False
|
||||
ContentAreaFilled = True
|
||||
HorizontalAlignment = CENTER
|
||||
VerticalAlignment = CENTER
|
||||
HorizontalTextPosition = RIGHT
|
||||
VerticalTextPosition = CENTER
|
||||
IconTextGap = 4
|
||||
RolloverEnabled = False
|
||||
Border.BorderType = NoBorder
|
||||
Border.LineColor = clBlack
|
||||
Border.LineThickness = 0
|
||||
Border.LineRounded = False
|
||||
Border.EtchHighlightColor = clBlack
|
||||
Border.EtchShadowColor = clBlack
|
||||
Border.Etchtype = 0
|
||||
Border.BevelHighlightColor = clBlack
|
||||
Border.BevelShadowColor = clBlack
|
||||
Border.Beveltype = 0
|
||||
Border.MatteColor = clBlack
|
||||
Border.MatteTop = 0
|
||||
Border.MatteLeft = 0
|
||||
Border.MatteBottom = 0
|
||||
Border.MatteRight = 0
|
||||
end
|
||||
object jBDoppel: TJButton
|
||||
Tag = 4
|
||||
Left = 752
|
||||
Top = 200
|
||||
Width = 193
|
||||
Height = 25
|
||||
Hint = 'jButton4'
|
||||
Foreground = 3355443
|
||||
Background = 15658734
|
||||
Font.Charset = DEFAULT_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -12
|
||||
Font.Name = 'Dialog'
|
||||
Font.Style = [fsBold]
|
||||
actionPerformed = 'jBDoppel_ActionPerformed'
|
||||
Text = 'Doppelbuchstaben-H'#228'ufigkeit'
|
||||
Mnemonic = 0
|
||||
DisplayedMnemonicIndex = 0
|
||||
Selected = False
|
||||
BorderPainted = True
|
||||
FocusPainted = False
|
||||
ContentAreaFilled = True
|
||||
HorizontalAlignment = CENTER
|
||||
VerticalAlignment = CENTER
|
||||
HorizontalTextPosition = RIGHT
|
||||
VerticalTextPosition = CENTER
|
||||
IconTextGap = 4
|
||||
RolloverEnabled = False
|
||||
Border.BorderType = NoBorder
|
||||
Border.LineColor = clBlack
|
||||
Border.LineThickness = 0
|
||||
Border.LineRounded = False
|
||||
Border.EtchHighlightColor = clBlack
|
||||
Border.EtchShadowColor = clBlack
|
||||
Border.Etchtype = 0
|
||||
Border.BevelHighlightColor = clBlack
|
||||
Border.BevelShadowColor = clBlack
|
||||
Border.Beveltype = 0
|
||||
Border.MatteColor = clBlack
|
||||
Border.MatteTop = 0
|
||||
Border.MatteLeft = 0
|
||||
Border.MatteBottom = 0
|
||||
Border.MatteRight = 0
|
||||
end
|
||||
object jTAKrypto: TJTextArea
|
||||
Tag = 3
|
||||
Left = 16
|
||||
Top = 24
|
||||
Width = 665
|
||||
Height = 105
|
||||
Cursor = crIBeam
|
||||
Hint = 'jTextArea1'
|
||||
Foreground = clWindowText
|
||||
Background = clWhite
|
||||
Font.Charset = ANSI_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -16
|
||||
Font.Name = 'Courier New'
|
||||
Font.Style = [fsBold]
|
||||
focusGained = 'jTAKrypto_FocusGained'
|
||||
inputMethodTextChanged = 'jTextArea1_InputMethodTextChanged'
|
||||
keyTyped = 'jTextArea1_KeyTyped'
|
||||
LineWrap = True
|
||||
HorizontalScrollBarPolicy = AS_NEEDED
|
||||
VerticalScrollBarPolicy = AS_NEEDED
|
||||
WrapStyleWord = False
|
||||
TabSize = 8
|
||||
Text.Strings = (
|
||||
|
||||
'JMLQMFNSKIOQNXGYZOQEBJLUKXHFCXGVLGBMREAJZCAEKVIFOWJLMFGJLPQZJIYH' +
|
||||
'QQHYJLAFGFLRLQYESTPMHIAWQZFIPPMZMIZGPDOIIIVGTHIIQVKHLVHQOPLNMIKM' +
|
||||
'SWCYKMUIVBREADEQOXLVVMILSMVWYZLVAONSIIVIKVKIVPOIZIEGXHLHCDILKIVP' +
|
||||
'KYAWKTKRIIVQJMRXQZKVHFBVULHRVQYXYMBTKQPYAUSNHLZUSJUJBQTFHRLEKMUI' +
|
||||
'AUTPHXMUTMZGPQXWWVIONINIAONVPIJQTIUWMONWIRLUMIUAMDQIZTWXEKYEXTOE' +
|
||||
'LPQNXMZIFEKGOWJONIYDCDVSSCODGTOMMMTKLKMNKRPRLQSRHGPEKMUIUFUHLZMD' +
|
||||
'LJLRBXOGOXMZHYJLAONPBKMDBSYRIONNLHMYKMUDMXTIUOTMXXLBBNAGOWBMHIUD' +
|
||||
'CYTGOWBQTESTPMHIAMVEKMUIZFGFBPINKVGYOQNIUYVPYSHPTQBIYJONGVLRIXVL' +
|
||||
'HFMFKEBWHGTYADMZJETMBQXJHRLQXHPIXDUKYIAEOZLTWXEESTPMHIAMAONIJLQR' +
|
||||
'LVPIZGTKHFMDKWDEZZUGOIQZLIZXMEBIYJITXIUSPZKWJLTEYISHQQYIYACDJIPQ' +
|
||||
'RMNVCSUUZESMMZOWJLMZQVFTBARSNIVSOSCEVNGXAMAFGFLPTMYSJEQZLSYQMUTI' +
|
||||
'ZZWYBIYWKTRWZPMDLVLMHGCLSIVPKRRIVZCSYXAAJIYIQZKWRIVZYEADMEBSYKME' +
|
||||
'ILSEOQTKLVVQARKOZKVXVKZMVLPWKTYGOAIONHHPMUILADCQXVHXMZCYYHMZJETE' +
|
||||
'TEREAIQZOWJLMEORUWXDILLFMZAXGXEUKFLMABOISWEQOWLZQDZZAMWYTMHTIDKR' +
|
||||
'AETXKWNIPAXGOXLQXXJLBUMOLMBPOIIYKTYXHFMZJIZOMZTWHXHQYFLWBUSQLRLU' +
|
||||
'KVLMPQTJVPOQORKIZPOICIZEILPILQTIUETBNEIIBQGYZHMDZEIYTMGYZKMINPAA'
|
||||
|
||||
'MDJIUQAEKRZMVPGPSIDQXFYECONXHPAAKMUQIXHIUYBLZAVVLQTLPIZZGGOOTMXX' +
|
||||
'LBBNAGOWBMHIUWWNKKPRVFSEUAQQJIYZWZBSYRMENEUHMXZWPGPEUQPXCYKMUIXQ' +
|
||||
'XMVHQEILLTWXEESTPMHIAMAONIZYJEZMAYBUURTMBUSFLMABOISIQZKVWIZUUHLZ' +
|
||||
'WZCLYIVPZVPXPQSMBWAUILHYNHKVZGPAHIUIAFGRKEZPGPWLINKXLFMEILYRSFKE' +
|
||||
'SWWPOINIEANRAIIXVLHFMFOWJLMDKMOIVRUPNILQXFBGPEZEIIVHKVDIVPKXLFMX' +
|
||||
'REZSJQXIPXAHKVDVNQRXLETBNEIIBQJMLIZMRPLVLUTKZMVHUPBXWDOWJLETRXLF' +
|
||||
'MUJIUQWZUESTPMHIAMAONIUWCNYXPXCFOSUWUQZLVHMZCEYHQQYWJLWZYIPXTMTK' +
|
||||
'LQJXOGOKZGTHZXHXOGOLIFZIKMMEHIYIQFYMTNITXESWWXGRNIDAXXYMBTKQPYAG' +
|
||||
'THIITXGWVHMDOXHPQQTMZGPQMISIPDZISIWZHEAXQEZEHPJQXXPIUBLSOPMZKVZG' +
|
||||
'PXAKCSZPOIHPXTGFLXMZGGONMIKMSWLDKMVHMDBMLVEDZIYRHGCIJLAQRRHPAYKG' +
|
||||
'OEVUYGOIATOPMWUUZXLPPMZXLIZTOIYDCPOIUEKTOLTFMZGRUXMMRFLVBUYGOIQN' +
|
||||
'KIYJCZJIUIQZKGOMNRXMLVAONIPFMNKWAIPQTHGYUQOWAECEFALMZGTHLRUQZESP' +
|
||||
'AONIPFMZJMLECRKMUIZSKQLMVEGQLRIONWLWQFFIUYVPYSCIZNARKIVEORKHIEYW' +
|
||||
'PGPPOIRPMUTIYIIGLHLVODKVLRLDKLLRSMTRUEPQFYLMVVGLYLCZJIYXABZIYMUV' +
|
||||
'GLYZMDGPSKMYKMUIZFKHLVVQGTVPQFGRPWKTKKLPMTXXLKQABEURQNGXAMAFGHLP' +
|
||||
'TMVSYXIMRFLVBUYZLVEDLISXMMRTOEJQZIBRLNKPSEAAYOLRVIUVAYVPYGOYNPOI'
|
||||
|
||||
'WSTKGPWLINKXPWKTKGOMNRXMLVCZMQPXDQXAYJMXZITETBNEIIBGTHZGPXYWLPPU' +
|
||||
'KVGYEGXHLETNKVAMAEILLMJQHIUYBLZHPIVMILQILQSFBGPEZEIIVLAHYIPQTAHV' +
|
||||
'QYPEOVODOJMHMDLVHRHAYIIPIUYIKIDUMIUVMBUVAEAUJILECRARKWKTRYNZWDYX' +
|
||||
'HXBPKVHPJQXXPWKTKMIILUKXHFCXGVLGBMJIZXZUZLLQQGYDBZMDCIUHMZJEIIQM' +
|
||||
'HIYEVPKVZETEOQVVQSORHPDQXAYJMXZIHPXTGFLXMQORGYBDGKLRLUKWLVSDETAS' +
|
||||
'ODGTOMAONWAEZWKZVVAONPHKDUMIUVMEMIYMMFORKIVRUPNIVPKRQEPDNYUHMDZI' +
|
||||
'UMVHKVNIAEKROIQFARKHQQAVZTZZMPPGPHURAVQFNITMCEBSYKMEILSEOQTITIBT' +
|
||||
'UHLACDJIBRBQXHLQVMSIUZQSKRYIKTOJMVMNKOHRVF')
|
||||
Editable = True
|
||||
end
|
||||
object jTextArea2: TJTextArea
|
||||
Tag = 3
|
||||
Left = 8
|
||||
Top = 480
|
||||
Width = 673
|
||||
Height = 105
|
||||
Cursor = crIBeam
|
||||
Hint = 'jTextArea2'
|
||||
Foreground = clWindowText
|
||||
Background = clWhite
|
||||
Font.Charset = ANSI_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -16
|
||||
Font.Name = 'Courier New'
|
||||
Font.Style = [fsBold]
|
||||
LineWrap = True
|
||||
HorizontalScrollBarPolicy = AS_NEEDED
|
||||
VerticalScrollBarPolicy = AS_NEEDED
|
||||
WrapStyleWord = False
|
||||
TabSize = 8
|
||||
Editable = True
|
||||
end
|
||||
object jLabel1: TJLabel
|
||||
Tag = 1
|
||||
Left = 16
|
||||
Top = 8
|
||||
Width = 110
|
||||
Height = 20
|
||||
Hint = 'jLabel1'
|
||||
Foreground = 3355443
|
||||
Background = clBtnFace
|
||||
Font.Charset = DEFAULT_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -12
|
||||
Font.Name = 'Dialog'
|
||||
Font.Style = [fsBold]
|
||||
Text = 'Kryptotext'
|
||||
HorizontalAlignment = LEFT
|
||||
VerticalAlignment = CENTER
|
||||
HorizontalTextPosition = RIGHT
|
||||
VerticalTextPosition = CENTER
|
||||
IconTextGap = 4
|
||||
DisplayedMnemonic = 0
|
||||
DisplayedMnemonicIndex = 0
|
||||
end
|
||||
object jLabel2: TJLabel
|
||||
Tag = 1
|
||||
Left = 8
|
||||
Top = 456
|
||||
Width = 110
|
||||
Height = 20
|
||||
Hint = 'jLabel1'
|
||||
Foreground = 3355443
|
||||
Background = clBtnFace
|
||||
Font.Charset = DEFAULT_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -12
|
||||
Font.Name = 'Dialog'
|
||||
Font.Style = [fsBold]
|
||||
Text = 'Klartext'
|
||||
HorizontalAlignment = LEFT
|
||||
VerticalAlignment = CENTER
|
||||
HorizontalTextPosition = RIGHT
|
||||
VerticalTextPosition = CENTER
|
||||
IconTextGap = 4
|
||||
DisplayedMnemonic = 0
|
||||
DisplayedMnemonicIndex = 0
|
||||
end
|
||||
object jLabel4: TJLabel
|
||||
Tag = 1
|
||||
Left = 128
|
||||
Top = 584
|
||||
Width = 419
|
||||
Height = 33
|
||||
Hint = 'jLabel4'
|
||||
Foreground = clWindowText
|
||||
Background = clBtnFace
|
||||
Font.Charset = DEFAULT_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -12
|
||||
Font.Name = 'Dialog'
|
||||
Font.Style = []
|
||||
Text = '(cc) Schaller (ZPG Informatik) - V1.0 (2017)'
|
||||
HorizontalAlignment = CENTER
|
||||
VerticalAlignment = CENTER
|
||||
HorizontalTextPosition = RIGHT
|
||||
VerticalTextPosition = CENTER
|
||||
IconTextGap = 4
|
||||
DisplayedMnemonic = 0
|
||||
DisplayedMnemonicIndex = 0
|
||||
end
|
||||
object jTAKorrelation: TJTextArea
|
||||
Tag = 3
|
||||
Left = 16
|
||||
Top = 160
|
||||
Width = 665
|
||||
Height = 57
|
||||
Cursor = crIBeam
|
||||
Hint = 'jTextArea3'
|
||||
Foreground = clWindowText
|
||||
Background = clWhite
|
||||
Font.Charset = ANSI_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -12
|
||||
Font.Name = 'Courier New'
|
||||
Font.Style = [fsBold]
|
||||
LineWrap = False
|
||||
HorizontalScrollBarPolicy = ALWAYS
|
||||
VerticalScrollBarPolicy = AS_NEEDED
|
||||
WrapStyleWord = False
|
||||
TabSize = 8
|
||||
Text.Strings = (
|
||||
'')
|
||||
Editable = False
|
||||
end
|
||||
object jSpVerschiebung: TJSpinner
|
||||
Tag = 22
|
||||
Left = 192
|
||||
Top = 232
|
||||
Width = 41
|
||||
Height = 25
|
||||
Hint = 'jSpinner1'
|
||||
Foreground = 3355443
|
||||
Background = clWhite
|
||||
Font.Charset = DEFAULT_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -12
|
||||
Font.Name = 'Dialog'
|
||||
Font.Style = [fsBold]
|
||||
stateChanged = 'jSpVerschiebung_StateChanged'
|
||||
Maximum = 99
|
||||
Minimum = 0
|
||||
StepSize = 1
|
||||
Value = '0'
|
||||
end
|
||||
object jNFAnzahlTreffer: TJNumberField
|
||||
Tag = 21
|
||||
Left = 192
|
||||
Top = 264
|
||||
Width = 41
|
||||
Height = 25
|
||||
Cursor = crIBeam
|
||||
Hint = 'jNumberField1'
|
||||
Foreground = 3355443
|
||||
Background = clWhite
|
||||
Font.Charset = DEFAULT_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -12
|
||||
Font.Name = 'Dialog'
|
||||
Font.Style = []
|
||||
HorizontalAlignment = LEFT
|
||||
Editable = False
|
||||
end
|
||||
object lVerschiebung: TJLabel
|
||||
Tag = 1
|
||||
Left = 16
|
||||
Top = 232
|
||||
Width = 110
|
||||
Height = 20
|
||||
Hint = 'jLabel3'
|
||||
Foreground = 3355443
|
||||
Background = clBtnFace
|
||||
Font.Charset = DEFAULT_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -12
|
||||
Font.Name = 'Dialog'
|
||||
Font.Style = [fsBold]
|
||||
Text = 'Verschiebung'
|
||||
HorizontalAlignment = LEFT
|
||||
VerticalAlignment = CENTER
|
||||
HorizontalTextPosition = RIGHT
|
||||
VerticalTextPosition = CENTER
|
||||
IconTextGap = 4
|
||||
DisplayedMnemonic = 0
|
||||
DisplayedMnemonicIndex = 0
|
||||
end
|
||||
object lAnzahlgleicherBuchstaben: TJLabel
|
||||
Tag = 1
|
||||
Left = 16
|
||||
Top = 264
|
||||
Width = 162
|
||||
Height = 20
|
||||
Hint = 'jLabel3'
|
||||
Foreground = 3355443
|
||||
Background = clBtnFace
|
||||
Font.Charset = DEFAULT_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -12
|
||||
Font.Name = 'Dialog'
|
||||
Font.Style = [fsBold]
|
||||
Text = 'Anzahl gleicher Buchstaben'
|
||||
HorizontalAlignment = LEFT
|
||||
VerticalAlignment = CENTER
|
||||
HorizontalTextPosition = RIGHT
|
||||
VerticalTextPosition = CENTER
|
||||
IconTextGap = 4
|
||||
DisplayedMnemonic = 0
|
||||
DisplayedMnemonicIndex = 0
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,210 @@
|
|||
// LineRenderer.java
|
||||
|
||||
// Copyright 2002 Regula Hoefer-Isenegger
|
||||
//
|
||||
// This file is part of The Java Turtle (TJT) package
|
||||
//
|
||||
// TJT 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
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// TJT 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 The Java Turtle Package; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package ch.aplu.turtle;
|
||||
|
||||
import ch.aplu.turtle.*;
|
||||
import java.awt.geom.*;
|
||||
/** This class is responsible for drawing the turtle's lines.
|
||||
|
||||
@author <a href="mailto:regula@hoefer.ch">Regula Hoefer-Isenegger</a>
|
||||
@version 0.1
|
||||
*/
|
||||
public class LineRenderer {
|
||||
private Point2D.Double point;
|
||||
private Turtle turtle;
|
||||
|
||||
LineRenderer(Turtle turtle) {
|
||||
this.point = new Point2D.Double();
|
||||
this.turtle = turtle;
|
||||
}
|
||||
|
||||
/** Initialisation with coordinates <code>x</code> and
|
||||
<code>y</code>.
|
||||
*/
|
||||
public void init(double x, double y) {
|
||||
this.point.setLocation(x, y);
|
||||
}
|
||||
/** Same as init(double x, double y), but with a Point2D.Double
|
||||
argument for convenience
|
||||
*/
|
||||
public void init(Point2D.Double p) {
|
||||
this.init(p.x, p.y);
|
||||
}
|
||||
/** Get the current x-coordinate in screen coordinates.*/
|
||||
private double getX(){
|
||||
return (toScreenCoords(point)).getX();
|
||||
}
|
||||
/** Get the current x-coordinate in screen coordinates.*/
|
||||
private double getY(){
|
||||
return toScreenCoords(point).getY();
|
||||
}
|
||||
/** Calls the clipLineTo and wrapLineTo methods, according
|
||||
to the turtle's edge behavior.
|
||||
|
||||
Only overwrite this method when working with another
|
||||
(one that you have defined) edge behaviour. <br>
|
||||
If you mean to change the manner of drawing lines, do this in
|
||||
the methods clipLineTo() and wrapLineTo().
|
||||
@see #clipLineTo
|
||||
@see #wrapLineTo
|
||||
*/
|
||||
protected void internalLineTo(double x, double y){
|
||||
Point2D.Double screenPos = toScreenCoords(x, y);
|
||||
if(turtle.isClip()){
|
||||
clipLineTo(screenPos.getX(), screenPos.getY());
|
||||
}
|
||||
if (turtle.isWrap()){
|
||||
wrapLineTo(screenPos.getX(), screenPos.getY());
|
||||
}
|
||||
init(x,y);
|
||||
}
|
||||
/** Calls the internalLineTo(x,y), which does the actual painting.
|
||||
*/
|
||||
public void lineTo(double x, double y) {
|
||||
internalLineTo(x, y);
|
||||
}
|
||||
/** Calls the internalLineTo(x,y), which does the actual painting.
|
||||
|
||||
This method works the same way as lineTo(double x, double y), but
|
||||
is added for convenience.
|
||||
*/
|
||||
public void lineTo(Point2D.Double p) {
|
||||
internalLineTo(p.getX(), p.getY());
|
||||
}
|
||||
/** Does the actual painting for clip mode.
|
||||
|
||||
It works already with ScreenCoords!
|
||||
For further comments cf. internalLineTo(double x, double y).
|
||||
@see #internalLineTo
|
||||
*/
|
||||
protected void clipLineTo(double x, double y){
|
||||
turtle.getPlayground().lineTo(getX(), getY(), x, y, turtle.getPen());
|
||||
}
|
||||
/** Does the actual painting for wrap mode.
|
||||
|
||||
It works already with ScreenCoords!
|
||||
For further comments cf. internalLineTo(double x, double y).
|
||||
@see #internalLineTo
|
||||
*/
|
||||
protected void wrapLineTo(double x, double y){
|
||||
double dx = getX() - x;
|
||||
double dy = getY() - y;
|
||||
Point2D.Double start = new Point2D.Double(x, y);
|
||||
Point2D.Double end = new Point2D.Double(start.x+dx, start.y+dy);
|
||||
|
||||
intoPanel(start, end);
|
||||
Point2D.Double tmp;
|
||||
while ((tmp = calcIntersection(start.x, start.y, end.x, end.y)) != null){
|
||||
turtle.getPlayground().lineTo(start.x, start.y, tmp.getX(), tmp.getY(), turtle.getPen());
|
||||
start = tmp;
|
||||
intoPanel(start, end);
|
||||
dx = end.x - start.x;
|
||||
dy = end.y - start.y;
|
||||
}
|
||||
|
||||
turtle.getPlayground().lineTo(start.x, start.y, end.x, end.y, turtle.getPen());
|
||||
}
|
||||
/** Makes the coordinates fit into the Panel.
|
||||
|
||||
Well, this is some sort of modulus calculation.
|
||||
*/
|
||||
private void intoPanel(Point2D.Double start, Point2D.Double end){
|
||||
int pWidth = turtle.getPlayground().getWidth();
|
||||
int pHeight = turtle.getPlayground().getHeight();
|
||||
while(start.x < 0){
|
||||
start.x += pWidth;
|
||||
end.x += pWidth;
|
||||
}
|
||||
while (start.x > pWidth){
|
||||
start.x -= pWidth;
|
||||
end.x -= pWidth;
|
||||
}
|
||||
if(start.x == 0 && end.x < start.x){
|
||||
start.x += pWidth;
|
||||
end.x += pWidth;
|
||||
}
|
||||
if(start.x == pWidth && end.x > start.x){
|
||||
start.x -= pWidth;
|
||||
end.x -= pWidth;
|
||||
}
|
||||
while(start.y < 0){
|
||||
start.y += pHeight;
|
||||
end.y += pHeight;
|
||||
}
|
||||
while (start.y > pHeight){
|
||||
start.y -= pHeight;
|
||||
end.y -= pHeight;
|
||||
}
|
||||
if(start.y == 0 && end.y < start.y){
|
||||
start.y += pHeight;
|
||||
end.y += pHeight;
|
||||
}
|
||||
if(start.y == pHeight && end.y > start.y){
|
||||
start.y -= pHeight;
|
||||
end.y -= pHeight;
|
||||
}
|
||||
|
||||
}
|
||||
/** Intersection line with playground-edges
|
||||
(startX / startY) MUST lie in the playground!
|
||||
*/
|
||||
private Point2D.Double calcIntersection(double startX, double startY, double endX, double endY){
|
||||
double dx = endX - startX;
|
||||
double dy = endY - startY;
|
||||
double W = turtle.getPlayground().getWidth();
|
||||
double H = turtle.getPlayground().getHeight();
|
||||
if(endX < 0){
|
||||
if((dy/dx <= startY/startX) && (dy/dx >= -(H-startY)/startX)){ // links
|
||||
return new Point2D.Double(0, startY-startX*dy/dx);
|
||||
}
|
||||
}
|
||||
else if(endX > W){
|
||||
if((dy/dx >= -startY/(W-startX)) && (dy/dx <= (H-startY)/(W-startX))){// rechts
|
||||
return new Point2D.Double(W, startY+(W-startX)*dy/dx);
|
||||
}
|
||||
}
|
||||
if(endY < 0){ // oben
|
||||
return new Point2D.Double(startX-startY*dx/dy, 0);
|
||||
}
|
||||
else if(endY > H){ // unten
|
||||
return new Point2D.Double(startX+(H-startY)*dx/dy, H);
|
||||
}
|
||||
else{
|
||||
return null; // Endpoint lies in the window
|
||||
}
|
||||
}
|
||||
/** Calculates the screen coordinates of the turtle's actual
|
||||
position according to the interpretation of the playground.
|
||||
*/
|
||||
private Point2D.Double toScreenCoords(double x, double y){
|
||||
return turtle.getPlayground().toScreenCoords(x, y);
|
||||
}
|
||||
/** Calculates the screen coordinates of the turtle's actual
|
||||
position according to the interpretation of the playground.
|
||||
|
||||
Added for convenience.
|
||||
@see #toScreenCoords(double, double)
|
||||
*/
|
||||
private Point2D.Double toScreenCoords(Point2D.Double p){
|
||||
return turtle.getPlayground().toScreenCoords(p.x, p.y);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,268 @@
|
|||
// Pen.java
|
||||
|
||||
// Copyright 2002 Regula Hoefer-Isenegger
|
||||
//
|
||||
// This file is part of The Java Turtle package (TJT)
|
||||
//
|
||||
// TJT 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
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// TJT 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 The Java Turtle Package; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package ch.aplu.turtle;
|
||||
|
||||
import ch.aplu.turtle.*;
|
||||
import java.awt.Color;
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Stroke;
|
||||
import java.awt.Font;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
|
||||
/** The Pen class provides anything used for drawing the lines, such as line width,
|
||||
pen color, end caps, dashed lines, etc.
|
||||
|
||||
@see java.awt.BasicStroke
|
||||
|
||||
@author <a href="mailto:regula@hoefer.ch">Regula Hoefer-Isenegger</a>
|
||||
@version 0.1.1
|
||||
*/
|
||||
public class Pen
|
||||
{
|
||||
/* Attributes *********************************************/
|
||||
|
||||
/** The default font that is used when drawing Text.
|
||||
|
||||
First argument must be one of "Serif", "SansSerif", "Monotyped", "Dialog" or "DialogInput"
|
||||
to guarantee that this font exists on all systems.
|
||||
|
||||
@see java.awt.Font for more information, e.g. on font styles.
|
||||
|
||||
*/
|
||||
public static Font DEFAULT_FONT = new Font("SansSerif", Font.PLAIN, 24);
|
||||
private Color color;
|
||||
private Color fillColor;
|
||||
private BasicStroke stroke;
|
||||
private Font font;
|
||||
|
||||
/* Constructors *******************************************/
|
||||
/** Constructor with standard Color and standard Stroke.
|
||||
|
||||
@see java.awt.BasicStroke
|
||||
*/
|
||||
public Pen(){
|
||||
color = Color.black;
|
||||
setFillColor(Color.black);
|
||||
stroke = new BasicStroke();
|
||||
font = DEFAULT_FONT;
|
||||
}
|
||||
/** Constructor with Color <code>color</code> and standard Stroke.
|
||||
|
||||
@see java.awt.BasicStroke
|
||||
*/
|
||||
public Pen(Color color){
|
||||
this.color = color;
|
||||
setFillColor(color);
|
||||
stroke = new BasicStroke();
|
||||
font = DEFAULT_FONT;
|
||||
}
|
||||
/* Methods ************************************************/
|
||||
/** Query the <code>Pen</code>s color.*/
|
||||
public Color getColor(){
|
||||
return color;
|
||||
}
|
||||
/** Set the <code>Pen</code>s color.*/
|
||||
public void setColor(Color color){
|
||||
this.color = color;
|
||||
}
|
||||
/** Set the <code>Pen</code>s fill color.
|
||||
*/
|
||||
public void setFillColor(Color color){
|
||||
this.fillColor = color;
|
||||
}
|
||||
/** Query the <code>Pen</code>s fill color.*/
|
||||
public Color getFillColor(){
|
||||
return this.fillColor;
|
||||
}
|
||||
/** Get the <code>Pen</code>s <code>Stroke</code>
|
||||
|
||||
@see BasicStroke
|
||||
@see Stroke
|
||||
*/
|
||||
public Stroke getStroke(){
|
||||
return stroke;
|
||||
}
|
||||
/** Query the <code>Pen</code>s line width*/
|
||||
public float getLineWidth(){
|
||||
return stroke.getLineWidth();
|
||||
}
|
||||
/** Query the <code>Pen</code>s end cap style.
|
||||
|
||||
@see java.awt.BasicStroke
|
||||
*/
|
||||
public int getEndCap(){
|
||||
return stroke.getEndCap();
|
||||
}
|
||||
/** Query the <code>Pen</code>s line join style.
|
||||
|
||||
@see java.awt.BasicStroke
|
||||
*/
|
||||
public int getLineJoin(){
|
||||
return stroke.getLineJoin();
|
||||
}
|
||||
/** Query the <code>Pen</code>s miter limit style.
|
||||
|
||||
@see java.awt.BasicStroke
|
||||
*/
|
||||
public float getMiterLimit(){
|
||||
return stroke.getMiterLimit();
|
||||
}
|
||||
/** Query the <code>Pen</code>s dash array.
|
||||
|
||||
@see java.awt.BasicStroke
|
||||
*/
|
||||
public float[] getDashArray(){
|
||||
return stroke.getDashArray();
|
||||
}
|
||||
/** Query the <code>Pen</code>s dash phase.
|
||||
|
||||
@see java.awt.BasicStroke
|
||||
*/
|
||||
public float getDashPhase(){
|
||||
return stroke.getDashPhase();
|
||||
}
|
||||
|
||||
/** Set the <code>Pen</code>s line width. */
|
||||
public void setLineWidth(float width){
|
||||
stroke = new BasicStroke((float)width,
|
||||
stroke.getEndCap(),
|
||||
stroke.getLineJoin(),
|
||||
stroke.getMiterLimit(),
|
||||
stroke.getDashArray(),
|
||||
stroke.getDashPhase());
|
||||
}
|
||||
/** Set the <code>Pen</code>s end cap style.
|
||||
|
||||
@see java.awt.BasicStroke
|
||||
*/
|
||||
public void setEndCap(int endCap){
|
||||
stroke = new BasicStroke(stroke.getLineWidth(),
|
||||
endCap,
|
||||
stroke.getLineJoin(),
|
||||
stroke.getMiterLimit(),
|
||||
stroke.getDashArray(),
|
||||
stroke.getDashPhase());
|
||||
}
|
||||
/** Set the <code>Pen</code>s line join style.
|
||||
|
||||
@see java.awt.BasicStroke
|
||||
*/
|
||||
public void setLineJoin(int join){
|
||||
stroke = new BasicStroke(stroke.getLineWidth(),
|
||||
stroke.getEndCap(),
|
||||
join,
|
||||
stroke.getMiterLimit(),
|
||||
stroke.getDashArray(),
|
||||
stroke.getDashPhase());
|
||||
}
|
||||
/** Set the <code>Pen</code>s miter limit.
|
||||
|
||||
@see java.awt.BasicStroke
|
||||
*/
|
||||
public void setMiterLimit(float miterlimit){
|
||||
stroke = new BasicStroke(stroke.getLineWidth(),
|
||||
stroke.getEndCap(),
|
||||
stroke.getLineJoin(),
|
||||
miterlimit,
|
||||
stroke.getDashArray(),
|
||||
stroke.getDashPhase());
|
||||
}
|
||||
/** Set the <code>Pen</code>s dash array.
|
||||
|
||||
@see java.awt.BasicStroke
|
||||
*/
|
||||
public void setDash(float[] dashArray){
|
||||
stroke = new BasicStroke(stroke.getLineWidth(),
|
||||
stroke.getEndCap(),
|
||||
stroke.getLineJoin(),
|
||||
stroke.getMiterLimit(),
|
||||
dashArray,
|
||||
stroke.getDashPhase());
|
||||
}
|
||||
/** Set the <code>Pen</code>s dash phase.
|
||||
|
||||
@see java.awt.BasicStroke
|
||||
*/
|
||||
public void setDashPhase(float dashPhase){
|
||||
stroke = new BasicStroke(stroke.getLineWidth(),
|
||||
stroke.getEndCap(),
|
||||
stroke.getLineJoin(),
|
||||
stroke.getMiterLimit(),
|
||||
stroke.getDashArray(),
|
||||
dashPhase);
|
||||
}
|
||||
/** Provides information about the currently available font families (e.g. "Roman").
|
||||
Each font name is a string packed into a array of strings.
|
||||
@see java.awt.Font for more information about font attributes etc.
|
||||
*/
|
||||
public static String[] getAvailableFontFamilies(){
|
||||
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
String s[] = ge.getAvailableFontFamilyNames();
|
||||
return s;
|
||||
}
|
||||
/** Change the font style.
|
||||
|
||||
@see java.awt.Font for possible styles.
|
||||
*/
|
||||
public void setFontStyle(int style){
|
||||
font = font.deriveFont(style);
|
||||
}
|
||||
/** Change the font size (in points).
|
||||
*/
|
||||
public void setFontSize(int size){
|
||||
font = font.deriveFont((float)size);
|
||||
}
|
||||
/** Change the font size (in points).
|
||||
You will probably only need the int version <a href="#setFontSize(int)">setFontSize(int)</a>.
|
||||
*/
|
||||
public void setFontSize(float size){
|
||||
font = font.deriveFont(size);
|
||||
}
|
||||
/** Query the size (in points, rounded to int) of the current font.
|
||||
*/
|
||||
public int getFontSize(){
|
||||
return font.getSize() ;
|
||||
}
|
||||
/** Change the font to the given one.
|
||||
*/
|
||||
public void setFont(Font f){
|
||||
font = f;
|
||||
}
|
||||
/** Query the current font.
|
||||
*/
|
||||
public Font getFont(){
|
||||
return font;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,789 @@
|
|||
// Playground.java
|
||||
|
||||
// Copyright 2002 Regula Hoefer-Isenegger
|
||||
// Major code modifications by Aegidius Pluess
|
||||
// Adaption for the Java-Editor by Gerhard Röhner
|
||||
//
|
||||
// This file is part of The Java Turtle package (TJT)
|
||||
//
|
||||
// TJT 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
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// TJT 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 The Java Turtle Package; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package ch.aplu.turtle;
|
||||
|
||||
import ch.aplu.turtle.*;
|
||||
import java.util.*;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.print.*;
|
||||
import java.awt.geom.*;
|
||||
import java.awt.image.*;
|
||||
import java.awt.font.*;
|
||||
|
||||
/**
|
||||
A <code>Playground</code> is the <code>Turtle</code>'s home, i.e. the <code>Turtle</code> lives
|
||||
and moves in the <code>Playground</code>.
|
||||
|
||||
The<code>Playground</code> is responsible for interpreting angle and position of the
|
||||
<code>Turtle</code> and for choosing the correct turtle image and putting it on the right
|
||||
spot of the Playground. This means: e.g. whenever you wish to switch the x- and y-axis, you
|
||||
should do it in this class, and not in the <code>Turtle</code> class.
|
||||
|
||||
@author <a href="mailto:regula@hoefer.ch">Regula Hoefer-Isenegger</a>
|
||||
@version 0.1.1
|
||||
*/
|
||||
|
||||
public class Playground extends JPanel implements Printable {
|
||||
|
||||
/** Hold the <code>Turtle</code>s of this Playground. */
|
||||
private Vector<Turtle> turtles;
|
||||
|
||||
/** Hold the offscreen buffer and graphics context
|
||||
* where Turtle traces are drawn.
|
||||
*/
|
||||
private BufferedImage traceBuffer = null;
|
||||
protected Graphics2D traceG2D = null;
|
||||
private Dimension playgroundSize;
|
||||
|
||||
/** Hold the offscreen buffer and graphics context
|
||||
* of the Turtles images.
|
||||
*/
|
||||
private BufferedImage turtleBuffer = null;
|
||||
protected Graphics2D turtleG2D = null;
|
||||
|
||||
/** Flag to tell whether we have at least one Turtle shown. */
|
||||
private boolean isTurtleVisible = false;
|
||||
|
||||
/** Flag to tell whether we use automatic repainting */
|
||||
private boolean isRepainting = true;
|
||||
|
||||
/** The default background color.
|
||||
*/
|
||||
protected static Color DEFAULT_BACKGROUND_COLOR = Color.white;
|
||||
|
||||
private double printerScale = 1; // Default printer scaling
|
||||
private TPrintable traceCanvas; // Store ref to user class
|
||||
private Graphics2D printerG2D = null;
|
||||
private boolean isPrintScreen = false; // Indicate we are printing the playground
|
||||
private double printerScaleFactor = 1.1; // Magnification factor for printer
|
||||
|
||||
/**
|
||||
* originX is the x-position of the cartesian coodinate system within the playground.
|
||||
*/
|
||||
public int originX;
|
||||
|
||||
/**
|
||||
* originY is the y-position of the cartesian coodinate system within the playground.
|
||||
*/
|
||||
public int originY;
|
||||
|
||||
private static Color[] ColorArray = {Color.cyan, Color.red, Color.green, Color.blue, Color.yellow,
|
||||
Color.lightGray, Color.magenta, Color.orange, Color.pink, Color.black, Color.gray
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a Playground with default background color.
|
||||
* e.g. creates a new vector (which holds the
|
||||
* <code>Turtle</code>s),
|
||||
*/
|
||||
public Playground() {
|
||||
turtles = new Vector<Turtle>();
|
||||
setDoubleBuffered(false);
|
||||
setBackground(DEFAULT_BACKGROUND_COLOR);
|
||||
initBuffers(new Dimension(100, 100));
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the offscreen buffers and sets the size.
|
||||
*/
|
||||
protected void initBuffers(Dimension size) {
|
||||
Color bkColor = getBackground();
|
||||
playgroundSize = size;
|
||||
traceBuffer = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_ARGB);
|
||||
traceG2D = traceBuffer.createGraphics();
|
||||
traceG2D.setColor(bkColor);
|
||||
traceG2D.fillRect(0, 0, size.width, size.height);
|
||||
traceG2D.setBackground(bkColor);
|
||||
|
||||
turtleBuffer = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_ARGB);
|
||||
turtleG2D = turtleBuffer.createGraphics();
|
||||
turtleG2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
originX = size.width/2;
|
||||
originY = size.height/2;
|
||||
}
|
||||
|
||||
/** Add a new <code>Turtle</code> to the Playground.
|
||||
*/
|
||||
public void add(Turtle turtle) {
|
||||
turtles.add(turtle);
|
||||
turtle.setPlayground(this);
|
||||
int i = turtles.size();
|
||||
while (i > 10) {
|
||||
i = i - 10;
|
||||
} // end of while
|
||||
turtle.init(ColorArray[i-1]);
|
||||
toTop(turtle);
|
||||
}
|
||||
|
||||
public void setBounds(int x, int y, int width, int height) {
|
||||
super.setBounds(x, y, width, height);
|
||||
initBuffers(new Dimension(width, height));
|
||||
}
|
||||
|
||||
/** Remove a <code>Turtle</code> from the Playground.
|
||||
*/
|
||||
public void remove(Turtle turtle) {
|
||||
turtles.remove(turtle);
|
||||
}
|
||||
|
||||
/** Tell current number of <code>Turtle</code>s in this Playground.
|
||||
*/
|
||||
public int countTurtles() {
|
||||
return turtles.size();
|
||||
}
|
||||
|
||||
/** Return the <code>Turtle</code> at index <code>index</code>.
|
||||
*/
|
||||
public Turtle getTurtle(int index) {
|
||||
return turtles.elementAt(index);
|
||||
}
|
||||
|
||||
/** Move the given <code>Turtle</code> above all the others, then
|
||||
paints all turtles.
|
||||
@see #toTop
|
||||
*/
|
||||
public void paintTurtles(Turtle turtle) {
|
||||
toTop(turtle);
|
||||
paintTurtles();
|
||||
}
|
||||
|
||||
/** Paint all turtles (calling paintComponent())
|
||||
*/
|
||||
public void paintTurtles() {
|
||||
isTurtleVisible = false;
|
||||
Graphics2D g2D = getTurtleG2D();
|
||||
for (int i = 0; i < countTurtles(); i++) {
|
||||
Turtle aTurtle = getTurtle(i);
|
||||
if (!aTurtle.isHidden()) {
|
||||
paintTurtle(aTurtle);
|
||||
}
|
||||
}
|
||||
|
||||
// This is the main repaint call, when the turtle is
|
||||
// moving (even when all turtles are hidden).
|
||||
// Strange behaviour an slow Mac machines (pre J2SE 1.4 version):
|
||||
// It happens that some turtle images are not completely redrawn.
|
||||
// This is probably due to an improper handling of fast multiple repaint requests.
|
||||
// Workaround: we wait a small amount of time (and give the thread away)
|
||||
// (No visible slow down on new machines.)
|
||||
|
||||
paintPlayground();
|
||||
if (printerG2D == null) {
|
||||
//if (isRepainting)
|
||||
//repaint();
|
||||
//paintPlayground();
|
||||
}
|
||||
|
||||
if (isTurtleVisible) {
|
||||
try {
|
||||
Thread.currentThread().sleep(10);
|
||||
}
|
||||
catch (Exception e) {}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Paint the given <code>Turtle</code>.
|
||||
* ( no repaint() )
|
||||
*/
|
||||
public void paintTurtle(Turtle turtle) {
|
||||
if (turtleBuffer == null){
|
||||
turtleBuffer = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
|
||||
turtleG2D = turtleBuffer.createGraphics();
|
||||
}
|
||||
Graphics2D turtleGraphics = getTurtleG2D();
|
||||
turtle.getTurtleRenderer().paint(turtle._getX(), turtle._getY(), turtleGraphics);
|
||||
isTurtleVisible = true;
|
||||
}
|
||||
|
||||
/** Put an image of the given <code>Turtle</code> in turtle buffer.
|
||||
*/
|
||||
protected void stampTurtle(Turtle turtle) {
|
||||
turtle.clone();
|
||||
isTurtleVisible = true;
|
||||
if (printerG2D == null)
|
||||
repaint();
|
||||
}
|
||||
|
||||
/** Draw a line from the point <code>(x0, y0)</code> to <code>(x1, y1)</code>
|
||||
with the color of the given <code>Pen</code>.
|
||||
*/
|
||||
protected void lineTo(double x0, double y0, double x1, double y1, Pen pen) {
|
||||
int ix0 = (int)Math.round(x0);
|
||||
int iy0 = (int)Math.round(y0);
|
||||
int ix1 = (int)Math.round(x1);
|
||||
int iy1 = (int)Math.round(y1);
|
||||
Color color = pen.getColor();
|
||||
|
||||
if (traceBuffer == null) {
|
||||
traceBuffer = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
|
||||
traceG2D = traceBuffer.createGraphics();
|
||||
}
|
||||
Graphics2D traceG2D = getTraceG2D();
|
||||
traceG2D.setColor(color);
|
||||
traceG2D.setStroke(pen.getStroke());
|
||||
traceG2D.drawLine(ix0, iy0, ix1, iy1);
|
||||
if (printerG2D != null)
|
||||
printerG2D.drawLine(ix0, iy0, ix1, iy1);
|
||||
}
|
||||
|
||||
/** A class for convenience. */
|
||||
protected class Point extends java.awt.Point {
|
||||
Point(int x, int y) {
|
||||
super(x, y);
|
||||
}
|
||||
Point() {
|
||||
super();
|
||||
}
|
||||
Point(Point p) {
|
||||
super(p.x, p.y);
|
||||
}
|
||||
|
||||
/** Get a new Point with coordinates (this.x+p.x, this.y+p.y).
|
||||
*/
|
||||
protected Point add(Point p) {
|
||||
return new Point(this.x+p.x, this.y+p.y);
|
||||
}
|
||||
|
||||
/** Translate by the amounts dx = p.x, dy = p.y. */
|
||||
protected void translate(Point p) {
|
||||
translate(p.x, p.y);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "(" + x + "," + y + ")";
|
||||
}
|
||||
}
|
||||
|
||||
/** Fill a region.
|
||||
The region is defined by the <code>Turtle</code>s actual position and
|
||||
is bounded by any other color than the give background color.
|
||||
*/
|
||||
public void fill(Turtle t, Color bgColor) {
|
||||
final Point[] diff = { new Point(0,-1), new Point(-1,0), new Point(1,0), new Point(0,1)};
|
||||
final int N=0;
|
||||
final int W=1;
|
||||
final int E=2;
|
||||
final int S=3;
|
||||
|
||||
int bgcolor = bgColor.getRGB();
|
||||
int fillColor = t.getPen().getFillColor().getRGB();
|
||||
Vector list = new Vector();
|
||||
Point2D.Double p1 = toScreenCoords(t.getPos());
|
||||
int startX = (int)Math.round(p1.getX());
|
||||
int startY = (int)Math.round(p1.getY());
|
||||
Point p = new Point(startX, startY);
|
||||
if (traceBuffer.getRGB(startX, startY) == bgcolor) {
|
||||
traceBuffer.setRGB(startX, startY, fillColor);
|
||||
list.addElement(new Point(startX, startY));
|
||||
int d = N;
|
||||
int back;
|
||||
while (list.size() > 0) {
|
||||
while (d <= S) { // forward
|
||||
Point tmp = p.add(diff[d]);
|
||||
try {
|
||||
if (traceBuffer.getRGB(tmp.x, tmp.y) == bgcolor) {
|
||||
p.translate(diff[d]);
|
||||
traceBuffer.setRGB(p.x, p.y, fillColor);
|
||||
if (printerG2D != null)
|
||||
{
|
||||
printerG2D.setColor(t.getPen().getFillColor());
|
||||
// printerG2D.drawLine(p.x,p.y, p.x, p.y);
|
||||
BasicStroke stroke = new BasicStroke(2);
|
||||
printerG2D.setStroke(stroke);
|
||||
Line2D line = new Line2D.Double(p.x, p.y, p.x, p.y);
|
||||
printerG2D.draw(line);
|
||||
}
|
||||
list.addElement(new Integer(d));
|
||||
d=N;
|
||||
}
|
||||
else {
|
||||
d++;
|
||||
}
|
||||
}
|
||||
catch (ArrayIndexOutOfBoundsException e) {
|
||||
d++;
|
||||
}
|
||||
}
|
||||
Object obj = list.remove(list.size()-1);
|
||||
try {
|
||||
d=((Integer)obj).intValue(); // last element
|
||||
back = S - d;
|
||||
p.translate(diff[back]);
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
// the first (zeroest) element in list is the start-point
|
||||
// just do nothing with it
|
||||
}
|
||||
}
|
||||
}
|
||||
traceG2D.drawLine(0, 0, 0, 0); // Workaround because on Mac the trace buffer is not drawn without this
|
||||
if (printerG2D == null)
|
||||
repaint();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the playground with given color.
|
||||
*/
|
||||
public void clear(Color color) {
|
||||
traceG2D.setColor(color);
|
||||
traceG2D.fillRect(0, 0, getWidth(), getHeight());
|
||||
turtleG2D.setColor(color);
|
||||
turtleG2D.fillRect(0, 0, getWidth(), getHeight());
|
||||
isTurtleVisible = true;
|
||||
if (printerG2D == null)
|
||||
repaint();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear playground.
|
||||
*/
|
||||
public void clear() {
|
||||
clear(getBackground());
|
||||
}
|
||||
|
||||
/** Paint the Playground.
|
||||
just a method for convenience.
|
||||
*/
|
||||
public void paintComponent() {
|
||||
paintComponent(getGraphics());
|
||||
}
|
||||
|
||||
/** Draw the trace and turtle buffers.
|
||||
*/
|
||||
public void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
Graphics2D g2D = (Graphics2D)g;
|
||||
g2D.drawImage(traceBuffer, 0, 0, this);
|
||||
if (isTurtleVisible)
|
||||
g2D.drawImage(turtleBuffer, 0, 0, this);
|
||||
}
|
||||
|
||||
public void paintPlayground() {
|
||||
Graphics g = getGraphics();
|
||||
if (g != null) {
|
||||
super.paintComponent(g);
|
||||
Graphics2D g2D = (Graphics2D)g;
|
||||
g2D.drawImage(traceBuffer, 0, 0, this);
|
||||
if (isTurtleVisible)
|
||||
g2D.drawImage(turtleBuffer, 0, 0, this);
|
||||
|
||||
} // end of if
|
||||
}
|
||||
|
||||
/** Remove all turtles from the turtle buffer.
|
||||
*/
|
||||
public void clearTurtles() {
|
||||
for (int i = 0; i < countTurtles(); i++) {
|
||||
Turtle turtle = getTurtle(i);
|
||||
clearTurtle(turtle);
|
||||
}
|
||||
}
|
||||
|
||||
/** Remove the given turtle from the turtle buffer.
|
||||
Override this method if you have added a new behaviour (like
|
||||
wrap or clip) to the turtle.
|
||||
*/
|
||||
public void clearTurtle(Turtle turtle) {
|
||||
if(turtle != null){
|
||||
if (!turtle.isHidden()) {
|
||||
if(turtle.isClip()){
|
||||
clearClipTurtle(turtle);
|
||||
}
|
||||
else if(turtle.isWrap()){
|
||||
clearWrapTurtle(turtle);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** This method is called when the given <code>Turtle</code> is in wrap mode.
|
||||
|
||||
@see ch.aplu.turtle.Turtle#wrap
|
||||
*/
|
||||
protected void clearWrapTurtle(Turtle turtle){
|
||||
clearWrapTurtle(turtle, turtleBuffer);
|
||||
}
|
||||
|
||||
/** Here the actual clearing of a <code>Turtle</code> in wrap mode from the
|
||||
given image is performed.
|
||||
*/
|
||||
protected void clearWrapTurtle(Turtle turtle, Image im){
|
||||
Rectangle bounds = getBounds(turtle);
|
||||
int pWidth = getWidth();
|
||||
int pHeight = getHeight();
|
||||
int x = bounds.x;
|
||||
int y = bounds.y;
|
||||
while (x > pWidth){
|
||||
x -= pWidth;
|
||||
}
|
||||
while (x < 0){
|
||||
x += pWidth;
|
||||
}
|
||||
while (y > pHeight){
|
||||
y -= pHeight;
|
||||
}
|
||||
while (y < 0){
|
||||
y += pHeight;
|
||||
}
|
||||
x = x % pWidth;
|
||||
y = y % pHeight;
|
||||
toAlphaNull(im, new Rectangle(x, y, bounds.width, bounds.height)); // OK
|
||||
boolean right = (x + bounds.width > getWidth());
|
||||
boolean bottom = (y + bounds.height > getHeight());
|
||||
if (right) {
|
||||
toAlphaNull(im, new Rectangle(x-pWidth, y, bounds.width, bounds.height));
|
||||
}
|
||||
if (bottom) {
|
||||
toAlphaNull(im, new Rectangle(x, y-pHeight, bounds.width, bounds.height));
|
||||
}
|
||||
if (right && bottom) {
|
||||
toAlphaNull(im, new Rectangle(x-pWidth, y-pHeight, bounds.width, bounds.height));
|
||||
}
|
||||
}
|
||||
|
||||
/** Copy and translate a given Rectangle.
|
||||
*/
|
||||
private Rectangle copyAndTranslate(Rectangle rect, int dx, int dy) {
|
||||
return new Rectangle(rect.x+dx, rect.y+dy,
|
||||
rect.width, rect.height);
|
||||
}
|
||||
|
||||
/** This method is called when the given <code>Turtle</code> is in clip mode.
|
||||
|
||||
@see ch.aplu.turtle.Turtle#clip
|
||||
*/
|
||||
protected void clearClipTurtle(Turtle turtle) {
|
||||
clearClipTurtle(turtle, turtleBuffer);
|
||||
}
|
||||
|
||||
/** Here the actual clearing of a <code>Turtle</code> in clip mode from the
|
||||
given image is performed.
|
||||
*/
|
||||
protected void clearClipTurtle(Turtle turtle, Image im) {
|
||||
Rectangle bounds = getBounds(turtle);
|
||||
toAlphaNull(im, bounds);
|
||||
}
|
||||
|
||||
/** Set the alpha channel of all pixels in the given image
|
||||
in the given Rectangle to zero (i.e. totally transparent).
|
||||
|
||||
This method is used byte the clearXXXTurtle methods.
|
||||
*/
|
||||
private void toAlphaNull(Image im, Rectangle rect) {
|
||||
Rectangle rim = new Rectangle(0, 0, im.getWidth(this), im.getHeight(this));
|
||||
Rectangle r = new Rectangle();
|
||||
if (rect.intersects(rim)) {
|
||||
r=rect.intersection(rim);
|
||||
}
|
||||
int size = r.width*r.height;
|
||||
float[] alphachannel = new float[r.width*r.height];
|
||||
((BufferedImage)im).getAlphaRaster().setPixels(r.x, r.y, r.width, r.height, alphachannel);
|
||||
}
|
||||
|
||||
/** Puts a Turtle above all others.
|
||||
*/
|
||||
public Turtle toTop(Turtle turtle) {
|
||||
if (turtles.removeElement(turtle)) {
|
||||
turtles.add(turtle);
|
||||
}
|
||||
return turtle;
|
||||
}
|
||||
/** Put a Turtle below all others.
|
||||
*/
|
||||
public Turtle toBottom(Turtle turtle) {
|
||||
if (turtles.removeElement(turtle)) {
|
||||
turtles.add(0,turtle);
|
||||
}
|
||||
return turtle;
|
||||
}
|
||||
|
||||
/** Calculate the screen coordinates of the given point.
|
||||
*/
|
||||
public Point2D.Double toScreenCoords(Point2D.Double p) {
|
||||
return internalToScreenCoords(p.x, p.y);
|
||||
}
|
||||
|
||||
/** Calculate the screen coordinates of the given point coordinates.
|
||||
*/
|
||||
public Point2D.Double toScreenCoords(double x, double y) {
|
||||
return internalToScreenCoords(x, y);
|
||||
}
|
||||
|
||||
protected Point2D.Double internalToScreenCoords(double x, double y) {
|
||||
// reflect at x-axis, then translate to center of Playground
|
||||
// pixel coordinates coorespond to turtle coordinates, only translation needed
|
||||
double newX = originX + x;
|
||||
double newY = originY - y;
|
||||
return new Point2D.Double(newX, newY);
|
||||
}
|
||||
|
||||
/** Calculate the turtle coordinates of the given screen coordinates.
|
||||
*/
|
||||
public Point2D.Double toTurtleCoords(double x, double y) {
|
||||
// pixel coordinates coorespond to turtle coordinates, only translation needed
|
||||
double newX = x - originX;
|
||||
double newY = originY - y;
|
||||
return new Point2D.Double(newX, newY);
|
||||
}
|
||||
|
||||
/** Calculate the turtle coordinates of the given screen point.
|
||||
*/
|
||||
public Point2D.Double toTurtleCoords(Point2D.Double p) {
|
||||
return toTurtleCoords(p.x, p.y);
|
||||
}
|
||||
|
||||
/** Calculate the screen angle.
|
||||
I.e. the interpretation of angle.
|
||||
@param radians The angle in radians.
|
||||
*/
|
||||
double toScreenAngle(double radians) {
|
||||
double sa = radians;
|
||||
if (sa < Math.PI/2){
|
||||
sa += 2*Math.PI;
|
||||
}
|
||||
sa -= Math.PI/2;
|
||||
if (sa != 0) {
|
||||
sa = Math.PI*2 - sa;
|
||||
}
|
||||
return sa;
|
||||
}
|
||||
|
||||
/** Calculate the bounds of the <code>Turtle</code>s picture on the screen.
|
||||
*/
|
||||
protected Rectangle getBounds(Turtle turtle) {
|
||||
Rectangle bounds = turtle.getBounds();
|
||||
Point2D.Double tmp = toScreenCoords(new Point2D.Double(bounds.getX(), bounds.getY()));
|
||||
bounds.setRect(tmp.x-2, tmp.y-2, bounds.width+4, bounds.height+4);
|
||||
return bounds;
|
||||
}
|
||||
|
||||
/** Return the graphics context of the turtle buffer.
|
||||
*/
|
||||
public Graphics2D getTurtleG2D() {
|
||||
return turtleG2D;
|
||||
}
|
||||
|
||||
/** Return the image of the turtle buffer.
|
||||
*/
|
||||
public BufferedImage getTurtleBuffer() {
|
||||
return turtleBuffer;
|
||||
}
|
||||
|
||||
/** Return the graphics context of the trace buffer.
|
||||
*/
|
||||
public Graphics2D getTraceG2D() {
|
||||
return traceG2D;
|
||||
}
|
||||
|
||||
/** Return the graphics context of the printer.
|
||||
*/
|
||||
public Graphics2D getPrinterG2D() {
|
||||
return printerG2D;
|
||||
}
|
||||
|
||||
/** Return the image of the trace buffer.
|
||||
*/
|
||||
public BufferedImage getTraceBuffer() {
|
||||
return traceBuffer;
|
||||
}
|
||||
|
||||
/** Clean the traces.
|
||||
All turtles stay how and where they are, only lines, text and stamps will be removed.
|
||||
*/
|
||||
void clean() {
|
||||
Graphics2D g = getTraceG2D();
|
||||
g.setColor(getBackground());
|
||||
g.fillRect(0,0,getWidth(), getHeight());
|
||||
if (printerG2D == null)
|
||||
repaint();
|
||||
}
|
||||
|
||||
/** Draw the <code>text</code> at the current position of the Turtle <code>t</code>.
|
||||
Drawing a text at some coordinates <code>(x,y)</code> we mean that the bottom left corner of
|
||||
the text will be at these coordinates.
|
||||
Font and colour are specified by the Turtle's Pen.
|
||||
*/
|
||||
public void label(String text, Turtle t) {
|
||||
Point2D.Double sc = toScreenCoords(t.getPos());
|
||||
int x = (int)Math.round(sc.x);
|
||||
int y = (int)Math.round(sc.y);
|
||||
Graphics2D traceG2D = getTraceG2D();
|
||||
FontRenderContext frc = traceG2D.getFontRenderContext();
|
||||
Font f = t.getFont();
|
||||
TextLayout tl = new TextLayout(text, f, frc);
|
||||
traceG2D.setColor(t.getPen().getColor());
|
||||
tl.draw(traceG2D, x, y);
|
||||
if (printerG2D != null)
|
||||
{
|
||||
printerG2D.setColor(t.getPen().getColor());
|
||||
tl.draw(printerG2D, x, y);
|
||||
}
|
||||
|
||||
if (printerG2D == null)
|
||||
repaint();
|
||||
}
|
||||
|
||||
/** Set antialiasing on or off for the turtle trace buffer
|
||||
* This may result in an better trace quality.
|
||||
*/
|
||||
public void setAntiAliasing(boolean on) {
|
||||
if (on)
|
||||
traceG2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
else
|
||||
traceG2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_OFF);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the given TPrintable (implementing draw()),
|
||||
* open a printer dialog and start printing with given scale.
|
||||
* Return false, if printer dialog is aborted,
|
||||
* otherwise return true.<br>
|
||||
* If tp == null, the current playground is printed.
|
||||
*
|
||||
*/
|
||||
protected boolean print(TPrintable tp, double scale) {
|
||||
if (tp == null)
|
||||
isPrintScreen = true;
|
||||
else
|
||||
isPrintScreen = false;
|
||||
printerScale = scale;
|
||||
PrinterJob pj = PrinterJob.getPrinterJob();
|
||||
pj.setPrintable(this);
|
||||
traceCanvas = tp;
|
||||
if (pj.printDialog()) {
|
||||
try {
|
||||
pj.print();
|
||||
}
|
||||
catch (PrinterException ex) {
|
||||
System.out.println(ex);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* For internal use only. Implementation of Printable.
|
||||
* (Callback method called by printing system.)
|
||||
*/
|
||||
public int print(Graphics g, PageFormat pf, int pageIndex) {
|
||||
if (pageIndex != 0)
|
||||
return NO_SUCH_PAGE;
|
||||
Graphics2D g2D = (Graphics2D)g;
|
||||
double printerWidth = pf.getImageableWidth();
|
||||
double printerHeight = pf.getImageableHeight();
|
||||
double printerSize = printerWidth > printerHeight ? printerWidth :
|
||||
printerHeight;
|
||||
double xZero = pf.getImageableX();
|
||||
double yZero = pf.getImageableY();
|
||||
|
||||
printerG2D = g2D; // Indicate also, we are printing now
|
||||
|
||||
// Needed for fill operations: the trace canvas must be empty in order to
|
||||
// perform the fill algoritm (searching for outline of figure)
|
||||
if (!isPrintScreen)
|
||||
clean();
|
||||
|
||||
g2D.scale(printerScaleFactor * printerScale, printerScaleFactor * printerScale);
|
||||
g2D.translate(xZero/printerScale, yZero/printerScale);
|
||||
|
||||
if (isPrintScreen)
|
||||
{
|
||||
print(g);
|
||||
}
|
||||
else // Printing the traceCanvas
|
||||
{
|
||||
// Hide all turtles
|
||||
boolean[] turtleState = new boolean[countTurtles()];
|
||||
for (int i = 0; i < countTurtles(); i++) {
|
||||
Turtle aTurtle = getTurtle(i);
|
||||
turtleState[i] = aTurtle.isHidden();
|
||||
aTurtle.ht();
|
||||
}
|
||||
traceCanvas.draw();
|
||||
|
||||
// Restore old context
|
||||
for (int i = 0; i < countTurtles(); i++) {
|
||||
Turtle aTurtle = getTurtle(i);
|
||||
if (!turtleState[i])
|
||||
aTurtle.st();
|
||||
}
|
||||
}
|
||||
|
||||
printerG2D = null;
|
||||
return PAGE_EXISTS;
|
||||
}
|
||||
|
||||
/** Return the color of the pixel at the current turtle position.
|
||||
*/
|
||||
public Color getPixelColor(Turtle t) {
|
||||
Point2D.Double p1 = toScreenCoords(t.getPos());
|
||||
int x = (int)Math.round(p1.getX());
|
||||
int y = (int)Math.round(p1.getY());
|
||||
return new Color(traceBuffer.getRGB(x, y));
|
||||
}
|
||||
|
||||
public void enableRepaint(boolean b) {
|
||||
isRepainting = b;
|
||||
}
|
||||
|
||||
/** set the background color of the playground
|
||||
*/
|
||||
public void setBackground(Color color) {
|
||||
super.setBackground(color);
|
||||
if (traceG2D != null) {
|
||||
clear(color);
|
||||
} // end of if
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the origin of the cartesian coordinate system within the playground
|
||||
*/
|
||||
public void setOrigin(int x, int y) {
|
||||
for (int i = 0; i < countTurtles(); i++) {
|
||||
Turtle turtle = getTurtle(i);
|
||||
Point2D.Double p1 = toScreenCoords(turtle.getPos());
|
||||
double newX = p1.getX() - x;
|
||||
double newY = y - p1.getY();
|
||||
turtle.internalSetPos(newX, newY);
|
||||
}
|
||||
originX = x;
|
||||
originY = y;
|
||||
}
|
||||
|
||||
public int getOriginX() {
|
||||
return originX;
|
||||
}
|
||||
|
||||
public int getOriginY() {
|
||||
return originY;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Binary file not shown.
|
|
@ -0,0 +1,84 @@
|
|||
// SharedConstants.java
|
||||
|
||||
// Copyright 2002 Regula Hoefer-Isenegger
|
||||
//
|
||||
// This file is part of The Java Turtle (TJT) package
|
||||
//
|
||||
// TJT 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
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// TJT 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 The Java Turtle Package; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
/* History;
|
||||
V1.36 - Sep 2004: First official release
|
||||
V1.37 - Nov 2004: Unchanged, modifications in ch.aplu.util
|
||||
V1.38 - Dec 2004: Unchanged, modifications in ch.aplu.util
|
||||
V1.39 - Jan 2005: Unchanged, modifications in ch.aplu.util
|
||||
V1.40 - Mar 2005: Add background color, TurtleKeyAdapter, TurtleArea
|
||||
V1.41 - May 2005: User defined turtle shape, minor changes in doc and code style
|
||||
V1.42 - Dec 2005: Unchanged, modifications in ch.aplu.util
|
||||
V1.43 - Feb 2006: Bug removed: Turtle.turtleFrame was not initialized in all ctors of class Turtle
|
||||
V1.44 - Mar 2007: Bug removed: stampTurtle did not work properly in wrap mode
|
||||
V1.45 - Aug 2007: TurtleKeyAdapter: use wait/notify to reduce CPU time (from 100% to 2%)
|
||||
V1.46 - Aug 2007: synchronize(playground) for forward and rotate animation,
|
||||
new method bong() using StreamingPlayer
|
||||
V1.47 - Sept 2007: Unchanged, modifications in ch.aplu.util
|
||||
V1.48 - Sept 2007: Unchanged, modifications in ch.aplu.util
|
||||
V1.49 - Oct 2007: Unchanged, modifications in ch.aplu.util
|
||||
V1.50 - Oct 2007: Unchanged, modifications in ch.aplu.util
|
||||
V1.51 - Nov 2007: Fixed: correct position of label, when wrapping is on
|
||||
Fixed: getPos() returns now the wrapped coordinates
|
||||
Added: _getPos() returns unwrapped coordinates
|
||||
V1.52 - Nov 2007: Added bean classes in order to use turtles with a Gui builder
|
||||
V1.53 - Nov 2007: Added TurtlePane visual information when used in Gui builder design mode
|
||||
V1.54 - Nov 2007: Minor changes to documentation
|
||||
V1.55 - Dec 2007: Added property enableFocus to GPane, default: setFocusable(false)
|
||||
V1.56 - Mar 2008: Unchanged, modifications in ch.aplu.util
|
||||
V1.57 - Mar 2008: Unchanged, modifications in ch.aplu.util
|
||||
V1.58 - Mar 2008: Modification to fill() (fill(x, y)):
|
||||
region is defined with pixel color at current position
|
||||
as opposed to background color
|
||||
V1.59 - Oct 2008: Added ctors TurtleFrame with window position (ulx, uly)
|
||||
Added Turtle.getPixelColor()
|
||||
V2.00 - Nov 2008: Unchanged, modifications in ch.aplu.util
|
||||
J2SE V1.4 no longer supported
|
||||
V2.01 - Jan 2009: Unchanged, modifications in ch.aplu.util
|
||||
V2.02 - Feb 2009 Turtle constructors run in EDT now
|
||||
V2.03 - Feb 2009 Unchanged, modifications in ch.aplu.util
|
||||
V2.04 - Feb 2009 Unchanged, modifications in ch.aplu.util
|
||||
V2.05 - Feb 2009 Unchanged, modifications in ch.aplu.util
|
||||
V2.06 - Mar 2009 Unchanged, modifications in ch.aplu.util
|
||||
V2.07 - Mar 2009 All except print methods synchronized, so Turtle package is
|
||||
now thread-safe
|
||||
V2.08 - Apr 2009 Unchanged, modifications in ch.aplu.util
|
||||
V2.09 - Jun 2009 Unchanged, modifications in ch.aplu.util
|
||||
V2.10 - Jun 2010 Version for the Java-Editor
|
||||
*/
|
||||
|
||||
package ch.aplu.turtle;
|
||||
|
||||
interface SharedConstants
|
||||
{
|
||||
int DEBUG_LEVEL_OFF = 0;
|
||||
int DEBUG_LEVEL_LOW = 1;
|
||||
int DEBUG_LEVEL_MEDIUM = 2;
|
||||
int DEBUG_LEVEL_HIGH = 3;
|
||||
|
||||
int DEBUG = DEBUG_LEVEL_OFF;
|
||||
|
||||
String ABOUT =
|
||||
"Copyright © 2002-2009\nRegula Hoefer-Isenegger, Aegidius Pluess\n, Gerhard Roehner\n" +
|
||||
"under GNU General Public License\n" +
|
||||
"http://www.aplu.ch\n" +
|
||||
"All rights reserved";
|
||||
String VERSION = "2.10 - June 2015";
|
||||
}
|
||||
|
|
@ -0,0 +1,84 @@
|
|||
// StreamingPlayer.java
|
||||
|
||||
package ch.aplu.turtle;
|
||||
|
||||
|
||||
import javax.sound.sampled.*;
|
||||
import java.io.*;
|
||||
|
||||
class StreamingPlayer
|
||||
{
|
||||
private class PlayerThread extends Thread
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
byte buf[] = new byte[20000];
|
||||
try
|
||||
{
|
||||
int cnt;
|
||||
while ((cnt = audioInputStream.read(buf, 0, buf.length)) != -1)
|
||||
{
|
||||
if (cnt > 0)
|
||||
sourceDataLine.write(buf, 0, cnt);
|
||||
}
|
||||
sourceDataLine.drain();
|
||||
sourceDataLine.close();
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
System.out.println(ex);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private AudioFormat audioFormat;
|
||||
private AudioInputStream audioInputStream;
|
||||
private SourceDataLine sourceDataLine;
|
||||
private PlayerThread playerThread;
|
||||
|
||||
StreamingPlayer(InputStream is)
|
||||
{
|
||||
try
|
||||
{
|
||||
audioInputStream =
|
||||
AudioSystem.getAudioInputStream(is);
|
||||
audioFormat = audioInputStream.getFormat();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{}
|
||||
}
|
||||
|
||||
void start(boolean doFinish)
|
||||
throws LineUnavailableException
|
||||
{
|
||||
DataLine.Info dataLineInfo =
|
||||
new DataLine.Info(SourceDataLine.class, audioFormat);
|
||||
sourceDataLine =
|
||||
(SourceDataLine)AudioSystem.getLine(dataLineInfo);
|
||||
sourceDataLine.open(audioFormat);
|
||||
sourceDataLine.start();
|
||||
playerThread = new PlayerThread();
|
||||
playerThread.start();
|
||||
if (doFinish)
|
||||
waitToFinish();
|
||||
}
|
||||
|
||||
boolean isPlaying()
|
||||
{
|
||||
if (playerThread == null)
|
||||
return false;
|
||||
return (playerThread.isAlive());
|
||||
}
|
||||
|
||||
void waitToFinish()
|
||||
{
|
||||
if (playerThread == null)
|
||||
return;
|
||||
try
|
||||
{
|
||||
playerThread.join();
|
||||
}
|
||||
catch (InterruptedException ex) {}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
// TPrintable.java
|
||||
|
||||
// Copyright 2002 Regula Hoefer-Isenegger
|
||||
|
||||
// This file is part of The Java Turtle (TJT) package
|
||||
//
|
||||
// TJT 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
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// TJT 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 The Java Turtle Package; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
// Added by Aegidius Pluess
|
||||
|
||||
package ch.aplu.turtle;
|
||||
|
||||
/**
|
||||
* Interface for printing on an attached printer.
|
||||
* Normally an application uses a Turtle and implements this interface.
|
||||
* draw() should contain all drawing operations into the
|
||||
* Turtle's Playground. The printing occures, when Turtle's print() is
|
||||
* called.<br><br>
|
||||
*/
|
||||
|
||||
|
||||
public interface TPrintable
|
||||
{
|
||||
/**
|
||||
* This method must perform all drawing operations.
|
||||
* Be aware that for some undocumented reason
|
||||
* draw() is called twice. So be sure you initialize it correctly.
|
||||
*/
|
||||
|
||||
public void draw();
|
||||
}
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -0,0 +1,66 @@
|
|||
// TurtleFactory.java
|
||||
|
||||
// Copyright 2002 Regula Hoefer-Isenegger
|
||||
//
|
||||
// This file is part of The Java Turtle (TJT) package
|
||||
//
|
||||
// TJT 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
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// TJT 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 The Java Turtle Package; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package ch.aplu.turtle;
|
||||
|
||||
import java.awt.image.*;
|
||||
import java.awt.*;
|
||||
|
||||
class TurtleFactory
|
||||
{
|
||||
/** Generates the shape of the turtle with <code>color</code>,
|
||||
* angle <code>angle</code>, width <code>w</code>
|
||||
* and height <code>h</code>.
|
||||
*/
|
||||
protected Image turtleImage(Color color, double angle, int w, int h)
|
||||
{
|
||||
BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_4BYTE_ABGR);
|
||||
Graphics2D g = (Graphics2D)bi.getGraphics();
|
||||
// Origin in center
|
||||
g.translate(w/2, h/2);
|
||||
// angle = 0 is direction east (as usual in mathematics)
|
||||
g.rotate(Math.PI/2 - angle);
|
||||
g.setColor(color);
|
||||
|
||||
// Body
|
||||
g.fillOval((int)( -0.35 * w), (int)( -0.35 * h),
|
||||
(int)(0.7 * w), (int)(0.7 * h));
|
||||
|
||||
// Head
|
||||
g.fillOval((int)( -0.1 * w), (int)( -0.5 * h),
|
||||
(int)(0.2 * w), (int)(0.2 * h));
|
||||
|
||||
// Tail
|
||||
int[] xcoords =
|
||||
{(int)( -0.05 * w), 0, (int)(0.05 * w)};
|
||||
int[] ycoords =
|
||||
{(int)(0.35 * h), (int)(0.45 * h), (int)(0.35 * h)};
|
||||
g.fillPolygon(xcoords, ycoords, 3);
|
||||
|
||||
// Feet
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
g.rotate(Math.PI / 2);
|
||||
g.fillOval((int)( -0.35 * w), (int)( -0.35 * h),
|
||||
(int)(0.125 * w), (int)(0.125 * h));
|
||||
}
|
||||
return (Image)bi;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,312 @@
|
|||
// TurtleRenderer.java
|
||||
|
||||
// Copyright 2002 Regula Hoefer-Isenegger
|
||||
// Some modifications by Aegidius Pluess
|
||||
|
||||
// This file is part of The Java Turtle (TJT) package
|
||||
//
|
||||
// TJT 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
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// TJT 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 The Java Turtle Package; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package ch.aplu.turtle;
|
||||
|
||||
import ch.aplu.turtle.*;
|
||||
import java.awt.image.*;
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import java.awt.geom.*;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
/** This class is responsible for creating and choosing the correct Turtle picture.
|
||||
@author <a href="mailto:regula@hoefer.ch">Regula Hoefer-Isenegger</a>
|
||||
@version 0.1
|
||||
*/
|
||||
public class TurtleRenderer implements ImageObserver {
|
||||
/** Holds the current image */
|
||||
private Image currentImage;
|
||||
/** Holds all images */
|
||||
private Vector images;
|
||||
/** Tells how many pictures are needed*/
|
||||
private int resolution;
|
||||
/** A reference to the <code>Turtle</code> */
|
||||
private Turtle turtle;
|
||||
/** Holds the current Angle */
|
||||
private double currentAngle;
|
||||
|
||||
private final int turtleSize = 29;
|
||||
|
||||
/***/
|
||||
public TurtleRenderer(Turtle turtle) {
|
||||
this.currentImage = null;
|
||||
this.images = new Vector();
|
||||
this.turtle = turtle;
|
||||
currentAngle = 0;
|
||||
}
|
||||
|
||||
/** As an image stays unchanged, there's no need to ever update it. So this method returns always false.
|
||||
|
||||
For further information cf. <code>java.awt.image.ImageObserver</code>.
|
||||
@see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
|
||||
*/
|
||||
public boolean imageUpdate(Image img, int infoflags,
|
||||
int x, int y, int width, int height) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Return the current image.
|
||||
*/
|
||||
public Image currentImage() {
|
||||
return this.currentImage;
|
||||
}
|
||||
|
||||
/** Tell whether the image has changed.
|
||||
*/
|
||||
public boolean imageChanged(double angle) {
|
||||
return (this.currentImage != getImage(angle));
|
||||
}
|
||||
|
||||
/** Set the current image to the specified one. */
|
||||
private void setCurrentImage(Image image) {
|
||||
currentImage = image;
|
||||
}
|
||||
|
||||
/** Choose the image for the angle <code>angle</code>.
|
||||
*/
|
||||
private Image getImage(double angle) {
|
||||
while (angle < 0) {
|
||||
angle += 2*Math.PI;
|
||||
}
|
||||
while (angle >= 2*Math.PI) {
|
||||
angle -= 2*Math.PI;
|
||||
}
|
||||
double res = 2*Math.PI/(double)this.resolution;
|
||||
int index = (int)(angle/res);
|
||||
return image(index);
|
||||
}
|
||||
|
||||
/** Set the current image to the one corresponding to the angle <code>angle</code>.
|
||||
*/
|
||||
public void setAngle(double angle) {
|
||||
currentAngle = angle;
|
||||
setCurrentImage(getImage(angle));
|
||||
}
|
||||
|
||||
/** @return the current angle. */
|
||||
protected double getAngle(){
|
||||
return currentAngle;
|
||||
}
|
||||
|
||||
/** Create the images. There are <code>resolution</code> images (i.e. two subsequent
|
||||
images contain an angle of 2π/<resolution> or 360/resolution degrees).
|
||||
*/
|
||||
public void init(TurtleFactory factory, int resolution) {
|
||||
this.resolution = resolution;
|
||||
Integer res = new Integer(resolution);
|
||||
double incRes = Math.PI*2/res.doubleValue();
|
||||
double angle = 0;
|
||||
images = new Vector();
|
||||
for (int i = 0; i < resolution; i++) {
|
||||
images.add(factory.turtleImage(turtle.getColor(),
|
||||
turtle.getPlayground().toScreenAngle(angle),
|
||||
turtleSize, turtleSize));
|
||||
angle += incRes;
|
||||
}
|
||||
setCurrentImage(getImage(currentAngle));
|
||||
}
|
||||
|
||||
/** Tell how many images this <code>TurtleRenderer</code> holds */
|
||||
private int countImages() {
|
||||
return this.images.size();
|
||||
}
|
||||
|
||||
/** Get the image at <code>index</code> */
|
||||
private Image image(int index) {
|
||||
return (Image)this.images.elementAt(index);
|
||||
}
|
||||
|
||||
/** This method is responsible for painting the turtle onto the
|
||||
playground at (<code>x, y</code>).
|
||||
*/
|
||||
public final void paint(double x, double y) {
|
||||
internalPaint(x, y, turtle.getPlayground().getGraphics());
|
||||
}
|
||||
|
||||
/** This method is responsible for painting the turtle onto the
|
||||
playground at <code>p</code>.
|
||||
*/
|
||||
public final void paint(Point2D.Double p) {
|
||||
internalPaint(p.x, p.y, turtle.getPlayground().getGraphics());
|
||||
}
|
||||
|
||||
/** This method is responsible for painting the <code>Turtle</code>
|
||||
at (<code>x, y</code>).<br>
|
||||
The Graphics argument tells where to paint.
|
||||
*/
|
||||
public final void paint(double x, double y, Graphics g) {
|
||||
internalPaint(x, y, g);
|
||||
}
|
||||
|
||||
/** This method is responsible for painting the <code>Turtle</code>
|
||||
at <code>p</code>.<br>
|
||||
The Graphics argument tells where to paint.
|
||||
*/
|
||||
public void paint(Point2D.Double p, Graphics g){
|
||||
internalPaint(p.x, p.y, g);
|
||||
}
|
||||
|
||||
/** Call clipPaint and wrapPaint().
|
||||
|
||||
You should override this method only, if you add a new (edge)
|
||||
behaviour to the turtle. I recommend to you then to first call this
|
||||
method from the overriding one.
|
||||
<br>
|
||||
If you want to change anything about the real painting, override
|
||||
clipPaint or wrapPaint.
|
||||
|
||||
@see #clipPaint(int, int, Graphics2D)
|
||||
@see #wrapPaint(int, int, Graphics2D)
|
||||
*/
|
||||
protected void internalPaint(double x, double y, Graphics g) {
|
||||
if(turtle.isClip()){
|
||||
Point2D.Double p =
|
||||
calcTopLeftCorner(turtle.getPlayground().toScreenCoords(x, y));
|
||||
clipPaint((int)p.x, (int)p.y, (Graphics2D)g);
|
||||
}
|
||||
else if(turtle.isWrap()){
|
||||
Point2D.Double p =
|
||||
calcTopLeftCorner(turtle.getPlayground().toScreenCoords(x, y));
|
||||
wrapPaint((int)p.x, (int)p.y, (Graphics2D)g);
|
||||
}
|
||||
}
|
||||
|
||||
/** Define how to paint in clip mode and do it */
|
||||
protected void clipPaint(int x, int y, Graphics2D g2D) {
|
||||
g2D.drawImage(currentImage, x, y, this);
|
||||
}
|
||||
|
||||
/** Define how to paint in wrap mode and do it */
|
||||
protected void wrapPaint(int x, int y, Graphics2D g2D) {
|
||||
int pWidth = turtle.getPlayground().getWidth();
|
||||
int pHeight = turtle.getPlayground().getHeight();
|
||||
int paintX = x;
|
||||
while (paintX > pWidth) {
|
||||
paintX -= pWidth;
|
||||
}
|
||||
while (paintX < 0) {
|
||||
paintX += pWidth;
|
||||
}
|
||||
int paintY = y;
|
||||
while (paintY > pHeight) {
|
||||
paintY -= pHeight;
|
||||
}
|
||||
while (paintY < 0) {
|
||||
paintY += pHeight;
|
||||
}
|
||||
g2D.drawImage(currentImage, paintX, paintY, this);
|
||||
int nWidth = currentImage.getWidth(this);
|
||||
int nHeight = currentImage.getHeight(this);
|
||||
boolean right = (paintX+nWidth > pWidth);
|
||||
boolean bottom = (paintY+nHeight > pHeight);
|
||||
if(right) {
|
||||
g2D.drawImage(currentImage,
|
||||
paintX-pWidth,
|
||||
paintY,
|
||||
this);
|
||||
}
|
||||
if(bottom) {
|
||||
g2D.drawImage(currentImage,
|
||||
paintX,
|
||||
paintY-pHeight,
|
||||
this);
|
||||
}
|
||||
if(right && bottom) {
|
||||
g2D.drawImage(currentImage,
|
||||
paintX-pWidth,
|
||||
paintY-pHeight,
|
||||
this);
|
||||
}
|
||||
}
|
||||
|
||||
/** Compute the x-coordinate of the top left corner of the Turtle image
|
||||
(it depends on the specified x-coordinate and the image width).
|
||||
*/
|
||||
protected int calcTopLeftCornerX(double x) {
|
||||
int intX = (int)x;
|
||||
int nWidth;
|
||||
if(currentImage == null) {
|
||||
setCurrentImage(new TurtleFactory().
|
||||
turtleImage(turtle.getColor(), getAngle(), turtleSize, turtleSize));
|
||||
}
|
||||
nWidth = this.currentImage.getWidth(this);
|
||||
// the center of the turtle lies on the turtle's location:
|
||||
intX -= nWidth/2;
|
||||
return intX; // top left corner of the Turtle's image
|
||||
}
|
||||
|
||||
/** Compute the y-coordinate of the top left corner of the Turtle image
|
||||
(it depends on the specified y-coordinate and the image height).
|
||||
*/
|
||||
protected int calcTopLeftCornerY(double y) {
|
||||
int intY = (int)y;
|
||||
if(currentImage == null) {
|
||||
setCurrentImage(new TurtleFactory().
|
||||
turtleImage(turtle.getColor(), getAngle(), turtleSize, turtleSize));
|
||||
}
|
||||
int nHeight = currentImage.getHeight(this);
|
||||
// the center of the turtle lies on the turtle's location:
|
||||
intY -= nHeight/2;
|
||||
|
||||
return intY; // top left corner of the Turtle's image
|
||||
}
|
||||
/** Compute the top left corner of the Turtle image
|
||||
(dependent on the specified x- and y-coordinate and the image
|
||||
width and height.
|
||||
*/
|
||||
protected Point2D.Double calcTopLeftCorner(double x, double y) {
|
||||
if(currentImage == null) {
|
||||
setCurrentImage(new TurtleFactory().
|
||||
turtleImage(turtle.getColor(), getAngle(), turtleSize, turtleSize));
|
||||
}
|
||||
int w = currentImage.getWidth(this);
|
||||
int h = currentImage.getHeight(this);
|
||||
return new Point2D.Double(x-w/2, y-h/2);
|
||||
}
|
||||
|
||||
/** Compute the top left corner of the Turtle image
|
||||
(dependent on the specified point <code>p</code> and the image
|
||||
width and height.
|
||||
*/
|
||||
protected Point2D.Double calcTopLeftCorner(Point2D.Double p) {
|
||||
return calcTopLeftCorner(p.x, p.y);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
public class Eval {
|
||||
|
||||
public static Wrap getOb(Object o) {
|
||||
return new Wrap(o);
|
||||
}
|
||||
|
||||
protected static Object getOb(final String s) {
|
||||
return new Object() {public String result = s;};
|
||||
}
|
||||
|
||||
protected static Object getOb(final boolean b) {
|
||||
return new Object() {public boolean result = b;};
|
||||
}
|
||||
|
||||
protected static Object getOb(final byte b) {
|
||||
return new Object() {public byte result = b;};
|
||||
}
|
||||
|
||||
protected static Object getOb(final char c) {
|
||||
return new Object() {public char result = c;};
|
||||
}
|
||||
|
||||
protected static Object getOb(final double d) {
|
||||
return new Object() {public double result = d;};
|
||||
}
|
||||
|
||||
protected static Object getOb(final float f) {
|
||||
return new Object() {public float result = f;};
|
||||
}
|
||||
|
||||
protected static Object getOb(final int i) {
|
||||
return new Object() {public int result = i;};
|
||||
}
|
||||
|
||||
protected static Object getOb(final long l) {
|
||||
return new Object() {public long result = l;};
|
||||
}
|
||||
protected static Object getOb(final short s) {
|
||||
return new Object() {public short result = s;};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Wrap {
|
||||
public Object result;
|
||||
|
||||
Wrap(Object result) {
|
||||
this.result = result;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,98 @@
|
|||
import java.io.*;
|
||||
|
||||
/**
|
||||
Support class for console input and output of numeric values.<br><br>
|
||||
|
||||
Example for input:<br>
|
||||
int age = InOut.readInt("Your age: ");<br><br>
|
||||
|
||||
Example for output:<br>
|
||||
System.out.println("price: " + InOut.format2(prize) + "Euro");<br>
|
||||
System.out.println("percent: " + InOut.formatN(percent, 1) + " %");
|
||||
*/
|
||||
|
||||
|
||||
public class InOut {
|
||||
|
||||
/** Formats a double-value with 2 decimal digits. */
|
||||
public static String format2(double d) {
|
||||
return String.format("%.2f", d);
|
||||
}
|
||||
|
||||
/** Formats a double-value with N decimal digits. */
|
||||
public static String formatN(double d, int N) {
|
||||
return String.format("%." + N + "f", d);
|
||||
}
|
||||
|
||||
/** Reads a boolean-value from console. */
|
||||
public static boolean readBoolean(String prompt) {
|
||||
final String[] trueValues =
|
||||
{ "1", "y", "t", "j", "w", "yes", "true", "ja", "wahr", "ok" };
|
||||
System.out.print(prompt);
|
||||
String input = readln().toLowerCase();
|
||||
for (int i = 0; i < trueValues.length; ++i)
|
||||
if (trueValues[i].equals(input))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Reads a char-value from console. */
|
||||
public static char readChar(String prompt) {
|
||||
System.out.print(prompt);
|
||||
return readln().charAt(0);
|
||||
}
|
||||
|
||||
/** Reads a double-value from console. */
|
||||
public static double readDouble(String prompt) {
|
||||
System.out.print(prompt);
|
||||
return Double.parseDouble(readln());
|
||||
}
|
||||
|
||||
/** Reads a float-value from console. */
|
||||
public static float readFloat(String prompt) {
|
||||
System.out.print(prompt);
|
||||
return Float.parseFloat(readln());
|
||||
}
|
||||
|
||||
/** Reads an int-value from console. */
|
||||
public static int readInt(String prompt) {
|
||||
System.out.print(prompt);
|
||||
return Integer.parseInt(readln());
|
||||
}
|
||||
|
||||
/** Reads a long-value from console. */
|
||||
public static long readLong(String prompt) {
|
||||
System.out.print(prompt);
|
||||
return Long.parseLong(readln());
|
||||
}
|
||||
|
||||
/** Reads a string-value from console. */
|
||||
public static String readString(String prompt) {
|
||||
System.out.print(prompt);
|
||||
return readln();
|
||||
}
|
||||
|
||||
/** Reads a string-value from console without prompt.
|
||||
For use at the end of a console program. */
|
||||
public static String readln() {
|
||||
try {
|
||||
return Input.readLine();
|
||||
} catch(Exception e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
private static BufferedReader Input;
|
||||
|
||||
static {
|
||||
try {
|
||||
Input = new BufferedReader(new InputStreamReader(System.in));
|
||||
}
|
||||
catch (Exception e) {
|
||||
System.out.println("console input not possible.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,311 @@
|
|||
package je.util;
|
||||
/*
|
||||
* Class : Turtle
|
||||
* Copyright: (c) Gerhard Röhner
|
||||
*
|
||||
* History
|
||||
* --------
|
||||
* 3.00 2000.10.10 first version as java class
|
||||
* 3.01 2002.10.22 DrawDynamic
|
||||
* 3.02 2010.10.11 sleepTime for paint delay
|
||||
* 3.03 2012.03.20 cartesian coordinate system, used with originX, originY, setOrigin
|
||||
* 3.04 2015.01.24 english version, integrated component
|
||||
*/
|
||||
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.image.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
/**
|
||||
* This class is a turtle component for simple graphic programming.
|
||||
*
|
||||
* @see <a href="http://www.javaeditor.org">
|
||||
* @author Gerhard Röhner
|
||||
* @version 3.03 20/03/2012
|
||||
*/
|
||||
|
||||
|
||||
public class Turtle extends Canvas {
|
||||
|
||||
// -- private Attribute ------------------------------------------------------
|
||||
|
||||
private BufferedImage myBufferedImage;
|
||||
private Graphics myBufferedGraphics;
|
||||
private Color foreground;
|
||||
private Color background;
|
||||
private static final double piDurch180 = Math.PI / 180;
|
||||
|
||||
// -- public attributes -----------------------------------------------------
|
||||
|
||||
/**
|
||||
* turtleX is the x-coordinate of the turtle
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.turtleX = 100;</PRE>
|
||||
*/
|
||||
public double turtleX;
|
||||
|
||||
/**
|
||||
* turtleY is the y-coordinate of the turtle.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.turtleY = 200;</PRE>
|
||||
*/
|
||||
public double turtleY;
|
||||
|
||||
/**
|
||||
* turtleW is the current angle of the turtle in the range form 0 to 360 degrees.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.turtleW = 180;</PRE>
|
||||
*/
|
||||
public double turtleW;
|
||||
|
||||
/**
|
||||
* originX is the x-position of the cartesian coodinate system within the turtle canvas.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.originX = 0;</PRE>
|
||||
*/
|
||||
public double originX;
|
||||
|
||||
/**
|
||||
* originY is the y-position of the cartesian coodinate system within the turtle canvas.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.originY = 100;</PRE>
|
||||
*/
|
||||
public double originY;
|
||||
|
||||
/**
|
||||
* If drawDynamic is true you can watch the drawing of the turtle.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.drawDynamic = true;</PRE>
|
||||
*/
|
||||
public boolean drawDynamic;
|
||||
|
||||
/**
|
||||
* For drawDynamic = true you set the delay in milliseconds for drawing.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.sleepTime = 500;</PRE>
|
||||
*/
|
||||
public int sleepTime = 0;
|
||||
|
||||
// --- constructor -----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Creates a Turtle with a canvas.
|
||||
* At the beginning the Turtle is placed in the middle of it's canvas.
|
||||
* The start angle is 0 degree, which means the Turtle looks to the right.
|
||||
* The background color is white, the drawing color black.
|
||||
* <P>
|
||||
* The turtle position can easily be changed by clicking into the canvas.
|
||||
* <P>
|
||||
* The size of the canvas can easily be changed with the mouse.
|
||||
* <P>
|
||||
* Example: <PRE>Turtle myTurtle = new Turtle();</PRE>
|
||||
*/
|
||||
|
||||
public Turtle() {
|
||||
myBufferedImage = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
|
||||
myBufferedGraphics = myBufferedImage.getGraphics();
|
||||
|
||||
setForeground(Color.black);
|
||||
setBackground(Color.white);
|
||||
drawDynamic = true;
|
||||
|
||||
addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent evt) {
|
||||
turtleMouseClicked(evt);}});
|
||||
addComponentListener(new ComponentAdapter() {
|
||||
public void componentResized(ComponentEvent evt) {
|
||||
turtleResized(evt);}});
|
||||
setOrigin(50, 50);
|
||||
}
|
||||
|
||||
private void turtleMouseClicked(MouseEvent evt) {
|
||||
turtleX = evt.getX() - originX;
|
||||
turtleY = originY - evt.getY();
|
||||
turtleW = 0;
|
||||
}
|
||||
|
||||
private void turtleResized(ComponentEvent evt) {
|
||||
int width = getWidth();
|
||||
int height = getHeight();
|
||||
|
||||
BufferedImage newBufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
|
||||
Graphics newGraphics = newBufferedImage.getGraphics();
|
||||
newGraphics.setColor(background);
|
||||
newGraphics.fillRect(0, 0, width, height);
|
||||
newGraphics.setColor(foreground);
|
||||
newGraphics.drawImage(myBufferedImage, 0, 0, this);
|
||||
|
||||
turtleX = 0;
|
||||
turtleY = 0;
|
||||
turtleW = 0;
|
||||
setOrigin(width / 2, height / 2);
|
||||
|
||||
myBufferedImage = newBufferedImage;
|
||||
myBufferedGraphics = newGraphics;
|
||||
}
|
||||
|
||||
public boolean isDoubleBuffered() {
|
||||
return true;
|
||||
}
|
||||
|
||||
private void wTurtleMod360() {
|
||||
while (turtleW >= 360)
|
||||
turtleW = turtleW - 360;
|
||||
while (turtleW < 0)
|
||||
turtleW = turtleW + 360;
|
||||
}
|
||||
|
||||
// --- angle and turns -------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Turns the angle of the turtle relativ by the parameter angle.
|
||||
* Positive values means a turn right, negative a turn left.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.turn(-90);</PRE>
|
||||
*/
|
||||
public void turn(double angle) {
|
||||
turtleW = turtleW + angle;
|
||||
wTurtleMod360();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the angle of the turtle absolute by the parameter angle.
|
||||
* The angle increases counterclockwise, therefore
|
||||
* right = 0, top = 90, left = 180, bottom = 270.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.turnto(270);</PRE>
|
||||
*/
|
||||
public void turnto(double angle) {
|
||||
turtleW = angle;
|
||||
wTurtleMod360();
|
||||
}
|
||||
|
||||
// --- Drawing ---------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* The Turtle draws a line of the length specified in the current direction.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.draw(100);</PRE>
|
||||
*/
|
||||
public void draw(double length) {
|
||||
drawto(turtleX + length * Math.cos(turtleW * piDurch180),
|
||||
turtleY + length * Math.sin(turtleW * piDurch180));
|
||||
}
|
||||
|
||||
/**
|
||||
* The Turtle draws a line form the current position (turtleX, turtleY) to the
|
||||
* position (x, y) relativ to the cartesian coordinate system.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.drawto(200, 300);</PRE>
|
||||
*/
|
||||
public void drawto(double x, double y) {
|
||||
int x1 = (int) (originX + turtleX);
|
||||
int x2 = (int) (originX + x);
|
||||
int y1 = (int) (originY - turtleY);
|
||||
int y2 = (int) (originY - y);
|
||||
|
||||
myBufferedGraphics.drawLine(x1, y1, x2, y2);
|
||||
if (drawDynamic){
|
||||
getGraphics().drawLine(x1, y1, x2, y2);
|
||||
try {
|
||||
Thread.currentThread().sleep(sleepTime);
|
||||
} catch(InterruptedException e) {
|
||||
}
|
||||
} else
|
||||
repaint();
|
||||
|
||||
turtleX = x;
|
||||
turtleY = y;
|
||||
}
|
||||
|
||||
// --- Moving ----------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* The Turtle moves without drawing the length specified in the current
|
||||
* direction.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.move(100);</PRE>
|
||||
*/
|
||||
public void move(double length) {
|
||||
turtleX = turtleX + length * Math.cos (turtleW * piDurch180);
|
||||
turtleY = turtleY + length * Math.sin (turtleW * piDurch180);
|
||||
}
|
||||
|
||||
/**
|
||||
* The Turtle moves without drawing to position (x, y) relativ to the
|
||||
* cartesian coordinate system.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.moveto(100, 200);</PRE>
|
||||
*/
|
||||
public void moveto(double x, double y) {
|
||||
turtleX = x;
|
||||
turtleY = y;
|
||||
}
|
||||
|
||||
// --- set origin -----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Sets the origin of the cartesian coordinate system within the turtle's canvas.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.setOrigin(100, 200);</PRE>
|
||||
*/
|
||||
public void setOrigin(double x, double y) {
|
||||
originX = x;
|
||||
originY = y;
|
||||
}
|
||||
|
||||
// --- fore- and background color --------------------------------------------
|
||||
|
||||
/**
|
||||
* Sets the drawing color of the Turtle to color c.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.setForeground(Color.red);</PRE>
|
||||
*/
|
||||
public void setForeground(Color c) {
|
||||
foreground = c;
|
||||
myBufferedGraphics.setColor(foreground);
|
||||
super.setForeground(foreground);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the canvas color of the Turtle to color c.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.setBackground(Color.blue); </PRE>
|
||||
*/
|
||||
public void setBackground(Color c) {
|
||||
background = c;
|
||||
myBufferedGraphics.setColor(background);
|
||||
myBufferedGraphics.fillRect(0, 0, getWidth(), getHeight());
|
||||
myBufferedGraphics.setColor(foreground);
|
||||
repaint();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the Turtle's canvas with the background color.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.clear();</PRE>
|
||||
*/
|
||||
public void clear() {
|
||||
setBackground(background);
|
||||
getGraphics().drawImage(myBufferedImage, 0, 0, this);
|
||||
repaint();
|
||||
}
|
||||
|
||||
// --- Showing --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Shows the Turtle's canvas.
|
||||
*/
|
||||
public void paint(Graphics g) {
|
||||
g.drawImage(myBufferedImage, 0, 0, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the Turtle's canvas.
|
||||
*/
|
||||
public void update(Graphics g) {
|
||||
paint(g);
|
||||
}
|
||||
|
||||
}
|
||||
Binary file not shown.
|
|
@ -0,0 +1,129 @@
|
|||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
Swing-component for input and output of numeric values.
|
||||
*/
|
||||
|
||||
public class JNumberField extends JTextField {
|
||||
|
||||
/** constructor for a JNumberField */
|
||||
public JNumberField() {
|
||||
enableEvents(AWTEvent.KEY_EVENT_MASK);
|
||||
}
|
||||
|
||||
/** Gets a double-value from the JNumberField. */
|
||||
public double getDouble() {
|
||||
Double d = new Double(getText());
|
||||
return d.doubleValue();
|
||||
}
|
||||
|
||||
/** Gets a float-value from the JNumberField. */
|
||||
public float getFloat() {
|
||||
Double d = new Double(getText());
|
||||
return d.floatValue();
|
||||
}
|
||||
|
||||
/** Gets an int-value from the JNumberField. */
|
||||
public int getInt() {
|
||||
Double d = new Double(getText());
|
||||
return d.intValue();
|
||||
}
|
||||
|
||||
/** Gets a long-value from the JNumberField. */
|
||||
public long getLong() {
|
||||
Double d = new Double(getText());
|
||||
return d.longValue();
|
||||
}
|
||||
|
||||
/** Checks wether the JNumberField contains a valid numeric value. */
|
||||
public boolean isNumeric() {
|
||||
final String Digits = "(\\p{Digit}+)";
|
||||
final String HexDigits = "(\\p{XDigit}+)";
|
||||
// an exponent is 'e' or 'E' followed by an optionally
|
||||
// signed decimal integer.
|
||||
final String Exp = "[eE][+-]?"+Digits;
|
||||
final String fpRegex =
|
||||
("[\\x00-\\x20]*"+ // Optional leading "whitespace"
|
||||
"[+-]?(" + // Optional sign character
|
||||
"NaN|" + // "NaN" string
|
||||
"Infinity|" + // "Infinity" string
|
||||
|
||||
// A decimal floating-point string representing a finite positive
|
||||
// number without a leading sign has at most five basic pieces:
|
||||
// Digits . Digits ExponentPart FloatTypeSuffix
|
||||
//
|
||||
// Since this method allows integer-only strings as input
|
||||
// in addition to strings of floating-point literals, the
|
||||
// two sub-patterns below are simplifications of the grammar
|
||||
// productions from the Java Language Specification, 2nd
|
||||
// edition, section 3.10.2.
|
||||
|
||||
// Digits ._opt Digits_opt ExponentPart_opt FloatTypeSuffix_opt
|
||||
"((("+Digits+"(\\.)?("+Digits+"?)("+Exp+")?)|"+
|
||||
|
||||
// . Digits ExponentPart_opt FloatTypeSuffix_opt
|
||||
"(\\.("+Digits+")("+Exp+")?)|"+
|
||||
|
||||
// Hexadecimal strings
|
||||
"((" +
|
||||
// 0[xX] HexDigits ._opt BinaryExponent FloatTypeSuffix_opt
|
||||
"(0[xX]" + HexDigits + "(\\.)?)|" +
|
||||
|
||||
// 0[xX] HexDigits_opt . HexDigits BinaryExponent FloatTypeSuffix_opt
|
||||
"(0[xX]" + HexDigits + "?(\\.)" + HexDigits + ")" +
|
||||
|
||||
")[pP][+-]?" + Digits + "))" +
|
||||
"[fFdD]?))" +
|
||||
"[\\x00-\\x20]*");// Optional trailing "whitespace"
|
||||
|
||||
return java.util.regex.Pattern.matches(fpRegex, getText());
|
||||
}
|
||||
|
||||
/** Sets a double-value into the JNumberField. */
|
||||
public void setDouble(double d) {
|
||||
setText(String.valueOf(d));
|
||||
}
|
||||
|
||||
/** Sets a double-value with N digits into the JNumberField. */
|
||||
public void setDouble(double d, int N) {
|
||||
setText(String.format(Locale.ENGLISH, "%." + N + "f", d));
|
||||
}
|
||||
|
||||
/** Sets a float-value into the JNumberField. */
|
||||
public void setFloat(float f) {
|
||||
setText(String.valueOf(f));
|
||||
}
|
||||
|
||||
/** Sets a float-value with N digits into the JNumberField. */
|
||||
public void setFloat(float f, int N) {
|
||||
setText(String.format(Locale.ENGLISH, "%." + N + "f", f));
|
||||
}
|
||||
|
||||
/** Sets an int-value into the JNumberField. */
|
||||
public void setInt(int i) {
|
||||
setText(String.valueOf(i));
|
||||
}
|
||||
|
||||
/** Sets a long-value into the JNumberField. */
|
||||
public void setLong(long l) {
|
||||
setText(String.valueOf(l));
|
||||
}
|
||||
|
||||
/** Clears the JNumberField */
|
||||
public void clear() {
|
||||
setText("");
|
||||
}
|
||||
|
||||
protected void processKeyEvent(KeyEvent e) {
|
||||
super.processKeyEvent(e);
|
||||
if (isNumeric() || getText().equals("-") ||
|
||||
getText().equals("") || getText().equals("."))
|
||||
setBackground(Color.white);
|
||||
else
|
||||
setBackground(Color.red);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
Manifest-Version: 1.0
|
||||
Class-Path: JEClasses.jar
|
||||
Created-By: 1.8.0_161 (Oracle Corporation)
|
||||
Main-Class: BreakVigenere
|
||||
|
||||
|
|
@ -0,0 +1,128 @@
|
|||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
AWT-component for input and output of numeric values.
|
||||
*/
|
||||
|
||||
public class NumberField extends TextField {
|
||||
|
||||
/** constructor for a NumberField */
|
||||
public NumberField() {
|
||||
enableEvents(AWTEvent.KEY_EVENT_MASK);
|
||||
}
|
||||
|
||||
/** Gets a double-value from the NumberField. */
|
||||
public double getDouble() {
|
||||
Double d = new Double(getText());
|
||||
return d.doubleValue();
|
||||
}
|
||||
|
||||
/** Gets a float-value from the NumberField. */
|
||||
public float getFloat() {
|
||||
Double d = new Double(getText());
|
||||
return d.floatValue();
|
||||
}
|
||||
|
||||
/** Gets an int-value from the NumberField. */
|
||||
public int getInt() {
|
||||
Double d = new Double(getText());
|
||||
return d.intValue();
|
||||
}
|
||||
|
||||
/** Gets a long-value from the NumberField. */
|
||||
public long getLong() {
|
||||
Double d = new Double(getText());
|
||||
return d.longValue();
|
||||
}
|
||||
|
||||
/** Checks wether the NumberField contains a valid numeric value. */
|
||||
public boolean isNumeric() {
|
||||
final String Digits = "(\\p{Digit}+)";
|
||||
final String HexDigits = "(\\p{XDigit}+)";
|
||||
// an exponent is 'e' or 'E' followed by an optionally
|
||||
// signed decimal integer.
|
||||
final String Exp = "[eE][+-]?"+Digits;
|
||||
final String fpRegex =
|
||||
("[\\x00-\\x20]*"+ // Optional leading "whitespace"
|
||||
"[+-]?(" + // Optional sign character
|
||||
"NaN|" + // "NaN" string
|
||||
"Infinity|" + // "Infinity" string
|
||||
|
||||
// A decimal floating-point string representing a finite positive
|
||||
// number without a leading sign has at most five basic pieces:
|
||||
// Digits . Digits ExponentPart FloatTypeSuffix
|
||||
//
|
||||
// Since this method allows integer-only strings as input
|
||||
// in addition to strings of floating-point literals, the
|
||||
// two sub-patterns below are simplifications of the grammar
|
||||
// productions from the Java Language Specification, 2nd
|
||||
// edition, section 3.10.2.
|
||||
|
||||
// Digits ._opt Digits_opt ExponentPart_opt FloatTypeSuffix_opt
|
||||
"((("+Digits+"(\\.)?("+Digits+"?)("+Exp+")?)|"+
|
||||
|
||||
// . Digits ExponentPart_opt FloatTypeSuffix_opt
|
||||
"(\\.("+Digits+")("+Exp+")?)|"+
|
||||
|
||||
// Hexadecimal strings
|
||||
"((" +
|
||||
// 0[xX] HexDigits ._opt BinaryExponent FloatTypeSuffix_opt
|
||||
"(0[xX]" + HexDigits + "(\\.)?)|" +
|
||||
|
||||
// 0[xX] HexDigits_opt . HexDigits BinaryExponent FloatTypeSuffix_opt
|
||||
"(0[xX]" + HexDigits + "?(\\.)" + HexDigits + ")" +
|
||||
|
||||
")[pP][+-]?" + Digits + "))" +
|
||||
"[fFdD]?))" +
|
||||
"[\\x00-\\x20]*");// Optional trailing "whitespace"
|
||||
|
||||
return java.util.regex.Pattern.matches(fpRegex, getText());
|
||||
}
|
||||
|
||||
/** Sets a double-value into the NumberField. */
|
||||
public void setDouble(double d) {
|
||||
setText(String.valueOf(d));
|
||||
}
|
||||
|
||||
/** Sets a double-value with N digits into the NumberField. */
|
||||
public void setDouble(double d, int N) {
|
||||
setText(String.format(Locale.ENGLISH, "%." + N + "f", d));
|
||||
}
|
||||
|
||||
/** Sets a float-value into the NumberField. */
|
||||
public void setFloat(float f) {
|
||||
setText(String.valueOf(f));
|
||||
}
|
||||
|
||||
/** Sets a float-value with N digits into the NumberField. */
|
||||
public void setFloat(float f, int N) {
|
||||
setText(String.format(Locale.ENGLISH, "%." + N + "f", f));
|
||||
}
|
||||
|
||||
/** Sets an int-value into the NumberField. */
|
||||
public void setInt(int i) {
|
||||
setText(String.valueOf(i));
|
||||
}
|
||||
|
||||
/** Sets a long-value into the NumberField. */
|
||||
public void setLong(long l) {
|
||||
setText(String.valueOf(l));
|
||||
}
|
||||
|
||||
/** Clears the NumberField */
|
||||
public void clear() {
|
||||
setText("");
|
||||
}
|
||||
|
||||
protected void processKeyEvent(KeyEvent e) {
|
||||
super.processKeyEvent(e);
|
||||
if (isNumeric() || getText().equals("-") ||
|
||||
getText().equals("") || getText().equals("."))
|
||||
setBackground(Color.white);
|
||||
else
|
||||
setBackground(Color.red);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
import java.awt.*;
|
||||
import java.awt.geom.Line2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import javax.swing.*;
|
||||
|
||||
public class Balkendiagramm extends JPanel {
|
||||
|
||||
private double gesamt;
|
||||
private double haeufigkeit[];
|
||||
private double maxwert;
|
||||
private int verschiebung = 0;
|
||||
private double haeufigkeit_de[] = { 0.0651, 0.0189, 0.0306, 0.0508, 0.174, 0.0166, 0.0301, 0.0476,0.0755, 0.0027, 0.0121,0.0344,0.0252,0.0978,0.0251,0.0079,0.0002,0.07,0.0727,0.0615,0.0435,0.067,0.0189,0.0003,0.0004,0.0113};
|
||||
private boolean zeigeDeutsch = true;
|
||||
|
||||
|
||||
public void setHaeufigkeit(double haeufigkeit[]) {
|
||||
|
||||
this.haeufigkeit = haeufigkeit;
|
||||
gesamt = 0;
|
||||
for (int i = 0; i < 26; i++) {
|
||||
gesamt += haeufigkeit[i];
|
||||
}
|
||||
for (int i = 0; i < 26; i++) {
|
||||
haeufigkeit[i] /= gesamt;
|
||||
}
|
||||
maxwert = 0.20;
|
||||
|
||||
}
|
||||
|
||||
public void setVerschiebung(int verschiebung) {
|
||||
if (verschiebung >= 0 && verschiebung < 26) {
|
||||
this.verschiebung = verschiebung;
|
||||
|
||||
} else {
|
||||
this.verschiebung = 0;
|
||||
} // end of if-else
|
||||
}
|
||||
public void setZeigeDeutsch(boolean show) {
|
||||
zeigeDeutsch = show;
|
||||
}
|
||||
|
||||
|
||||
public void paintComponent(Graphics g) {
|
||||
Graphics2D g2 = (Graphics2D) g;
|
||||
super.paintComponent(g2);
|
||||
Dimension d = getSize(null);
|
||||
//Skalieren auf 100x100 mit y-Invertierung
|
||||
g2.scale(d.getWidth() / 120.0, -d.getHeight() / 100.0);
|
||||
// Ursprung verschieben nach (15,-90)
|
||||
g2.translate(5, -90);
|
||||
// Linien etwas breiter
|
||||
g2.setStroke(new BasicStroke(1.5f));
|
||||
// x-Achse zeichnen
|
||||
g2.draw(new Line2D.Double(0, 0, 104, 0));
|
||||
// Linien etwas dünner
|
||||
g2.setStroke(new BasicStroke(0.5f));
|
||||
// Deutsche Häufigkeit grau
|
||||
g2.setColor(Color.darkGray);
|
||||
if(zeigeDeutsch) {
|
||||
|
||||
// Säulen zeichnen
|
||||
for (int i = 0; i < 26; i++) {
|
||||
g2.fill(new Rectangle2D.Double(4 * i+1, 0, 2, haeufigkeit_de[i] / maxwert *100));
|
||||
}
|
||||
}
|
||||
|
||||
// Texthäufigkeit blau
|
||||
g2.setColor(Color.blue);
|
||||
// Säulen zeichnen
|
||||
for (int i = 0; i < 26; i++) {
|
||||
g2.fill(new Rectangle2D.Double(4 * i, 0, 2, haeufigkeit[(i+verschiebung)%26] / maxwert *100));
|
||||
}
|
||||
// y-Invertierung rückgängig machen
|
||||
g2.scale(1, -1);
|
||||
// Beschriftung x-Achse
|
||||
String xAchse = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
// Fontgröße für Beschriftung ändern
|
||||
g2.setColor(Color.black);
|
||||
g2.setFont(g2.getFont().deriveFont(5f));
|
||||
for (int i = 0; i < 26; i++) {
|
||||
g2.drawString(xAchse.substring(i, i + 1),
|
||||
i * 4, +6);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
public class Baustein implements Comparable<Baustein>{
|
||||
|
||||
// Anfang Attribute
|
||||
private String zeichen;
|
||||
private int anzahl;
|
||||
// Ende Attribute
|
||||
|
||||
public Baustein(String zeichen) {
|
||||
super();
|
||||
anzahl = 1;
|
||||
this.zeichen = zeichen;
|
||||
}
|
||||
// Anfang Methoden
|
||||
|
||||
|
||||
|
||||
public int compareTo(Baustein c) {
|
||||
|
||||
int anz = c.getAnzahl();
|
||||
|
||||
//ascending order
|
||||
return anz - this.anzahl;
|
||||
|
||||
//descending order
|
||||
//return compareQuantity - this.quantity;
|
||||
|
||||
}
|
||||
public String getZeichen() {
|
||||
return zeichen;
|
||||
}
|
||||
|
||||
public int getAnzahl() {
|
||||
return anzahl;
|
||||
}
|
||||
|
||||
public void incAnzahl() {
|
||||
anzahl++;
|
||||
}
|
||||
|
||||
|
||||
// Ende Methoden
|
||||
}
|
||||
Binary file not shown.
|
|
@ -0,0 +1,360 @@
|
|||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
import javax.swing.table.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import javax.swing.text.DefaultHighlighter;
|
||||
import javax.swing.text.Highlighter;
|
||||
import javax.swing.text.Highlighter.HighlightPainter;
|
||||
import javax.swing.text.BadLocationException;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Programm zur Kryptoanalyse
|
||||
* von monoalphabetischen Substitutionen
|
||||
*
|
||||
* @version 1.0 from 23.11.2016
|
||||
* @author Thomas Schaller
|
||||
*/
|
||||
|
||||
public class BreakVigenere extends JFrame {
|
||||
// Anfang Attribute
|
||||
private JTextField[] buchstabe;
|
||||
|
||||
private JButton jButton1 = new JButton();
|
||||
private JButton jBBuchstabe = new JButton();
|
||||
private Balkendiagramm bdText = new Balkendiagramm();
|
||||
private Balkendiagramm bdBruteForce = new Balkendiagramm();
|
||||
private Balkendiagramm bdDeutsch = new Balkendiagramm();
|
||||
|
||||
private JTextArea jTAKrypto = new JTextArea("");
|
||||
private JScrollPane jTAKryptoScrollPane = new JScrollPane(jTAKrypto);
|
||||
private JTextArea jTAKlartext = new JTextArea("");
|
||||
private JScrollPane jTAKlartextScrollPane = new JScrollPane(jTAKlartext);
|
||||
private JLabel jLKryptotext = new JLabel();
|
||||
private JLabel jLKlartext = new JLabel();
|
||||
private JLabel jLCopyright = new JLabel();
|
||||
private JTextArea jTAKorrelation = new JTextArea("");
|
||||
private JScrollPane jTAKorrelationScrollPane = new JScrollPane(jTAKorrelation);
|
||||
private JSpinner jSpVerschiebung = new JSpinner();
|
||||
private SpinnerNumberModel jSpVerschiebungModel = new SpinnerNumberModel(0, 0, 99, 1);
|
||||
private JNumberField jNFAnzahlTreffer = new JNumberField();
|
||||
private JLabel lVerschiebung = new JLabel();
|
||||
private JLabel lAnzahlgleicherBuchstaben = new JLabel();
|
||||
// Ende Attribute
|
||||
|
||||
public BreakVigenere (String title) {
|
||||
super (title);
|
||||
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
|
||||
int frameWidth = 702;
|
||||
int frameHeight = 651;
|
||||
setSize(frameWidth, frameHeight);
|
||||
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
int x = (d.width - getSize().width) / 2;
|
||||
int y = (d.height - getSize().height) / 2;
|
||||
setLocation(x, y);
|
||||
Container cp = getContentPane();
|
||||
cp.setLayout(null);
|
||||
// Anfang Komponenten
|
||||
|
||||
jTAKryptoScrollPane.setBounds(16, 24, 665, 105);
|
||||
jTAKrypto.setLineWrap(true);
|
||||
jTAKrypto.setFont(new Font("Courier New", Font.BOLD, 16));
|
||||
jTAKrypto.setText("JMLQMFNSKIOQNXGYZOQEBJLUKXHFCXGVLGBMREAJZCAEKVIFOWJLMFGJLPQZJIYHQQHYJLAFGFLRLQYESTPMHIAWQZFIPPMZMIZGPDOIIIVGTHIIQVKHLVHQOPLNMIKMSWCYKMUIVBREADEQOXLVVMILSMVWYZLVAONSIIVIKVKIVPOIZIEGXHLHCDILKIVPKYAWKTKRIIVQJMRXQZKVHFBVULHRVQYXYMBTKQPYAUSNHLZUSJUJBQTFHRLEKMUIAUTPHXMUTMZGPQXWWVIONINIAONVPIJQTIUWMONWIRLUMIUAMDQIZTWXEKYEXTOELPQNXMZIFEKGOWJONIYDCDVSSCODGTOMMMTKLKMNKRPRLQSRHGPEKMUIUFUHLZMDLJLRBXOGOXMZHYJLAONPBKMDBSYRIONNLHMYKMUDMXTIUOTMXXLBBNAGOWBMHIUDCYTGOWBQTESTPMHIAMVEKMUIZFGFBPINKVGYOQNIUYVPYSHPTQBIYJONGVLRIXVLHFMFKEBWHGTYADMZJETMBQXJHRLQXHPIXDUKYIAEOZLTWXEESTPMHIAMAONIJLQRLVPIZGTKHFMDKWDEZZUGOIQZLIZXMEBIYJITXIUSPZKWJLTEYISHQQYIYACDJIPQRMNVCSUUZESMMZOWJLMZQVFTBARSNIVSOSCEVNGXAMAFGFLPTMYSJEQZLSYQMUTIZZWYBIYWKTRWZPMDLVLMHGCLSIVPKRRIVZCSYXAAJIYIQZKWRIVZYEADMEBSYKMEILSEOQTKLVVQARKOZKVXVKZMVLPWKTYGOAIONHHPMUILADCQXVHXMZCYYHMZJETETEREAIQZOWJLMEORUWXDILLFMZAXGXEUKFLMABOISWEQOWLZQDZZAMWYTMHTIDKRAETXKWNIPAXGOXLQXXJLBUMOLMBPOIIYKTYXHFMZJIZOMZTWHXHQYFLWBUSQLRLUKVLMPQTJVPOQORKIZPOICIZEILPILQTIUETBNEIIBQGYZHMDZEIYTMGYZKMINPAA\nMDJIUQAEKRZMVPGPSIDQXFYECONXHPAAKMUQIXHIUYBLZAVVLQTLPIZZGGOOTMXXLBBNAGOWBMHIUWWNKKPRVFSEUAQQJIYZWZBSYRMENEUHMXZWPGPEUQPXCYKMUIXQXMVHQEILLTWXEESTPMHIAMAONIZYJEZMAYBUURTMBUSFLMABOISIQZKVWIZUUHLZWZCLYIVPZVPXPQSMBWAUILHYNHKVZGPAHIUIAFGRKEZPGPWLINKXLFMEILYRSFKESWWPOINIEANRAIIXVLHFMFOWJLMDKMOIVRUPNILQXFBGPEZEIIVHKVDIVPKXLFMXREZSJQXIPXAHKVDVNQRXLETBNEIIBQJMLIZMRPLVLUTKZMVHUPBXWDOWJLETRXLFMUJIUQWZUESTPMHIAMAONIUWCNYXPXCFOSUWUQZLVHMZCEYHQQYWJLWZYIPXTMTKLQJXOGOKZGTHZXHXOGOLIFZIKMMEHIYIQFYMTNITXESWWXGRNIDAXXYMBTKQPYAGTHIITXGWVHMDOXHPQQTMZGPQMISIPDZISIWZHEAXQEZEHPJQXXPIUBLSOPMZKVZGPXAKCSZPOIHPXTGFLXMZGGONMIKMSWLDKMVHMDBMLVEDZIYRHGCIJLAQRRHPAYKGOEVUYGOIATOPMWUUZXLPPMZXLIZTOIYDCPOIUEKTOLTFMZGRUXMMRFLVBUYGOIQNKIYJCZJIUIQZKGOMNRXMLVAONIPFMNKWAIPQTHGYUQOWAECEFALMZGTHLRUQZESPAONIPFMZJMLECRKMUIZSKQLMVEGQLRIONWLWQFFIUYVPYSCIZNARKIVEORKHIEYWPGPPOIRPMUTIYIIGLHLVODKVLRLDKLLRSMTRUEPQFYLMVVGLYLCZJIYXABZIYMUVGLYZMDGPSKMYKMUIZFKHLVVQGTVPQFGRPWKTKKLPMTXXLKQABEURQNGXAMAFGHLPTMVSYXIMRFLVBUYZLVEDLISXMMRTOEJQZIBRLNKPSEAAYOLRVIUVAYVPYGOYNPOI\nWSTKGPWLINKXPWKTKGOMNRXMLVCZMQPXDQXAYJMXZITETBNEIIBGTHZGPXYWLPPUKVGYEGXHLETNKVAMAEILLMJQHIUYBLZHPIVMILQILQSFBGPEZEIIVLAHYIPQTAHVQYPEOVODOJMHMDLVHRHAYIIPIUYIKIDUMIUVMBUVAEAUJILECRARKWKTRYNZWDYXHXBPKVHPJQXXPWKTKMIILUKXHFCXGVLGBMJIZXZUZLLQQGYDBZMDCIUHMZJEIIQMHIYEVPKVZETEOQVVQSORHPDQXAYJMXZIHPXTGFLXMQORGYBDGKLRLUKWLVSDETASODGTOMAONWAEZWKZVVAONPHKDUMIUVMEMIYMMFORKIVRUPNIVPKRQEPDNYUHMDZIUMVHKVNIAEKROIQFARKHQQAVZTZZMPPGPHURAVQFNITMCEBSYKMEILSEOQTITIBTUHLACDJIBRBQXHLQVMSIUZQSKRYIKTOJMVMNKOHRVF");
|
||||
jTAKrypto.addKeyListener(new KeyAdapter() {
|
||||
public void keyTyped(KeyEvent evt) {
|
||||
jTAKrypto_KeyTyped(evt);
|
||||
}
|
||||
});
|
||||
cp.add(jTAKryptoScrollPane);
|
||||
|
||||
jTAKlartextScrollPane.setBounds(16, 480, 665, 105);
|
||||
jTAKlartext.setLineWrap(true);
|
||||
jTAKlartext.setFont(new Font("Courier New", Font.BOLD, 16));
|
||||
cp.add(jTAKlartextScrollPane);
|
||||
jLKryptotext.setText("Kryptotext");
|
||||
jLKryptotext.setBounds(16, 3, 110, 20);
|
||||
cp.add(jLKryptotext);
|
||||
jLKlartext.setText("Klartext");
|
||||
jLKlartext.setBounds(16, 456, 110, 20);
|
||||
cp.add(jLKlartext);
|
||||
jLCopyright.setText("(cc) Schaller (ZPG Informatik) - V1.0 (2017)");
|
||||
jLCopyright.setBounds(128, 584, 419, 33);
|
||||
jLCopyright.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
jLCopyright.setFont(new Font("Dialog", Font.PLAIN, 12));
|
||||
cp.add(jLCopyright);
|
||||
|
||||
// -------------------------------- Tab 1 ---------------------------------------------
|
||||
JPanel tab1 = new JPanel();
|
||||
tab1.setLayout(null);
|
||||
|
||||
jSpVerschiebung.setBounds(192, 40, 41, 25);
|
||||
jSpVerschiebung.setValue(1);
|
||||
jSpVerschiebung.setModel(jSpVerschiebungModel);
|
||||
jSpVerschiebung.addChangeListener(new ChangeListener() {
|
||||
public void stateChanged(ChangeEvent evt) {
|
||||
jSpVerschiebung_StateChanged(evt);
|
||||
}
|
||||
});
|
||||
tab1.add(jSpVerschiebung);
|
||||
|
||||
lVerschiebung.setBounds(16, 10, 310, 20);
|
||||
lVerschiebung.setText("Angriff auf die Schlüssellänge mit Brute Force");
|
||||
tab1.add(lVerschiebung);
|
||||
JLabel l = new JLabel();
|
||||
l.setBounds(14, 80, 320, 100);
|
||||
l.setText("<html>Die meisten Schlüsselwörter sind nicht länger als 10 bis maximal 15 Buchstaben. Probiere daher systematisch die Schlüssellänge durch und schaue, ob die Häufigkeitsverteilungen des ersten Teiltextes in etwa dem deutschen Alphabet entspricht. Eine Verschiebung ist dabei erlaubt.</html>");
|
||||
tab1.add(l);
|
||||
l = new JLabel();
|
||||
l.setBounds(16, 40, 162, 20);
|
||||
l.setText("Vermutete Schlüssellänge:");
|
||||
tab1.add(l);
|
||||
|
||||
double[] h2 = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
|
||||
bdBruteForce.setBounds(380,10,300,120);
|
||||
bdBruteForce.setHaeufigkeit(h2);
|
||||
bdBruteForce.setZeigeDeutsch(false);
|
||||
tab1.add(bdBruteForce);
|
||||
|
||||
double[] h3 = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
|
||||
bdDeutsch.setBounds(380,140,300,120);
|
||||
bdDeutsch.setHaeufigkeit(h3);
|
||||
tab1.add(bdDeutsch);
|
||||
|
||||
|
||||
|
||||
// ---------------------------------- Tab 2 -------------------------------
|
||||
JPanel tab2 = new JPanel();
|
||||
tab2.setLayout(null);
|
||||
|
||||
l = new JLabel();
|
||||
l.setBounds(16, 10, 310, 20);
|
||||
l.setText("Angriff auf die Teiltexte mit Häufigkeitsanalyse");
|
||||
tab2.add(l);
|
||||
|
||||
l = new JLabel();
|
||||
l.setBounds(380, 10, 300, 25);
|
||||
l.setText("Buchstabenhäufigkeit Deutsch");
|
||||
tab2.add(l);
|
||||
|
||||
l = new JLabel();
|
||||
l.setBounds(16, 40, 300, 25);
|
||||
l.setText("Schlüssel");
|
||||
tab2.add(l);
|
||||
|
||||
l = new JLabel();
|
||||
l.setBounds(16, 100, 300, 100);
|
||||
l.setText("<html>Versuche den Schlüssel zu knacken, indem du in jedem Teiltext die Häufigkeitsverteilung der Buchstaben mit der üblichen Häufigkeitsverteilung in deutschen Texten in Einklang bringst.</html>");
|
||||
tab2.add(l);
|
||||
|
||||
double[] h = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
|
||||
bdText.setBounds(380,40,300,180);
|
||||
bdText.setHaeufigkeit(h);
|
||||
tab2.add(bdText);
|
||||
|
||||
jButton1.setBounds(16, 210, 193, 25);
|
||||
jButton1.setText("Entschlüsselung versuchen");
|
||||
jButton1.setMargin(new Insets(2, 2, 2, 2));
|
||||
jButton1.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent evt) {
|
||||
jButton1_ActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
tab2.add(jButton1);
|
||||
|
||||
|
||||
|
||||
// Ende Komponenten
|
||||
buchstabe = new JTextField[26];
|
||||
for (int i = 0; i<26 ;i++ ) {
|
||||
buchstabe[i] = new JTextField();
|
||||
buchstabe[i].setBounds(16+i*25, 65, 25, 25);
|
||||
buchstabe[i].setText("A");
|
||||
buchstabe[i].setHorizontalAlignment(SwingConstants.CENTER);
|
||||
buchstabe[i].setVisible(false);
|
||||
buchstabe[i].addFocusListener(new FocusAdapter() {
|
||||
public void focusGained(FocusEvent evt) {
|
||||
highlightKryptotext(evt);
|
||||
}
|
||||
});
|
||||
buchstabe[i].addKeyListener(new KeyAdapter() {
|
||||
public void keyReleased(KeyEvent e) {
|
||||
e.consume();
|
||||
}
|
||||
|
||||
public void keyTyped(KeyEvent e) {
|
||||
e.consume();
|
||||
}
|
||||
|
||||
public void keyPressed(KeyEvent e) {
|
||||
JTextField textField = (JTextField) e.getSource();
|
||||
String text = textField.getText();
|
||||
if ((e.getKeyChar()>='a' && e.getKeyChar()<='z') ||(e.getKeyChar()>='A' && e.getKeyChar()<='Z')) {
|
||||
text = ""+e.getKeyChar();
|
||||
}
|
||||
if (e.getKeyChar()==' ' || e.getKeyChar() == KeyEvent.VK_BACK_SPACE || e.getKeyChar() == KeyEvent.VK_DELETE) {
|
||||
text = "";
|
||||
|
||||
} // end of if
|
||||
textField.setText(text.toUpperCase());
|
||||
e.consume();
|
||||
if (textField.getText().length()>0) {
|
||||
bdText.setVerschiebung((int) textField.getText().charAt(0)-65);
|
||||
|
||||
} else {
|
||||
bdText.setVerschiebung(0);
|
||||
} // end of if-else
|
||||
bdText.repaint();
|
||||
|
||||
} // end of if
|
||||
|
||||
});
|
||||
|
||||
tab2.add(buchstabe[i]);
|
||||
} // end of for
|
||||
|
||||
JTabbedPane tabpane = new JTabbedPane
|
||||
(JTabbedPane.TOP,JTabbedPane.SCROLL_TAB_LAYOUT );
|
||||
tabpane.setBounds(10,140,672,290);
|
||||
|
||||
tabpane.addTab("Schritt 1", tab1);
|
||||
tabpane.addTab("Schritt 2", tab2);
|
||||
cp.add(tabpane);
|
||||
|
||||
setResizable(false);
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Anfang Methoden
|
||||
public void jButton1_ActionPerformed(ActionEvent evt) {
|
||||
String krypttext = jTAKrypto.getText().toUpperCase();
|
||||
String klartext="";
|
||||
int c = 0;
|
||||
int diff = (Integer) jSpVerschiebung.getValue();
|
||||
for (int i=0;i<krypttext.length() ;i++ ) {
|
||||
int asc = krypttext.charAt(i);
|
||||
if (asc != 10) {
|
||||
String z = buchstabe[c%diff].getText().toUpperCase();
|
||||
if (z.equals("")) {
|
||||
klartext += "*";
|
||||
} else {
|
||||
int v = (int) z.charAt(0)-65;
|
||||
asc = (asc-65-v+26)%26+65;
|
||||
klartext += (char) asc;
|
||||
} // end of if
|
||||
c++;
|
||||
}
|
||||
|
||||
} // end of for
|
||||
jTAKlartext.setText(klartext);
|
||||
} // end of jButton1_ActionPerformed
|
||||
|
||||
|
||||
|
||||
|
||||
public void highlightKryptotext(FocusEvent evt) {
|
||||
int start, diff;
|
||||
for (start = 0; start < 26 ; start++) {
|
||||
if (buchstabe[start] == evt.getSource()) {
|
||||
break;
|
||||
} // end of if-else
|
||||
} // end of for
|
||||
jBBuchstabe.setText("Buchstabenhäufigkeit Deutsch");
|
||||
|
||||
diff = (Integer) jSpVerschiebung.getValue();
|
||||
Highlighter h1 = jTAKrypto.getHighlighter();
|
||||
h1.removeAllHighlights();
|
||||
int c = 0;
|
||||
String krypto = jTAKrypto.getText().toUpperCase();
|
||||
double[] h = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
|
||||
try{
|
||||
for (int i=0;i<krypto.length() ;i++) {
|
||||
int asc = (int)krypto.charAt(i);
|
||||
if (asc!=10) {
|
||||
|
||||
if (c%diff == start) {
|
||||
h1.addHighlight(i, i+1,
|
||||
new DefaultHighlighter.DefaultHighlightPainter(new Color(100,100,255)));
|
||||
if (asc>=65 && asc<=90) {
|
||||
h[asc-65]++;
|
||||
}
|
||||
} // end of if
|
||||
c++;
|
||||
} // end of if
|
||||
}
|
||||
bdText.setHaeufigkeit(h);
|
||||
if (buchstabe[start].getText().length()>0) {
|
||||
bdText.setVerschiebung((int) buchstabe[start].getText().charAt(0)-65);
|
||||
|
||||
} else {
|
||||
bdText.setVerschiebung(0);
|
||||
} // end of if-else
|
||||
bdText.repaint();
|
||||
} catch(BadLocationException e) {}
|
||||
}
|
||||
|
||||
|
||||
public void jSpVerschiebung_StateChanged(ChangeEvent evt) {
|
||||
String krypto = jTAKrypto.getText().toUpperCase();
|
||||
String krypto2="";
|
||||
int diff = (Integer) jSpVerschiebung.getValue();
|
||||
Highlighter h1 = jTAKrypto.getHighlighter();
|
||||
h1.removeAllHighlights();
|
||||
int c = 0;
|
||||
double[] h = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
|
||||
try{
|
||||
for (int i=0;i<krypto.length() ;i++) {
|
||||
int asc = (int)krypto.charAt(i);
|
||||
if (asc!=10) {
|
||||
|
||||
if (c%diff == 0) {
|
||||
h1.addHighlight(i, i+1,
|
||||
new DefaultHighlighter.DefaultHighlightPainter(new Color(100,100,255)));
|
||||
if (asc>=65 && asc<=90) {
|
||||
h[asc-65]++;
|
||||
}
|
||||
} // end of if
|
||||
c++;
|
||||
} // end of if
|
||||
}
|
||||
bdBruteForce.setHaeufigkeit(h);
|
||||
bdBruteForce.repaint();
|
||||
} catch(BadLocationException e) {}
|
||||
|
||||
for (int i=0; i<buchstabe.length ;i++ ) {
|
||||
if (i<diff) {
|
||||
buchstabe[i].setVisible(true);
|
||||
} else {
|
||||
buchstabe[i].setVisible(false);
|
||||
|
||||
} // end of if-else
|
||||
} // end of for
|
||||
|
||||
} // end of jSpVerschiebung_StateChanged
|
||||
|
||||
public void jTAKrypto_KeyTyped(KeyEvent evt) {
|
||||
//jSpVerschiebung_StateChanged(null);
|
||||
|
||||
} // end of jTAKrypto_KeyTyped
|
||||
|
||||
public void jTAKrypto_InputMethodTextChanged(InputMethodEvent evt) {
|
||||
jSpVerschiebung_StateChanged(null);
|
||||
|
||||
} // end of jTAKrypto_InputMethodTextChanged
|
||||
|
||||
public void jTAKrypto_FocusGained(FocusEvent evt) {
|
||||
// TODO hier Quelltext einfügen
|
||||
|
||||
} // end of jTAKrypto_FocusGained
|
||||
|
||||
// Ende Methoden
|
||||
|
||||
public static void main(String[] args) {
|
||||
new BreakVigenere("BreakVigenere");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,577 @@
|
|||
object breakVigenere: TFGUIForm
|
||||
Left = 824
|
||||
Top = 58
|
||||
BorderIcons = [biSystemMenu]
|
||||
Caption = 'BreakVigenere'
|
||||
ClientHeight = 612
|
||||
ClientWidth = 691
|
||||
Color = clBtnFace
|
||||
Font.Charset = DEFAULT_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -10
|
||||
Font.Name = 'MS Sans Serif'
|
||||
Font.Style = []
|
||||
FormStyle = fsStayOnTop
|
||||
OldCreateOrder = True
|
||||
Position = poDesigned
|
||||
ShowHint = True
|
||||
Visible = True
|
||||
OnClose = FormClose
|
||||
OnCloseQuery = FormCloseQuery
|
||||
OnResize = FormResize
|
||||
FrameType = 5
|
||||
Resizable = False
|
||||
Undecorated = False
|
||||
Background = clBtnFace
|
||||
PixelsPerInch = 96
|
||||
TextHeight = 13
|
||||
object jButton1: TJButton
|
||||
Tag = 4
|
||||
Left = 216
|
||||
Top = 440
|
||||
Width = 241
|
||||
Height = 25
|
||||
Hint = 'jButton1'
|
||||
Foreground = 3355443
|
||||
Background = 15658734
|
||||
Font.Charset = DEFAULT_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -12
|
||||
Font.Name = 'Dialog'
|
||||
Font.Style = [fsBold]
|
||||
actionPerformed = 'jButton1_ActionPerformed'
|
||||
Text = 'Entschl'#252'sselung versuchen'
|
||||
Mnemonic = 0
|
||||
DisplayedMnemonicIndex = 0
|
||||
Selected = False
|
||||
BorderPainted = True
|
||||
FocusPainted = False
|
||||
ContentAreaFilled = True
|
||||
HorizontalAlignment = CENTER
|
||||
VerticalAlignment = CENTER
|
||||
HorizontalTextPosition = RIGHT
|
||||
VerticalTextPosition = CENTER
|
||||
IconTextGap = 4
|
||||
RolloverEnabled = False
|
||||
Border.BorderType = NoBorder
|
||||
Border.LineColor = clBlack
|
||||
Border.LineThickness = 0
|
||||
Border.LineRounded = False
|
||||
Border.EtchHighlightColor = clBlack
|
||||
Border.EtchShadowColor = clBlack
|
||||
Border.Etchtype = 0
|
||||
Border.BevelHighlightColor = clBlack
|
||||
Border.BevelShadowColor = clBlack
|
||||
Border.Beveltype = 0
|
||||
Border.MatteColor = clBlack
|
||||
Border.MatteTop = 0
|
||||
Border.MatteLeft = 0
|
||||
Border.MatteBottom = 0
|
||||
Border.MatteRight = 0
|
||||
end
|
||||
object jTable1: TJTable
|
||||
Tag = 19
|
||||
Left = 656
|
||||
Top = 408
|
||||
Width = 193
|
||||
Height = 89
|
||||
Hint = 'jTable1'
|
||||
Foreground = clWindowText
|
||||
Background = clWhite
|
||||
Font.Charset = GB2312_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -12
|
||||
Font.Name = '@Fixedsys'
|
||||
Font.Style = []
|
||||
RowHeight = 16
|
||||
ShowHorizontalLines = True
|
||||
ShowVerticalLines = True
|
||||
ShowGrid = True
|
||||
Columns.Strings = (
|
||||
'Title 1'
|
||||
'Title 2'
|
||||
'Title 3'
|
||||
'Title 4'
|
||||
'Title 5')
|
||||
ColCount = 5
|
||||
RowCount = 5
|
||||
FillsViewportHeight = False
|
||||
AutoCreateRowSorter = False
|
||||
RowSelectionAllowed = True
|
||||
ColumnSelectionAllowed = False
|
||||
CellSelectionEnabled = False
|
||||
DragEnabled = False
|
||||
HorizontalScrollBarPolicy = AS_NEEDED
|
||||
VerticalScrollBarPolicy = AS_NEEDED
|
||||
end
|
||||
object jTable2: TJTable
|
||||
Tag = 19
|
||||
Left = 656
|
||||
Top = 336
|
||||
Width = 201
|
||||
Height = 81
|
||||
Hint = 'jTable2'
|
||||
Foreground = 3355443
|
||||
Background = clWhite
|
||||
Font.Charset = DEFAULT_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -12
|
||||
Font.Name = 'Dialog'
|
||||
Font.Style = []
|
||||
RowHeight = 16
|
||||
ShowHorizontalLines = True
|
||||
ShowVerticalLines = True
|
||||
ShowGrid = True
|
||||
Columns.Strings = (
|
||||
'Title 1'
|
||||
'Title 2'
|
||||
'Title 3'
|
||||
'Title 4'
|
||||
'Title 5')
|
||||
ColCount = 5
|
||||
RowCount = 5
|
||||
FillsViewportHeight = False
|
||||
AutoCreateRowSorter = False
|
||||
RowSelectionAllowed = True
|
||||
ColumnSelectionAllowed = False
|
||||
CellSelectionEnabled = False
|
||||
DragEnabled = False
|
||||
HorizontalScrollBarPolicy = AS_NEEDED
|
||||
VerticalScrollBarPolicy = AS_NEEDED
|
||||
end
|
||||
object jTable3: TJTable
|
||||
Tag = 19
|
||||
Left = 648
|
||||
Top = 320
|
||||
Width = 193
|
||||
Height = 57
|
||||
Hint = 'jTable3'
|
||||
Foreground = 3355443
|
||||
Background = clWhite
|
||||
Font.Charset = DEFAULT_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -12
|
||||
Font.Name = 'Dialog'
|
||||
Font.Style = []
|
||||
RowHeight = 16
|
||||
ShowHorizontalLines = True
|
||||
ShowVerticalLines = True
|
||||
ShowGrid = True
|
||||
Columns.Strings = (
|
||||
'Title 1'
|
||||
'Title 2'
|
||||
'Title 3'
|
||||
'Title 4'
|
||||
'Title 5')
|
||||
ColCount = 5
|
||||
RowCount = 5
|
||||
FillsViewportHeight = False
|
||||
AutoCreateRowSorter = False
|
||||
RowSelectionAllowed = True
|
||||
ColumnSelectionAllowed = False
|
||||
CellSelectionEnabled = False
|
||||
DragEnabled = False
|
||||
HorizontalScrollBarPolicy = AS_NEEDED
|
||||
VerticalScrollBarPolicy = AS_NEEDED
|
||||
end
|
||||
object jBBuchstabe: TJButton
|
||||
Tag = 4
|
||||
Left = 248
|
||||
Top = 232
|
||||
Width = 193
|
||||
Height = 25
|
||||
Hint = 'jButton2'
|
||||
Foreground = 3355443
|
||||
Background = 15658734
|
||||
Font.Charset = DEFAULT_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -12
|
||||
Font.Name = 'Dialog'
|
||||
Font.Style = [fsBold]
|
||||
actionPerformed = 'jBBuchstabe_ActionPerformed'
|
||||
Text = 'Buchstabenh'#228'ufigkeit'
|
||||
Mnemonic = 0
|
||||
DisplayedMnemonicIndex = 0
|
||||
Selected = False
|
||||
BorderPainted = True
|
||||
FocusPainted = False
|
||||
ContentAreaFilled = True
|
||||
HorizontalAlignment = CENTER
|
||||
VerticalAlignment = CENTER
|
||||
HorizontalTextPosition = RIGHT
|
||||
VerticalTextPosition = CENTER
|
||||
IconTextGap = 4
|
||||
RolloverEnabled = False
|
||||
Border.BorderType = NoBorder
|
||||
Border.LineColor = clBlack
|
||||
Border.LineThickness = 0
|
||||
Border.LineRounded = False
|
||||
Border.EtchHighlightColor = clBlack
|
||||
Border.EtchShadowColor = clBlack
|
||||
Border.Etchtype = 0
|
||||
Border.BevelHighlightColor = clBlack
|
||||
Border.BevelShadowColor = clBlack
|
||||
Border.Beveltype = 0
|
||||
Border.MatteColor = clBlack
|
||||
Border.MatteTop = 0
|
||||
Border.MatteLeft = 0
|
||||
Border.MatteBottom = 0
|
||||
Border.MatteRight = 0
|
||||
end
|
||||
object jBBigramm: TJButton
|
||||
Tag = 4
|
||||
Left = 632
|
||||
Top = 296
|
||||
Width = 201
|
||||
Height = 25
|
||||
Hint = 'jButton3'
|
||||
Foreground = 3355443
|
||||
Background = 15658734
|
||||
Font.Charset = DEFAULT_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -12
|
||||
Font.Name = 'Dialog'
|
||||
Font.Style = [fsBold]
|
||||
actionPerformed = 'jBBigramm_ActionPerformed'
|
||||
Text = 'Bigramm-H'#228'ufigkeit'
|
||||
Mnemonic = 0
|
||||
DisplayedMnemonicIndex = 0
|
||||
Selected = False
|
||||
BorderPainted = True
|
||||
FocusPainted = False
|
||||
ContentAreaFilled = True
|
||||
HorizontalAlignment = CENTER
|
||||
VerticalAlignment = CENTER
|
||||
HorizontalTextPosition = RIGHT
|
||||
VerticalTextPosition = CENTER
|
||||
IconTextGap = 4
|
||||
RolloverEnabled = False
|
||||
Border.BorderType = NoBorder
|
||||
Border.LineColor = clBlack
|
||||
Border.LineThickness = 0
|
||||
Border.LineRounded = False
|
||||
Border.EtchHighlightColor = clBlack
|
||||
Border.EtchShadowColor = clBlack
|
||||
Border.Etchtype = 0
|
||||
Border.BevelHighlightColor = clBlack
|
||||
Border.BevelShadowColor = clBlack
|
||||
Border.Beveltype = 0
|
||||
Border.MatteColor = clBlack
|
||||
Border.MatteTop = 0
|
||||
Border.MatteLeft = 0
|
||||
Border.MatteBottom = 0
|
||||
Border.MatteRight = 0
|
||||
end
|
||||
object jBDoppel: TJButton
|
||||
Tag = 4
|
||||
Left = 656
|
||||
Top = 280
|
||||
Width = 193
|
||||
Height = 25
|
||||
Hint = 'jButton4'
|
||||
Foreground = 3355443
|
||||
Background = 15658734
|
||||
Font.Charset = DEFAULT_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -12
|
||||
Font.Name = 'Dialog'
|
||||
Font.Style = [fsBold]
|
||||
actionPerformed = 'jBDoppel_ActionPerformed'
|
||||
Text = 'Doppelbuchstaben-H'#228'ufigkeit'
|
||||
Mnemonic = 0
|
||||
DisplayedMnemonicIndex = 0
|
||||
Selected = False
|
||||
BorderPainted = True
|
||||
FocusPainted = False
|
||||
ContentAreaFilled = True
|
||||
HorizontalAlignment = CENTER
|
||||
VerticalAlignment = CENTER
|
||||
HorizontalTextPosition = RIGHT
|
||||
VerticalTextPosition = CENTER
|
||||
IconTextGap = 4
|
||||
RolloverEnabled = False
|
||||
Border.BorderType = NoBorder
|
||||
Border.LineColor = clBlack
|
||||
Border.LineThickness = 0
|
||||
Border.LineRounded = False
|
||||
Border.EtchHighlightColor = clBlack
|
||||
Border.EtchShadowColor = clBlack
|
||||
Border.Etchtype = 0
|
||||
Border.BevelHighlightColor = clBlack
|
||||
Border.BevelShadowColor = clBlack
|
||||
Border.Beveltype = 0
|
||||
Border.MatteColor = clBlack
|
||||
Border.MatteTop = 0
|
||||
Border.MatteLeft = 0
|
||||
Border.MatteBottom = 0
|
||||
Border.MatteRight = 0
|
||||
end
|
||||
object jTAKrypto: TJTextArea
|
||||
Tag = 3
|
||||
Left = 16
|
||||
Top = 24
|
||||
Width = 665
|
||||
Height = 105
|
||||
Cursor = crIBeam
|
||||
Hint = 'jTextArea1'
|
||||
Foreground = clWindowText
|
||||
Background = clWhite
|
||||
Font.Charset = ANSI_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -16
|
||||
Font.Name = 'Courier New'
|
||||
Font.Style = [fsBold]
|
||||
focusGained = 'jTAKrypto_FocusGained'
|
||||
inputMethodTextChanged = 'jTextArea1_InputMethodTextChanged'
|
||||
keyTyped = 'jTextArea1_KeyTyped'
|
||||
LineWrap = True
|
||||
HorizontalScrollBarPolicy = AS_NEEDED
|
||||
VerticalScrollBarPolicy = AS_NEEDED
|
||||
WrapStyleWord = False
|
||||
TabSize = 8
|
||||
Text.Strings = (
|
||||
|
||||
'JMLQMFNSKIOQNXGYZOQEBJLUKXHFCXGVLGBMREAJZCAEKVIFOWJLMFGJLPQZJIYH' +
|
||||
'QQHYJLAFGFLRLQYESTPMHIAWQZFIPPMZMIZGPDOIIIVGTHIIQVKHLVHQOPLNMIKM' +
|
||||
'SWCYKMUIVBREADEQOXLVVMILSMVWYZLVAONSIIVIKVKIVPOIZIEGXHLHCDILKIVP' +
|
||||
'KYAWKTKRIIVQJMRXQZKVHFBVULHRVQYXYMBTKQPYAUSNHLZUSJUJBQTFHRLEKMUI' +
|
||||
'AUTPHXMUTMZGPQXWWVIONINIAONVPIJQTIUWMONWIRLUMIUAMDQIZTWXEKYEXTOE' +
|
||||
'LPQNXMZIFEKGOWJONIYDCDVSSCODGTOMMMTKLKMNKRPRLQSRHGPEKMUIUFUHLZMD' +
|
||||
'LJLRBXOGOXMZHYJLAONPBKMDBSYRIONNLHMYKMUDMXTIUOTMXXLBBNAGOWBMHIUD' +
|
||||
'CYTGOWBQTESTPMHIAMVEKMUIZFGFBPINKVGYOQNIUYVPYSHPTQBIYJONGVLRIXVL' +
|
||||
'HFMFKEBWHGTYADMZJETMBQXJHRLQXHPIXDUKYIAEOZLTWXEESTPMHIAMAONIJLQR' +
|
||||
'LVPIZGTKHFMDKWDEZZUGOIQZLIZXMEBIYJITXIUSPZKWJLTEYISHQQYIYACDJIPQ' +
|
||||
'RMNVCSUUZESMMZOWJLMZQVFTBARSNIVSOSCEVNGXAMAFGFLPTMYSJEQZLSYQMUTI' +
|
||||
'ZZWYBIYWKTRWZPMDLVLMHGCLSIVPKRRIVZCSYXAAJIYIQZKWRIVZYEADMEBSYKME' +
|
||||
'ILSEOQTKLVVQARKOZKVXVKZMVLPWKTYGOAIONHHPMUILADCQXVHXMZCYYHMZJETE' +
|
||||
'TEREAIQZOWJLMEORUWXDILLFMZAXGXEUKFLMABOISWEQOWLZQDZZAMWYTMHTIDKR' +
|
||||
'AETXKWNIPAXGOXLQXXJLBUMOLMBPOIIYKTYXHFMZJIZOMZTWHXHQYFLWBUSQLRLU' +
|
||||
'KVLMPQTJVPOQORKIZPOICIZEILPILQTIUETBNEIIBQGYZHMDZEIYTMGYZKMINPAA'
|
||||
|
||||
'MDJIUQAEKRZMVPGPSIDQXFYECONXHPAAKMUQIXHIUYBLZAVVLQTLPIZZGGOOTMXX' +
|
||||
'LBBNAGOWBMHIUWWNKKPRVFSEUAQQJIYZWZBSYRMENEUHMXZWPGPEUQPXCYKMUIXQ' +
|
||||
'XMVHQEILLTWXEESTPMHIAMAONIZYJEZMAYBUURTMBUSFLMABOISIQZKVWIZUUHLZ' +
|
||||
'WZCLYIVPZVPXPQSMBWAUILHYNHKVZGPAHIUIAFGRKEZPGPWLINKXLFMEILYRSFKE' +
|
||||
'SWWPOINIEANRAIIXVLHFMFOWJLMDKMOIVRUPNILQXFBGPEZEIIVHKVDIVPKXLFMX' +
|
||||
'REZSJQXIPXAHKVDVNQRXLETBNEIIBQJMLIZMRPLVLUTKZMVHUPBXWDOWJLETRXLF' +
|
||||
'MUJIUQWZUESTPMHIAMAONIUWCNYXPXCFOSUWUQZLVHMZCEYHQQYWJLWZYIPXTMTK' +
|
||||
'LQJXOGOKZGTHZXHXOGOLIFZIKMMEHIYIQFYMTNITXESWWXGRNIDAXXYMBTKQPYAG' +
|
||||
'THIITXGWVHMDOXHPQQTMZGPQMISIPDZISIWZHEAXQEZEHPJQXXPIUBLSOPMZKVZG' +
|
||||
'PXAKCSZPOIHPXTGFLXMZGGONMIKMSWLDKMVHMDBMLVEDZIYRHGCIJLAQRRHPAYKG' +
|
||||
'OEVUYGOIATOPMWUUZXLPPMZXLIZTOIYDCPOIUEKTOLTFMZGRUXMMRFLVBUYGOIQN' +
|
||||
'KIYJCZJIUIQZKGOMNRXMLVAONIPFMNKWAIPQTHGYUQOWAECEFALMZGTHLRUQZESP' +
|
||||
'AONIPFMZJMLECRKMUIZSKQLMVEGQLRIONWLWQFFIUYVPYSCIZNARKIVEORKHIEYW' +
|
||||
'PGPPOIRPMUTIYIIGLHLVODKVLRLDKLLRSMTRUEPQFYLMVVGLYLCZJIYXABZIYMUV' +
|
||||
'GLYZMDGPSKMYKMUIZFKHLVVQGTVPQFGRPWKTKKLPMTXXLKQABEURQNGXAMAFGHLP' +
|
||||
'TMVSYXIMRFLVBUYZLVEDLISXMMRTOEJQZIBRLNKPSEAAYOLRVIUVAYVPYGOYNPOI'
|
||||
|
||||
'WSTKGPWLINKXPWKTKGOMNRXMLVCZMQPXDQXAYJMXZITETBNEIIBGTHZGPXYWLPPU' +
|
||||
'KVGYEGXHLETNKVAMAEILLMJQHIUYBLZHPIVMILQILQSFBGPEZEIIVLAHYIPQTAHV' +
|
||||
'QYPEOVODOJMHMDLVHRHAYIIPIUYIKIDUMIUVMBUVAEAUJILECRARKWKTRYNZWDYX' +
|
||||
'HXBPKVHPJQXXPWKTKMIILUKXHFCXGVLGBMJIZXZUZLLQQGYDBZMDCIUHMZJEIIQM' +
|
||||
'HIYEVPKVZETEOQVVQSORHPDQXAYJMXZIHPXTGFLXMQORGYBDGKLRLUKWLVSDETAS' +
|
||||
'ODGTOMAONWAEZWKZVVAONPHKDUMIUVMEMIYMMFORKIVRUPNIVPKRQEPDNYUHMDZI' +
|
||||
'UMVHKVNIAEKROIQFARKHQQAVZTZZMPPGPHURAVQFNITMCEBSYKMEILSEOQTITIBT' +
|
||||
'UHLACDJIBRBQXHLQVMSIUZQSKRYIKTOJMVMNKOHRVF')
|
||||
Editable = True
|
||||
end
|
||||
object jTextArea2: TJTextArea
|
||||
Tag = 3
|
||||
Left = 8
|
||||
Top = 480
|
||||
Width = 673
|
||||
Height = 105
|
||||
Cursor = crIBeam
|
||||
Hint = 'jTextArea2'
|
||||
Foreground = clWindowText
|
||||
Background = clWhite
|
||||
Font.Charset = ANSI_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -16
|
||||
Font.Name = 'Courier New'
|
||||
Font.Style = [fsBold]
|
||||
LineWrap = True
|
||||
HorizontalScrollBarPolicy = AS_NEEDED
|
||||
VerticalScrollBarPolicy = AS_NEEDED
|
||||
WrapStyleWord = False
|
||||
TabSize = 8
|
||||
Editable = True
|
||||
end
|
||||
object jLabel1: TJLabel
|
||||
Tag = 1
|
||||
Left = 16
|
||||
Top = 8
|
||||
Width = 110
|
||||
Height = 20
|
||||
Hint = 'jLabel1'
|
||||
Foreground = 3355443
|
||||
Background = clBtnFace
|
||||
Font.Charset = DEFAULT_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -12
|
||||
Font.Name = 'Dialog'
|
||||
Font.Style = [fsBold]
|
||||
Text = 'Kryptotext'
|
||||
HorizontalAlignment = LEFT
|
||||
VerticalAlignment = CENTER
|
||||
HorizontalTextPosition = RIGHT
|
||||
VerticalTextPosition = CENTER
|
||||
IconTextGap = 4
|
||||
DisplayedMnemonic = 0
|
||||
DisplayedMnemonicIndex = 0
|
||||
end
|
||||
object jLabel2: TJLabel
|
||||
Tag = 1
|
||||
Left = 8
|
||||
Top = 456
|
||||
Width = 110
|
||||
Height = 20
|
||||
Hint = 'jLabel1'
|
||||
Foreground = 3355443
|
||||
Background = clBtnFace
|
||||
Font.Charset = DEFAULT_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -12
|
||||
Font.Name = 'Dialog'
|
||||
Font.Style = [fsBold]
|
||||
Text = 'Klartext'
|
||||
HorizontalAlignment = LEFT
|
||||
VerticalAlignment = CENTER
|
||||
HorizontalTextPosition = RIGHT
|
||||
VerticalTextPosition = CENTER
|
||||
IconTextGap = 4
|
||||
DisplayedMnemonic = 0
|
||||
DisplayedMnemonicIndex = 0
|
||||
end
|
||||
object jLabel4: TJLabel
|
||||
Tag = 1
|
||||
Left = 128
|
||||
Top = 584
|
||||
Width = 419
|
||||
Height = 33
|
||||
Hint = 'jLabel4'
|
||||
Foreground = clWindowText
|
||||
Background = clBtnFace
|
||||
Font.Charset = DEFAULT_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -12
|
||||
Font.Name = 'Dialog'
|
||||
Font.Style = []
|
||||
Text = '(cc) Schaller (ZPG Informatik) - V1.0 (2017)'
|
||||
HorizontalAlignment = CENTER
|
||||
VerticalAlignment = CENTER
|
||||
HorizontalTextPosition = RIGHT
|
||||
VerticalTextPosition = CENTER
|
||||
IconTextGap = 4
|
||||
DisplayedMnemonic = 0
|
||||
DisplayedMnemonicIndex = 0
|
||||
end
|
||||
object jTAKorrelation: TJTextArea
|
||||
Tag = 3
|
||||
Left = 16
|
||||
Top = 160
|
||||
Width = 665
|
||||
Height = 57
|
||||
Cursor = crIBeam
|
||||
Hint = 'jTextArea3'
|
||||
Foreground = clWindowText
|
||||
Background = clWhite
|
||||
Font.Charset = ANSI_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -12
|
||||
Font.Name = 'Courier New'
|
||||
Font.Style = [fsBold]
|
||||
LineWrap = False
|
||||
HorizontalScrollBarPolicy = ALWAYS
|
||||
VerticalScrollBarPolicy = AS_NEEDED
|
||||
WrapStyleWord = False
|
||||
TabSize = 8
|
||||
Text.Strings = (
|
||||
'')
|
||||
Editable = False
|
||||
end
|
||||
object jSpVerschiebung: TJSpinner
|
||||
Tag = 22
|
||||
Left = 192
|
||||
Top = 232
|
||||
Width = 41
|
||||
Height = 25
|
||||
Hint = 'jSpinner1'
|
||||
Foreground = 3355443
|
||||
Background = clWhite
|
||||
Font.Charset = DEFAULT_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -12
|
||||
Font.Name = 'Dialog'
|
||||
Font.Style = [fsBold]
|
||||
stateChanged = 'jSpVerschiebung_StateChanged'
|
||||
Maximum = 99
|
||||
Minimum = 0
|
||||
StepSize = 1
|
||||
Value = '0'
|
||||
end
|
||||
object jNFAnzahlTreffer: TJNumberField
|
||||
Tag = 21
|
||||
Left = 192
|
||||
Top = 264
|
||||
Width = 41
|
||||
Height = 25
|
||||
Cursor = crIBeam
|
||||
Hint = 'jNumberField1'
|
||||
Foreground = 3355443
|
||||
Background = clWhite
|
||||
Font.Charset = DEFAULT_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -12
|
||||
Font.Name = 'Dialog'
|
||||
Font.Style = []
|
||||
HorizontalAlignment = LEFT
|
||||
Editable = False
|
||||
end
|
||||
object lVerschiebung: TJLabel
|
||||
Tag = 1
|
||||
Left = 16
|
||||
Top = 232
|
||||
Width = 110
|
||||
Height = 20
|
||||
Hint = 'jLabel3'
|
||||
Foreground = 3355443
|
||||
Background = clBtnFace
|
||||
Font.Charset = DEFAULT_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -12
|
||||
Font.Name = 'Dialog'
|
||||
Font.Style = [fsBold]
|
||||
Text = 'Verschiebung'
|
||||
HorizontalAlignment = LEFT
|
||||
VerticalAlignment = CENTER
|
||||
HorizontalTextPosition = RIGHT
|
||||
VerticalTextPosition = CENTER
|
||||
IconTextGap = 4
|
||||
DisplayedMnemonic = 0
|
||||
DisplayedMnemonicIndex = 0
|
||||
end
|
||||
object lAnzahlgleicherBuchstaben: TJLabel
|
||||
Tag = 1
|
||||
Left = 16
|
||||
Top = 264
|
||||
Width = 162
|
||||
Height = 20
|
||||
Hint = 'jLabel3'
|
||||
Foreground = 3355443
|
||||
Background = clBtnFace
|
||||
Font.Charset = DEFAULT_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -12
|
||||
Font.Name = 'Dialog'
|
||||
Font.Style = [fsBold]
|
||||
Text = 'Anzahl gleicher Buchstaben'
|
||||
HorizontalAlignment = LEFT
|
||||
VerticalAlignment = CENTER
|
||||
HorizontalTextPosition = RIGHT
|
||||
VerticalTextPosition = CENTER
|
||||
IconTextGap = 4
|
||||
DisplayedMnemonic = 0
|
||||
DisplayedMnemonicIndex = 0
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,210 @@
|
|||
// LineRenderer.java
|
||||
|
||||
// Copyright 2002 Regula Hoefer-Isenegger
|
||||
//
|
||||
// This file is part of The Java Turtle (TJT) package
|
||||
//
|
||||
// TJT 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
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// TJT 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 The Java Turtle Package; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package ch.aplu.turtle;
|
||||
|
||||
import ch.aplu.turtle.*;
|
||||
import java.awt.geom.*;
|
||||
/** This class is responsible for drawing the turtle's lines.
|
||||
|
||||
@author <a href="mailto:regula@hoefer.ch">Regula Hoefer-Isenegger</a>
|
||||
@version 0.1
|
||||
*/
|
||||
public class LineRenderer {
|
||||
private Point2D.Double point;
|
||||
private Turtle turtle;
|
||||
|
||||
LineRenderer(Turtle turtle) {
|
||||
this.point = new Point2D.Double();
|
||||
this.turtle = turtle;
|
||||
}
|
||||
|
||||
/** Initialisation with coordinates <code>x</code> and
|
||||
<code>y</code>.
|
||||
*/
|
||||
public void init(double x, double y) {
|
||||
this.point.setLocation(x, y);
|
||||
}
|
||||
/** Same as init(double x, double y), but with a Point2D.Double
|
||||
argument for convenience
|
||||
*/
|
||||
public void init(Point2D.Double p) {
|
||||
this.init(p.x, p.y);
|
||||
}
|
||||
/** Get the current x-coordinate in screen coordinates.*/
|
||||
private double getX(){
|
||||
return (toScreenCoords(point)).getX();
|
||||
}
|
||||
/** Get the current x-coordinate in screen coordinates.*/
|
||||
private double getY(){
|
||||
return toScreenCoords(point).getY();
|
||||
}
|
||||
/** Calls the clipLineTo and wrapLineTo methods, according
|
||||
to the turtle's edge behavior.
|
||||
|
||||
Only overwrite this method when working with another
|
||||
(one that you have defined) edge behaviour. <br>
|
||||
If you mean to change the manner of drawing lines, do this in
|
||||
the methods clipLineTo() and wrapLineTo().
|
||||
@see #clipLineTo
|
||||
@see #wrapLineTo
|
||||
*/
|
||||
protected void internalLineTo(double x, double y){
|
||||
Point2D.Double screenPos = toScreenCoords(x, y);
|
||||
if(turtle.isClip()){
|
||||
clipLineTo(screenPos.getX(), screenPos.getY());
|
||||
}
|
||||
if (turtle.isWrap()){
|
||||
wrapLineTo(screenPos.getX(), screenPos.getY());
|
||||
}
|
||||
init(x,y);
|
||||
}
|
||||
/** Calls the internalLineTo(x,y), which does the actual painting.
|
||||
*/
|
||||
public void lineTo(double x, double y) {
|
||||
internalLineTo(x, y);
|
||||
}
|
||||
/** Calls the internalLineTo(x,y), which does the actual painting.
|
||||
|
||||
This method works the same way as lineTo(double x, double y), but
|
||||
is added for convenience.
|
||||
*/
|
||||
public void lineTo(Point2D.Double p) {
|
||||
internalLineTo(p.getX(), p.getY());
|
||||
}
|
||||
/** Does the actual painting for clip mode.
|
||||
|
||||
It works already with ScreenCoords!
|
||||
For further comments cf. internalLineTo(double x, double y).
|
||||
@see #internalLineTo
|
||||
*/
|
||||
protected void clipLineTo(double x, double y){
|
||||
turtle.getPlayground().lineTo(getX(), getY(), x, y, turtle.getPen());
|
||||
}
|
||||
/** Does the actual painting for wrap mode.
|
||||
|
||||
It works already with ScreenCoords!
|
||||
For further comments cf. internalLineTo(double x, double y).
|
||||
@see #internalLineTo
|
||||
*/
|
||||
protected void wrapLineTo(double x, double y){
|
||||
double dx = getX() - x;
|
||||
double dy = getY() - y;
|
||||
Point2D.Double start = new Point2D.Double(x, y);
|
||||
Point2D.Double end = new Point2D.Double(start.x+dx, start.y+dy);
|
||||
|
||||
intoPanel(start, end);
|
||||
Point2D.Double tmp;
|
||||
while ((tmp = calcIntersection(start.x, start.y, end.x, end.y)) != null){
|
||||
turtle.getPlayground().lineTo(start.x, start.y, tmp.getX(), tmp.getY(), turtle.getPen());
|
||||
start = tmp;
|
||||
intoPanel(start, end);
|
||||
dx = end.x - start.x;
|
||||
dy = end.y - start.y;
|
||||
}
|
||||
|
||||
turtle.getPlayground().lineTo(start.x, start.y, end.x, end.y, turtle.getPen());
|
||||
}
|
||||
/** Makes the coordinates fit into the Panel.
|
||||
|
||||
Well, this is some sort of modulus calculation.
|
||||
*/
|
||||
private void intoPanel(Point2D.Double start, Point2D.Double end){
|
||||
int pWidth = turtle.getPlayground().getWidth();
|
||||
int pHeight = turtle.getPlayground().getHeight();
|
||||
while(start.x < 0){
|
||||
start.x += pWidth;
|
||||
end.x += pWidth;
|
||||
}
|
||||
while (start.x > pWidth){
|
||||
start.x -= pWidth;
|
||||
end.x -= pWidth;
|
||||
}
|
||||
if(start.x == 0 && end.x < start.x){
|
||||
start.x += pWidth;
|
||||
end.x += pWidth;
|
||||
}
|
||||
if(start.x == pWidth && end.x > start.x){
|
||||
start.x -= pWidth;
|
||||
end.x -= pWidth;
|
||||
}
|
||||
while(start.y < 0){
|
||||
start.y += pHeight;
|
||||
end.y += pHeight;
|
||||
}
|
||||
while (start.y > pHeight){
|
||||
start.y -= pHeight;
|
||||
end.y -= pHeight;
|
||||
}
|
||||
if(start.y == 0 && end.y < start.y){
|
||||
start.y += pHeight;
|
||||
end.y += pHeight;
|
||||
}
|
||||
if(start.y == pHeight && end.y > start.y){
|
||||
start.y -= pHeight;
|
||||
end.y -= pHeight;
|
||||
}
|
||||
|
||||
}
|
||||
/** Intersection line with playground-edges
|
||||
(startX / startY) MUST lie in the playground!
|
||||
*/
|
||||
private Point2D.Double calcIntersection(double startX, double startY, double endX, double endY){
|
||||
double dx = endX - startX;
|
||||
double dy = endY - startY;
|
||||
double W = turtle.getPlayground().getWidth();
|
||||
double H = turtle.getPlayground().getHeight();
|
||||
if(endX < 0){
|
||||
if((dy/dx <= startY/startX) && (dy/dx >= -(H-startY)/startX)){ // links
|
||||
return new Point2D.Double(0, startY-startX*dy/dx);
|
||||
}
|
||||
}
|
||||
else if(endX > W){
|
||||
if((dy/dx >= -startY/(W-startX)) && (dy/dx <= (H-startY)/(W-startX))){// rechts
|
||||
return new Point2D.Double(W, startY+(W-startX)*dy/dx);
|
||||
}
|
||||
}
|
||||
if(endY < 0){ // oben
|
||||
return new Point2D.Double(startX-startY*dx/dy, 0);
|
||||
}
|
||||
else if(endY > H){ // unten
|
||||
return new Point2D.Double(startX+(H-startY)*dx/dy, H);
|
||||
}
|
||||
else{
|
||||
return null; // Endpoint lies in the window
|
||||
}
|
||||
}
|
||||
/** Calculates the screen coordinates of the turtle's actual
|
||||
position according to the interpretation of the playground.
|
||||
*/
|
||||
private Point2D.Double toScreenCoords(double x, double y){
|
||||
return turtle.getPlayground().toScreenCoords(x, y);
|
||||
}
|
||||
/** Calculates the screen coordinates of the turtle's actual
|
||||
position according to the interpretation of the playground.
|
||||
|
||||
Added for convenience.
|
||||
@see #toScreenCoords(double, double)
|
||||
*/
|
||||
private Point2D.Double toScreenCoords(Point2D.Double p){
|
||||
return turtle.getPlayground().toScreenCoords(p.x, p.y);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,268 @@
|
|||
// Pen.java
|
||||
|
||||
// Copyright 2002 Regula Hoefer-Isenegger
|
||||
//
|
||||
// This file is part of The Java Turtle package (TJT)
|
||||
//
|
||||
// TJT 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
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// TJT 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 The Java Turtle Package; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package ch.aplu.turtle;
|
||||
|
||||
import ch.aplu.turtle.*;
|
||||
import java.awt.Color;
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Stroke;
|
||||
import java.awt.Font;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
|
||||
/** The Pen class provides anything used for drawing the lines, such as line width,
|
||||
pen color, end caps, dashed lines, etc.
|
||||
|
||||
@see java.awt.BasicStroke
|
||||
|
||||
@author <a href="mailto:regula@hoefer.ch">Regula Hoefer-Isenegger</a>
|
||||
@version 0.1.1
|
||||
*/
|
||||
public class Pen
|
||||
{
|
||||
/* Attributes *********************************************/
|
||||
|
||||
/** The default font that is used when drawing Text.
|
||||
|
||||
First argument must be one of "Serif", "SansSerif", "Monotyped", "Dialog" or "DialogInput"
|
||||
to guarantee that this font exists on all systems.
|
||||
|
||||
@see java.awt.Font for more information, e.g. on font styles.
|
||||
|
||||
*/
|
||||
public static Font DEFAULT_FONT = new Font("SansSerif", Font.PLAIN, 24);
|
||||
private Color color;
|
||||
private Color fillColor;
|
||||
private BasicStroke stroke;
|
||||
private Font font;
|
||||
|
||||
/* Constructors *******************************************/
|
||||
/** Constructor with standard Color and standard Stroke.
|
||||
|
||||
@see java.awt.BasicStroke
|
||||
*/
|
||||
public Pen(){
|
||||
color = Color.black;
|
||||
setFillColor(Color.black);
|
||||
stroke = new BasicStroke();
|
||||
font = DEFAULT_FONT;
|
||||
}
|
||||
/** Constructor with Color <code>color</code> and standard Stroke.
|
||||
|
||||
@see java.awt.BasicStroke
|
||||
*/
|
||||
public Pen(Color color){
|
||||
this.color = color;
|
||||
setFillColor(color);
|
||||
stroke = new BasicStroke();
|
||||
font = DEFAULT_FONT;
|
||||
}
|
||||
/* Methods ************************************************/
|
||||
/** Query the <code>Pen</code>s color.*/
|
||||
public Color getColor(){
|
||||
return color;
|
||||
}
|
||||
/** Set the <code>Pen</code>s color.*/
|
||||
public void setColor(Color color){
|
||||
this.color = color;
|
||||
}
|
||||
/** Set the <code>Pen</code>s fill color.
|
||||
*/
|
||||
public void setFillColor(Color color){
|
||||
this.fillColor = color;
|
||||
}
|
||||
/** Query the <code>Pen</code>s fill color.*/
|
||||
public Color getFillColor(){
|
||||
return this.fillColor;
|
||||
}
|
||||
/** Get the <code>Pen</code>s <code>Stroke</code>
|
||||
|
||||
@see BasicStroke
|
||||
@see Stroke
|
||||
*/
|
||||
public Stroke getStroke(){
|
||||
return stroke;
|
||||
}
|
||||
/** Query the <code>Pen</code>s line width*/
|
||||
public float getLineWidth(){
|
||||
return stroke.getLineWidth();
|
||||
}
|
||||
/** Query the <code>Pen</code>s end cap style.
|
||||
|
||||
@see java.awt.BasicStroke
|
||||
*/
|
||||
public int getEndCap(){
|
||||
return stroke.getEndCap();
|
||||
}
|
||||
/** Query the <code>Pen</code>s line join style.
|
||||
|
||||
@see java.awt.BasicStroke
|
||||
*/
|
||||
public int getLineJoin(){
|
||||
return stroke.getLineJoin();
|
||||
}
|
||||
/** Query the <code>Pen</code>s miter limit style.
|
||||
|
||||
@see java.awt.BasicStroke
|
||||
*/
|
||||
public float getMiterLimit(){
|
||||
return stroke.getMiterLimit();
|
||||
}
|
||||
/** Query the <code>Pen</code>s dash array.
|
||||
|
||||
@see java.awt.BasicStroke
|
||||
*/
|
||||
public float[] getDashArray(){
|
||||
return stroke.getDashArray();
|
||||
}
|
||||
/** Query the <code>Pen</code>s dash phase.
|
||||
|
||||
@see java.awt.BasicStroke
|
||||
*/
|
||||
public float getDashPhase(){
|
||||
return stroke.getDashPhase();
|
||||
}
|
||||
|
||||
/** Set the <code>Pen</code>s line width. */
|
||||
public void setLineWidth(float width){
|
||||
stroke = new BasicStroke((float)width,
|
||||
stroke.getEndCap(),
|
||||
stroke.getLineJoin(),
|
||||
stroke.getMiterLimit(),
|
||||
stroke.getDashArray(),
|
||||
stroke.getDashPhase());
|
||||
}
|
||||
/** Set the <code>Pen</code>s end cap style.
|
||||
|
||||
@see java.awt.BasicStroke
|
||||
*/
|
||||
public void setEndCap(int endCap){
|
||||
stroke = new BasicStroke(stroke.getLineWidth(),
|
||||
endCap,
|
||||
stroke.getLineJoin(),
|
||||
stroke.getMiterLimit(),
|
||||
stroke.getDashArray(),
|
||||
stroke.getDashPhase());
|
||||
}
|
||||
/** Set the <code>Pen</code>s line join style.
|
||||
|
||||
@see java.awt.BasicStroke
|
||||
*/
|
||||
public void setLineJoin(int join){
|
||||
stroke = new BasicStroke(stroke.getLineWidth(),
|
||||
stroke.getEndCap(),
|
||||
join,
|
||||
stroke.getMiterLimit(),
|
||||
stroke.getDashArray(),
|
||||
stroke.getDashPhase());
|
||||
}
|
||||
/** Set the <code>Pen</code>s miter limit.
|
||||
|
||||
@see java.awt.BasicStroke
|
||||
*/
|
||||
public void setMiterLimit(float miterlimit){
|
||||
stroke = new BasicStroke(stroke.getLineWidth(),
|
||||
stroke.getEndCap(),
|
||||
stroke.getLineJoin(),
|
||||
miterlimit,
|
||||
stroke.getDashArray(),
|
||||
stroke.getDashPhase());
|
||||
}
|
||||
/** Set the <code>Pen</code>s dash array.
|
||||
|
||||
@see java.awt.BasicStroke
|
||||
*/
|
||||
public void setDash(float[] dashArray){
|
||||
stroke = new BasicStroke(stroke.getLineWidth(),
|
||||
stroke.getEndCap(),
|
||||
stroke.getLineJoin(),
|
||||
stroke.getMiterLimit(),
|
||||
dashArray,
|
||||
stroke.getDashPhase());
|
||||
}
|
||||
/** Set the <code>Pen</code>s dash phase.
|
||||
|
||||
@see java.awt.BasicStroke
|
||||
*/
|
||||
public void setDashPhase(float dashPhase){
|
||||
stroke = new BasicStroke(stroke.getLineWidth(),
|
||||
stroke.getEndCap(),
|
||||
stroke.getLineJoin(),
|
||||
stroke.getMiterLimit(),
|
||||
stroke.getDashArray(),
|
||||
dashPhase);
|
||||
}
|
||||
/** Provides information about the currently available font families (e.g. "Roman").
|
||||
Each font name is a string packed into a array of strings.
|
||||
@see java.awt.Font for more information about font attributes etc.
|
||||
*/
|
||||
public static String[] getAvailableFontFamilies(){
|
||||
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
String s[] = ge.getAvailableFontFamilyNames();
|
||||
return s;
|
||||
}
|
||||
/** Change the font style.
|
||||
|
||||
@see java.awt.Font for possible styles.
|
||||
*/
|
||||
public void setFontStyle(int style){
|
||||
font = font.deriveFont(style);
|
||||
}
|
||||
/** Change the font size (in points).
|
||||
*/
|
||||
public void setFontSize(int size){
|
||||
font = font.deriveFont((float)size);
|
||||
}
|
||||
/** Change the font size (in points).
|
||||
You will probably only need the int version <a href="#setFontSize(int)">setFontSize(int)</a>.
|
||||
*/
|
||||
public void setFontSize(float size){
|
||||
font = font.deriveFont(size);
|
||||
}
|
||||
/** Query the size (in points, rounded to int) of the current font.
|
||||
*/
|
||||
public int getFontSize(){
|
||||
return font.getSize() ;
|
||||
}
|
||||
/** Change the font to the given one.
|
||||
*/
|
||||
public void setFont(Font f){
|
||||
font = f;
|
||||
}
|
||||
/** Query the current font.
|
||||
*/
|
||||
public Font getFont(){
|
||||
return font;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,789 @@
|
|||
// Playground.java
|
||||
|
||||
// Copyright 2002 Regula Hoefer-Isenegger
|
||||
// Major code modifications by Aegidius Pluess
|
||||
// Adaption for the Java-Editor by Gerhard Röhner
|
||||
//
|
||||
// This file is part of The Java Turtle package (TJT)
|
||||
//
|
||||
// TJT 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
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// TJT 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 The Java Turtle Package; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package ch.aplu.turtle;
|
||||
|
||||
import ch.aplu.turtle.*;
|
||||
import java.util.*;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.print.*;
|
||||
import java.awt.geom.*;
|
||||
import java.awt.image.*;
|
||||
import java.awt.font.*;
|
||||
|
||||
/**
|
||||
A <code>Playground</code> is the <code>Turtle</code>'s home, i.e. the <code>Turtle</code> lives
|
||||
and moves in the <code>Playground</code>.
|
||||
|
||||
The<code>Playground</code> is responsible for interpreting angle and position of the
|
||||
<code>Turtle</code> and for choosing the correct turtle image and putting it on the right
|
||||
spot of the Playground. This means: e.g. whenever you wish to switch the x- and y-axis, you
|
||||
should do it in this class, and not in the <code>Turtle</code> class.
|
||||
|
||||
@author <a href="mailto:regula@hoefer.ch">Regula Hoefer-Isenegger</a>
|
||||
@version 0.1.1
|
||||
*/
|
||||
|
||||
public class Playground extends JPanel implements Printable {
|
||||
|
||||
/** Hold the <code>Turtle</code>s of this Playground. */
|
||||
private Vector<Turtle> turtles;
|
||||
|
||||
/** Hold the offscreen buffer and graphics context
|
||||
* where Turtle traces are drawn.
|
||||
*/
|
||||
private BufferedImage traceBuffer = null;
|
||||
protected Graphics2D traceG2D = null;
|
||||
private Dimension playgroundSize;
|
||||
|
||||
/** Hold the offscreen buffer and graphics context
|
||||
* of the Turtles images.
|
||||
*/
|
||||
private BufferedImage turtleBuffer = null;
|
||||
protected Graphics2D turtleG2D = null;
|
||||
|
||||
/** Flag to tell whether we have at least one Turtle shown. */
|
||||
private boolean isTurtleVisible = false;
|
||||
|
||||
/** Flag to tell whether we use automatic repainting */
|
||||
private boolean isRepainting = true;
|
||||
|
||||
/** The default background color.
|
||||
*/
|
||||
protected static Color DEFAULT_BACKGROUND_COLOR = Color.white;
|
||||
|
||||
private double printerScale = 1; // Default printer scaling
|
||||
private TPrintable traceCanvas; // Store ref to user class
|
||||
private Graphics2D printerG2D = null;
|
||||
private boolean isPrintScreen = false; // Indicate we are printing the playground
|
||||
private double printerScaleFactor = 1.1; // Magnification factor for printer
|
||||
|
||||
/**
|
||||
* originX is the x-position of the cartesian coodinate system within the playground.
|
||||
*/
|
||||
public int originX;
|
||||
|
||||
/**
|
||||
* originY is the y-position of the cartesian coodinate system within the playground.
|
||||
*/
|
||||
public int originY;
|
||||
|
||||
private static Color[] ColorArray = {Color.cyan, Color.red, Color.green, Color.blue, Color.yellow,
|
||||
Color.lightGray, Color.magenta, Color.orange, Color.pink, Color.black, Color.gray
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a Playground with default background color.
|
||||
* e.g. creates a new vector (which holds the
|
||||
* <code>Turtle</code>s),
|
||||
*/
|
||||
public Playground() {
|
||||
turtles = new Vector<Turtle>();
|
||||
setDoubleBuffered(false);
|
||||
setBackground(DEFAULT_BACKGROUND_COLOR);
|
||||
initBuffers(new Dimension(100, 100));
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the offscreen buffers and sets the size.
|
||||
*/
|
||||
protected void initBuffers(Dimension size) {
|
||||
Color bkColor = getBackground();
|
||||
playgroundSize = size;
|
||||
traceBuffer = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_ARGB);
|
||||
traceG2D = traceBuffer.createGraphics();
|
||||
traceG2D.setColor(bkColor);
|
||||
traceG2D.fillRect(0, 0, size.width, size.height);
|
||||
traceG2D.setBackground(bkColor);
|
||||
|
||||
turtleBuffer = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_ARGB);
|
||||
turtleG2D = turtleBuffer.createGraphics();
|
||||
turtleG2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
originX = size.width/2;
|
||||
originY = size.height/2;
|
||||
}
|
||||
|
||||
/** Add a new <code>Turtle</code> to the Playground.
|
||||
*/
|
||||
public void add(Turtle turtle) {
|
||||
turtles.add(turtle);
|
||||
turtle.setPlayground(this);
|
||||
int i = turtles.size();
|
||||
while (i > 10) {
|
||||
i = i - 10;
|
||||
} // end of while
|
||||
turtle.init(ColorArray[i-1]);
|
||||
toTop(turtle);
|
||||
}
|
||||
|
||||
public void setBounds(int x, int y, int width, int height) {
|
||||
super.setBounds(x, y, width, height);
|
||||
initBuffers(new Dimension(width, height));
|
||||
}
|
||||
|
||||
/** Remove a <code>Turtle</code> from the Playground.
|
||||
*/
|
||||
public void remove(Turtle turtle) {
|
||||
turtles.remove(turtle);
|
||||
}
|
||||
|
||||
/** Tell current number of <code>Turtle</code>s in this Playground.
|
||||
*/
|
||||
public int countTurtles() {
|
||||
return turtles.size();
|
||||
}
|
||||
|
||||
/** Return the <code>Turtle</code> at index <code>index</code>.
|
||||
*/
|
||||
public Turtle getTurtle(int index) {
|
||||
return turtles.elementAt(index);
|
||||
}
|
||||
|
||||
/** Move the given <code>Turtle</code> above all the others, then
|
||||
paints all turtles.
|
||||
@see #toTop
|
||||
*/
|
||||
public void paintTurtles(Turtle turtle) {
|
||||
toTop(turtle);
|
||||
paintTurtles();
|
||||
}
|
||||
|
||||
/** Paint all turtles (calling paintComponent())
|
||||
*/
|
||||
public void paintTurtles() {
|
||||
isTurtleVisible = false;
|
||||
Graphics2D g2D = getTurtleG2D();
|
||||
for (int i = 0; i < countTurtles(); i++) {
|
||||
Turtle aTurtle = getTurtle(i);
|
||||
if (!aTurtle.isHidden()) {
|
||||
paintTurtle(aTurtle);
|
||||
}
|
||||
}
|
||||
|
||||
// This is the main repaint call, when the turtle is
|
||||
// moving (even when all turtles are hidden).
|
||||
// Strange behaviour an slow Mac machines (pre J2SE 1.4 version):
|
||||
// It happens that some turtle images are not completely redrawn.
|
||||
// This is probably due to an improper handling of fast multiple repaint requests.
|
||||
// Workaround: we wait a small amount of time (and give the thread away)
|
||||
// (No visible slow down on new machines.)
|
||||
|
||||
paintPlayground();
|
||||
if (printerG2D == null) {
|
||||
//if (isRepainting)
|
||||
//repaint();
|
||||
//paintPlayground();
|
||||
}
|
||||
|
||||
if (isTurtleVisible) {
|
||||
try {
|
||||
Thread.currentThread().sleep(10);
|
||||
}
|
||||
catch (Exception e) {}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Paint the given <code>Turtle</code>.
|
||||
* ( no repaint() )
|
||||
*/
|
||||
public void paintTurtle(Turtle turtle) {
|
||||
if (turtleBuffer == null){
|
||||
turtleBuffer = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
|
||||
turtleG2D = turtleBuffer.createGraphics();
|
||||
}
|
||||
Graphics2D turtleGraphics = getTurtleG2D();
|
||||
turtle.getTurtleRenderer().paint(turtle._getX(), turtle._getY(), turtleGraphics);
|
||||
isTurtleVisible = true;
|
||||
}
|
||||
|
||||
/** Put an image of the given <code>Turtle</code> in turtle buffer.
|
||||
*/
|
||||
protected void stampTurtle(Turtle turtle) {
|
||||
turtle.clone();
|
||||
isTurtleVisible = true;
|
||||
if (printerG2D == null)
|
||||
repaint();
|
||||
}
|
||||
|
||||
/** Draw a line from the point <code>(x0, y0)</code> to <code>(x1, y1)</code>
|
||||
with the color of the given <code>Pen</code>.
|
||||
*/
|
||||
protected void lineTo(double x0, double y0, double x1, double y1, Pen pen) {
|
||||
int ix0 = (int)Math.round(x0);
|
||||
int iy0 = (int)Math.round(y0);
|
||||
int ix1 = (int)Math.round(x1);
|
||||
int iy1 = (int)Math.round(y1);
|
||||
Color color = pen.getColor();
|
||||
|
||||
if (traceBuffer == null) {
|
||||
traceBuffer = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
|
||||
traceG2D = traceBuffer.createGraphics();
|
||||
}
|
||||
Graphics2D traceG2D = getTraceG2D();
|
||||
traceG2D.setColor(color);
|
||||
traceG2D.setStroke(pen.getStroke());
|
||||
traceG2D.drawLine(ix0, iy0, ix1, iy1);
|
||||
if (printerG2D != null)
|
||||
printerG2D.drawLine(ix0, iy0, ix1, iy1);
|
||||
}
|
||||
|
||||
/** A class for convenience. */
|
||||
protected class Point extends java.awt.Point {
|
||||
Point(int x, int y) {
|
||||
super(x, y);
|
||||
}
|
||||
Point() {
|
||||
super();
|
||||
}
|
||||
Point(Point p) {
|
||||
super(p.x, p.y);
|
||||
}
|
||||
|
||||
/** Get a new Point with coordinates (this.x+p.x, this.y+p.y).
|
||||
*/
|
||||
protected Point add(Point p) {
|
||||
return new Point(this.x+p.x, this.y+p.y);
|
||||
}
|
||||
|
||||
/** Translate by the amounts dx = p.x, dy = p.y. */
|
||||
protected void translate(Point p) {
|
||||
translate(p.x, p.y);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "(" + x + "," + y + ")";
|
||||
}
|
||||
}
|
||||
|
||||
/** Fill a region.
|
||||
The region is defined by the <code>Turtle</code>s actual position and
|
||||
is bounded by any other color than the give background color.
|
||||
*/
|
||||
public void fill(Turtle t, Color bgColor) {
|
||||
final Point[] diff = { new Point(0,-1), new Point(-1,0), new Point(1,0), new Point(0,1)};
|
||||
final int N=0;
|
||||
final int W=1;
|
||||
final int E=2;
|
||||
final int S=3;
|
||||
|
||||
int bgcolor = bgColor.getRGB();
|
||||
int fillColor = t.getPen().getFillColor().getRGB();
|
||||
Vector list = new Vector();
|
||||
Point2D.Double p1 = toScreenCoords(t.getPos());
|
||||
int startX = (int)Math.round(p1.getX());
|
||||
int startY = (int)Math.round(p1.getY());
|
||||
Point p = new Point(startX, startY);
|
||||
if (traceBuffer.getRGB(startX, startY) == bgcolor) {
|
||||
traceBuffer.setRGB(startX, startY, fillColor);
|
||||
list.addElement(new Point(startX, startY));
|
||||
int d = N;
|
||||
int back;
|
||||
while (list.size() > 0) {
|
||||
while (d <= S) { // forward
|
||||
Point tmp = p.add(diff[d]);
|
||||
try {
|
||||
if (traceBuffer.getRGB(tmp.x, tmp.y) == bgcolor) {
|
||||
p.translate(diff[d]);
|
||||
traceBuffer.setRGB(p.x, p.y, fillColor);
|
||||
if (printerG2D != null)
|
||||
{
|
||||
printerG2D.setColor(t.getPen().getFillColor());
|
||||
// printerG2D.drawLine(p.x,p.y, p.x, p.y);
|
||||
BasicStroke stroke = new BasicStroke(2);
|
||||
printerG2D.setStroke(stroke);
|
||||
Line2D line = new Line2D.Double(p.x, p.y, p.x, p.y);
|
||||
printerG2D.draw(line);
|
||||
}
|
||||
list.addElement(new Integer(d));
|
||||
d=N;
|
||||
}
|
||||
else {
|
||||
d++;
|
||||
}
|
||||
}
|
||||
catch (ArrayIndexOutOfBoundsException e) {
|
||||
d++;
|
||||
}
|
||||
}
|
||||
Object obj = list.remove(list.size()-1);
|
||||
try {
|
||||
d=((Integer)obj).intValue(); // last element
|
||||
back = S - d;
|
||||
p.translate(diff[back]);
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
// the first (zeroest) element in list is the start-point
|
||||
// just do nothing with it
|
||||
}
|
||||
}
|
||||
}
|
||||
traceG2D.drawLine(0, 0, 0, 0); // Workaround because on Mac the trace buffer is not drawn without this
|
||||
if (printerG2D == null)
|
||||
repaint();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the playground with given color.
|
||||
*/
|
||||
public void clear(Color color) {
|
||||
traceG2D.setColor(color);
|
||||
traceG2D.fillRect(0, 0, getWidth(), getHeight());
|
||||
turtleG2D.setColor(color);
|
||||
turtleG2D.fillRect(0, 0, getWidth(), getHeight());
|
||||
isTurtleVisible = true;
|
||||
if (printerG2D == null)
|
||||
repaint();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear playground.
|
||||
*/
|
||||
public void clear() {
|
||||
clear(getBackground());
|
||||
}
|
||||
|
||||
/** Paint the Playground.
|
||||
just a method for convenience.
|
||||
*/
|
||||
public void paintComponent() {
|
||||
paintComponent(getGraphics());
|
||||
}
|
||||
|
||||
/** Draw the trace and turtle buffers.
|
||||
*/
|
||||
public void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
Graphics2D g2D = (Graphics2D)g;
|
||||
g2D.drawImage(traceBuffer, 0, 0, this);
|
||||
if (isTurtleVisible)
|
||||
g2D.drawImage(turtleBuffer, 0, 0, this);
|
||||
}
|
||||
|
||||
public void paintPlayground() {
|
||||
Graphics g = getGraphics();
|
||||
if (g != null) {
|
||||
super.paintComponent(g);
|
||||
Graphics2D g2D = (Graphics2D)g;
|
||||
g2D.drawImage(traceBuffer, 0, 0, this);
|
||||
if (isTurtleVisible)
|
||||
g2D.drawImage(turtleBuffer, 0, 0, this);
|
||||
|
||||
} // end of if
|
||||
}
|
||||
|
||||
/** Remove all turtles from the turtle buffer.
|
||||
*/
|
||||
public void clearTurtles() {
|
||||
for (int i = 0; i < countTurtles(); i++) {
|
||||
Turtle turtle = getTurtle(i);
|
||||
clearTurtle(turtle);
|
||||
}
|
||||
}
|
||||
|
||||
/** Remove the given turtle from the turtle buffer.
|
||||
Override this method if you have added a new behaviour (like
|
||||
wrap or clip) to the turtle.
|
||||
*/
|
||||
public void clearTurtle(Turtle turtle) {
|
||||
if(turtle != null){
|
||||
if (!turtle.isHidden()) {
|
||||
if(turtle.isClip()){
|
||||
clearClipTurtle(turtle);
|
||||
}
|
||||
else if(turtle.isWrap()){
|
||||
clearWrapTurtle(turtle);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** This method is called when the given <code>Turtle</code> is in wrap mode.
|
||||
|
||||
@see ch.aplu.turtle.Turtle#wrap
|
||||
*/
|
||||
protected void clearWrapTurtle(Turtle turtle){
|
||||
clearWrapTurtle(turtle, turtleBuffer);
|
||||
}
|
||||
|
||||
/** Here the actual clearing of a <code>Turtle</code> in wrap mode from the
|
||||
given image is performed.
|
||||
*/
|
||||
protected void clearWrapTurtle(Turtle turtle, Image im){
|
||||
Rectangle bounds = getBounds(turtle);
|
||||
int pWidth = getWidth();
|
||||
int pHeight = getHeight();
|
||||
int x = bounds.x;
|
||||
int y = bounds.y;
|
||||
while (x > pWidth){
|
||||
x -= pWidth;
|
||||
}
|
||||
while (x < 0){
|
||||
x += pWidth;
|
||||
}
|
||||
while (y > pHeight){
|
||||
y -= pHeight;
|
||||
}
|
||||
while (y < 0){
|
||||
y += pHeight;
|
||||
}
|
||||
x = x % pWidth;
|
||||
y = y % pHeight;
|
||||
toAlphaNull(im, new Rectangle(x, y, bounds.width, bounds.height)); // OK
|
||||
boolean right = (x + bounds.width > getWidth());
|
||||
boolean bottom = (y + bounds.height > getHeight());
|
||||
if (right) {
|
||||
toAlphaNull(im, new Rectangle(x-pWidth, y, bounds.width, bounds.height));
|
||||
}
|
||||
if (bottom) {
|
||||
toAlphaNull(im, new Rectangle(x, y-pHeight, bounds.width, bounds.height));
|
||||
}
|
||||
if (right && bottom) {
|
||||
toAlphaNull(im, new Rectangle(x-pWidth, y-pHeight, bounds.width, bounds.height));
|
||||
}
|
||||
}
|
||||
|
||||
/** Copy and translate a given Rectangle.
|
||||
*/
|
||||
private Rectangle copyAndTranslate(Rectangle rect, int dx, int dy) {
|
||||
return new Rectangle(rect.x+dx, rect.y+dy,
|
||||
rect.width, rect.height);
|
||||
}
|
||||
|
||||
/** This method is called when the given <code>Turtle</code> is in clip mode.
|
||||
|
||||
@see ch.aplu.turtle.Turtle#clip
|
||||
*/
|
||||
protected void clearClipTurtle(Turtle turtle) {
|
||||
clearClipTurtle(turtle, turtleBuffer);
|
||||
}
|
||||
|
||||
/** Here the actual clearing of a <code>Turtle</code> in clip mode from the
|
||||
given image is performed.
|
||||
*/
|
||||
protected void clearClipTurtle(Turtle turtle, Image im) {
|
||||
Rectangle bounds = getBounds(turtle);
|
||||
toAlphaNull(im, bounds);
|
||||
}
|
||||
|
||||
/** Set the alpha channel of all pixels in the given image
|
||||
in the given Rectangle to zero (i.e. totally transparent).
|
||||
|
||||
This method is used byte the clearXXXTurtle methods.
|
||||
*/
|
||||
private void toAlphaNull(Image im, Rectangle rect) {
|
||||
Rectangle rim = new Rectangle(0, 0, im.getWidth(this), im.getHeight(this));
|
||||
Rectangle r = new Rectangle();
|
||||
if (rect.intersects(rim)) {
|
||||
r=rect.intersection(rim);
|
||||
}
|
||||
int size = r.width*r.height;
|
||||
float[] alphachannel = new float[r.width*r.height];
|
||||
((BufferedImage)im).getAlphaRaster().setPixels(r.x, r.y, r.width, r.height, alphachannel);
|
||||
}
|
||||
|
||||
/** Puts a Turtle above all others.
|
||||
*/
|
||||
public Turtle toTop(Turtle turtle) {
|
||||
if (turtles.removeElement(turtle)) {
|
||||
turtles.add(turtle);
|
||||
}
|
||||
return turtle;
|
||||
}
|
||||
/** Put a Turtle below all others.
|
||||
*/
|
||||
public Turtle toBottom(Turtle turtle) {
|
||||
if (turtles.removeElement(turtle)) {
|
||||
turtles.add(0,turtle);
|
||||
}
|
||||
return turtle;
|
||||
}
|
||||
|
||||
/** Calculate the screen coordinates of the given point.
|
||||
*/
|
||||
public Point2D.Double toScreenCoords(Point2D.Double p) {
|
||||
return internalToScreenCoords(p.x, p.y);
|
||||
}
|
||||
|
||||
/** Calculate the screen coordinates of the given point coordinates.
|
||||
*/
|
||||
public Point2D.Double toScreenCoords(double x, double y) {
|
||||
return internalToScreenCoords(x, y);
|
||||
}
|
||||
|
||||
protected Point2D.Double internalToScreenCoords(double x, double y) {
|
||||
// reflect at x-axis, then translate to center of Playground
|
||||
// pixel coordinates coorespond to turtle coordinates, only translation needed
|
||||
double newX = originX + x;
|
||||
double newY = originY - y;
|
||||
return new Point2D.Double(newX, newY);
|
||||
}
|
||||
|
||||
/** Calculate the turtle coordinates of the given screen coordinates.
|
||||
*/
|
||||
public Point2D.Double toTurtleCoords(double x, double y) {
|
||||
// pixel coordinates coorespond to turtle coordinates, only translation needed
|
||||
double newX = x - originX;
|
||||
double newY = originY - y;
|
||||
return new Point2D.Double(newX, newY);
|
||||
}
|
||||
|
||||
/** Calculate the turtle coordinates of the given screen point.
|
||||
*/
|
||||
public Point2D.Double toTurtleCoords(Point2D.Double p) {
|
||||
return toTurtleCoords(p.x, p.y);
|
||||
}
|
||||
|
||||
/** Calculate the screen angle.
|
||||
I.e. the interpretation of angle.
|
||||
@param radians The angle in radians.
|
||||
*/
|
||||
double toScreenAngle(double radians) {
|
||||
double sa = radians;
|
||||
if (sa < Math.PI/2){
|
||||
sa += 2*Math.PI;
|
||||
}
|
||||
sa -= Math.PI/2;
|
||||
if (sa != 0) {
|
||||
sa = Math.PI*2 - sa;
|
||||
}
|
||||
return sa;
|
||||
}
|
||||
|
||||
/** Calculate the bounds of the <code>Turtle</code>s picture on the screen.
|
||||
*/
|
||||
protected Rectangle getBounds(Turtle turtle) {
|
||||
Rectangle bounds = turtle.getBounds();
|
||||
Point2D.Double tmp = toScreenCoords(new Point2D.Double(bounds.getX(), bounds.getY()));
|
||||
bounds.setRect(tmp.x-2, tmp.y-2, bounds.width+4, bounds.height+4);
|
||||
return bounds;
|
||||
}
|
||||
|
||||
/** Return the graphics context of the turtle buffer.
|
||||
*/
|
||||
public Graphics2D getTurtleG2D() {
|
||||
return turtleG2D;
|
||||
}
|
||||
|
||||
/** Return the image of the turtle buffer.
|
||||
*/
|
||||
public BufferedImage getTurtleBuffer() {
|
||||
return turtleBuffer;
|
||||
}
|
||||
|
||||
/** Return the graphics context of the trace buffer.
|
||||
*/
|
||||
public Graphics2D getTraceG2D() {
|
||||
return traceG2D;
|
||||
}
|
||||
|
||||
/** Return the graphics context of the printer.
|
||||
*/
|
||||
public Graphics2D getPrinterG2D() {
|
||||
return printerG2D;
|
||||
}
|
||||
|
||||
/** Return the image of the trace buffer.
|
||||
*/
|
||||
public BufferedImage getTraceBuffer() {
|
||||
return traceBuffer;
|
||||
}
|
||||
|
||||
/** Clean the traces.
|
||||
All turtles stay how and where they are, only lines, text and stamps will be removed.
|
||||
*/
|
||||
void clean() {
|
||||
Graphics2D g = getTraceG2D();
|
||||
g.setColor(getBackground());
|
||||
g.fillRect(0,0,getWidth(), getHeight());
|
||||
if (printerG2D == null)
|
||||
repaint();
|
||||
}
|
||||
|
||||
/** Draw the <code>text</code> at the current position of the Turtle <code>t</code>.
|
||||
Drawing a text at some coordinates <code>(x,y)</code> we mean that the bottom left corner of
|
||||
the text will be at these coordinates.
|
||||
Font and colour are specified by the Turtle's Pen.
|
||||
*/
|
||||
public void label(String text, Turtle t) {
|
||||
Point2D.Double sc = toScreenCoords(t.getPos());
|
||||
int x = (int)Math.round(sc.x);
|
||||
int y = (int)Math.round(sc.y);
|
||||
Graphics2D traceG2D = getTraceG2D();
|
||||
FontRenderContext frc = traceG2D.getFontRenderContext();
|
||||
Font f = t.getFont();
|
||||
TextLayout tl = new TextLayout(text, f, frc);
|
||||
traceG2D.setColor(t.getPen().getColor());
|
||||
tl.draw(traceG2D, x, y);
|
||||
if (printerG2D != null)
|
||||
{
|
||||
printerG2D.setColor(t.getPen().getColor());
|
||||
tl.draw(printerG2D, x, y);
|
||||
}
|
||||
|
||||
if (printerG2D == null)
|
||||
repaint();
|
||||
}
|
||||
|
||||
/** Set antialiasing on or off for the turtle trace buffer
|
||||
* This may result in an better trace quality.
|
||||
*/
|
||||
public void setAntiAliasing(boolean on) {
|
||||
if (on)
|
||||
traceG2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
else
|
||||
traceG2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_OFF);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the given TPrintable (implementing draw()),
|
||||
* open a printer dialog and start printing with given scale.
|
||||
* Return false, if printer dialog is aborted,
|
||||
* otherwise return true.<br>
|
||||
* If tp == null, the current playground is printed.
|
||||
*
|
||||
*/
|
||||
protected boolean print(TPrintable tp, double scale) {
|
||||
if (tp == null)
|
||||
isPrintScreen = true;
|
||||
else
|
||||
isPrintScreen = false;
|
||||
printerScale = scale;
|
||||
PrinterJob pj = PrinterJob.getPrinterJob();
|
||||
pj.setPrintable(this);
|
||||
traceCanvas = tp;
|
||||
if (pj.printDialog()) {
|
||||
try {
|
||||
pj.print();
|
||||
}
|
||||
catch (PrinterException ex) {
|
||||
System.out.println(ex);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* For internal use only. Implementation of Printable.
|
||||
* (Callback method called by printing system.)
|
||||
*/
|
||||
public int print(Graphics g, PageFormat pf, int pageIndex) {
|
||||
if (pageIndex != 0)
|
||||
return NO_SUCH_PAGE;
|
||||
Graphics2D g2D = (Graphics2D)g;
|
||||
double printerWidth = pf.getImageableWidth();
|
||||
double printerHeight = pf.getImageableHeight();
|
||||
double printerSize = printerWidth > printerHeight ? printerWidth :
|
||||
printerHeight;
|
||||
double xZero = pf.getImageableX();
|
||||
double yZero = pf.getImageableY();
|
||||
|
||||
printerG2D = g2D; // Indicate also, we are printing now
|
||||
|
||||
// Needed for fill operations: the trace canvas must be empty in order to
|
||||
// perform the fill algoritm (searching for outline of figure)
|
||||
if (!isPrintScreen)
|
||||
clean();
|
||||
|
||||
g2D.scale(printerScaleFactor * printerScale, printerScaleFactor * printerScale);
|
||||
g2D.translate(xZero/printerScale, yZero/printerScale);
|
||||
|
||||
if (isPrintScreen)
|
||||
{
|
||||
print(g);
|
||||
}
|
||||
else // Printing the traceCanvas
|
||||
{
|
||||
// Hide all turtles
|
||||
boolean[] turtleState = new boolean[countTurtles()];
|
||||
for (int i = 0; i < countTurtles(); i++) {
|
||||
Turtle aTurtle = getTurtle(i);
|
||||
turtleState[i] = aTurtle.isHidden();
|
||||
aTurtle.ht();
|
||||
}
|
||||
traceCanvas.draw();
|
||||
|
||||
// Restore old context
|
||||
for (int i = 0; i < countTurtles(); i++) {
|
||||
Turtle aTurtle = getTurtle(i);
|
||||
if (!turtleState[i])
|
||||
aTurtle.st();
|
||||
}
|
||||
}
|
||||
|
||||
printerG2D = null;
|
||||
return PAGE_EXISTS;
|
||||
}
|
||||
|
||||
/** Return the color of the pixel at the current turtle position.
|
||||
*/
|
||||
public Color getPixelColor(Turtle t) {
|
||||
Point2D.Double p1 = toScreenCoords(t.getPos());
|
||||
int x = (int)Math.round(p1.getX());
|
||||
int y = (int)Math.round(p1.getY());
|
||||
return new Color(traceBuffer.getRGB(x, y));
|
||||
}
|
||||
|
||||
public void enableRepaint(boolean b) {
|
||||
isRepainting = b;
|
||||
}
|
||||
|
||||
/** set the background color of the playground
|
||||
*/
|
||||
public void setBackground(Color color) {
|
||||
super.setBackground(color);
|
||||
if (traceG2D != null) {
|
||||
clear(color);
|
||||
} // end of if
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the origin of the cartesian coordinate system within the playground
|
||||
*/
|
||||
public void setOrigin(int x, int y) {
|
||||
for (int i = 0; i < countTurtles(); i++) {
|
||||
Turtle turtle = getTurtle(i);
|
||||
Point2D.Double p1 = toScreenCoords(turtle.getPos());
|
||||
double newX = p1.getX() - x;
|
||||
double newY = y - p1.getY();
|
||||
turtle.internalSetPos(newX, newY);
|
||||
}
|
||||
originX = x;
|
||||
originY = y;
|
||||
}
|
||||
|
||||
public int getOriginX() {
|
||||
return originX;
|
||||
}
|
||||
|
||||
public int getOriginY() {
|
||||
return originY;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Binary file not shown.
|
|
@ -0,0 +1,84 @@
|
|||
// SharedConstants.java
|
||||
|
||||
// Copyright 2002 Regula Hoefer-Isenegger
|
||||
//
|
||||
// This file is part of The Java Turtle (TJT) package
|
||||
//
|
||||
// TJT 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
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// TJT 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 The Java Turtle Package; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
/* History;
|
||||
V1.36 - Sep 2004: First official release
|
||||
V1.37 - Nov 2004: Unchanged, modifications in ch.aplu.util
|
||||
V1.38 - Dec 2004: Unchanged, modifications in ch.aplu.util
|
||||
V1.39 - Jan 2005: Unchanged, modifications in ch.aplu.util
|
||||
V1.40 - Mar 2005: Add background color, TurtleKeyAdapter, TurtleArea
|
||||
V1.41 - May 2005: User defined turtle shape, minor changes in doc and code style
|
||||
V1.42 - Dec 2005: Unchanged, modifications in ch.aplu.util
|
||||
V1.43 - Feb 2006: Bug removed: Turtle.turtleFrame was not initialized in all ctors of class Turtle
|
||||
V1.44 - Mar 2007: Bug removed: stampTurtle did not work properly in wrap mode
|
||||
V1.45 - Aug 2007: TurtleKeyAdapter: use wait/notify to reduce CPU time (from 100% to 2%)
|
||||
V1.46 - Aug 2007: synchronize(playground) for forward and rotate animation,
|
||||
new method bong() using StreamingPlayer
|
||||
V1.47 - Sept 2007: Unchanged, modifications in ch.aplu.util
|
||||
V1.48 - Sept 2007: Unchanged, modifications in ch.aplu.util
|
||||
V1.49 - Oct 2007: Unchanged, modifications in ch.aplu.util
|
||||
V1.50 - Oct 2007: Unchanged, modifications in ch.aplu.util
|
||||
V1.51 - Nov 2007: Fixed: correct position of label, when wrapping is on
|
||||
Fixed: getPos() returns now the wrapped coordinates
|
||||
Added: _getPos() returns unwrapped coordinates
|
||||
V1.52 - Nov 2007: Added bean classes in order to use turtles with a Gui builder
|
||||
V1.53 - Nov 2007: Added TurtlePane visual information when used in Gui builder design mode
|
||||
V1.54 - Nov 2007: Minor changes to documentation
|
||||
V1.55 - Dec 2007: Added property enableFocus to GPane, default: setFocusable(false)
|
||||
V1.56 - Mar 2008: Unchanged, modifications in ch.aplu.util
|
||||
V1.57 - Mar 2008: Unchanged, modifications in ch.aplu.util
|
||||
V1.58 - Mar 2008: Modification to fill() (fill(x, y)):
|
||||
region is defined with pixel color at current position
|
||||
as opposed to background color
|
||||
V1.59 - Oct 2008: Added ctors TurtleFrame with window position (ulx, uly)
|
||||
Added Turtle.getPixelColor()
|
||||
V2.00 - Nov 2008: Unchanged, modifications in ch.aplu.util
|
||||
J2SE V1.4 no longer supported
|
||||
V2.01 - Jan 2009: Unchanged, modifications in ch.aplu.util
|
||||
V2.02 - Feb 2009 Turtle constructors run in EDT now
|
||||
V2.03 - Feb 2009 Unchanged, modifications in ch.aplu.util
|
||||
V2.04 - Feb 2009 Unchanged, modifications in ch.aplu.util
|
||||
V2.05 - Feb 2009 Unchanged, modifications in ch.aplu.util
|
||||
V2.06 - Mar 2009 Unchanged, modifications in ch.aplu.util
|
||||
V2.07 - Mar 2009 All except print methods synchronized, so Turtle package is
|
||||
now thread-safe
|
||||
V2.08 - Apr 2009 Unchanged, modifications in ch.aplu.util
|
||||
V2.09 - Jun 2009 Unchanged, modifications in ch.aplu.util
|
||||
V2.10 - Jun 2010 Version for the Java-Editor
|
||||
*/
|
||||
|
||||
package ch.aplu.turtle;
|
||||
|
||||
interface SharedConstants
|
||||
{
|
||||
int DEBUG_LEVEL_OFF = 0;
|
||||
int DEBUG_LEVEL_LOW = 1;
|
||||
int DEBUG_LEVEL_MEDIUM = 2;
|
||||
int DEBUG_LEVEL_HIGH = 3;
|
||||
|
||||
int DEBUG = DEBUG_LEVEL_OFF;
|
||||
|
||||
String ABOUT =
|
||||
"Copyright © 2002-2009\nRegula Hoefer-Isenegger, Aegidius Pluess\n, Gerhard Roehner\n" +
|
||||
"under GNU General Public License\n" +
|
||||
"http://www.aplu.ch\n" +
|
||||
"All rights reserved";
|
||||
String VERSION = "2.10 - June 2015";
|
||||
}
|
||||
|
|
@ -0,0 +1,84 @@
|
|||
// StreamingPlayer.java
|
||||
|
||||
package ch.aplu.turtle;
|
||||
|
||||
|
||||
import javax.sound.sampled.*;
|
||||
import java.io.*;
|
||||
|
||||
class StreamingPlayer
|
||||
{
|
||||
private class PlayerThread extends Thread
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
byte buf[] = new byte[20000];
|
||||
try
|
||||
{
|
||||
int cnt;
|
||||
while ((cnt = audioInputStream.read(buf, 0, buf.length)) != -1)
|
||||
{
|
||||
if (cnt > 0)
|
||||
sourceDataLine.write(buf, 0, cnt);
|
||||
}
|
||||
sourceDataLine.drain();
|
||||
sourceDataLine.close();
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
System.out.println(ex);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private AudioFormat audioFormat;
|
||||
private AudioInputStream audioInputStream;
|
||||
private SourceDataLine sourceDataLine;
|
||||
private PlayerThread playerThread;
|
||||
|
||||
StreamingPlayer(InputStream is)
|
||||
{
|
||||
try
|
||||
{
|
||||
audioInputStream =
|
||||
AudioSystem.getAudioInputStream(is);
|
||||
audioFormat = audioInputStream.getFormat();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{}
|
||||
}
|
||||
|
||||
void start(boolean doFinish)
|
||||
throws LineUnavailableException
|
||||
{
|
||||
DataLine.Info dataLineInfo =
|
||||
new DataLine.Info(SourceDataLine.class, audioFormat);
|
||||
sourceDataLine =
|
||||
(SourceDataLine)AudioSystem.getLine(dataLineInfo);
|
||||
sourceDataLine.open(audioFormat);
|
||||
sourceDataLine.start();
|
||||
playerThread = new PlayerThread();
|
||||
playerThread.start();
|
||||
if (doFinish)
|
||||
waitToFinish();
|
||||
}
|
||||
|
||||
boolean isPlaying()
|
||||
{
|
||||
if (playerThread == null)
|
||||
return false;
|
||||
return (playerThread.isAlive());
|
||||
}
|
||||
|
||||
void waitToFinish()
|
||||
{
|
||||
if (playerThread == null)
|
||||
return;
|
||||
try
|
||||
{
|
||||
playerThread.join();
|
||||
}
|
||||
catch (InterruptedException ex) {}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
// TPrintable.java
|
||||
|
||||
// Copyright 2002 Regula Hoefer-Isenegger
|
||||
|
||||
// This file is part of The Java Turtle (TJT) package
|
||||
//
|
||||
// TJT 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
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// TJT 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 The Java Turtle Package; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
// Added by Aegidius Pluess
|
||||
|
||||
package ch.aplu.turtle;
|
||||
|
||||
/**
|
||||
* Interface for printing on an attached printer.
|
||||
* Normally an application uses a Turtle and implements this interface.
|
||||
* draw() should contain all drawing operations into the
|
||||
* Turtle's Playground. The printing occures, when Turtle's print() is
|
||||
* called.<br><br>
|
||||
*/
|
||||
|
||||
|
||||
public interface TPrintable
|
||||
{
|
||||
/**
|
||||
* This method must perform all drawing operations.
|
||||
* Be aware that for some undocumented reason
|
||||
* draw() is called twice. So be sure you initialize it correctly.
|
||||
*/
|
||||
|
||||
public void draw();
|
||||
}
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -0,0 +1,66 @@
|
|||
// TurtleFactory.java
|
||||
|
||||
// Copyright 2002 Regula Hoefer-Isenegger
|
||||
//
|
||||
// This file is part of The Java Turtle (TJT) package
|
||||
//
|
||||
// TJT 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
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// TJT 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 The Java Turtle Package; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package ch.aplu.turtle;
|
||||
|
||||
import java.awt.image.*;
|
||||
import java.awt.*;
|
||||
|
||||
class TurtleFactory
|
||||
{
|
||||
/** Generates the shape of the turtle with <code>color</code>,
|
||||
* angle <code>angle</code>, width <code>w</code>
|
||||
* and height <code>h</code>.
|
||||
*/
|
||||
protected Image turtleImage(Color color, double angle, int w, int h)
|
||||
{
|
||||
BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_4BYTE_ABGR);
|
||||
Graphics2D g = (Graphics2D)bi.getGraphics();
|
||||
// Origin in center
|
||||
g.translate(w/2, h/2);
|
||||
// angle = 0 is direction east (as usual in mathematics)
|
||||
g.rotate(Math.PI/2 - angle);
|
||||
g.setColor(color);
|
||||
|
||||
// Body
|
||||
g.fillOval((int)( -0.35 * w), (int)( -0.35 * h),
|
||||
(int)(0.7 * w), (int)(0.7 * h));
|
||||
|
||||
// Head
|
||||
g.fillOval((int)( -0.1 * w), (int)( -0.5 * h),
|
||||
(int)(0.2 * w), (int)(0.2 * h));
|
||||
|
||||
// Tail
|
||||
int[] xcoords =
|
||||
{(int)( -0.05 * w), 0, (int)(0.05 * w)};
|
||||
int[] ycoords =
|
||||
{(int)(0.35 * h), (int)(0.45 * h), (int)(0.35 * h)};
|
||||
g.fillPolygon(xcoords, ycoords, 3);
|
||||
|
||||
// Feet
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
g.rotate(Math.PI / 2);
|
||||
g.fillOval((int)( -0.35 * w), (int)( -0.35 * h),
|
||||
(int)(0.125 * w), (int)(0.125 * h));
|
||||
}
|
||||
return (Image)bi;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,312 @@
|
|||
// TurtleRenderer.java
|
||||
|
||||
// Copyright 2002 Regula Hoefer-Isenegger
|
||||
// Some modifications by Aegidius Pluess
|
||||
|
||||
// This file is part of The Java Turtle (TJT) package
|
||||
//
|
||||
// TJT 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
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// TJT 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 The Java Turtle Package; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package ch.aplu.turtle;
|
||||
|
||||
import ch.aplu.turtle.*;
|
||||
import java.awt.image.*;
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import java.awt.geom.*;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
/** This class is responsible for creating and choosing the correct Turtle picture.
|
||||
@author <a href="mailto:regula@hoefer.ch">Regula Hoefer-Isenegger</a>
|
||||
@version 0.1
|
||||
*/
|
||||
public class TurtleRenderer implements ImageObserver {
|
||||
/** Holds the current image */
|
||||
private Image currentImage;
|
||||
/** Holds all images */
|
||||
private Vector images;
|
||||
/** Tells how many pictures are needed*/
|
||||
private int resolution;
|
||||
/** A reference to the <code>Turtle</code> */
|
||||
private Turtle turtle;
|
||||
/** Holds the current Angle */
|
||||
private double currentAngle;
|
||||
|
||||
private final int turtleSize = 29;
|
||||
|
||||
/***/
|
||||
public TurtleRenderer(Turtle turtle) {
|
||||
this.currentImage = null;
|
||||
this.images = new Vector();
|
||||
this.turtle = turtle;
|
||||
currentAngle = 0;
|
||||
}
|
||||
|
||||
/** As an image stays unchanged, there's no need to ever update it. So this method returns always false.
|
||||
|
||||
For further information cf. <code>java.awt.image.ImageObserver</code>.
|
||||
@see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
|
||||
*/
|
||||
public boolean imageUpdate(Image img, int infoflags,
|
||||
int x, int y, int width, int height) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Return the current image.
|
||||
*/
|
||||
public Image currentImage() {
|
||||
return this.currentImage;
|
||||
}
|
||||
|
||||
/** Tell whether the image has changed.
|
||||
*/
|
||||
public boolean imageChanged(double angle) {
|
||||
return (this.currentImage != getImage(angle));
|
||||
}
|
||||
|
||||
/** Set the current image to the specified one. */
|
||||
private void setCurrentImage(Image image) {
|
||||
currentImage = image;
|
||||
}
|
||||
|
||||
/** Choose the image for the angle <code>angle</code>.
|
||||
*/
|
||||
private Image getImage(double angle) {
|
||||
while (angle < 0) {
|
||||
angle += 2*Math.PI;
|
||||
}
|
||||
while (angle >= 2*Math.PI) {
|
||||
angle -= 2*Math.PI;
|
||||
}
|
||||
double res = 2*Math.PI/(double)this.resolution;
|
||||
int index = (int)(angle/res);
|
||||
return image(index);
|
||||
}
|
||||
|
||||
/** Set the current image to the one corresponding to the angle <code>angle</code>.
|
||||
*/
|
||||
public void setAngle(double angle) {
|
||||
currentAngle = angle;
|
||||
setCurrentImage(getImage(angle));
|
||||
}
|
||||
|
||||
/** @return the current angle. */
|
||||
protected double getAngle(){
|
||||
return currentAngle;
|
||||
}
|
||||
|
||||
/** Create the images. There are <code>resolution</code> images (i.e. two subsequent
|
||||
images contain an angle of 2π/<resolution> or 360/resolution degrees).
|
||||
*/
|
||||
public void init(TurtleFactory factory, int resolution) {
|
||||
this.resolution = resolution;
|
||||
Integer res = new Integer(resolution);
|
||||
double incRes = Math.PI*2/res.doubleValue();
|
||||
double angle = 0;
|
||||
images = new Vector();
|
||||
for (int i = 0; i < resolution; i++) {
|
||||
images.add(factory.turtleImage(turtle.getColor(),
|
||||
turtle.getPlayground().toScreenAngle(angle),
|
||||
turtleSize, turtleSize));
|
||||
angle += incRes;
|
||||
}
|
||||
setCurrentImage(getImage(currentAngle));
|
||||
}
|
||||
|
||||
/** Tell how many images this <code>TurtleRenderer</code> holds */
|
||||
private int countImages() {
|
||||
return this.images.size();
|
||||
}
|
||||
|
||||
/** Get the image at <code>index</code> */
|
||||
private Image image(int index) {
|
||||
return (Image)this.images.elementAt(index);
|
||||
}
|
||||
|
||||
/** This method is responsible for painting the turtle onto the
|
||||
playground at (<code>x, y</code>).
|
||||
*/
|
||||
public final void paint(double x, double y) {
|
||||
internalPaint(x, y, turtle.getPlayground().getGraphics());
|
||||
}
|
||||
|
||||
/** This method is responsible for painting the turtle onto the
|
||||
playground at <code>p</code>.
|
||||
*/
|
||||
public final void paint(Point2D.Double p) {
|
||||
internalPaint(p.x, p.y, turtle.getPlayground().getGraphics());
|
||||
}
|
||||
|
||||
/** This method is responsible for painting the <code>Turtle</code>
|
||||
at (<code>x, y</code>).<br>
|
||||
The Graphics argument tells where to paint.
|
||||
*/
|
||||
public final void paint(double x, double y, Graphics g) {
|
||||
internalPaint(x, y, g);
|
||||
}
|
||||
|
||||
/** This method is responsible for painting the <code>Turtle</code>
|
||||
at <code>p</code>.<br>
|
||||
The Graphics argument tells where to paint.
|
||||
*/
|
||||
public void paint(Point2D.Double p, Graphics g){
|
||||
internalPaint(p.x, p.y, g);
|
||||
}
|
||||
|
||||
/** Call clipPaint and wrapPaint().
|
||||
|
||||
You should override this method only, if you add a new (edge)
|
||||
behaviour to the turtle. I recommend to you then to first call this
|
||||
method from the overriding one.
|
||||
<br>
|
||||
If you want to change anything about the real painting, override
|
||||
clipPaint or wrapPaint.
|
||||
|
||||
@see #clipPaint(int, int, Graphics2D)
|
||||
@see #wrapPaint(int, int, Graphics2D)
|
||||
*/
|
||||
protected void internalPaint(double x, double y, Graphics g) {
|
||||
if(turtle.isClip()){
|
||||
Point2D.Double p =
|
||||
calcTopLeftCorner(turtle.getPlayground().toScreenCoords(x, y));
|
||||
clipPaint((int)p.x, (int)p.y, (Graphics2D)g);
|
||||
}
|
||||
else if(turtle.isWrap()){
|
||||
Point2D.Double p =
|
||||
calcTopLeftCorner(turtle.getPlayground().toScreenCoords(x, y));
|
||||
wrapPaint((int)p.x, (int)p.y, (Graphics2D)g);
|
||||
}
|
||||
}
|
||||
|
||||
/** Define how to paint in clip mode and do it */
|
||||
protected void clipPaint(int x, int y, Graphics2D g2D) {
|
||||
g2D.drawImage(currentImage, x, y, this);
|
||||
}
|
||||
|
||||
/** Define how to paint in wrap mode and do it */
|
||||
protected void wrapPaint(int x, int y, Graphics2D g2D) {
|
||||
int pWidth = turtle.getPlayground().getWidth();
|
||||
int pHeight = turtle.getPlayground().getHeight();
|
||||
int paintX = x;
|
||||
while (paintX > pWidth) {
|
||||
paintX -= pWidth;
|
||||
}
|
||||
while (paintX < 0) {
|
||||
paintX += pWidth;
|
||||
}
|
||||
int paintY = y;
|
||||
while (paintY > pHeight) {
|
||||
paintY -= pHeight;
|
||||
}
|
||||
while (paintY < 0) {
|
||||
paintY += pHeight;
|
||||
}
|
||||
g2D.drawImage(currentImage, paintX, paintY, this);
|
||||
int nWidth = currentImage.getWidth(this);
|
||||
int nHeight = currentImage.getHeight(this);
|
||||
boolean right = (paintX+nWidth > pWidth);
|
||||
boolean bottom = (paintY+nHeight > pHeight);
|
||||
if(right) {
|
||||
g2D.drawImage(currentImage,
|
||||
paintX-pWidth,
|
||||
paintY,
|
||||
this);
|
||||
}
|
||||
if(bottom) {
|
||||
g2D.drawImage(currentImage,
|
||||
paintX,
|
||||
paintY-pHeight,
|
||||
this);
|
||||
}
|
||||
if(right && bottom) {
|
||||
g2D.drawImage(currentImage,
|
||||
paintX-pWidth,
|
||||
paintY-pHeight,
|
||||
this);
|
||||
}
|
||||
}
|
||||
|
||||
/** Compute the x-coordinate of the top left corner of the Turtle image
|
||||
(it depends on the specified x-coordinate and the image width).
|
||||
*/
|
||||
protected int calcTopLeftCornerX(double x) {
|
||||
int intX = (int)x;
|
||||
int nWidth;
|
||||
if(currentImage == null) {
|
||||
setCurrentImage(new TurtleFactory().
|
||||
turtleImage(turtle.getColor(), getAngle(), turtleSize, turtleSize));
|
||||
}
|
||||
nWidth = this.currentImage.getWidth(this);
|
||||
// the center of the turtle lies on the turtle's location:
|
||||
intX -= nWidth/2;
|
||||
return intX; // top left corner of the Turtle's image
|
||||
}
|
||||
|
||||
/** Compute the y-coordinate of the top left corner of the Turtle image
|
||||
(it depends on the specified y-coordinate and the image height).
|
||||
*/
|
||||
protected int calcTopLeftCornerY(double y) {
|
||||
int intY = (int)y;
|
||||
if(currentImage == null) {
|
||||
setCurrentImage(new TurtleFactory().
|
||||
turtleImage(turtle.getColor(), getAngle(), turtleSize, turtleSize));
|
||||
}
|
||||
int nHeight = currentImage.getHeight(this);
|
||||
// the center of the turtle lies on the turtle's location:
|
||||
intY -= nHeight/2;
|
||||
|
||||
return intY; // top left corner of the Turtle's image
|
||||
}
|
||||
/** Compute the top left corner of the Turtle image
|
||||
(dependent on the specified x- and y-coordinate and the image
|
||||
width and height.
|
||||
*/
|
||||
protected Point2D.Double calcTopLeftCorner(double x, double y) {
|
||||
if(currentImage == null) {
|
||||
setCurrentImage(new TurtleFactory().
|
||||
turtleImage(turtle.getColor(), getAngle(), turtleSize, turtleSize));
|
||||
}
|
||||
int w = currentImage.getWidth(this);
|
||||
int h = currentImage.getHeight(this);
|
||||
return new Point2D.Double(x-w/2, y-h/2);
|
||||
}
|
||||
|
||||
/** Compute the top left corner of the Turtle image
|
||||
(dependent on the specified point <code>p</code> and the image
|
||||
width and height.
|
||||
*/
|
||||
protected Point2D.Double calcTopLeftCorner(Point2D.Double p) {
|
||||
return calcTopLeftCorner(p.x, p.y);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
public class Eval {
|
||||
|
||||
public static Wrap getOb(Object o) {
|
||||
return new Wrap(o);
|
||||
}
|
||||
|
||||
protected static Object getOb(final String s) {
|
||||
return new Object() {public String result = s;};
|
||||
}
|
||||
|
||||
protected static Object getOb(final boolean b) {
|
||||
return new Object() {public boolean result = b;};
|
||||
}
|
||||
|
||||
protected static Object getOb(final byte b) {
|
||||
return new Object() {public byte result = b;};
|
||||
}
|
||||
|
||||
protected static Object getOb(final char c) {
|
||||
return new Object() {public char result = c;};
|
||||
}
|
||||
|
||||
protected static Object getOb(final double d) {
|
||||
return new Object() {public double result = d;};
|
||||
}
|
||||
|
||||
protected static Object getOb(final float f) {
|
||||
return new Object() {public float result = f;};
|
||||
}
|
||||
|
||||
protected static Object getOb(final int i) {
|
||||
return new Object() {public int result = i;};
|
||||
}
|
||||
|
||||
protected static Object getOb(final long l) {
|
||||
return new Object() {public long result = l;};
|
||||
}
|
||||
protected static Object getOb(final short s) {
|
||||
return new Object() {public short result = s;};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Wrap {
|
||||
public Object result;
|
||||
|
||||
Wrap(Object result) {
|
||||
this.result = result;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,98 @@
|
|||
import java.io.*;
|
||||
|
||||
/**
|
||||
Support class for console input and output of numeric values.<br><br>
|
||||
|
||||
Example for input:<br>
|
||||
int age = InOut.readInt("Your age: ");<br><br>
|
||||
|
||||
Example for output:<br>
|
||||
System.out.println("price: " + InOut.format2(prize) + "Euro");<br>
|
||||
System.out.println("percent: " + InOut.formatN(percent, 1) + " %");
|
||||
*/
|
||||
|
||||
|
||||
public class InOut {
|
||||
|
||||
/** Formats a double-value with 2 decimal digits. */
|
||||
public static String format2(double d) {
|
||||
return String.format("%.2f", d);
|
||||
}
|
||||
|
||||
/** Formats a double-value with N decimal digits. */
|
||||
public static String formatN(double d, int N) {
|
||||
return String.format("%." + N + "f", d);
|
||||
}
|
||||
|
||||
/** Reads a boolean-value from console. */
|
||||
public static boolean readBoolean(String prompt) {
|
||||
final String[] trueValues =
|
||||
{ "1", "y", "t", "j", "w", "yes", "true", "ja", "wahr", "ok" };
|
||||
System.out.print(prompt);
|
||||
String input = readln().toLowerCase();
|
||||
for (int i = 0; i < trueValues.length; ++i)
|
||||
if (trueValues[i].equals(input))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Reads a char-value from console. */
|
||||
public static char readChar(String prompt) {
|
||||
System.out.print(prompt);
|
||||
return readln().charAt(0);
|
||||
}
|
||||
|
||||
/** Reads a double-value from console. */
|
||||
public static double readDouble(String prompt) {
|
||||
System.out.print(prompt);
|
||||
return Double.parseDouble(readln());
|
||||
}
|
||||
|
||||
/** Reads a float-value from console. */
|
||||
public static float readFloat(String prompt) {
|
||||
System.out.print(prompt);
|
||||
return Float.parseFloat(readln());
|
||||
}
|
||||
|
||||
/** Reads an int-value from console. */
|
||||
public static int readInt(String prompt) {
|
||||
System.out.print(prompt);
|
||||
return Integer.parseInt(readln());
|
||||
}
|
||||
|
||||
/** Reads a long-value from console. */
|
||||
public static long readLong(String prompt) {
|
||||
System.out.print(prompt);
|
||||
return Long.parseLong(readln());
|
||||
}
|
||||
|
||||
/** Reads a string-value from console. */
|
||||
public static String readString(String prompt) {
|
||||
System.out.print(prompt);
|
||||
return readln();
|
||||
}
|
||||
|
||||
/** Reads a string-value from console without prompt.
|
||||
For use at the end of a console program. */
|
||||
public static String readln() {
|
||||
try {
|
||||
return Input.readLine();
|
||||
} catch(Exception e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
private static BufferedReader Input;
|
||||
|
||||
static {
|
||||
try {
|
||||
Input = new BufferedReader(new InputStreamReader(System.in));
|
||||
}
|
||||
catch (Exception e) {
|
||||
System.out.println("console input not possible.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,311 @@
|
|||
package je.util;
|
||||
/*
|
||||
* Class : Turtle
|
||||
* Copyright: (c) Gerhard Röhner
|
||||
*
|
||||
* History
|
||||
* --------
|
||||
* 3.00 2000.10.10 first version as java class
|
||||
* 3.01 2002.10.22 DrawDynamic
|
||||
* 3.02 2010.10.11 sleepTime for paint delay
|
||||
* 3.03 2012.03.20 cartesian coordinate system, used with originX, originY, setOrigin
|
||||
* 3.04 2015.01.24 english version, integrated component
|
||||
*/
|
||||
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.image.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
/**
|
||||
* This class is a turtle component for simple graphic programming.
|
||||
*
|
||||
* @see <a href="http://www.javaeditor.org">
|
||||
* @author Gerhard Röhner
|
||||
* @version 3.03 20/03/2012
|
||||
*/
|
||||
|
||||
|
||||
public class Turtle extends Canvas {
|
||||
|
||||
// -- private Attribute ------------------------------------------------------
|
||||
|
||||
private BufferedImage myBufferedImage;
|
||||
private Graphics myBufferedGraphics;
|
||||
private Color foreground;
|
||||
private Color background;
|
||||
private static final double piDurch180 = Math.PI / 180;
|
||||
|
||||
// -- public attributes -----------------------------------------------------
|
||||
|
||||
/**
|
||||
* turtleX is the x-coordinate of the turtle
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.turtleX = 100;</PRE>
|
||||
*/
|
||||
public double turtleX;
|
||||
|
||||
/**
|
||||
* turtleY is the y-coordinate of the turtle.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.turtleY = 200;</PRE>
|
||||
*/
|
||||
public double turtleY;
|
||||
|
||||
/**
|
||||
* turtleW is the current angle of the turtle in the range form 0 to 360 degrees.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.turtleW = 180;</PRE>
|
||||
*/
|
||||
public double turtleW;
|
||||
|
||||
/**
|
||||
* originX is the x-position of the cartesian coodinate system within the turtle canvas.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.originX = 0;</PRE>
|
||||
*/
|
||||
public double originX;
|
||||
|
||||
/**
|
||||
* originY is the y-position of the cartesian coodinate system within the turtle canvas.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.originY = 100;</PRE>
|
||||
*/
|
||||
public double originY;
|
||||
|
||||
/**
|
||||
* If drawDynamic is true you can watch the drawing of the turtle.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.drawDynamic = true;</PRE>
|
||||
*/
|
||||
public boolean drawDynamic;
|
||||
|
||||
/**
|
||||
* For drawDynamic = true you set the delay in milliseconds for drawing.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.sleepTime = 500;</PRE>
|
||||
*/
|
||||
public int sleepTime = 0;
|
||||
|
||||
// --- constructor -----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Creates a Turtle with a canvas.
|
||||
* At the beginning the Turtle is placed in the middle of it's canvas.
|
||||
* The start angle is 0 degree, which means the Turtle looks to the right.
|
||||
* The background color is white, the drawing color black.
|
||||
* <P>
|
||||
* The turtle position can easily be changed by clicking into the canvas.
|
||||
* <P>
|
||||
* The size of the canvas can easily be changed with the mouse.
|
||||
* <P>
|
||||
* Example: <PRE>Turtle myTurtle = new Turtle();</PRE>
|
||||
*/
|
||||
|
||||
public Turtle() {
|
||||
myBufferedImage = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
|
||||
myBufferedGraphics = myBufferedImage.getGraphics();
|
||||
|
||||
setForeground(Color.black);
|
||||
setBackground(Color.white);
|
||||
drawDynamic = true;
|
||||
|
||||
addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent evt) {
|
||||
turtleMouseClicked(evt);}});
|
||||
addComponentListener(new ComponentAdapter() {
|
||||
public void componentResized(ComponentEvent evt) {
|
||||
turtleResized(evt);}});
|
||||
setOrigin(50, 50);
|
||||
}
|
||||
|
||||
private void turtleMouseClicked(MouseEvent evt) {
|
||||
turtleX = evt.getX() - originX;
|
||||
turtleY = originY - evt.getY();
|
||||
turtleW = 0;
|
||||
}
|
||||
|
||||
private void turtleResized(ComponentEvent evt) {
|
||||
int width = getWidth();
|
||||
int height = getHeight();
|
||||
|
||||
BufferedImage newBufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
|
||||
Graphics newGraphics = newBufferedImage.getGraphics();
|
||||
newGraphics.setColor(background);
|
||||
newGraphics.fillRect(0, 0, width, height);
|
||||
newGraphics.setColor(foreground);
|
||||
newGraphics.drawImage(myBufferedImage, 0, 0, this);
|
||||
|
||||
turtleX = 0;
|
||||
turtleY = 0;
|
||||
turtleW = 0;
|
||||
setOrigin(width / 2, height / 2);
|
||||
|
||||
myBufferedImage = newBufferedImage;
|
||||
myBufferedGraphics = newGraphics;
|
||||
}
|
||||
|
||||
public boolean isDoubleBuffered() {
|
||||
return true;
|
||||
}
|
||||
|
||||
private void wTurtleMod360() {
|
||||
while (turtleW >= 360)
|
||||
turtleW = turtleW - 360;
|
||||
while (turtleW < 0)
|
||||
turtleW = turtleW + 360;
|
||||
}
|
||||
|
||||
// --- angle and turns -------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Turns the angle of the turtle relativ by the parameter angle.
|
||||
* Positive values means a turn right, negative a turn left.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.turn(-90);</PRE>
|
||||
*/
|
||||
public void turn(double angle) {
|
||||
turtleW = turtleW + angle;
|
||||
wTurtleMod360();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the angle of the turtle absolute by the parameter angle.
|
||||
* The angle increases counterclockwise, therefore
|
||||
* right = 0, top = 90, left = 180, bottom = 270.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.turnto(270);</PRE>
|
||||
*/
|
||||
public void turnto(double angle) {
|
||||
turtleW = angle;
|
||||
wTurtleMod360();
|
||||
}
|
||||
|
||||
// --- Drawing ---------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* The Turtle draws a line of the length specified in the current direction.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.draw(100);</PRE>
|
||||
*/
|
||||
public void draw(double length) {
|
||||
drawto(turtleX + length * Math.cos(turtleW * piDurch180),
|
||||
turtleY + length * Math.sin(turtleW * piDurch180));
|
||||
}
|
||||
|
||||
/**
|
||||
* The Turtle draws a line form the current position (turtleX, turtleY) to the
|
||||
* position (x, y) relativ to the cartesian coordinate system.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.drawto(200, 300);</PRE>
|
||||
*/
|
||||
public void drawto(double x, double y) {
|
||||
int x1 = (int) (originX + turtleX);
|
||||
int x2 = (int) (originX + x);
|
||||
int y1 = (int) (originY - turtleY);
|
||||
int y2 = (int) (originY - y);
|
||||
|
||||
myBufferedGraphics.drawLine(x1, y1, x2, y2);
|
||||
if (drawDynamic){
|
||||
getGraphics().drawLine(x1, y1, x2, y2);
|
||||
try {
|
||||
Thread.currentThread().sleep(sleepTime);
|
||||
} catch(InterruptedException e) {
|
||||
}
|
||||
} else
|
||||
repaint();
|
||||
|
||||
turtleX = x;
|
||||
turtleY = y;
|
||||
}
|
||||
|
||||
// --- Moving ----------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* The Turtle moves without drawing the length specified in the current
|
||||
* direction.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.move(100);</PRE>
|
||||
*/
|
||||
public void move(double length) {
|
||||
turtleX = turtleX + length * Math.cos (turtleW * piDurch180);
|
||||
turtleY = turtleY + length * Math.sin (turtleW * piDurch180);
|
||||
}
|
||||
|
||||
/**
|
||||
* The Turtle moves without drawing to position (x, y) relativ to the
|
||||
* cartesian coordinate system.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.moveto(100, 200);</PRE>
|
||||
*/
|
||||
public void moveto(double x, double y) {
|
||||
turtleX = x;
|
||||
turtleY = y;
|
||||
}
|
||||
|
||||
// --- set origin -----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Sets the origin of the cartesian coordinate system within the turtle's canvas.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.setOrigin(100, 200);</PRE>
|
||||
*/
|
||||
public void setOrigin(double x, double y) {
|
||||
originX = x;
|
||||
originY = y;
|
||||
}
|
||||
|
||||
// --- fore- and background color --------------------------------------------
|
||||
|
||||
/**
|
||||
* Sets the drawing color of the Turtle to color c.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.setForeground(Color.red);</PRE>
|
||||
*/
|
||||
public void setForeground(Color c) {
|
||||
foreground = c;
|
||||
myBufferedGraphics.setColor(foreground);
|
||||
super.setForeground(foreground);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the canvas color of the Turtle to color c.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.setBackground(Color.blue); </PRE>
|
||||
*/
|
||||
public void setBackground(Color c) {
|
||||
background = c;
|
||||
myBufferedGraphics.setColor(background);
|
||||
myBufferedGraphics.fillRect(0, 0, getWidth(), getHeight());
|
||||
myBufferedGraphics.setColor(foreground);
|
||||
repaint();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the Turtle's canvas with the background color.
|
||||
* <P>
|
||||
* Example: <PRE>myTurtle.clear();</PRE>
|
||||
*/
|
||||
public void clear() {
|
||||
setBackground(background);
|
||||
getGraphics().drawImage(myBufferedImage, 0, 0, this);
|
||||
repaint();
|
||||
}
|
||||
|
||||
// --- Showing --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Shows the Turtle's canvas.
|
||||
*/
|
||||
public void paint(Graphics g) {
|
||||
g.drawImage(myBufferedImage, 0, 0, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the Turtle's canvas.
|
||||
*/
|
||||
public void update(Graphics g) {
|
||||
paint(g);
|
||||
}
|
||||
|
||||
}
|
||||
Binary file not shown.
|
|
@ -0,0 +1,129 @@
|
|||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
Swing-component for input and output of numeric values.
|
||||
*/
|
||||
|
||||
public class JNumberField extends JTextField {
|
||||
|
||||
/** constructor for a JNumberField */
|
||||
public JNumberField() {
|
||||
enableEvents(AWTEvent.KEY_EVENT_MASK);
|
||||
}
|
||||
|
||||
/** Gets a double-value from the JNumberField. */
|
||||
public double getDouble() {
|
||||
Double d = new Double(getText());
|
||||
return d.doubleValue();
|
||||
}
|
||||
|
||||
/** Gets a float-value from the JNumberField. */
|
||||
public float getFloat() {
|
||||
Double d = new Double(getText());
|
||||
return d.floatValue();
|
||||
}
|
||||
|
||||
/** Gets an int-value from the JNumberField. */
|
||||
public int getInt() {
|
||||
Double d = new Double(getText());
|
||||
return d.intValue();
|
||||
}
|
||||
|
||||
/** Gets a long-value from the JNumberField. */
|
||||
public long getLong() {
|
||||
Double d = new Double(getText());
|
||||
return d.longValue();
|
||||
}
|
||||
|
||||
/** Checks wether the JNumberField contains a valid numeric value. */
|
||||
public boolean isNumeric() {
|
||||
final String Digits = "(\\p{Digit}+)";
|
||||
final String HexDigits = "(\\p{XDigit}+)";
|
||||
// an exponent is 'e' or 'E' followed by an optionally
|
||||
// signed decimal integer.
|
||||
final String Exp = "[eE][+-]?"+Digits;
|
||||
final String fpRegex =
|
||||
("[\\x00-\\x20]*"+ // Optional leading "whitespace"
|
||||
"[+-]?(" + // Optional sign character
|
||||
"NaN|" + // "NaN" string
|
||||
"Infinity|" + // "Infinity" string
|
||||
|
||||
// A decimal floating-point string representing a finite positive
|
||||
// number without a leading sign has at most five basic pieces:
|
||||
// Digits . Digits ExponentPart FloatTypeSuffix
|
||||
//
|
||||
// Since this method allows integer-only strings as input
|
||||
// in addition to strings of floating-point literals, the
|
||||
// two sub-patterns below are simplifications of the grammar
|
||||
// productions from the Java Language Specification, 2nd
|
||||
// edition, section 3.10.2.
|
||||
|
||||
// Digits ._opt Digits_opt ExponentPart_opt FloatTypeSuffix_opt
|
||||
"((("+Digits+"(\\.)?("+Digits+"?)("+Exp+")?)|"+
|
||||
|
||||
// . Digits ExponentPart_opt FloatTypeSuffix_opt
|
||||
"(\\.("+Digits+")("+Exp+")?)|"+
|
||||
|
||||
// Hexadecimal strings
|
||||
"((" +
|
||||
// 0[xX] HexDigits ._opt BinaryExponent FloatTypeSuffix_opt
|
||||
"(0[xX]" + HexDigits + "(\\.)?)|" +
|
||||
|
||||
// 0[xX] HexDigits_opt . HexDigits BinaryExponent FloatTypeSuffix_opt
|
||||
"(0[xX]" + HexDigits + "?(\\.)" + HexDigits + ")" +
|
||||
|
||||
")[pP][+-]?" + Digits + "))" +
|
||||
"[fFdD]?))" +
|
||||
"[\\x00-\\x20]*");// Optional trailing "whitespace"
|
||||
|
||||
return java.util.regex.Pattern.matches(fpRegex, getText());
|
||||
}
|
||||
|
||||
/** Sets a double-value into the JNumberField. */
|
||||
public void setDouble(double d) {
|
||||
setText(String.valueOf(d));
|
||||
}
|
||||
|
||||
/** Sets a double-value with N digits into the JNumberField. */
|
||||
public void setDouble(double d, int N) {
|
||||
setText(String.format(Locale.ENGLISH, "%." + N + "f", d));
|
||||
}
|
||||
|
||||
/** Sets a float-value into the JNumberField. */
|
||||
public void setFloat(float f) {
|
||||
setText(String.valueOf(f));
|
||||
}
|
||||
|
||||
/** Sets a float-value with N digits into the JNumberField. */
|
||||
public void setFloat(float f, int N) {
|
||||
setText(String.format(Locale.ENGLISH, "%." + N + "f", f));
|
||||
}
|
||||
|
||||
/** Sets an int-value into the JNumberField. */
|
||||
public void setInt(int i) {
|
||||
setText(String.valueOf(i));
|
||||
}
|
||||
|
||||
/** Sets a long-value into the JNumberField. */
|
||||
public void setLong(long l) {
|
||||
setText(String.valueOf(l));
|
||||
}
|
||||
|
||||
/** Clears the JNumberField */
|
||||
public void clear() {
|
||||
setText("");
|
||||
}
|
||||
|
||||
protected void processKeyEvent(KeyEvent e) {
|
||||
super.processKeyEvent(e);
|
||||
if (isNumeric() || getText().equals("-") ||
|
||||
getText().equals("") || getText().equals("."))
|
||||
setBackground(Color.white);
|
||||
else
|
||||
setBackground(Color.red);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
Manifest-Version: 1.0
|
||||
Class-Path: JEClasses.jar
|
||||
Created-By: 1.8.0_161 (Oracle Corporation)
|
||||
Main-Class: BreakVigenere
|
||||
|
||||
|
|
@ -0,0 +1,128 @@
|
|||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
AWT-component for input and output of numeric values.
|
||||
*/
|
||||
|
||||
public class NumberField extends TextField {
|
||||
|
||||
/** constructor for a NumberField */
|
||||
public NumberField() {
|
||||
enableEvents(AWTEvent.KEY_EVENT_MASK);
|
||||
}
|
||||
|
||||
/** Gets a double-value from the NumberField. */
|
||||
public double getDouble() {
|
||||
Double d = new Double(getText());
|
||||
return d.doubleValue();
|
||||
}
|
||||
|
||||
/** Gets a float-value from the NumberField. */
|
||||
public float getFloat() {
|
||||
Double d = new Double(getText());
|
||||
return d.floatValue();
|
||||
}
|
||||
|
||||
/** Gets an int-value from the NumberField. */
|
||||
public int getInt() {
|
||||
Double d = new Double(getText());
|
||||
return d.intValue();
|
||||
}
|
||||
|
||||
/** Gets a long-value from the NumberField. */
|
||||
public long getLong() {
|
||||
Double d = new Double(getText());
|
||||
return d.longValue();
|
||||
}
|
||||
|
||||
/** Checks wether the NumberField contains a valid numeric value. */
|
||||
public boolean isNumeric() {
|
||||
final String Digits = "(\\p{Digit}+)";
|
||||
final String HexDigits = "(\\p{XDigit}+)";
|
||||
// an exponent is 'e' or 'E' followed by an optionally
|
||||
// signed decimal integer.
|
||||
final String Exp = "[eE][+-]?"+Digits;
|
||||
final String fpRegex =
|
||||
("[\\x00-\\x20]*"+ // Optional leading "whitespace"
|
||||
"[+-]?(" + // Optional sign character
|
||||
"NaN|" + // "NaN" string
|
||||
"Infinity|" + // "Infinity" string
|
||||
|
||||
// A decimal floating-point string representing a finite positive
|
||||
// number without a leading sign has at most five basic pieces:
|
||||
// Digits . Digits ExponentPart FloatTypeSuffix
|
||||
//
|
||||
// Since this method allows integer-only strings as input
|
||||
// in addition to strings of floating-point literals, the
|
||||
// two sub-patterns below are simplifications of the grammar
|
||||
// productions from the Java Language Specification, 2nd
|
||||
// edition, section 3.10.2.
|
||||
|
||||
// Digits ._opt Digits_opt ExponentPart_opt FloatTypeSuffix_opt
|
||||
"((("+Digits+"(\\.)?("+Digits+"?)("+Exp+")?)|"+
|
||||
|
||||
// . Digits ExponentPart_opt FloatTypeSuffix_opt
|
||||
"(\\.("+Digits+")("+Exp+")?)|"+
|
||||
|
||||
// Hexadecimal strings
|
||||
"((" +
|
||||
// 0[xX] HexDigits ._opt BinaryExponent FloatTypeSuffix_opt
|
||||
"(0[xX]" + HexDigits + "(\\.)?)|" +
|
||||
|
||||
// 0[xX] HexDigits_opt . HexDigits BinaryExponent FloatTypeSuffix_opt
|
||||
"(0[xX]" + HexDigits + "?(\\.)" + HexDigits + ")" +
|
||||
|
||||
")[pP][+-]?" + Digits + "))" +
|
||||
"[fFdD]?))" +
|
||||
"[\\x00-\\x20]*");// Optional trailing "whitespace"
|
||||
|
||||
return java.util.regex.Pattern.matches(fpRegex, getText());
|
||||
}
|
||||
|
||||
/** Sets a double-value into the NumberField. */
|
||||
public void setDouble(double d) {
|
||||
setText(String.valueOf(d));
|
||||
}
|
||||
|
||||
/** Sets a double-value with N digits into the NumberField. */
|
||||
public void setDouble(double d, int N) {
|
||||
setText(String.format(Locale.ENGLISH, "%." + N + "f", d));
|
||||
}
|
||||
|
||||
/** Sets a float-value into the NumberField. */
|
||||
public void setFloat(float f) {
|
||||
setText(String.valueOf(f));
|
||||
}
|
||||
|
||||
/** Sets a float-value with N digits into the NumberField. */
|
||||
public void setFloat(float f, int N) {
|
||||
setText(String.format(Locale.ENGLISH, "%." + N + "f", f));
|
||||
}
|
||||
|
||||
/** Sets an int-value into the NumberField. */
|
||||
public void setInt(int i) {
|
||||
setText(String.valueOf(i));
|
||||
}
|
||||
|
||||
/** Sets a long-value into the NumberField. */
|
||||
public void setLong(long l) {
|
||||
setText(String.valueOf(l));
|
||||
}
|
||||
|
||||
/** Clears the NumberField */
|
||||
public void clear() {
|
||||
setText("");
|
||||
}
|
||||
|
||||
protected void processKeyEvent(KeyEvent e) {
|
||||
super.processKeyEvent(e);
|
||||
if (isNumeric() || getText().equals("-") ||
|
||||
getText().equals("") || getText().equals("."))
|
||||
setBackground(Color.white);
|
||||
else
|
||||
setBackground(Color.red);
|
||||
}
|
||||
|
||||
}
|
||||
12
Software/iud_key_angriffe_vigenere/readme.adoc
Normal file
12
Software/iud_key_angriffe_vigenere/readme.adoc
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
= Material der ZPG IMP 8:
|
||||
|
||||
|===
|
||||
|Zuordnung| Rechner und Netze
|
||||
|Klassenstufe| IMP 8
|
||||
|Bildungsplanbezug |
|
||||
|Werkzeug|
|
||||
|Autoren|
|
||||
|===
|
||||
|
||||
== Inhalt
|
||||
Programme für die Kryptoanalyse der Vigenèreverschlüsselung
|
||||
Loading…
Add table
Add a link
Reference in a new issue