Skip to content

Commit

Permalink
Commit Algo modif and Graph by Diego
Browse files Browse the repository at this point in the history
  • Loading branch information
gogus4 committed Nov 27, 2013
1 parent aedd2b4 commit 61d4a28
Show file tree
Hide file tree
Showing 76 changed files with 671 additions and 11 deletions.
Binary file added src/LeftRight.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 26 additions & 9 deletions src/algo/graph/Graph.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void Init(Map<String, Node> node,Node depart)
{
if(!ville.equals(depart.town))
{
node.get(ville).poids = Integer.MAX_VALUE;
node.get(ville).poids = 9999999;
node.get(ville).nodePrecedent = null;
}
}
Expand Down Expand Up @@ -150,6 +150,31 @@ public List<Node> Dijkstra(Map<String, Node> graph,String depart,String fin,Stri
{
graph.get(n1.town).getRelations().get(i).getEndNode().poids = graph.get(n1.town).getRelations().get(i).getStartNode().poids + Poids(graph.get(n1.town).getRelations().get(i).getStartNode(),graph.get(n1.town).getRelations().get(i).getEndNode());
graph.get(n1.town).getRelations().get(i).getEndNode().nodePrecedent = graph.get(n1.town).getRelations().get(i).getStartNode();

try
{
graph.get(n1.town).getRelations().get(i).getEndNode().ligne = graph.get(n1.town).getRelations().get(i).getmodeTransport();

// System.out.println("Ligne : " + graph.get(n1.town).getRelations().get(i).getLigneTransport());
if(graph.get(n1.town).getRelations().get(i).getStartNode().ligne != null)
{
if(!graph.get(n1.town).getRelations().get(i).getStartNode().ligne.equalsIgnoreCase(graph.get(n1.town).getRelations().get(i).getEndNode().ligne))
{
/*if(graph.get(n1.town).getRelations().get(i).getEndNode().town.equals("Chatelet"))
{
System.out.println("Start node : " + graph.get(n1.town).getRelations().get(i).getStartNode().town);
System.out.println("End node : " + graph.get(n1.town).getRelations().get(i).getEndNode().town);
}*/

// graph.get(n1.town).getRelations().get(i).setWeight(graph.get(n1.town).getRelations().get(i).getWeight() + 5);
graph.get(n1.town).getRelations().get(i).getEndNode().poids += 5;
}
}
}
catch(Exception E)
{

}
}
}
}
Expand Down Expand Up @@ -223,15 +248,7 @@ public static void main(String[] args)
Parse parse = new Parse();
Graph g = parse.getGraph();

<<<<<<< HEAD
<<<<<<< HEAD
List<Node> chemin = g.Dijkstra(g.node,"Châtelet","Solférino","TOUS");
=======
List<Node> chemin = g.Dijkstra(g.node,"La Courneuve-8-Mai-1945","Buttes-Chaumont","TOUS");
>>>>>>> 5a6f5ab703b3e68888ee7120e81a8aad33605e90
=======
List<Node> chemin = g.Dijkstra(g.node,"La Courneuve-Aubervilliers","La Courneuve-8-Mai-1945","TOUS");
>>>>>>> 42afe4225fabdef69d970b3de30d750eff9e8b34

String ligne = "";
for(int i = chemin.size()-1 ; i >= 0 ; i--)
Expand Down
95 changes: 95 additions & 0 deletions src/algo/graph/graphic/AutoCompleteDocument.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package algo.graph.graphic;


import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.JTextComponent;
import javax.swing.text.PlainDocument;

import algo.graph.parsing.Stops;

public class AutoCompleteDocument extends PlainDocument
{
private static final long serialVersionUID = 1L;

private List<String> dictionary = new ArrayList<String>();

private final JTextComponent _textField;

public AutoCompleteDocument(JTextComponent field, List<Stops> aDictionary)
{
_textField = field;

for(Stops stop : aDictionary)
{
dictionary.add(stop.stop_name);
}
}

public void addDictionaryEntry(String item)
{
dictionary.add(item);
}

@Override
public void insertString(int offs, String str, AttributeSet a)
throws BadLocationException
{
super.insertString(offs, str, a);
String word = autoComplete(getText(0, getLength()));
if (word != null) {
super.insertString(offs + str.length(), word, a);
_textField.setCaretPosition(offs + str.length());
_textField.moveCaretPosition(getLength());
}
}

public String autoComplete(String text) {
for (Iterator<String> i = dictionary.iterator(); i.hasNext();) {
String word = i.next();
if (word.startsWith(text)) {
return word.substring(text.length());
}
}
return null;
}


public static JTextField createAutoCompleteTextField(List<Stops> dictionary)
{
JTextField field = new JTextField(20);
field.setPreferredSize(new Dimension(180, 20));
field.setBorder(BorderFactory.createLineBorder(Color.BLACK));

AutoCompleteDocument doc = new AutoCompleteDocument(field, dictionary);
field.setDocument(doc);
return field;
}

/*public static void main(String[] args)
{
//String[] dict = { "Alef++", "alef++", "sourceForge", "SourceFORGE", "JAVA","JAVA2","PROGRAMMATION", "programmation", "Team" };
JTextField field = AutoCompleteDocument.createAutoCompleteTextField(dict);
JFrame frame = new JFrame("Autocomplete");
frame.setLayout(new FlowLayout());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(new JLabel("Text Field: "));
frame.add(field);
frame.pack();
frame.setVisible(true);
}*/
}

Loading

0 comments on commit 61d4a28

Please sign in to comment.