From 999c64037fb7251f87bd7b105231b3763e003c07 Mon Sep 17 00:00:00 2001 From: hg Date: Sun, 27 Jul 2014 00:52:28 -0400 Subject: made gui responsive to caret position and show identifier info --- src/cuchaz/enigma/analysis/SourceIndex.java | 30 ++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) (limited to 'src/cuchaz/enigma/analysis/SourceIndex.java') diff --git a/src/cuchaz/enigma/analysis/SourceIndex.java b/src/cuchaz/enigma/analysis/SourceIndex.java index a4b5329..ee92d1e 100644 --- a/src/cuchaz/enigma/analysis/SourceIndex.java +++ b/src/cuchaz/enigma/analysis/SourceIndex.java @@ -19,10 +19,12 @@ import jsyntaxpane.Token; import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; -public class SourceIndex implements Iterable> +import cuchaz.enigma.mapping.Entry; + +public class SourceIndex implements Iterable> { - private BiMap m_entryToToken; - private BiMap m_tokenToEntry; + private BiMap m_entryToToken; + private BiMap m_tokenToEntry; public SourceIndex( ) { @@ -30,12 +32,12 @@ public class SourceIndex implements Iterable> m_tokenToEntry = m_entryToToken.inverse(); } - public void add( Object entry, Token token ) + public void add( Entry entry, Token token ) { m_entryToToken.put( entry, token ); } - public Iterator> iterator( ) + public Iterator> iterator( ) { return m_entryToToken.entrySet().iterator(); } @@ -45,12 +47,26 @@ public class SourceIndex implements Iterable> return m_entryToToken.values(); } - public Object getEntry( Token token ) + public Entry getEntry( Token token ) { return m_tokenToEntry.get( token ); } - public Object getToken( Object entry ) + public Entry getEntry( int pos ) + { + // linear search is fast enough for now + for( Map.Entry entry : this ) + { + Token token = entry.getValue(); + if( pos >= token.start && pos <= token.end() ) + { + return entry.getKey(); + } + } + return null; + } + + public Token getToken( Entry entry ) { return m_entryToToken.get( entry ); } -- cgit v1.2.3