AMADEUS html plain
This sketchy text is generated by AMADEUS
* import java.
io.*;
awt.*;
util.*;
net.*;
URI
class AmFile
class AmFile
public static String ReadOrInput = "Read text";
selle muudab ajutiselt Item0B2Listener
static int namecounter = 1;
Uute failide nimede loendur
SketchyText main;
vastav skeemtekst
String name = "";
Too"deldava faili nimi
boolean opened = false;
Kas fail on avatud
boolean changed = false;
Kas faili on muudetud
boolean newfile = false;
Kas on tegemist loodud failiga
static Stack SchemeStack = new Stack();
static Stack IdStack = new Stack();
static Stack NumStack = new Stack();
enne R-i: FileReader in;
//FileInputStream in;
R Loetav fail
BufferedInputStream in;
RR Loetav fail
BufferedOutputStream out;
PrintWriter out;
static int c;
Textifailist loetud symbol; -1, kui faili lopp
AmFile(SketchyText mn)
konstruktor
main = mn;
? main.frame != null
main.frame.setTitle
(AmFrame.TITLE0 + " - ");
namecounter++;
String name = "";
???
opened = false; changed = false; newfile = false;
?
String readLn()
Loeme yhe rea failist, tagastame String tyypi objekti
String s = "";
loeme char-i kaupa failist, ise kontrollime kas pole faili l6pp v6i reavahetus
!!
c = in.read();
* ;(c != -1) && ((char) c != '\n');
? (c != '\r')
s = s + (char) c;
? (c == '\t')
* int i = 0; i < Default.tabSpaces; i++
c = in.read();
kui juhtus mingi jama, siis saame exceptioni
! (IOException e)
System.err.println("Caught IOException: " + e.getMessage());
<======s
tagastame loetud rea
void write2file (String buf)
Kirjutame etteantud stringi faili
Read text korral tab järele lisatud tühikud maha
String tt = " ";
String tühikud = tt.substring(0, Default.tabSpaces);
StringBuffer sb = new StringBuffer(buf);
int j = 0;
int i = sb.substring(j).indexOf("\t" + tühikud);
? i < 0
<======
sb.replace(i+j, i+j+Default.tabSpaces+1,"\t");
j = i+1;
buf = sb.toString();
out.println(buf);
!!
//out.writeBytes(buf + "\r\n");
out.println(buf);
* int i = 0, n = buf.length(); i < n; i++
out.write(buf.charAt(i));
out.write('\r');
out.write('\n');
! (IOException e)
insertImage NT
public boolean insertImage()
pildi failist lugemine
name = ActionController.getFileNameFromDialog(main.frame, (new File(ActionController.getUntitledName(Utils.gif))), "Insert image", "Insert image", (new AmadeusImageFilter()));
? name == null || name.trim().equals("")
<==========false
<======true
public void readText()
? !ActionController.continueOpen(main.frame)
<======
String title = AmLocale.Read_text();
String fileName = ActionController.getFileName(main.frame, null);
name = ActionController.getFileNameFromDialog(main.frame, (new File(fileName)), title, title, null);
? name == null || name.trim().equals("")
<==========
AutoSave
kasuta recovery fail kui selline on
? ActionController.recover(main.frame, name)
<==========
main.frame.newContents();
main.frame.contents.file = new AmFile(main.frame.contents);
08.10.2002
main.frame.contents.file.name = name;
? main.main.branch(0).body.size() > 0
28.07.03
kui ikka haru sisu on; pole nt siis kui enne on tehtud
File + Input java + cancel
main.main.branch(0).removeMember(0);
readTextFile();
public void readTextFile()
Avame tekstifaili ja loeme selle AmSketch-i tyypi objekti
Avame etteantud nimelise faili
!!
enne R-i in = new FileReader(name);
//in = new FileInputStream(name);
R
in = new BufferedInputStream(new FileInputStream(name));
RR
pyyame erindi, kui ei 6nnestunud faili avada
! (IOException e)
System.err.println("Caught IOException: " + e.getMessage());
<==========
main.frame.setTitle(AmFrame.TITLE0 + " - " + name);
Kutsume va"lja meetodi, mis hakkab stringe too"tlema
PrimitiveMember p;
String t;
Branch b = main.frame.contents.main.branch(0);
* int i = 1; ; i++
p = new PrimitiveMember(PrimitiveMember.SIMPLE, new Text());
t = readLn();
eel- ja lo~pu tyh/tab/r maha
p.text.insert(new Row(t, Default.foregroundColor), 0);
p.text.remove(1);
b.insert(p,i);
? (c == -1)
? t.length() == 0
viimasena loeti tühi rida
b.removeMember(b.body.size()-1);
<======
b.removeMember(0);
fail kinni ...
!!
! (IOException e)
System.err.println("Caught IOException: " + e.getMessage());
kui Java ??
AmMenu.setEnabled(Am.mb, "Tools", "Sketchify Java text", true);
<======
public void imports()
? !ActionController.continueOpen(main.frame)
<======
String title = AmLocale.Import();
String fileName = ActionController.getFileName(main.frame, Utils.html);
name = ActionController.getFileNameFromDialog(main.frame, (new File(fileName)), title, title, null);
name == null || name.trim().equals("")
? name == null || name.trim().equals("")
<==========
AutoSave
kasuta recovery fail kui selline on
? ActionController.recover(main.frame, name)
<==========
seni oli veel vana all
Sketch sk = main.main;
sk.head.removeAllElements();
päis tühjaks
harud maha (jääb üks suvaline haru)
? sk.body.size() > 1
sk.removeMember(0);
importsFile();
public boolean importsFile()
Avame etteantud nimelise faili
!!
enne R-i in = new FileReader(name);
//in = new FileInputStream(name);
R
in = new BufferedInputStream(new FileInputStream(name));
RR
pyyame erindi, kui ei 6nnestunud faili avada
! (IOException e)
System.err.println("Caught IOException: " + e.getMessage());
AmDialog d = new AmDialog(main.frame, AmLocale.Open(),
AmDialog.B_OK,
AmLocale.New()
+"\n"+ name);
main.frame.setTitle(AmFrame.TITLE0 + " - " + name);
//main.frame.newContents();
<==========false
? main.frame != null
main.frame.setTitle(AmFrame.TITLE0 + " - " + name);
readLn();
tavaliselt: "This file is generated by Amadeus"
String t = readLn();
teine rida
readExported(t, 999);
? main.frame != null
main.frame.setTitle(AmFrame.TITLE0 + " - " + name);
main.file = this;
<======true
public void importsHelp(int tag)
?? tag
? 0:
main.frame.setTitle(AmFrame.TITLE0 + ". " +
AmLocale.Help() + ". " + AmLocale.Actions());
readExported(Help0.s[1], 0);
<======
? 1:
main.frame.setTitle(AmFrame.TITLE0 + ". " +
AmLocale.Help() + ". " + "LaTeX");
readExported(Help1.s[1], 1);
<======
? 2:
main.frame.setTitle(AmFrame.TITLE0 + ". " +
AmLocale.Help() + ". " + "Html");
readExported(Help2.s[1], 2);
<======
? 3:
main.frame.setTitle(AmFrame.TITLE0 + ". " +
AmLocale.Help() + ". " + AmLocale.Program());
readExported(Help3.s[1], 3);
<======
? 4:
main.frame.setTitle(AmFrame.TITLE0 + ". " +
AmLocale.Help() + ". " + AmLocale.Model());
readExported(Help4.s[1], 4);
<======
? 5:
main.frame.setTitle(AmFrame.TITLE0 + ". " +
AmLocale.Help() + ". " + AmLocale.View());
readExported(Help5.s[1], 5);
<======
? 6:
main.frame.setTitle(AmFrame.TITLE0 + ". " +
AmLocale.Help() + ". " + AmLocale.Base());
readExported(Help6.s[1], 6);
<======
? 7:
main.frame.setTitle(AmFrame.TITLE0 + ". " +
AmLocale.Help() + ". " + AmLocale.Macros());
readExported(Help7.s[1], 7);
<======
? 8:
main.frame.setTitle(AmFrame.TITLE0 + ". " +
AmLocale.Help() + ". " + AmLocale.Project());
readExported(Help8.s[1], 8);
<======
ebaõnnestult omistatud vaated
JK 26.01.06
static boolean[] failedView = new boolean[View.N];
vastaval kohal on tunnus, kas selle vaate omistamine juba ebaõnnestus
static void failedViewInit()
* int i = 0; i < failedView.length ; i++
static boolean failedViewIsIn(byte view)
kontrollib; kui ei olnud, paneb true
int i = (int)view;
? failedView[i]
<======true
oli juba
<======false
ei olnud, sai pandud true
private void readExported(String exportTag, int tag)
changed [SG]
failedViewInit();
? (exportTag.compareTo(Sketch2HtmlPlain.TITLE)== 0)
readPlainHtml(tag);
<======
? (exportTag.compareTo(Sketch2Html.TITLE)== 0)
readHtml(tag);
<======
? (exportTag.compareTo(Sketch2XmlPlain.TITLE)== 0)
readPlainXml(tag);
<======
ei oska
AmDialog d = new AmDialog(main.frame, AmLocale.Warning(),
AmDialog.B_OK, AmLocale.Illegal()+
" " + AmLocale.format() + "! "+
AmLocale.Read_text() +".");
main.frame.newContents();
Kui oli seotf fail sketctekstiga, miks nüüd see peab puuduma?
main.frame.contents.file = new AmFile(main.frame.contents);
main.frame.contents.file = this;
readTextFile();
private void readPlainXml(int tag)
sulgeme faili
!!
pyyame erindi, kui ei 6nnestunud faili sulgeda
! (IOException e)
System.err.println("Caught IOException: " + e.getMessage());
teisendame faili plain-HTML väljundformaati:
st. skeemistada name ==> fnimi1
String fnimi1 = Default.tempSketchifyXmlSketchified;
Xml2Sketch.inName = name;
Xml2Sketch.outName = fnimi1;
String viga = Xml2Sketch.xml2sketch();
nimeks: uus - fnimi1
String name_backup = name;
name = fnimi1;
importsFile();
impordime
redutseerime:
name = name_backup;
Sketch sk0 = main.main;
välimine
Branch br0 = sk0.branch(0);
? viga.length() != 0
sk0 sisaldab ainult DTD kohta ja veateadet
br0.removeMember(0);
DTD koht maha
JK 03.05.02
keelata veateate salvestamine (selle faili pähe)
? main.frame instanceof AmProjectFileFrame
main.frame.menuBar.setEnabled(AmLocale.File(),
AmLocale.Save(), false);
<==========
Sketch sk1 = (Sketch)(br0.member(3));
SKETCHY_TEXT
Branch br1 = sk1.branch(0);
Sketch sk2 = (Sketch)(br1.member(0));
SKETCH
sk2.baseLanguage.reduce(sk2);
eemaldame välimised:
sk0.comment = sk2.comment;
välise kommentaariks
sk0.baseLanguage = sk2.baseLanguage;
välise baaskeeleks
//sk0.view = sk2.view;
välise vaateks JK 08.01.06
View.set(sk0, sk2.view.type);
välise vaateks JK 16.02.06
br0.comment = sk2.branch(0).comment;
välise kommentaariks
br0.baseLanguage = sk2.branch(0).baseLanguage;
välise baaskeeleks
//br0.view = sk2.view;
välise vaateks JK 08.01.06
View.set(br0, sk2.branch(0).view.type);
välise vaateks JK 16.02.06
sk2.open();
sk1.open();
br0.removeMember(0);
br0.removeMember(0);
br0.removeMember(0);
eemald. alguse kommentaarid ja thokDTDkoht
sk0.setDefaultTextColorAndFont();
ALGJAVA 12.07.06
readPlainHtml*
LUGEDA PlainHtml ==> tyhja lihtskeemi main.frame.contents.main
olekud:
* static final int
SCHEME_START = 0;
IN_HEAD = 1;
IN_PRIMITIVE_HEAD = 2;
IN_BODY = 3;
IN_PRIMITIVE_MEMBER = 4;
IN_ARROW = 5;
static int rowNo;
loetava rea nr Help(i)-s
private String readLn(int tag)
seda kasutab ka readHtml
loeb rea (ka suurendab rowNo++)
failist, kui tag == 999
nr rowNo klassist Help+tag, vastasel korral
kui loetud viimane rida, siis rowNo = -1
seda kasutab ka readHtml
String res;
??tag
? 0:
res = Help0.s[rowNo++];
? (rowNo >= Help0.s.length - 1)
rowNo = -1;
<======
? 1:
res = Help1.s[rowNo++];
..if
? (rowNo >= Help1.s.length - 1)
rowNo = -1;
<======;
..case
? 2:
res = Help2.s[rowNo++];
..if
? (rowNo >= Help2.s.length - 1)
rowNo = -1;
<======;
..case
? 3:
res = Help3.s[rowNo++];
? (rowNo >= Help3.s.length - 1)
rowNo = -1;
<======
? 4:
res = Help4.s[rowNo++];
? (rowNo >= Help4.s.length - 1)
rowNo = -1;
<======
? 5:
res = Help5.s[rowNo++];
? (rowNo >= Help5.s.length - 1)
rowNo = -1;
<======
? 6:
res = Help6.s[rowNo++];
? (rowNo >= Help6.s.length - 1)
rowNo = -1;
<======
? 7:
res = Help7.s[rowNo++];
? (rowNo >= Help7.s.length - 1)
rowNo = -1;
<======
? 8:
res = Help8.s[rowNo++];
? (rowNo >= Help8.s.length - 1)
rowNo = -1;
<======
? :
== 999
<======res
private void readPlainHtml(int tag)
loeb failist (tag == 999)
vo~i klassist (Help+tag)
eeldab, et tyhi lihtskeem on aknasse juba tehtud,
sinna lisabki (failist) saadava lihtskeemi sisu
tehtava primitiivi jaoks:
byte type = 0;
Text text = null;
rowNo = 2;
la"htetekstis
juba tehtud uus:
Scheme s = main.main;//main.frame.contents.main;
String r;
r = readLn(tag);
? ((r.length() != 7) || (r.charAt(0) != '<') ||
(r.charAt(1) != '!') || (r.charAt(6) != '>'))
failed(rowNo);
setAttributes(s, r);
int state = SCHEME_START;
LOOP:
iga jrgm rea korral
? (rowNo == -1)
<======LOOP;
r = readLn(tag);
int n = r.length();
? (r.indexOf("
skeemikommentaar
??state
? SCHEME_START:
panna skeemikommentaar
s.comment = new Row(r.substring(3,n-4),
Default.commentColor);
s.comment.planSize();
state = IN_HEAD;
<======
? :
<==========LOOP;
<------
? ((n == 4) && (r.indexOf("(r.charAt(3) == '>'))
primitiiv
??state
? IN_HEAD:
type = (byte)(r.charAt(2) - '0');
text = new Text();
state = IN_PRIMITIVE_HEAD;
<======
? IN_BODY:
type = (byte)(r.charAt(2) - '0');
text = new Text();
state = IN_PRIMITIVE_MEMBER;
<======
? :
<==========LOOP
<------
? ((n >= 6) &&
(r.substring(0,6).compareTo(" ") == 0))
teksti 1.rida
??state
? IN_PRIMITIVE_HEAD:
? IN_PRIMITIVE_MEMBER:
text.rows.removeElementAt(0);
text.rows.addElement(
new Row(r.substring(r.indexOf("X")+2),
Default.foregroundColor));
text.plan(0,0);
<======;
? :
<------
? ((n >= 4) &&
(r.substring(0,4).compareTo("
") == 0))
teksti jrk rida
??state
? IN_PRIMITIVE_HEAD:
? IN_PRIMITIVE_MEMBER:
text.rows.addElement(new Row(r.substring(4),
Default.foregroundColor));
text.plan(0,0);
<======
? :
<==========LOOP;
<------
? ((n >= 3) &&
(r.substring(0,3).compareTo("") == 0))
teksti kommentaar
??state
? IN_PRIMITIVE_HEAD:
text.comment = new Row(r.substring(3, n-4),
Default.commentColor);
s.head.addElement(new PrimitiveHead(type, text));
? (s instanceof Sketch)
text.setColor(Default.sketchHeadColor);
<======
text.setColor(Default.branchHeadColor);
state = IN_HEAD;
<======
? IN_PRIMITIVE_MEMBER:
? ((n > 9)
&& (r.charAt(3) == '<')
&& (r.charAt(4) == '!')
&& (r.charAt(8) == '>'))
noole lo~pp
text.comment = new Row(r.substring(9, n-4),
Default.commentColor);
int level = (new Integer(r.substring(5,8)).intValue());
Arrow a = new Arrow(type, level-100);
a.text = text;
s.body.addElement(a);
<======
lihtliikme lo~pp
text.comment = new Row(r.substring(3, n-4),
Default.commentColor);
s.body.addElement(new PrimitiveMember(type, text));
? (type == Primitive.BREAKPOINT)
text.setColor(Default.breakpointColor);
<======
? (type == Primitive.CONDITION)
text.setColor(Default.conditionColor);
noole lo~pp
lihtliikme lo~pp
state = IN_BODY;
<======
? :
<==========LOOP;
<------
? (r.compareTo("") == 0)
lo~petab haru pa"ise
state = IN_BODY;
<------
? (r.compareTo("")==0)
skeemi lo~pp
??state
? IN_HEAD:
? (s instanceof Branch)
failed(rowNo);
no break
? IN_BODY:
? (s.parent == null)
valmis
eemaldada 1. haru
s.body.removeElementAt(0);
<==========LOOP;
s = s.parent;
state = IN_BODY;
<======;
..default
? :
<==========LOOP;
<------
? ((r.length() == 7) && (r.charAt(0) == '<') &&
(r.charAt(1) == '!') && (r.charAt(6) == '>'))
algab jrk skeem
??state
? IN_HEAD:
? IN_BODY:
Scheme sNew;
? (s instanceof Sketch)
sNew = (Branch)(new Branch((byte)0,
new BaseLanguage0()));
sNew.body.removeElementAt(0);
<======
sNew = (Sketch)(new Sketch((byte)0,
new BaseLanguage0()));
setAttributes(sNew, r);
sNew.parent = s;
s.body.addElement(sNew);
s = sNew;
state = SCHEME_START;
<======;
..default
? :
<==========LOOP;
<------
? (tag == 999)
!!
! (IOException e)
System.err.println("Caught IOException: " + e.getMessage());
<======
private void setAttributes(Scheme s, String r)
r on skeemi alguse tunnus html plain tekstis
seab skeemile s:
reast r saadava tyybi, baaskeele, vaate, ikoonitunnuse
byte b = (byte)(r.charAt(2) - '0');
s.type = b;
//b = (byte)(r.charAt(3) - '0');
b = BaseLanguage.char2blConstant(r.charAt(3));
JK 17.02.05
s.baseLanguage = BaseLanguage.newBaseLanguage(b);
byte bb;
JK 04.01.06
char c = r.charAt(4);
? Character.isDigit(c)
bb = (byte)(c - '0');
<======
bb = (byte)(10 + c - 'A');
vt ka Sketch2HtmlPlain:str()
JK 26.01.06:
View v = View.newView(bb, s);
? v != null
s.view = v;
<======
? !failedViewIsIn(bb)
anda hoiatus
View.setLocaleNames();
AmDialog d =
new AmDialog(main.frame,
AmLocale.Warning(),
AmDialog.B_OK,
"! " + AmLocale.View()+"\n " +
View.getViewName(bb) + "==>" +
View.getViewName(View.SKETCHY)+".");
s.view = View.newView(View.SKETCHY, s);
? (r.charAt(5) == '0')
s.icon = false;
<======
private void failed(int i)
System.out.println("AmFile: html plain to scheme failed."+
" Source row no = "+i);
readHtml*
private String decode(String buf)
asendab (suuremad) koodid sss; symboliga
StringBuffer sbuf = new StringBuffer();
StringTokenizer stt = new StringTokenizer(buf, "", true);
String nextt;
String nextt1;
int ccode;
* ;stt.hasMoreTokens();
nextt = stt.nextToken();
? nextt.compareTo("&") != 0
sbuf.append(nextt);
<------
? !stt.hasMoreTokens()
sbuf.append(nextt);
<======
nextt = stt.nextToken();
? nextt.compareTo("#") != 0
sbuf.append(nextt);
<------
algab kood
? !stt.hasMoreTokens()
sbuf.append(nextt);
<======
nextt = stt.nextToken();
? nextt.compareTo(";") == 0
sbuf.append(""+nextt);
<------
!!
ccode = (Integer.valueOf(nextt)).intValue();
! (NumberFormatException e)
<----------
? ccode < 0
ccode < 256
sbuf.append(""+nextt);
<------
? !stt.hasMoreTokens()
sbuf.append(""+nextt);
<======
nextt1 = stt.nextToken();
? nextt1.compareTo(";") != 0
sbuf.append(""+nextt);
sbuf.append(nextt1);
<------
asendada
sbuf.append((char)ccode);
<======sbuf.toString()
private int getInt(String s,int i)
int bb;
JK 04.01.06 vt ka readPlainHtml:setAttributes
char c = s.charAt(i);
? Character.isDigit(c)
bb = (int)(c - '0');
<======
bb = (int)(10 + c - 'A');
vt ka Sketch2HtmlPlain:str()
<======bb
<==========(Character.digit(s.charAt(i),10))
private Arrow getArrow(int tag, byte type,int level)
String str;
Arrow a = new Arrow(type,level);
str = decode(readLn(tag));
* ;!str.startsWith("");
? (str.startsWith(""))
body
a.text.rows.addElement(new Row(str));
? (str.startsWith(""))
comment begins
a.text.comment = new Row(str);
str = decode(readLn(tag));
a.text.rows.removeElementAt(0);
<======(a)
private PrimitiveHead getPrimitiveHead(int tag, byte type,int c)
c=0 - Default.sketchHeadColot
c=1 Default.branchHeadColor
String str;
PrimitiveHead h = new PrimitiveHead(type, new Text());
str = decode(readLn(tag));
* ;!str.startsWith("");
? (str.startsWith(""))
body
? (c==0)
h.text.rows.addElement(new Row(str,Default.sketchHeadColor));
h.text.rows.addElement(new Row(str));
<======
h.text.rows.addElement(new Row(str));
? (str.startsWith(""))
comment begins
str = readLn();
h.text.comment = new Row(str);
str = decode(readLn(tag));
h.text.rows.removeElementAt(0);
<======(h)
private PrimitiveMember getPrimitiveMember(int tag, byte type)
String str;
PrimitiveMember p = new PrimitiveMember(type,new Text());
str = decode(readLn(tag));
* ;!str.startsWith("");
? (str.startsWith(""))
body
??type
? 0:
p.text.rows.addElement(new Row(str));
<======
? 1:
p.text.rows.addElement(new Row(str));
<======
? (str.startsWith(""))
comment begins
p.text.comment = new Row(str);
str = decode(readLn(tag));
p.text.rows.removeElementAt(0);
<======(p)
private BaseLanguage getLanguage(byte bl)
<======BaseLanguage.newBaseLanguage(bl)
private Branch getBranch(int tag, byte type, byte bl, byte view)
String str;
Branch b = new Branch(type,getLanguage(bl));
b.removeMember(0);
int i=0;
int iHead=0;
str = decode(readLn(tag));
* ;!str.startsWith("");
? (str.startsWith("
Sketch sk = new Sketch((byte)0,getLanguage(bl));
b.insert(sk,i);
SchemeStack.push(b);
IdStack.push(str.substring(3,str.length()-1));
NumStack.push(new Integer(i));
i++;
? (str.startsWith("
Sketch begins
Sketch s = getSketch(tag,
(byte)getInt(str,3),(byte) getInt(str,5),(byte)getInt(str,6));
b.insert(s,i);
i++;
? (str.startsWith("
arrow begins
Arrow a = getArrow(tag,
(byte)getInt(str,3),getInt(str,4));
b.body.addElement(a);
i++;
<======
? (str.startsWith("
primitive begins
PrimitiveMember p = getPrimitiveMember(tag,
(byte)getInt(str,3));
b.insert(p,i);
i++;
? (str.startsWith("
head begins
PrimitiveHead h = getPrimitiveHead(tag,
(byte)getInt(str,3),1);
b.head.insertElementAt(h,iHead);
iHead++;
? (str.startsWith(""))
comment begins
b.comment = new Row(str);
str = decode(readLn(tag));
found!
View.set(b,view);
<======(b)
private Sketch getSketch(int tag, byte type, byte bl, byte view)
String str;
Sketch s = new Sketch(type,getLanguage(bl));
int i=0;
int iHead = 0;
str = decode(readLn(tag));
* ;!str.startsWith("");
? (str.startsWith("
Branch b = new Branch(type,getLanguage(bl));
type,bl do not matter
b.removeMember(0);
s.insert(b,i);
SchemeStack.push(s);
IdStack.push(str.substring(3,str.length()-1));
NumStack.push(new Integer(i));
i++;
? (str.startsWith("
branch begins
Branch b = getBranch(tag, (byte)getInt(str,3),(byte) getInt(str,5),(byte) getInt(str,6));
s.insert(b,i);
i++;
? (str.startsWith("
arrow begins
Arrow a = getArrow(tag,
(byte)getInt(str,3),getInt(str,4));
s.body.addElement(a);
i++;
<======
? (str.startsWith("
primitive begins
PrimitiveMember p = getPrimitiveMember(tag,
(byte)getInt(str,3));
s.insert(p,i);
i++;
? (str.startsWith("
head begins
PrimitiveHead h = getPrimitiveHead(tag,
(byte)getInt(str,3),0);
s.head.insertElementAt(h,iHead);
iHead++;
? (str.startsWith(""))
comment begins
s.comment = new Row(str);
str = decode(readLn(tag));
end of while
found!
View.set(s,view);
<======(s)
private void readHtml(int tag)
rowNo = 2;
String str;
String tempStr;
otsime esimese
* ;true;
str = decode(readLn(tag));
? (str.startsWith("
<======
Sketch s=getSketch(tag,
(byte)getInt(str,3),(byte) getInt(str,5),(byte)getInt(str,6));
* ;!SchemeStack.empty();
str = decode(readLn(tag));
? (str.startsWith("
tempStr = str.substring(3,str.length()-1);
int index = IdStack.indexOf(tempStr);
? (index ==-1)
System.out.println("subsketch not found");
<==============
str = decode(readLn(tag));
? (str.startsWith("
sketch
Branch b =(Branch) SchemeStack.elementAt(index);
SchemeStack.removeElementAt(index);
IdStack.removeElementAt(index);
int i = ((Integer )NumStack.elementAt(index)).intValue();
NumStack.removeElementAt(index);
Sketch sk = getSketch(tag,
(byte)getInt(str,3),(byte) getInt(str,5),(byte) getInt(str,6));
sk.icon=true;
b.removeMember(i);
b.insert(sk, i);
<======
branch
Sketch sk =(Sketch) SchemeStack.elementAt(index);
SchemeStack.removeElementAt(index);
IdStack.removeElementAt(index);
int i = ((Integer)NumStack.elementAt(index)).intValue();
NumStack.removeElementAt(index);
Branch br = getBranch(tag,
(byte)getInt(str,3),(byte) getInt(str,5),(byte) getInt(str,6));
br.icon=true;
sk.insert(br, i);
sk.removeMember(i+1);
? main.frame != null
pole kulissitagune skeemtekst
main.frame.newContents(s);
<======
main.main = s;
lihtsalt s ==> skeemteksti
public void writeTextFile (String fname)
Votame vastu 2 parameetrit: Sketchi ja faili nime
skeemi harus on iga rida lihtprimitiiv, yherealise tekstiga
Avame etteantud nimelise faili
!!
out = new BufferedOutputStream(new FileOutputStream(fname, false));
out = new PrintWriter(new FileWriter(fname));
! (IOException e)
e.printStackTrace();
return;
//
!!
out = new PrintWriter(new FileWriter(fname));
! (IOException e)
System.err.println("Caught IOException: " + e.getMessage());
pyyame exceptioni kui ei 6nnestunud faili luua
Branch b = main.main.branch(0);
* int i = 0; i < b.body.size(); i++
write2file(((PrimitiveMember)(b.member(i))).text.row(0).toString());
out.close();
!!
out.flush();
out.close();
! (IOException e)
Javadoc
* Programmist väljumine ja faili salvestamise vajaduse kontrollimine
static boolean onOlemasKaust(String kaustatee)
Kasutavad: Default.setProperties jt ...
1.12.2005
<======(new File(kaustatee)).isDirectory()
static boolean onOlemasFail(String failitee)
Kasutavad: Default.setProperties jt ...
1.12.2005
<======(new File(failitee)).isFile()
public static boolean onOlemasURLfail(String kust)
..try
!!
URL url = new URL ( kust ) ;
url . openStream ( );
..catch
! (MalformedURLException mue)
URL c'tor
System . out . println ( "AmFile:onOlemasURLfile: " + kust + " is an invalid URL: " + mue ) ;
<==========false
..catch
! (IOException ioe)
//System . out . println ( "AmFile:onOlemasURLfile: " + "IOException: " + ioe ) ;
<==========false
<======true
static int kustutadaFail(String failitee)
File fail = new File(failitee);
? !fail.exists()
<======2
faili ei ole
<======1
ei saanud kustutada (nt !access)
<======0
kustutatud
public static boolean kustutadaKaust(File kaust)
<======false
ei saanud kustutada (ei ole kaust)
String kaustaNimi = kaust.getPath();
File[] loend = kaust.listFiles();
kaustas kust olevate failide loend
* int i = 0; i < loend.length; i++
? loend[i].isFile()
kustutadaFail( loend[i].getPath());
<------
? !loend[i].isDirectory()
<==========false
ei saanud kustutada (alam ei ole fail ega kaust)
loend[i] on alamkaust
kustutadaKaust(loend[i]);
<======kaust.delete()
public static boolean kopeerida(String kust, String kuhu)
(NT)
File inFile=new File(kust);
File outFile=new File(kuhu);
? inFile.exists()
faili kopeerimine
!!
BufferedReader bufRdr = new BufferedReader(new FileReader(inFile));
BufferedWriter bufWrtr = new BufferedWriter(new FileWriter(outFile));
String line = null;
* ;((line = bufRdr.readLine()) != null);
bufWrtr.write(line);
//bufWrtr.newLine();
bufWrtr.write("\n");
bufRdr.close();
bufWrtr.close();
! (IOException e)
<==========false
<======true
System.out.println("AmFile:kopeerida:Problem with file("+kust+") copying");
<======false
public static boolean kopeerida(File kust, File kuhu)
kas
faili "kust" sisu ==> uueks failiks "kuhu"
või
kausta "kust" sisu ==> kausta "kuhu" sisuks
sel korral kaustad "kust" ja "kuhu" juba eksisteerivad
baidikaupa
? kust.isFile()
fail ==> fail
!!
BufferedInputStream sfail = new BufferedInputStream(new FileInputStream(kust));
RR
BufferedOutputStream vfail = new BufferedOutputStream(new FileOutputStream(kuhu));
RR
int c;
* ; (c = sfail.read()) != -1;
sfail.close();
vfail.close();
! (IOException e)
System.out.println("AmFile.kopeerida baidid" + e );
<==============false
<==========true
? kust.isDirectory() && kuhu.isDirectory()
String er = Default.er;
//String kustDirNimi = kust.getName();
String kuhuDirNimi = kuhu.getPath();
kauta "kust" sisu ==> kausta "kuhu" sisuks
File[] loend = kust.listFiles();
kaustas kust olevate failide loend
!!
* int i = 0; i < loend.length; i++
String nameSource = loend[i].getName();
kopeeritava nimi
? loend[i].isFile()
File targetFile = new File(kuhuDirNimi + er + nameSource);
targetFile.createNewFile();
uus, kuhu kopeerida
kopeerida(loend[i], targetFile);
<------
? loend[i].isDirectory()
loend[i] on alamkaust
File targetDir = new File(kuhu + er + nameSource);
targetDir.mkdir();
kopeerida(loend[i], targetDir );
! (IOException e)
System.out.println("AmFile:kopeerida " + e );
<==============false
<==========true
<======false
ei ole mõlemad sama tüüpi
public static boolean kopeeridaURLst(String kust, String kuhu)
Marty Hall void main
// A pure 1.1 variation of a utility that appears in
// Core Web Programming from Prentice Hall Publishers.
// May be freely used or adapted.
// 1998 Marty Hall, http://www.apl.jhu.edu/~hall/java/.
..try
!!
URL url = new URL ( kust ) ;
BufferedReader in =
new BufferedReader (
new InputStreamReader ( url . openStream ( ) ) ) ;
PrintWriter vfail =
new PrintWriter(new FileWriter(kuhu),true);
String line ;
..while
* ; ( line = in . readLine ( ) ) != null ;
? line.length() > 0
muidu topib tühjad read vahele
//System . out . println ( "> " + line + "<" ) ;
vfail.println( line) ;
in . close ( ) ;
..catch
! (MalformedURLException mue)
URL c'tor
System . out . println ( "AmFile:kopeeridaURLst: " + kust + " is an invalid URL: " + mue ) ;
<==========false
..catch
! (IOException ioe)
Stream constructors
System . out . println ( "AmFile:kopeeridaURLst: " + "IOException: " + ioe ) ;
<==========false
<======true
public static boolean kopeeridaURLstBaidid(String kust, String kuhu)
Marty Hall void main
// A pure 1.1 variation of a utility that appears in
// Core Web Programming from Prentice Hall Publishers.
// May be freely used or adapted.
// 1998 Marty Hall, http://www.apl.jhu.edu/~hall/java/.
..try
!!
URL url = new URL ( kust ) ;
InputStream ips = (url.openStream());
FileOutputStream vfail = new FileOutputStream(kuhu);
int c;
? (c = ips.read()) == -1
<======
ips. close ( ) ;
vfail. close ( ) ;
..catch
! (MalformedURLException mue)
URL c'tor
System . out . println ( "AmFile:kopeeridaURLstBaidid: " + kust + " is an invalid URL: " + mue ) ;
<==========false
..catch
! (IOException ioe)
Stream constructors
System . out . println ( "AmFile:kopeeridaURLst: " + "IOException: " + ioe ) ;
<==========false
<======true
public static Vector lugedaReadURLst(String kust)
loeb trimmitud read vektori elementideks
tagastab vektori või (vea korral) null
Vector v = new Vector();
Marty Hall void main
// A pure 1.1 variation of a utility that appears in
// Core Web Programming from Prentice Hall Publishers.
// May be freely used or adapted.
// 1998 Marty Hall, http://www.apl.jhu.edu/~hall/java/.
..try
!!
URL url = new URL ( kust ) ;
BufferedReader in =
new BufferedReader (
new InputStreamReader ( url . openStream ( ) ) ) ;
String line ;
..while
* ; ( line = in . readLine ( ) ) != null ;
? line.length() > 0
muidu topib tühjad read vahele
//System . out . println ( "> " + line + "<" ) ;
v.addElement("" + line.trim());
in . close ( ) ;
<==============v
..catch
! (MalformedURLException mue)
URL c'tor
System . out . println ( "AmFile:kopeeridaURLst: " + kust + " is an invalid URL: " + mue ) ;
<==============null
..catch
! (IOException ioe)
Stream constructors
System . out . println ( "AmFile:kopeeridaURLst: " + "IOException: " + ioe ) ;
<==============null
public static boolean teisaldada(File kust, File kuhu)
esialgu ainult faili teisaldamine(?)
boolean OK;
OK = kopeerida(kust, kuhu);
? ! OK
System.out.println("AmFile:teisaldada:ei saanud kopeerida! Tegemata: ");
System.out.println(" AmFile:teisaldada: kust = " + kust.getPath() );
System.out.println(" AmFile:teisaldada: kuhu = " + kuhu.getPath() );
<======false
<======true
System.out.println("AmFile:teisaldada:ei saanud kustutada! Vaid kopeeritud: kust-->kuhu");
System.out.println(" AmFile:teisaldada: kust = " + kust.getPath() );
System.out.println(" AmFile:teisaldada: kuhu = " + kuhu.getPath() );
<======false