# HG changeset patch # User viric@llimona # Date 1169057666 -3600 # Node ID 3932322b7d8313ca66618add9be12465f4f243b1 # Parent 27ba8edb34371e1a14a41f7b586b0fee231c0b74 Half-commit. Not finished. diff -r 27ba8edb3437 -r 3932322b7d83 README --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README Wed Jan 17 19:14:26 2007 +0100 @@ -0,0 +1,7 @@ +Mi laciĝis daŭrigi la skribadon de kodo. + +Mankas ĉi voje: +- Reskribi Tempo.java por ke ĝi enhavu ĉiujn datumojn de trafa trajno. +- Ligi HoraroTransportan al Trajno. +- Ligi Trajnon al nova Tempo. +- Ligi iel la liston de TimeList. diff -r 27ba8edb3437 -r 3932322b7d83 src/horaris/File2Horaro.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/horaris/File2Horaro.java Wed Jan 17 19:14:26 2007 +0100 @@ -0,0 +1,53 @@ +package horaris; + +import javax.microedition.midlet.MIDlet; + +import ogdl.Graph; +import ogdl.Ogdl2Graph; +import ogdl.OgdlParser; +import java.io.InputStream; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.io.InputStreamReader; +import java.lang.Class; + +public class File2Horaro +{ + public static Horaro load(String filename, MIDlet main) + { + /* Open file */ + InputStream is = main.getClass().getResourceAsStream(filename); + if (is == null) + { + System.err.println("Resource "+ filename + + " not found"); + return null; + } + InputStreamReader in; + try { + in = new InputStreamReader(is, + "UTF-8"); + } catch (UnsupportedEncodingException e) { + System.err.println("Enconding error " + e); + return null; + } + + Horaro horaroevents = new Horaro(); + try { + OgdlParser parser = new OgdlParser(in, horaroevents); + parser.parse(); + } catch (Exception e) { + System.err.println("Exception parsing." + e.getMessage()); + } + + + try { + in.close(); + } catch (IOException e) + { + System.err.println("Exception closing is"); + } + + return horaroevents; + } +} diff -r 27ba8edb3437 -r 3932322b7d83 src/horaris/Horaro.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/horaris/Horaro.java Wed Jan 17 19:14:26 2007 +0100 @@ -0,0 +1,94 @@ +package horaris; + +import ogdl.OgdlParser; +import ogdl.parser.*; +import java.util.Vector; +import java.util.Hashtable; + +public class Horaro extends ParserHandlerBase +{ + private final int S_RADIKO = 0; + private final int S_TAGOJ = 1; + private final int S_ENTAGO = 2; + private final int S_LOKOJ = 3; + private final int S_SENCOJ = 4; + private final int S_FINO = 5; + public Vector tagoj; + public int defaulttago = 0; + public Vector lokoj; + public Vector sencoj; + public Hashtable sencolokoj; + private int state; + private int nivelo; + + public Horaro() + { + tagoj = new Vector(); + lokoj = new Vector(); + sencoj = new Vector(); + } + + private void addTago(String s) + { + tagoj.addElement(s); + } + + private void addLoko(String s) + { + lokoj.addElement(s); + } + + private void addSenco(String s) + { + sencoj.addElement(s); + } + + private void add(String s) + { + if (nivelo == 0) + { + System.err.println("Nivelo 0: " + s); + if (s.equals("Dies")) + state = S_TAGOJ; + else if (s.equals("Sentits")) + state = S_SENCOJ; + else if (s.equals("Llocs")) + state = S_LOKOJ; + else if (s.equals("Comboi")) + state = S_FINO; + } else if (nivelo == 1) + { + System.err.println("Nivelo 1: " + s); + switch(state) + { + case S_TAGOJ: + addTago(s); + break; + case S_LOKOJ: + addLoko(s); + break; + case S_SENCOJ: + addSenco(s); + break; + } + } else if (nivelo == 2) { + System.err.println("Nivelo 2"); + } + + } + + public boolean event(int speco, int level, String s) + { + if (speco != OgdlParser.CONTENT) + return true; + + if (s == null) return true; + + nivelo = level; + add(s); + if (state == S_FINO) + return false; + else + return true; + } +} diff -r 27ba8edb3437 -r 3932322b7d83 src/horaris/HoraroTransporta.java --- a/src/horaris/HoraroTransporta.java Sun Jan 14 20:27:03 2007 +0100 +++ b/src/horaris/HoraroTransporta.java Wed Jan 17 19:14:26 2007 +0100 @@ -10,11 +10,7 @@ public class HoraroTransporta implements CommandListener, ItemStateListener, Ekrano { - private Graph radiko; - private Graph tagoj; - private Graph direktoj; - private Graph lokoj; - private Graph sencoj; + private Horaro h; private Form myform; private ChoiceGroup ftagoj; @@ -33,15 +29,11 @@ private Hashtable inforezulto; - public HoraroTransporta(Graph _radiko, Ekrano _last) throws Exception + public HoraroTransporta(Horaro _h, Ekrano _last) throws Exception { - radiko = _radiko; + h = _h; last = _last; - tagoj = radiko.getNode("Dies"); - lokoj = radiko.getNode("Llocs"); - sencoj = radiko.getNode("Sentits"); - myform = new Form("Cerca"); /* Items */ @@ -62,7 +54,9 @@ addLokoj(ffino); myform.append(ffino); + /* defaultKomencoFino(); + */ /* Commands */ cmd_sercxi = new Command("Buscar", Command.OK, 0); @@ -83,20 +77,20 @@ private void addTagoj(ChoiceGroup g) { - for (int i=0; i < tagoj.size(); i++) - g.append(tagoj.get(i).getName(), null); + for (int i=0; i < h.tagoj.size(); i++) + g.append((String) h.tagoj.elementAt(i), null); } private void addSencoj(ChoiceGroup g) { - for (int i=0; i < sencoj.size(); i++) - g.append(sencoj.get(i).getName(), null); + for (int i=0; i < h.sencoj.size(); i++) + g.append((String) h.sencoj.elementAt(i), null); } private void addLokoj(ChoiceGroup g) { - for (int i=0; i < lokoj.size(); i++) - g.append(lokoj.get(i).getName(), null); + for (int i=0; i < h.lokoj.size(); i++) + g.append((String) h.lokoj.elementAt(i), null); } private boolean inVector(Vector v, String s) @@ -110,78 +104,78 @@ private void sercxiTempojn(Vector tagoj, String senco, String komenco, String fino) { - temporezulto = new Vector(); - tmpTempoj = new Vector(); - inforezulto = new Hashtable(); - - for (int i=0; i < radiko.size(); i++) - { - if (! radiko.get(i).getName().equals("Comboi")) - continue; - - Graph veturo = radiko.get(i); - Graph gtmp; - boolean bona; - - String elirtempo = null, alventempo = null; - - /* Dies */ - gtmp = veturo.getNode("Dies"); - bona = false; - for(int j=0; j < gtmp.size(); j++) - { - if (inVector(tagoj, gtmp.get(j).getName()) ) - bona = true; - } - if (bona != true) - continue; - - /* Sentits */ - gtmp = veturo.getNode("Sentit"); - bona = false; - for(int j=0; j < gtmp.size(); j++) - { - if (senco.equals(gtmp.get(j).getName())) - bona = true; - } - if (bona != true) - continue; - - /* Komenco kaj Fino */ - gtmp = veturo.getNode("Hores"); - for(int j=0; j < gtmp.size(); j++) - { - String stacio = gtmp.get(j).get(0).getName(); - - if (stacio.equals(komenco)) - { - elirtempo = gtmp.get(j).getName(); - } - else if (stacio.equals(fino)) - { - alventempo = gtmp.get(j).getName(); - } - } - if (elirtempo == null || alventempo == null) - continue; - - /* Krei la informon aldonan */ - gtmp = veturo.getNode("Comentari"); - Vector comments = new Vector(); - if (gtmp != null) - { - for (int j = 0; j < gtmp.size(); j++) - { - comments.addElement(gtmp.get(j).getName()); - } - } - - /* Trovita! */ - addSortedTime(elirtempo, alventempo, comments); - } - - /* Free memory */ - tmpTempoj = null; +// temporezulto = new Vector(); +// tmpTempoj = new Vector(); +// inforezulto = new Hashtable(); +// +// for (int i=0; i < radiko.size(); i++) +// { +// if (! radiko.get(i).getName().equals("Comboi")) +// continue; +// +// Graph veturo = radiko.get(i); +// Graph gtmp; +// boolean bona; +// +// String elirtempo = null, alventempo = null; +// +// /* Dies */ +// gtmp = veturo.getNode("Dies"); +// bona = false; +// for(int j=0; j < gtmp.size(); j++) +// { +// if (inVector(tagoj, gtmp.get(j).getName()) ) +// bona = true; +// } +// if (bona != true) +// continue; +// +// /* Sentits */ +// gtmp = veturo.getNode("Sentit"); +// bona = false; +// for(int j=0; j < gtmp.size(); j++) +// { +// if (senco.equals(gtmp.get(j).getName())) +// bona = true; +// } +// if (bona != true) +// continue; +// +// /* Komenco kaj Fino */ +// gtmp = veturo.getNode("Hores"); +// for(int j=0; j < gtmp.size(); j++) +// { +// String stacio = gtmp.get(j).get(0).getName(); +// +// if (stacio.equals(komenco)) +// { +// elirtempo = gtmp.get(j).getName(); +// } +// else if (stacio.equals(fino)) +// { +// alventempo = gtmp.get(j).getName(); +// } +// } +// if (elirtempo == null || alventempo == null) +// continue; +// +// /* Krei la informon aldonan */ +// gtmp = veturo.getNode("Comentari"); +// Vector comments = new Vector(); +// if (gtmp != null) +// { +// for (int j = 0; j < gtmp.size(); j++) +// { +// comments.addElement(gtmp.get(j).getName()); +// } +// } +// +// /* Trovita! */ +// addSortedTime(elirtempo, alventempo, comments); +// } +// +// /* Free memory */ +// tmpTempoj = null; } private Tempo str2Tempo(String s) @@ -222,6 +216,7 @@ if (c == cmd_sercxi) { + /* Vector tagoj = new Vector(); for (int i = 0; i < ftagoj.size(); i++) { @@ -234,15 +229,20 @@ fkomenco.getString(fkomenco.getSelectedIndex()); String fino = ffino.getString(ffino.getSelectedIndex()); + */ /* Donos rezulton en temporezulto kaj inforezulto */ + /* sercxiTempojn(tagoj, senco, komenco, fino); + */ + /* if (temporezulto.size() > 0) { mytimelist = new TimeList(temporezulto, inforezulto, this); mytimelist.show(); } + */ } else if (c == cmd_malantauxen) { last.show(); @@ -251,15 +251,10 @@ private void defaultTagoj() { - for (int i = 0; i < ftagoj.size(); i++) - { - if (tagoj.getNode(ftagoj.getString(i)).get(0) != null) - ftagoj.setSelectedIndex(i, true); - else - ftagoj.setSelectedIndex(i, false); - } + ftagoj.setSelectedIndex(h.defaulttago, true); } + /* private void defaultKomencoFino() { String elektita; @@ -283,12 +278,15 @@ if (ffino.getString(i).equals(fino.getName())) ffino.setSelectedIndex(i, true); } + */ public void itemStateChanged(Item item) { if (item == fsenco) { + /* defaultKomencoFino(); + */ } } } diff -r 27ba8edb3437 -r 3932322b7d83 src/horaris/MainList.java --- a/src/horaris/MainList.java Sun Jan 14 20:27:03 2007 +0100 +++ b/src/horaris/MainList.java Wed Jan 17 19:14:26 2007 +0100 @@ -81,15 +81,17 @@ private void loadHoraro(String dosiero) { - Graph horaro = new Graph("RootHoraro");; - File2Graph.load("/data/"+dosiero, horaro, main); + Horaro horaro = + File2Horaro.load("/data/"+dosiero, main); + /* int speco = Horaroj.distingi(horaro); + */ /* if (speco == Horaroj.CXEESTA) { newCxeesta(horaro); - } else */ if (speco == Horaroj.TRANSPORTA); + } else if (speco == Horaroj.TRANSPORTA); */ { try { newTransporta(horaro); @@ -101,9 +103,9 @@ } } - private void newTransporta(Graph g) throws Exception + private void newTransporta(Horaro h) throws Exception { - HoraroTransporta horaro = new HoraroTransporta(g, this); + HoraroTransporta horaro = new HoraroTransporta(h, this); } /* diff -r 27ba8edb3437 -r 3932322b7d83 src/horaris/Tempo.java --- a/src/horaris/Tempo.java Sun Jan 14 20:27:03 2007 +0100 +++ b/src/horaris/Tempo.java Wed Jan 17 19:14:26 2007 +0100 @@ -6,7 +6,8 @@ public int horoj; public int minutoj; - public Tempo(String _s) + public Tempo(String _komenco, String _fino, String _komencoloko, + String _finoloko, Vector komentoj) { fromStr(_s); } diff -r 27ba8edb3437 -r 3932322b7d83 src/horaris/Trajno.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/horaris/Trajno.java Wed Jan 17 19:14:26 2007 +0100 @@ -0,0 +1,184 @@ +package horaris; + +import ogdl.OgdlParser; +import ogdl.parser.*; +import java.util.Vector; +import java.util.Hashtable; + +class Trajnoj extends ParserHandlerBase +{ + private final int S_RADIKO = 0; + private final int S_TRAJNO = 1; + private final int S_TAGOJ = 2; + private final int S_ENTAGO = 3; + private final int S_HOROJ = 4; + private final int S_LOKOJ = 5; + private final int S_SENCOJ = 6; + private final int S_KOMENTOJ = 7; + private final int S_FINO = 8; + public Vector tempoj; + public Hashtable komentoj; + private int stato; + + private Vector sercxotagoj; + private String sercxosenco; + private String sercxokomenco; + private String sercxofino; + + private Tempo komencotempo; + private Tempo finotempo; + private String tmptempo; + + private boolean tagobona[]; + private boolean sencobona; + private boolean komencobona; + private boolean finobona; + + private Vector rezultoj; + + public Trajnoj(Vector tagoj, String senco, String komenco, String fino) + { + sercxotagoj = tagoj; + sercxosenco = senco; + sercxokomenco = komenco; + sercxofino = fino; + tagobona = new boolean[sercxotagoj.size()]; + clearSearch(); + rezultoj = new Vector(); + } + + /** Return true if the result should be noted. */ + private boolean novarezulto() + { + /* Tagoj */ + for (int i=0; i < sercxotagoj.size(); i++) + if (tagobona[i] != true) + return false; + if (komencobona && finobona && sencobona) + { + /* Add the result */ + } + } + + private void clearSearch() + { + for (int i=0; i < sercxotagoj.size(); i++) + tagobona[i] = false; + sencobona = false; + komencobona = false; + finobona = false; + } + + /** Returns the index where found or -1 if not found */ + private int inVector(Vector v, String s) + { + for (int i=0; i < v.size(); i++) + if(s.equals((String)v.elementAt(i))) + return i; + return -1; + } + + private void proviTagon(String s) + { + int i; + i = inVector(sercxotagoj, s); + if( i >= 0) + tagobona[i] = true; + } + + /** Returns if the place matches komencon aux finon */ + private boolean proviLokon(String s) + { + if (komencobona == false) + { + if (s.equals(sercxosenco)) + { + komencobona = true; + komencotempo = new Tempo(tmptempo); + return true; + } + } else if (komencobona == true && finobona == false) + { + if (s.equals(sercxosenco)) + { + finobona = true; + finotempo = new Tempo(tmptempo); + return true; + } + } + return false; + } + + private void proviSencon(String s) + { + if (sencobona == false) + { + if (s.equals(sercxosenco)) + sencobona = true; + } + } + + private void add(int nivelo, String s) + { + if (nivelo == 0) + { + System.err.println("Nivelo 0: " + s); + if (s.equals("Comboi")) + stato = S_TRAJNO; + else + stato = S_RADIKO; + } else if (nivelo == 1) + { + /* S_TRAJNO when set from level 0 to 1 */ + System.err.println("Nivelo 1: " + s); + if (s.equals("Dies")) + stato = S_TAGOJ; + else if (s.equals("Sentit")) + stato = S_SENCOJ; + else if (s.equals("Hores")) + stato = S_HOROJ; + else if (s.equals("Comentari")) + stato = S_KOMENTOJ; + } else if (nivelo == 2) { + System.err.println("Nivelo 2: " + s); + switch(stato) + { + case S_TAGOJ: + proviTagon(s); + break; + case S_HOROJ: + /* Konservi tempon */ + tmptempo = s; + break; + case S_SENCOJ: + proviSencon(s); + break; + case S_KOMENTOJ: + /* *** ALDONI KOMENTON */ + break; + } + } else if (nivelo == 3) { + switch(stato) + { + case S_HOROJ: + proviLokon(s); + break; + } + } + + } + + public boolean event(int speco, int level, String s) + { + if (speco != OgdlParser.CONTENT) + return true; + + if (s == null) return true; + + add(level, s); + if (stato == S_FINO) + return false; + else + return true; + } +} diff -r 27ba8edb3437 -r 3932322b7d83 src/ogdl/Ogdl2Graph.java --- a/src/ogdl/Ogdl2Graph.java Sun Jan 14 20:27:03 2007 +0100 +++ b/src/ogdl/Ogdl2Graph.java Wed Jan 17 19:14:26 2007 +0100 @@ -22,12 +22,12 @@ this.g[0] = g; } - public void event(int i, int j, String s) + public boolean event(int i, int j, String s) { - if (i != OgdlBinaryParser.CONTENT) - return; + if (i != OgdlParser.CONTENT) + return true; - if (s == null) return; + if (s == null) return true; edge = s; level = j; @@ -37,14 +37,16 @@ g[level].add(node); level++; g[level] = node; + return true; } - public void event(int i, int j, Object s) + /* + public boolean event(int i, int j, Object s) { - if (i != OgdlBinaryParser.CONTENT && i != OgdlBinaryParser.BINARY) - return; + if (i != OgdlParser.CONTENT && i != OgdlParser.BINARY) + return true; - if (s == null) return; + if (s == null) return true; if (i == OgdlBinaryParser.BINARY) { g[level].setValue(s); @@ -57,5 +59,7 @@ level++; g[level] = node; } + return true; } + */ } diff -r 27ba8edb3437 -r 3932322b7d83 src/ogdl/OgdlParser.java --- a/src/ogdl/OgdlParser.java Sun Jan 14 20:27:03 2007 +0100 +++ b/src/ogdl/OgdlParser.java Wed Jan 17 19:14:26 2007 +0100 @@ -41,6 +41,8 @@ int savedSpaces = 0; boolean savedNewline = false; + boolean continueParsing = true; + private IParserHandler event; /* leaf buffer, for first level string processing: escape sequences */ @@ -259,7 +261,7 @@ public int node() throws IOException { if (block()) { - event.event(CONTENT,level, sb.toString()); + continueParsing = event.event(CONTENT,level, sb.toString()); return -1; } @@ -291,7 +293,7 @@ return 1; if (len != 0) - event.event(CONTENT, level, sb.toString()); + continueParsing = event.event(CONTENT, level, sb.toString()); level++; @@ -331,6 +333,8 @@ while ( (i=node()) > 0) space(); + if (!continueParsing) + return false; if (i > 0) { /* after a block don't eat spaces */ space(); diff -r 27ba8edb3437 -r 3932322b7d83 src/ogdl/parser/IParserHandler.java --- a/src/ogdl/parser/IParserHandler.java Sun Jan 14 20:27:03 2007 +0100 +++ b/src/ogdl/parser/IParserHandler.java Wed Jan 17 19:14:26 2007 +0100 @@ -15,10 +15,10 @@ public interface IParserHandler { - void event(int i); - void event(int i, String s); - void event(int i, int j); - void event(int i, int j, String s); - void event(int i, int j, Object s); - void error(Exception e, int line); + boolean event(int i); + boolean event(int i, String s); + boolean event(int i, int j); + boolean event(int i, int j, String s); + boolean event(int i, int j, Object s); + boolean error(Exception e, int line); } diff -r 27ba8edb3437 -r 3932322b7d83 src/ogdl/parser/ParserHandlerBase.java --- a/src/ogdl/parser/ParserHandlerBase.java Sun Jan 14 20:27:03 2007 +0100 +++ b/src/ogdl/parser/ParserHandlerBase.java Wed Jan 17 19:14:26 2007 +0100 @@ -14,10 +14,10 @@ public class ParserHandlerBase implements IParserHandler { - public void event(int i){} - public void event(int i, int j){} - public void event(int i, String s){} - public void event(int i, int j, String s){} - public void event(int i, int j, Object s){} - public void error(Exception e, int line){} + public boolean event(int i){return true;} + public boolean event(int i, int j){return true;} + public boolean event(int i, String s){return true;} + public boolean event(int i, int j, String s){return true;} + public boolean event(int i, int j, Object s){return true;} + public boolean error(Exception e, int line){return true;} }