text
stringlengths
30
1.67M
<s> package annis . gui . media . impl ; import de . hu_berlin . german . korpling . saltnpepper . salt . graph . Edge ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCommon . sDocumentStructure . SSpan ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCommon . sDocumentStructure . SSpanningRelation ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCommon . sDocumentStructure . SToken ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCore . SAnnotation ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCore . SGraph ; import java . util . Collections ; import java . util . LinkedList ; import java . util . List ; import org . eclipse . emf . common . util . EList ; public class TimeHelper { public static double [ ] getOverlappedTime ( SSpan node ) { SGraph graph = node . getSGraph ( ) ; final List < Double > startTimes = new LinkedList < Double > ( ) ; final List < Double > endTimes = new LinkedList < Double > ( ) ; EList < Edge > outEdges = graph . getOutEdges ( node . getSId ( ) ) ; if ( outEdges != null ) { for ( Edge e : outEdges ) { if ( e instanceof SSpanningRelation ) { SToken tok = ( ( SSpanningRelation ) e ) . getSToken ( ) ; SAnnotation anno = tok . getSAnnotation ( "<STR_LIT>" ) ; if ( anno != null ) { String [ ] split = anno . getSValueSTEXT ( ) . split ( "<STR_LIT:->" ) ; if ( split . length == <NUM_LIT:1> ) { startTimes . add ( Double . parseDouble ( split [ <NUM_LIT:0> ] ) ) ; } if ( split . length == <NUM_LIT:2> ) { startTimes . add ( Double . parseDouble ( split [ <NUM_LIT:0> ] ) ) ; endTimes . add ( Double . parseDouble ( split [ <NUM_LIT:1> ] ) ) ; } } } } } if ( startTimes . size ( ) > <NUM_LIT:0> && endTimes . size ( ) > <NUM_LIT:0> ) { return new double [ ] { Collections . min ( startTimes ) , Collections . max ( endTimes ) } ; } else if ( startTimes . size ( ) > <NUM_LIT:0> ) { return new double [ ] { Collections . min ( startTimes ) } ; } return new double [ <NUM_LIT:0> ] ; } } </s>
<s> package annis . gui . media . impl ; import annis . gui . VisualizationToggle ; import annis . gui . media . MediaController ; import annis . gui . media . MediaPlayer ; import annis . visualizers . LoadableVisualizer ; import java . util . HashMap ; import java . util . LinkedList ; import java . util . List ; import java . util . Map ; import java . util . TreeMap ; import java . util . concurrent . locks . ReadWriteLock ; import java . util . concurrent . locks . ReentrantReadWriteLock ; public class MediaControllerImpl implements MediaController { private Map < String , List < MediaPlayer > > mediaPlayers ; private Map < String , MediaPlayer > lastUsedPlayer ; private Map < MediaPlayer , VisualizationToggle > visToggle ; private ReadWriteLock lock = new ReentrantReadWriteLock ( ) ; public MediaControllerImpl ( ) { lock . writeLock ( ) . lock ( ) ; try { mediaPlayers = new TreeMap < String , List < MediaPlayer > > ( ) ; lastUsedPlayer = new TreeMap < String , MediaPlayer > ( ) ; visToggle = new HashMap < MediaPlayer , VisualizationToggle > ( ) ; } finally { lock . writeLock ( ) . unlock ( ) ; } } private MediaPlayer getPlayerForResult ( String resultID ) { List < MediaPlayer > allPlayers = mediaPlayers . get ( resultID ) ; if ( allPlayers != null && allPlayers . size ( ) > <NUM_LIT:0> ) { MediaPlayer lastPlayer = lastUsedPlayer . get ( resultID ) ; MediaPlayer player ; if ( lastPlayer == null ) { player = allPlayers . get ( <NUM_LIT:0> ) ; } else { player = lastPlayer ; } return player ; } return null ; } @ Override public void play ( String resultID , final double startTime ) { lock . readLock ( ) . lock ( ) ; try { final MediaPlayer player = getPlayerForResult ( resultID ) ; if ( player != null ) { closeOtherPlayers ( player ) ; VisualizationToggle t = visToggle . get ( player ) ; if ( t != null ) { t . toggleVisualizer ( true , new LoadableVisualizer . Callback ( ) { @ Override public void visualizerLoaded ( LoadableVisualizer origin ) { player . play ( startTime ) ; } } ) ; } } } finally { lock . readLock ( ) . unlock ( ) ; } } @ Override public void play ( String resultID , final double startTime , final double endTime ) { lock . readLock ( ) . lock ( ) ; try { final MediaPlayer player = getPlayerForResult ( resultID ) ; if ( player != null ) { closeOtherPlayers ( player ) ; VisualizationToggle t = visToggle . get ( player ) ; if ( t != null ) { t . toggleVisualizer ( true , new LoadableVisualizer . Callback ( ) { @ Override public void visualizerLoaded ( LoadableVisualizer origin ) { player . play ( startTime , endTime ) ; } } ) ; } } } finally { lock . readLock ( ) . unlock ( ) ; } } public void closeOtherPlayers ( MediaPlayer doNotCloseThisOne ) { for ( List < MediaPlayer > playersForID : mediaPlayers . values ( ) ) { for ( MediaPlayer player : playersForID ) { if ( player != doNotCloseThisOne ) { VisualizationToggle t = visToggle . get ( player ) ; if ( t != null ) { t . toggleVisualizer ( false , null ) ; } } } } } @ Override public void pauseAll ( ) { lock . readLock ( ) . lock ( ) ; try { for ( List < MediaPlayer > playersForID : mediaPlayers . values ( ) ) { for ( MediaPlayer player : playersForID ) { player . pause ( ) ; } } } finally { lock . readLock ( ) . unlock ( ) ; } } @ Override public void addMediaPlayer ( MediaPlayer player , String resultID , VisualizationToggle toggle ) { if ( resultID == null ) { return ; } lock . writeLock ( ) . lock ( ) ; try { if ( mediaPlayers . get ( resultID ) == null ) { mediaPlayers . put ( resultID , new LinkedList < MediaPlayer > ( ) ) ; } List < MediaPlayer > playerList = mediaPlayers . get ( resultID ) ; playerList . add ( player ) ; visToggle . put ( player , toggle ) ; } finally { lock . writeLock ( ) . unlock ( ) ; } } @ Override public void clearMediaPlayers ( ) { lock . writeLock ( ) . lock ( ) ; try { mediaPlayers . clear ( ) ; visToggle . clear ( ) ; lastUsedPlayer . clear ( ) ; } finally { lock . writeLock ( ) . unlock ( ) ; } } } </s>
<s> package annis . gui . media . impl ; import annis . gui . media . MediaController ; import annis . gui . media . MediaControllerFactory ; import annis . gui . media . MediaControllerHolder ; import net . xeoh . plugins . base . annotations . PluginImplementation ; @ PluginImplementation public class MediaControllerFactoryImpl implements MediaControllerFactory { @ Override public MediaController getOrCreate ( MediaControllerHolder holder ) { if ( holder == null ) { return new MediaControllerImpl ( ) ; } else if ( holder . getMediaController ( ) == null ) { holder . setMediaController ( new MediaControllerImpl ( ) ) ; } return holder . getMediaController ( ) ; } } </s>
<s> package annis . gui . resultview ; import annis . service . objects . Match ; import annis . gui . Helper ; import annis . security . AnnisUser ; import annis . security . IllegalCorpusAccessException ; import com . sun . jersey . api . client . GenericType ; import com . sun . jersey . api . client . UniformInterfaceException ; import com . sun . jersey . api . client . WebResource ; import com . vaadin . Application ; import java . io . Serializable ; import java . util . LinkedList ; import java . util . List ; import java . util . Set ; import java . util . TreeSet ; import org . apache . commons . lang3 . StringUtils ; import org . slf4j . LoggerFactory ; public class AnnisResultQuery implements Serializable { private static final org . slf4j . Logger log = LoggerFactory . getLogger ( AnnisResultQuery . class ) ; private Set < String > corpora ; private String aql ; private Application app ; public AnnisResultQuery ( Set < String > corpora , String aql , Application app ) { this . corpora = corpora ; this . aql = aql ; this . app = app ; } public List < Match > loadBeans ( int startIndex , int count , AnnisUser user ) throws IllegalCorpusAccessException { Set < String > filteredCorpora = new TreeSet < String > ( corpora ) ; if ( user != null ) { filteredCorpora . retainAll ( user . getCorpusNameList ( ) ) ; } if ( filteredCorpora . size ( ) != corpora . size ( ) ) { throw new IllegalCorpusAccessException ( "<STR_LIT>" ) ; } List < Match > result = new LinkedList < Match > ( ) ; if ( app != null ) { WebResource annisResource = Helper . getAnnisWebResource ( app ) ; try { annisResource = annisResource . path ( "<STR_LIT>" ) . path ( "<STR_LIT>" ) . queryParam ( "<STR_LIT:q>" , aql ) . queryParam ( "<STR_LIT>" , "<STR_LIT>" + startIndex ) . queryParam ( "<STR_LIT>" , "<STR_LIT>" + count ) . queryParam ( "<STR_LIT>" , StringUtils . join ( corpora , "<STR_LIT:U+002C>" ) ) ; result = annisResource . get ( new GenericType < List < Match > > ( ) { } ) ; } catch ( UniformInterfaceException ex ) { log . error ( ex . getResponse ( ) . getEntity ( String . class ) , ex ) ; } } return result ; } } </s>
<s> package annis . gui . resultview ; import annis . gui . Helper ; import annis . gui . PluginSystem ; import annis . gui . VisualizationToggle ; import annis . gui . media . MediaControllerFactory ; import annis . gui . media . MediaControllerHolder ; import annis . gui . media . MediaPlayer ; import annis . gui . visualizers . VisualizerInput ; import annis . gui . visualizers . VisualizerPlugin ; import annis . resolver . ResolverEntry ; import annis . visualizers . LoadableVisualizer ; import com . sun . jersey . api . client . WebResource ; import com . vaadin . Application ; import com . vaadin . terminal . ApplicationResource ; import com . vaadin . terminal . StreamResource ; import com . vaadin . terminal . ThemeResource ; import com . vaadin . ui . Button ; import com . vaadin . ui . Button . ClickEvent ; import com . vaadin . ui . Component ; import com . vaadin . ui . CustomLayout ; import com . vaadin . ui . Window ; import com . vaadin . ui . themes . ChameleonTheme ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCommon . SaltProject ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCommon . sCorpusStructure . SDocument ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCommon . sDocumentStructure . STextualDS ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCommon . sDocumentStructure . SToken ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCore . SNode ; import java . io . ByteArrayInputStream ; import java . io . ByteArrayOutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . net . URLEncoder ; import java . util . List ; import java . util . Map ; import java . util . Random ; import java . util . Set ; import org . slf4j . Logger ; import org . slf4j . LoggerFactory ; public class VisualizerPanel extends CustomLayout implements Button . ClickListener , VisualizationToggle { private final Logger log = LoggerFactory . getLogger ( VisualizerPanel . class ) ; public static final ThemeResource ICON_COLLAPSE = new ThemeResource ( "<STR_LIT>" ) ; public static final ThemeResource ICON_EXPAND = new ThemeResource ( "<STR_LIT>" ) ; private ApplicationResource resource = null ; private Component vis ; private SDocument result ; private PluginSystem ps ; private ResolverEntry entry ; private Random rand = new Random ( ) ; private Map < SNode , Long > markedAndCovered ; private List < SToken > token ; private Map < String , String > markersExact ; private Map < String , String > markersCovered ; private Button btEntry ; private String htmlID ; private String resultID ; ; private VisualizerPlugin visPlugin ; private Set < String > visibleTokenAnnos ; private STextualDS text ; private String segmentationName ; private boolean showTextID ; private final String PERMANENT = "<STR_LIT>" ; private final String ISVISIBLE = "<STR_LIT>" ; private final String HIDDEN = "<STR_LIT>" ; private final String PRELOADED = "<STR_LIT>" ; private final static String htmlTemplate = "<STR_LIT>" + "<STR_LIT>" ; public VisualizerPanel ( final ResolverEntry entry , SDocument result , List < SToken > token , Set < String > visibleTokenAnnos , Map < SNode , Long > markedAndCovered , @ Deprecated Map < String , String > markedAndCoveredMap , @ Deprecated Map < String , String > markedExactMap , STextualDS text , String htmlID , String resultID , SingleResultPanel parent , String segmentationName , PluginSystem ps , boolean showTextID ) throws IOException { super ( new ByteArrayInputStream ( htmlTemplate . replace ( "<STR_LIT>" , htmlID ) . getBytes ( "<STR_LIT:UTF-8>" ) ) ) ; visPlugin = ps . getVisualizer ( entry . getVisType ( ) ) ; this . ps = ps ; this . entry = entry ; this . markersExact = markedExactMap ; this . markersCovered = markedAndCoveredMap ; this . result = result ; this . token = token ; this . visibleTokenAnnos = visibleTokenAnnos ; this . markedAndCovered = markedAndCovered ; this . text = text ; this . segmentationName = segmentationName ; this . htmlID = htmlID ; this . resultID = resultID ; this . showTextID = showTextID ; this . addStyleName ( ChameleonTheme . PANEL_BORDERLESS ) ; this . setWidth ( "<STR_LIT>" ) ; } @ Override public void attach ( ) { if ( visPlugin == null ) { entry . setVisType ( PluginSystem . DEFAULT_VISUALIZER ) ; visPlugin = ps . getVisualizer ( entry . getVisType ( ) ) ; } if ( entry != null ) { if ( HIDDEN . equalsIgnoreCase ( entry . getVisibility ( ) ) ) { btEntry = new Button ( entry . getDisplayName ( ) + ( showTextID ? "<STR_LIT:U+0020(>" + text . getSName ( ) + "<STR_LIT:)>" : "<STR_LIT>" ) ) ; btEntry . setIcon ( ICON_EXPAND ) ; btEntry . setStyleName ( ChameleonTheme . BUTTON_BORDERLESS + "<STR_LIT:U+0020>" + ChameleonTheme . BUTTON_SMALL ) ; btEntry . addListener ( ( Button . ClickListener ) this ) ; addComponent ( btEntry , "<STR_LIT>" ) ; } else { if ( ISVISIBLE . equalsIgnoreCase ( entry . getVisibility ( ) ) || PRELOADED . equalsIgnoreCase ( entry . getVisibility ( ) ) ) { btEntry = new Button ( entry . getDisplayName ( ) + ( showTextID ? "<STR_LIT:U+0020(>" + text . getSName ( ) + "<STR_LIT:)>" : "<STR_LIT>" ) ) ; btEntry . setIcon ( ICON_COLLAPSE ) ; btEntry . setStyleName ( ChameleonTheme . BUTTON_BORDERLESS + "<STR_LIT:U+0020>" + ChameleonTheme . BUTTON_SMALL ) ; btEntry . addListener ( ( Button . ClickListener ) this ) ; addComponent ( btEntry , "<STR_LIT>" ) ; } try { vis = createComponent ( ) ; vis . setVisible ( true ) ; addComponent ( vis , "<STR_LIT>" ) ; } catch ( Exception ex ) { getWindow ( ) . showNotification ( "<STR_LIT>" + visPlugin . getShortName ( ) , ex . toString ( ) , Window . Notification . TYPE_TRAY_NOTIFICATION ) ; log . error ( "<STR_LIT>" + visPlugin . getShortName ( ) , ex ) ; } if ( PRELOADED . equalsIgnoreCase ( entry . getVisibility ( ) ) ) { btEntry . setIcon ( ICON_EXPAND ) ; vis . setVisible ( false ) ; } } } } private Component createComponent ( ) { Application application = getApplication ( ) ; VisualizerInput input = createInput ( ) ; Component c = this . visPlugin . createComponent ( input , application ) ; c . setVisible ( false ) ; return c ; } private VisualizerInput createInput ( ) { VisualizerInput input = new VisualizerInput ( ) ; input . setAnnisWebServiceURL ( getApplication ( ) . getProperty ( "<STR_LIT>" ) ) ; input . setContextPath ( Helper . getContext ( getApplication ( ) ) ) ; input . setDotPath ( getApplication ( ) . getProperty ( "<STR_LIT>" ) ) ; input . setId ( resultID ) ; input . setMarkableExactMap ( markersExact ) ; input . setMarkableMap ( markersCovered ) ; input . setMarkedAndCovered ( markedAndCovered ) ; input . setVisPanel ( this ) ; input . setResult ( result ) ; input . setToken ( token ) ; input . setVisibleTokenAnnos ( visibleTokenAnnos ) ; input . setText ( text ) ; input . setSegmentationName ( segmentationName ) ; if ( entry != null ) { input . setMappings ( entry . getMappings ( ) ) ; input . setNamespace ( entry . getNamespace ( ) ) ; String template = Helper . getContext ( getApplication ( ) ) + "<STR_LIT>" + entry . getVisType ( ) + "<STR_LIT>" ; input . setResourcePathTemplate ( template ) ; } if ( visPlugin . isUsingText ( ) && result . getSDocumentGraph ( ) . getSNodes ( ) . size ( ) > <NUM_LIT:0> ) { SaltProject p = getText ( result . getSCorpusGraph ( ) . getSRootCorpus ( ) . get ( <NUM_LIT:0> ) . getSName ( ) , result . getSName ( ) ) ; input . setDocument ( p . getSCorpusGraphs ( ) . get ( <NUM_LIT:0> ) . getSDocuments ( ) . get ( <NUM_LIT:0> ) ) ; } else { input . setDocument ( result ) ; } return input ; } public void setVisibleTokenAnnosVisible ( Set < String > annos ) { this . visibleTokenAnnos = annos ; if ( visPlugin != null && vis != null ) { visPlugin . setVisibleTokenAnnosVisible ( vis , annos ) ; } } public void setSegmentationLayer ( String segmentationName , Map < SNode , Long > markedAndCovered ) { this . segmentationName = segmentationName ; this . markedAndCovered = markedAndCovered ; if ( visPlugin != null && vis != null ) { visPlugin . setSegmentationLayer ( vis , segmentationName , markedAndCovered ) ; } } public ApplicationResource createResource ( final ByteArrayOutputStream byteStream , String mimeType ) { StreamResource r ; r = new StreamResource ( new StreamResource . StreamSource ( ) { @ Override public InputStream getStream ( ) { return new ByteArrayInputStream ( byteStream . toByteArray ( ) ) ; } } , entry . getVisType ( ) + "<STR_LIT:_>" + rand . nextInt ( Integer . MAX_VALUE ) , getApplication ( ) ) ; r . setMIMEType ( mimeType ) ; return r ; } private SaltProject getText ( String toplevelCorpusName , String documentName ) { SaltProject txt = null ; try { toplevelCorpusName = URLEncoder . encode ( toplevelCorpusName , "<STR_LIT:UTF-8>" ) ; documentName = URLEncoder . encode ( documentName , "<STR_LIT:UTF-8>" ) ; WebResource annisResource = Helper . getAnnisWebResource ( getApplication ( ) ) ; txt = annisResource . path ( "<STR_LIT>" ) . path ( toplevelCorpusName ) . path ( documentName ) . get ( SaltProject . class ) ; } catch ( Exception e ) { log . error ( "<STR_LIT>" , e ) ; } return txt ; } @ Override public void detach ( ) { super . detach ( ) ; if ( resource != null ) { getApplication ( ) . removeResource ( resource ) ; } } @ Override public void buttonClick ( ClickEvent event ) { toggleVisualizer ( ! visualizerIsVisible ( ) , null ) ; } @ Override public boolean visualizerIsVisible ( ) { if ( vis == null || ! vis . isVisible ( ) ) { return false ; } return true ; } @ Override public void toggleVisualizer ( boolean visible , LoadableVisualizer . Callback callback ) { if ( visible ) { if ( visPlugin != null && vis == null ) { try { vis = createComponent ( ) ; } catch ( Exception ex ) { getWindow ( ) . showNotification ( "<STR_LIT>" + visPlugin . getShortName ( ) , ex . toString ( ) , Window . Notification . TYPE_WARNING_MESSAGE ) ; log . error ( "<STR_LIT>" + visPlugin . getShortName ( ) , ex ) ; } } if ( callback != null && vis instanceof LoadableVisualizer ) { LoadableVisualizer loadableVis = ( LoadableVisualizer ) vis ; if ( loadableVis . isLoaded ( ) ) { callback . visualizerLoaded ( ( LoadableVisualizer ) vis ) ; } else { loadableVis . clearCallbacks ( ) ; loadableVis . addOnLoadCallBack ( callback ) ; } } btEntry . setIcon ( ICON_COLLAPSE ) ; vis . setVisible ( true ) ; if ( getComponent ( "<STR_LIT>" ) == null ) { addComponent ( vis , "<STR_LIT>" ) ; } } else { if ( vis != null ) { vis . setVisible ( false ) ; if ( vis instanceof MediaPlayer ) { removeComponent ( vis ) ; } } btEntry . setIcon ( ICON_EXPAND ) ; } } public String getHtmlID ( ) { return htmlID ; } } </s>
<s> package annis . gui . resultview ; import annis . exceptions . AnnisCorpusAccessException ; import annis . exceptions . AnnisQLSemanticsException ; import annis . exceptions . AnnisQLSyntaxException ; import annis . gui . CitationWindow ; import annis . gui . PluginSystem ; import annis . gui . paging . PagingCallback ; import annis . gui . paging . PagingComponent ; import annis . security . AnnisUser ; import annis . service . objects . AnnisCorpus ; import annis . service . objects . Match ; import com . vaadin . terminal . PaintException ; import com . vaadin . terminal . PaintTarget ; import com . vaadin . ui . Alignment ; import com . vaadin . ui . MenuBar ; import com . vaadin . ui . MenuBar . MenuItem ; import com . vaadin . ui . Panel ; import com . vaadin . ui . ProgressIndicator ; import com . vaadin . ui . VerticalLayout ; import com . vaadin . ui . Window ; import java . util . List ; import java . util . Map ; import java . util . Map . Entry ; import java . util . Set ; import java . util . TreeMap ; import java . util . TreeSet ; import org . slf4j . LoggerFactory ; public class ResultViewPanel extends Panel implements PagingCallback { private static final org . slf4j . Logger log = LoggerFactory . getLogger ( ResultViewPanel . class ) ; private PagingComponent paging ; private ResultSetPanel resultPanel ; private String aql ; private Map < String , AnnisCorpus > corpora ; private int contextLeft , contextRight , pageSize ; private AnnisResultQuery query ; private ProgressIndicator progressResult ; private PluginSystem ps ; private MenuItem miTokAnnos ; private MenuItem miSegmentation ; private TreeMap < String , Boolean > tokenAnnoVisible ; private String currentSegmentationLayer ; private VerticalLayout mainLayout ; public ResultViewPanel ( String aql , Map < String , AnnisCorpus > corpora , int contextLeft , int contextRight , String segmentationLayer , int pageSize , PluginSystem ps ) { this . tokenAnnoVisible = new TreeMap < String , Boolean > ( ) ; this . aql = aql ; this . corpora = corpora ; this . contextLeft = contextLeft ; this . contextRight = contextRight ; this . pageSize = pageSize ; this . ps = ps ; this . currentSegmentationLayer = segmentationLayer ; setSizeFull ( ) ; mainLayout = ( VerticalLayout ) getContent ( ) ; mainLayout . setMargin ( false ) ; mainLayout . setSizeFull ( ) ; MenuBar mbResult = new MenuBar ( ) ; mbResult . setWidth ( "<STR_LIT>" ) ; miSegmentation = mbResult . addItem ( "<STR_LIT>" , null ) ; miTokAnnos = mbResult . addItem ( "<STR_LIT>" , null ) ; mbResult . addItem ( "<STR_LIT>" , new MenuBar . Command ( ) { @ Override public void menuSelected ( MenuItem selectedItem ) { showCitationURLWindow ( ) ; } } ) ; paging = new PagingComponent ( <NUM_LIT:0> , pageSize ) ; paging . setInfo ( "<STR_LIT>" + aql . replaceAll ( "<STR_LIT:n>" , "<STR_LIT:U+0020>" ) + "<STR_LIT:\">" ) ; paging . addCallback ( ( PagingCallback ) this ) ; mainLayout . addComponent ( mbResult ) ; mainLayout . addComponent ( paging ) ; mainLayout . setSizeFull ( ) ; progressResult = new ProgressIndicator ( ) ; progressResult . setIndeterminate ( true ) ; progressResult . setEnabled ( false ) ; progressResult . setPollingInterval ( <NUM_LIT> ) ; progressResult . setCaption ( "<STR_LIT>" + aql . replaceAll ( "<STR_LIT:n>" , "<STR_LIT:U+0020>" ) + "<STR_LIT:\">" ) ; mainLayout . addComponent ( progressResult ) ; mainLayout . setComponentAlignment ( progressResult , Alignment . TOP_CENTER ) ; mainLayout . setExpandRatio ( paging , <NUM_LIT:0.0f> ) ; mainLayout . setExpandRatio ( progressResult , <NUM_LIT:1.0f> ) ; } @ Override public void attach ( ) { try { query = new AnnisResultQuery ( corpora . keySet ( ) , aql , getApplication ( ) ) ; createPage ( <NUM_LIT:0> , pageSize ) ; super . attach ( ) ; } catch ( Exception ex ) { log . error ( "<STR_LIT>" , ex ) ; } } public void setCount ( int count ) { paging . setCount ( count , false ) ; } @ Override public void createPage ( final int start , final int limit ) { if ( query != null ) { progressResult . setEnabled ( true ) ; progressResult . setVisible ( true ) ; if ( resultPanel != null ) { resultPanel . setVisible ( false ) ; } final ResultViewPanel finalThis = this ; Runnable r = new Runnable ( ) { @ Override public void run ( ) { try { AnnisUser user = null ; synchronized ( getApplication ( ) ) { if ( getApplication ( ) != null ) { user = ( AnnisUser ) getApplication ( ) . getUser ( ) ; } } List < Match > result = query . loadBeans ( start , limit , user ) ; synchronized ( getApplication ( ) ) { if ( resultPanel != null ) { mainLayout . removeComponent ( resultPanel ) ; } resultPanel = new ResultSetPanel ( result , start , ps , contextLeft , contextRight , currentSegmentationLayer , finalThis ) ; mainLayout . addComponent ( resultPanel ) ; mainLayout . setExpandRatio ( resultPanel , <NUM_LIT:1.0f> ) ; mainLayout . setExpandRatio ( progressResult , <NUM_LIT:0.0f> ) ; resultPanel . setVisible ( true ) ; } } catch ( AnnisQLSemanticsException ex ) { synchronized ( getApplication ( ) ) { paging . setInfo ( "<STR_LIT>" + ex . getLocalizedMessage ( ) ) ; } } catch ( AnnisQLSyntaxException ex ) { synchronized ( getApplication ( ) ) { paging . setInfo ( "<STR_LIT>" + ex . getLocalizedMessage ( ) ) ; } } catch ( AnnisCorpusAccessException ex ) { synchronized ( getApplication ( ) ) { paging . setInfo ( "<STR_LIT>" + ex . getLocalizedMessage ( ) ) ; } } catch ( Exception ex ) { log . error ( "<STR_LIT>" , ex ) ; synchronized ( getApplication ( ) ) { paging . setInfo ( "<STR_LIT>" + ex . getLocalizedMessage ( ) ) ; } } finally { synchronized ( getApplication ( ) ) { progressResult . setVisible ( false ) ; progressResult . setEnabled ( false ) ; } } } } ; Thread t = new Thread ( r ) ; t . start ( ) ; } } public Set < String > getVisibleTokenAnnos ( ) { TreeSet < String > result = new TreeSet < String > ( ) ; for ( Entry < String , Boolean > e : tokenAnnoVisible . entrySet ( ) ) { if ( e . getValue ( ) . booleanValue ( ) == true ) { result . add ( e . getKey ( ) ) ; } } return result ; } private void showCitationURLWindow ( ) { final Window w = new CitationWindow ( getApplication ( ) , aql , corpora , contextLeft , contextRight ) ; getWindow ( ) . addWindow ( w ) ; w . center ( ) ; } public void updateSegmentationLayer ( Set < String > segLayers ) { miSegmentation . removeChildren ( ) ; segLayers . add ( "<STR_LIT>" ) ; for ( String s : segLayers ) { MenuItem miSingleSegLayer = miSegmentation . addItem ( "<STR_LIT>" . equals ( s ) ? "<STR_LIT>" : s , new MenuBar . Command ( ) { @ Override public void menuSelected ( MenuItem selectedItem ) { currentSegmentationLayer = selectedItem . getText ( ) ; for ( MenuItem mi : miSegmentation . getChildren ( ) ) { mi . setChecked ( mi == selectedItem ) ; } resultPanel . setSegmentationLayer ( currentSegmentationLayer ) ; } } ) ; miSingleSegLayer . setCheckable ( true ) ; miSingleSegLayer . setChecked ( ( currentSegmentationLayer == null && "<STR_LIT>" . equals ( s ) ) || s . equals ( currentSegmentationLayer ) ) ; } } public void updateTokenAnnos ( Set < String > tokenAnnotationLevelSet ) { for ( String s : tokenAnnotationLevelSet ) { if ( ! tokenAnnoVisible . containsKey ( s ) ) { tokenAnnoVisible . put ( s , Boolean . TRUE ) ; } } miTokAnnos . removeChildren ( ) ; for ( String a : tokenAnnotationLevelSet ) { MenuItem miSingleTokAnno = miTokAnnos . addItem ( a , new MenuBar . Command ( ) { @ Override public void menuSelected ( MenuItem selectedItem ) { if ( selectedItem . isChecked ( ) ) { tokenAnnoVisible . put ( selectedItem . getText ( ) , Boolean . TRUE ) ; } else { tokenAnnoVisible . put ( selectedItem . getText ( ) , Boolean . FALSE ) ; } resultPanel . setVisibleTokenAnnosVisible ( getVisibleTokenAnnos ( ) ) ; } } ) ; miSingleTokAnno . setCheckable ( true ) ; miSingleTokAnno . setChecked ( tokenAnnoVisible . get ( a ) . booleanValue ( ) ) ; } } @ Override public void paintContent ( PaintTarget target ) throws PaintException { super . paintContent ( target ) ; } } </s>
<s> package annis . gui . resultview ; import annis . CommonHelper ; import annis . gui . Helper ; import annis . gui . PluginSystem ; import annis . gui . media . MediaController ; import annis . gui . media . MediaControllerFactory ; import annis . gui . media . MediaControllerHolder ; import annis . resolver . ResolverEntry ; import annis . resolver . ResolverEntry . ElementType ; import annis . resolver . SingleResolverRequest ; import annis . service . objects . Match ; import com . sun . jersey . api . client . GenericType ; import com . sun . jersey . api . client . UniformInterfaceException ; import com . sun . jersey . api . client . WebResource ; import com . vaadin . data . util . BeanItemContainer ; import com . vaadin . terminal . gwt . server . WebApplicationContext ; import com . vaadin . ui . * ; import com . vaadin . ui . themes . ChameleonTheme ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCommon . SaltProject ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCommon . sCorpusStructure . SDocument ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCore . SLayer ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCore . SNode ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCore . SRelation ; import java . io . UnsupportedEncodingException ; import java . net . URLEncoder ; import java . util . * ; import java . util . concurrent . * ; import javax . ws . rs . core . Response ; import org . apache . commons . lang3 . StringUtils ; import org . apache . commons . lang3 . Validate ; import org . slf4j . LoggerFactory ; public class ResultSetPanel extends Panel implements ResolverProvider { private static final org . slf4j . Logger log = LoggerFactory . getLogger ( ResultSetPanel . class ) ; private Map < HashSet < SingleResolverRequest > , List < ResolverEntry > > cacheResolver ; public static final String FILESYSTEM_CACHE_RESULT = "<STR_LIT>" ; private BeanItemContainer < Match > container ; private List < SingleResultPanel > resultPanelList ; private PluginSystem ps ; private String segmentationName ; private int start ; private int contextLeft ; private int contextRight ; private ResultViewPanel parent ; private List < Match > matches ; private Set < String > tokenAnnotationLevelSet = Collections . synchronizedSet ( new HashSet < String > ( ) ) ; private Set < String > segmentationLayerSet = Collections . synchronizedSet ( new HashSet < String > ( ) ) ; private ProgressIndicator indicator ; private VerticalLayout layout ; public ResultSetPanel ( List < Match > matches , int start , PluginSystem ps , int contextLeft , int contextRight , String segmentationName , ResultViewPanel parent ) { this . ps = ps ; this . segmentationName = segmentationName ; this . start = start ; this . contextLeft = contextLeft ; this . contextRight = contextRight ; this . parent = parent ; this . matches = Collections . synchronizedList ( matches ) ; resultPanelList = Collections . synchronizedList ( new LinkedList < SingleResultPanel > ( ) ) ; cacheResolver = Collections . synchronizedMap ( new HashMap < HashSet < SingleResolverRequest > , List < ResolverEntry > > ( ) ) ; setSizeFull ( ) ; layout = ( VerticalLayout ) getContent ( ) ; layout . setWidth ( "<STR_LIT>" ) ; layout . setHeight ( "<STR_LIT>" ) ; addStyleName ( ChameleonTheme . PANEL_BORDERLESS ) ; layout . setMargin ( false ) ; addStyleName ( "<STR_LIT>" ) ; container = new BeanItemContainer < Match > ( Match . class , this . matches ) ; indicator = new ProgressIndicator ( ) ; indicator . setIndeterminate ( true ) ; indicator . setValue ( <NUM_LIT> ) ; indicator . setPollingInterval ( <NUM_LIT> ) ; indicator . setCaption ( "<STR_LIT>" ) ; layout . addComponent ( indicator ) ; layout . setComponentAlignment ( indicator , Alignment . BOTTOM_CENTER ) ; } @ Override public void attach ( ) { super . attach ( ) ; MediaControllerFactory mcFactory = ps . getPluginManager ( ) . getPlugin ( MediaControllerFactory . class ) ; if ( mcFactory != null && getApplication ( ) instanceof MediaControllerHolder ) { mcFactory . getOrCreate ( ( MediaControllerHolder ) getApplication ( ) ) . clearMediaPlayers ( ) ; } String propBatchSize = getApplication ( ) . getProperty ( "<STR_LIT>" ) ; final int batchSize = propBatchSize == null ? <NUM_LIT:5> : Integer . parseInt ( propBatchSize ) ; indicator . setEnabled ( true ) ; ExecutorService singleExecutor = Executors . newSingleThreadExecutor ( ) ; Runnable run = new AllResultsFetcher ( batchSize ) ; singleExecutor . submit ( run ) ; } private Map < Integer , Future < SingleResultPanel > > loadNextResultBatch ( int batchSize , int offset , ExecutorService executorService , WebResource resWithoutMatch ) { Map < Integer , Future < SingleResultPanel > > tasks = Collections . synchronizedMap ( new HashMap < Integer , Future < SingleResultPanel > > ( ) ) ; ListIterator < Match > it = matches . listIterator ( offset ) ; while ( it . hasNext ( ) && ( it . nextIndex ( ) - offset ) < batchSize ) { int i = it . nextIndex ( ) ; Match m = it . next ( ) ; List < String > encodedSaltIDs = new LinkedList < String > ( ) ; for ( String s : m . getSaltIDs ( ) ) { try { encodedSaltIDs . add ( URLEncoder . encode ( s , "<STR_LIT:UTF-8>" ) ) ; } catch ( UnsupportedEncodingException ex ) { log . error ( null , ex ) ; } } WebResource res = resWithoutMatch . queryParam ( "<STR_LIT:q>" , StringUtils . join ( encodedSaltIDs , "<STR_LIT:U+002C>" ) ) ; if ( res != null ) { Future < SingleResultPanel > f = lazyLoadResultPanel ( executorService , res , i , this ) ; tasks . put ( i , f ) ; } } return tasks ; } @ Override public ResolverEntry [ ] getResolverEntries ( SDocument doc ) { HashSet < ResolverEntry > visSet = new HashSet < ResolverEntry > ( ) ; HashSet < SingleResolverRequest > resolverRequests = new HashSet < SingleResolverRequest > ( ) ; Set < String > nodeLayers = new HashSet < String > ( ) ; for ( SNode n : doc . getSDocumentGraph ( ) . getSNodes ( ) ) { for ( SLayer layer : n . getSLayers ( ) ) { nodeLayers . add ( layer . getSName ( ) ) ; } } Set < String > edgeLayers = new HashSet < String > ( ) ; for ( SRelation e : doc . getSDocumentGraph ( ) . getSRelations ( ) ) { for ( SLayer layer : e . getSLayers ( ) ) { try { edgeLayers . add ( layer . getSName ( ) ) ; } catch ( NullPointerException ex ) { log . warn ( "<STR_LIT>" , ex ) ; } } } for ( String ns : nodeLayers ) { resolverRequests . add ( new SingleResolverRequest ( doc . getSCorpusGraph ( ) . getSRootCorpus ( ) . get ( <NUM_LIT:0> ) . getSName ( ) , ns , ElementType . node ) ) ; } for ( String ns : edgeLayers ) { resolverRequests . add ( new SingleResolverRequest ( doc . getSCorpusGraph ( ) . getSRootCorpus ( ) . get ( <NUM_LIT:0> ) . getSName ( ) , ns , ElementType . edge ) ) ; } if ( cacheResolver . containsKey ( resolverRequests ) ) { visSet . addAll ( cacheResolver . get ( resolverRequests ) ) ; } else { List < ResolverEntry > resolverList = new LinkedList < ResolverEntry > ( ) ; WebResource resResolver = Helper . getAnnisWebResource ( getApplication ( ) ) . path ( "<STR_LIT>" ) ; for ( SingleResolverRequest r : resolverRequests ) { List < ResolverEntry > tmp ; try { String corpusName = URLEncoder . encode ( r . getCorpusName ( ) , "<STR_LIT:UTF-8>" ) ; String namespace = r . getNamespace ( ) ; String type = r . getType ( ) == null ? null : r . getType ( ) . toString ( ) ; if ( corpusName != null && namespace != null && type != null ) { WebResource res = resResolver . path ( corpusName ) . path ( namespace ) . path ( type ) ; try { tmp = res . get ( new GenericType < List < ResolverEntry > > ( ) { } ) ; resolverList . addAll ( tmp ) ; } catch ( Exception ex ) { log . error ( "<STR_LIT>" + res . toString ( ) , ex ) ; } } } catch ( Exception ex ) { log . error ( null , ex ) ; } } visSet . addAll ( resolverList ) ; cacheResolver . put ( resolverRequests , resolverList ) ; } ResolverEntry [ ] visArray = visSet . toArray ( new ResolverEntry [ <NUM_LIT:0> ] ) ; Arrays . sort ( visArray , new Comparator < ResolverEntry > ( ) { @ Override public int compare ( ResolverEntry o1 , ResolverEntry o2 ) { if ( o1 . getOrder ( ) < o2 . getOrder ( ) ) { return - <NUM_LIT:1> ; } else if ( o1 . getOrder ( ) > o2 . getOrder ( ) ) { return <NUM_LIT:1> ; } else { return <NUM_LIT:0> ; } } } ) ; return visArray ; } public void setSegmentationLayer ( String segmentationLayer ) { for ( SingleResultPanel p : resultPanelList ) { p . setSegmentationLayer ( segmentationLayer ) ; } } public void setVisibleTokenAnnosVisible ( Set < String > annos ) { for ( SingleResultPanel p : resultPanelList ) { p . setVisibleTokenAnnosVisible ( annos ) ; } } private Future < SingleResultPanel > lazyLoadResultPanel ( final ExecutorService executorService , final WebResource subgraphRes , final int offset , final ResolverProvider rsProvider ) { final int resultNumber = start + offset ; Callable < SingleResultPanel > run = new SingleResultFetcher ( subgraphRes , resultNumber , rsProvider ) ; return executorService . submit ( run ) ; } public class SingleResultFetcher implements Callable < SingleResultPanel > { private WebResource subgraphRes ; private int resultNumber ; private ResolverProvider rsProvider ; public SingleResultFetcher ( WebResource subgraphRes , int resultNumber , ResolverProvider rsProvider ) { this . subgraphRes = subgraphRes ; this . resultNumber = resultNumber ; this . rsProvider = rsProvider ; } @ Override public SingleResultPanel call ( ) { SaltProject p = null ; int tries = <NUM_LIT:0> ; while ( p == null && tries < <NUM_LIT:100> ) { try { p = subgraphRes . get ( SaltProject . class ) ; } catch ( UniformInterfaceException ex ) { if ( ex . getResponse ( ) . getStatus ( ) != Response . Status . SERVICE_UNAVAILABLE . getStatusCode ( ) ) { log . error ( ex . getMessage ( ) , ex ) ; break ; } try { Thread . sleep ( <NUM_LIT> ) ; } catch ( InterruptedException ex1 ) { log . error ( null , ex1 ) ; } } catch ( Exception ex ) { log . error ( ex . getMessage ( ) , ex ) ; break ; } tries ++ ; } Validate . notNull ( p ) ; SingleResultPanel result ; synchronized ( getApplication ( ) ) { segmentationLayerSet . addAll ( CommonHelper . getOrderingTypes ( p ) ) ; tokenAnnotationLevelSet . addAll ( CommonHelper . getTokenAnnotationLevelSet ( p ) ) ; parent . updateSegmentationLayer ( segmentationLayerSet ) ; parent . updateTokenAnnos ( tokenAnnotationLevelSet ) ; if ( p != null && p . getSCorpusGraphs ( ) . size ( ) > <NUM_LIT:0> && p . getSCorpusGraphs ( ) . get ( <NUM_LIT:0> ) . getSDocuments ( ) . size ( ) > <NUM_LIT:0> ) { result = new SingleResultPanel ( p . getSCorpusGraphs ( ) . get ( <NUM_LIT:0> ) . getSDocuments ( ) . get ( <NUM_LIT:0> ) , resultNumber , rsProvider , ps , parent . getVisibleTokenAnnos ( ) , segmentationName ) ; } else { log . warn ( "<STR_LIT>" , subgraphRes . toString ( ) ) ; result = null ; } } return result ; } } public class AllResultsFetcher implements Runnable { private int batchSize ; public AllResultsFetcher ( int batchSize ) { this . batchSize = batchSize ; } @ Override public void run ( ) { ExecutorService executorService = Executors . newFixedThreadPool ( batchSize ) ; WebResource res = Helper . getAnnisWebResource ( getApplication ( ) ) ; if ( res != null ) { res = res . path ( "<STR_LIT>" ) . queryParam ( "<STR_LIT>" , "<STR_LIT>" + contextLeft ) . queryParam ( "<STR_LIT>" , "<STR_LIT>" + contextRight ) ; if ( segmentationName != null ) { res = res . queryParam ( "<STR_LIT>" , segmentationName ) ; } for ( int offset = <NUM_LIT:0> ; offset < matches . size ( ) ; offset += batchSize ) { Map < Integer , Future < SingleResultPanel > > tasks = loadNextResultBatch ( batchSize , offset , executorService , res ) ; waitForTasks ( tasks , offset ) ; } } synchronized ( getApplication ( ) ) { indicator . setEnabled ( false ) ; indicator . setVisible ( false ) ; for ( SingleResultPanel panel : resultPanelList ) { layout . addComponent ( panel ) ; } } } private void waitForTasks ( Map < Integer , Future < SingleResultPanel > > tasks , int offset ) { for ( int i = offset ; i < offset + batchSize ; i ++ ) { if ( tasks . containsKey ( i ) ) { Future < SingleResultPanel > future = tasks . get ( i ) ; try { SingleResultPanel panel = future . get ( ) ; if ( panel == null ) { synchronized ( getApplication ( ) ) { getWindow ( ) . showNotification ( "<STR_LIT>" + i , Window . Notification . TYPE_TRAY_NOTIFICATION ) ; } } else { panel . setWidth ( "<STR_LIT>" ) ; panel . setHeight ( "<STR_LIT>" ) ; resultPanelList . add ( panel ) ; } } catch ( Exception ex ) { log . error ( null , ex ) ; } } } } } } </s>
<s> package annis . gui . resultview ; import annis . CommonHelper ; import annis . gui . MatchedNodeColors ; import annis . gui . MetaDataPanel ; import annis . gui . PluginSystem ; import static annis . model . AnnisConstants . * ; import annis . resolver . ResolverEntry ; import com . vaadin . terminal . ThemeResource ; import com . vaadin . ui . Button ; import com . vaadin . ui . Button . ClickEvent ; import com . vaadin . ui . CssLayout ; import com . vaadin . ui . HorizontalLayout ; import com . vaadin . ui . Label ; import com . vaadin . ui . Window ; import com . vaadin . ui . themes . ChameleonTheme ; import de . hu_berlin . german . korpling . saltnpepper . salt . graph . GRAPH_TRAVERSE_TYPE ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCommon . sCorpusStructure . SDocument ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCommon . sDocumentStructure . * ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCore . SFeature ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCore . SGraphTraverseHandler ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCore . SNode ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCore . SRelation ; import java . util . Collections ; import java . util . HashMap ; import java . util . HashSet ; import java . util . LinkedList ; import java . util . List ; import java . util . Map ; import java . util . Map . Entry ; import java . util . Properties ; import java . util . Random ; import java . util . Set ; import org . apache . commons . lang3 . StringUtils ; import org . eclipse . emf . common . util . BasicEList ; import org . eclipse . emf . common . util . EList ; import org . slf4j . LoggerFactory ; public class SingleResultPanel extends CssLayout implements Button . ClickListener { private static final String HIDE_KWIC = "<STR_LIT>" ; private static final String INITIAL_OPEN = "<STR_LIT>" ; private static final ThemeResource ICON_RESOURCE = new ThemeResource ( "<STR_LIT>" ) ; private SDocument result ; private Map < SNode , Long > markedAndCovered ; private Map < String , String > markedCoveredMap ; private Map < String , String > markedExactMap ; private ResolverProvider resolverProvider ; private PluginSystem ps ; private List < VisualizerPanel > visualizers ; private Button btInfo ; private int resultNumber ; private List < String > path ; private Set < String > visibleTokenAnnos ; private String segmentationName ; private List < SToken > token ; private boolean wasAttached ; private static final org . slf4j . Logger log = LoggerFactory . getLogger ( SingleResultPanel . class ) ; public SingleResultPanel ( final SDocument result , int resultNumber , ResolverProvider resolverProvider , PluginSystem ps , Set < String > visibleTokenAnnos , String segmentationName ) { this . ps = ps ; this . result = result ; this . resolverProvider = resolverProvider ; this . resultNumber = resultNumber ; this . visibleTokenAnnos = visibleTokenAnnos ; this . segmentationName = segmentationName ; calculateHelperVariables ( ) ; setWidth ( "<STR_LIT>" ) ; setHeight ( "<STR_LIT>" ) ; setMargin ( false ) ; HorizontalLayout infoBar = new HorizontalLayout ( ) ; infoBar . addStyleName ( "<STR_LIT>" ) ; infoBar . setWidth ( "<STR_LIT>" ) ; infoBar . setHeight ( "<STR_LIT>" ) ; addComponent ( infoBar ) ; Label lblNumber = new Label ( "<STR_LIT>" + ( resultNumber + <NUM_LIT:1> ) ) ; infoBar . addComponent ( lblNumber ) ; lblNumber . setSizeUndefined ( ) ; btInfo = new Button ( ) ; btInfo . setStyleName ( ChameleonTheme . BUTTON_LINK ) ; btInfo . setIcon ( ICON_RESOURCE ) ; btInfo . addListener ( ( Button . ClickListener ) this ) ; infoBar . addComponent ( btInfo ) ; path = CommonHelper . getCorpusPath ( result . getSCorpusGraph ( ) , result ) ; Collections . reverse ( path ) ; Label lblPath = new Label ( "<STR_LIT>" + StringUtils . join ( path , "<STR_LIT>" ) ) ; lblPath . setWidth ( "<STR_LIT>" ) ; lblPath . setHeight ( "<STR_LIT>" ) ; infoBar . addComponent ( lblPath ) ; infoBar . setExpandRatio ( lblPath , <NUM_LIT:1.0f> ) ; infoBar . setSpacing ( true ) ; } @ Override public void attach ( ) { try { if ( wasAttached ) { return ; } wasAttached = true ; ResolverEntry [ ] entries = resolverProvider . getResolverEntries ( result ) ; visualizers = new LinkedList < VisualizerPanel > ( ) ; List < VisualizerPanel > openVisualizers = new LinkedList < VisualizerPanel > ( ) ; token = result . getSDocumentGraph ( ) . getSortedSTokenByText ( ) ; List < SNode > segNodes = CommonHelper . getSortedSegmentationNodes ( segmentationName , result . getSDocumentGraph ( ) ) ; markedAndCovered = calculateMarkedAndCoveredIDs ( result , segNodes ) ; calulcateColorsForMarkedAndCoverd ( ) ; String resultID = "<STR_LIT>" + new Random ( ) . nextInt ( Integer . MAX_VALUE ) ; for ( int i = <NUM_LIT:0> ; i < entries . length ; i ++ ) { int textNr = <NUM_LIT:0> ; EList < STextualDS > allTexts = result . getSDocumentGraph ( ) . getSTextualDSs ( ) ; for ( STextualDS text : allTexts ) { String htmlID = "<STR_LIT>" + resultNumber + "<STR_LIT:_>" + textNr + "<STR_LIT:->" + i ; VisualizerPanel p = new VisualizerPanel ( entries [ i ] , result , token , visibleTokenAnnos , markedAndCovered , markedCoveredMap , markedExactMap , text , htmlID , resultID , this , segmentationName , ps , allTexts . size ( ) > <NUM_LIT:1> ) ; visualizers . add ( p ) ; Properties mappings = entries [ i ] . getMappings ( ) ; if ( Boolean . parseBoolean ( mappings . getProperty ( INITIAL_OPEN , "<STR_LIT:false>" ) ) ) { openVisualizers . add ( p ) ; } textNr ++ ; } } for ( VisualizerPanel p : visualizers ) { addComponent ( p ) ; } for ( VisualizerPanel p : openVisualizers ) { p . toggleVisualizer ( true , null ) ; } } catch ( Exception ex ) { log . error ( "<STR_LIT>" , ex ) ; } } public void setSegmentationLayer ( String segmentationName ) { this . segmentationName = segmentationName ; List < SNode > segNodes = CommonHelper . getSortedSegmentationNodes ( segmentationName , result . getSDocumentGraph ( ) ) ; markedAndCovered = calculateMarkedAndCoveredIDs ( result , segNodes ) ; for ( VisualizerPanel p : visualizers ) { p . setSegmentationLayer ( segmentationName , markedAndCovered ) ; } } public void setVisibleTokenAnnosVisible ( Set < String > annos ) { for ( VisualizerPanel p : visualizers ) { p . setVisibleTokenAnnosVisible ( annos ) ; } } private void calculateHelperVariables ( ) { markedExactMap = new HashMap < String , String > ( ) ; markedCoveredMap = new HashMap < String , String > ( ) ; SDocumentGraph g = result . getSDocumentGraph ( ) ; if ( g != null ) { for ( SNode n : result . getSDocumentGraph ( ) . getSNodes ( ) ) { SFeature featMatched = n . getSFeature ( ANNIS_NS , FEAT_MATCHEDNODE ) ; Long match = featMatched == null ? null : featMatched . getSValueSNUMERIC ( ) ; if ( match != null ) { int color = Math . max ( <NUM_LIT:0> , Math . min ( ( int ) match . longValue ( ) - <NUM_LIT:1> , MatchedNodeColors . values ( ) . length - <NUM_LIT:1> ) ) ; SFeature feat = n . getSFeature ( ANNIS_NS , FEAT_INTERNALID ) ; if ( feat != null ) { markedExactMap . put ( "<STR_LIT>" + feat . getSValueSNUMERIC ( ) , MatchedNodeColors . values ( ) [ color ] . name ( ) ) ; } } } } } private void calulcateColorsForMarkedAndCoverd ( ) { for ( Entry < SNode , Long > markedEntry : markedAndCovered . entrySet ( ) ) { int color = Math . max ( <NUM_LIT:0> , Math . min ( ( int ) markedEntry . getValue ( ) . longValue ( ) - <NUM_LIT:1> , MatchedNodeColors . values ( ) . length - <NUM_LIT:1> ) ) ; SFeature feat = markedEntry . getKey ( ) . getSFeature ( ANNIS_NS , FEAT_INTERNALID ) ; if ( feat != null ) { markedCoveredMap . put ( "<STR_LIT>" + feat . getSValueSNUMERIC ( ) , MatchedNodeColors . values ( ) [ color ] . name ( ) ) ; } } } private Map < SNode , Long > calculateMarkedAndCoveredIDs ( SDocument doc , List < SNode > segNodes ) { Set < String > matchedNodes = new HashSet < String > ( ) ; Map < SNode , Long > initialCovered = new HashMap < SNode , Long > ( ) ; for ( SNode n : doc . getSDocumentGraph ( ) . getSNodes ( ) ) { SFeature featMatched = n . getSFeature ( ANNIS_NS , FEAT_MATCHEDNODE ) ; Long match = featMatched == null ? null : featMatched . getSValueSNUMERIC ( ) ; if ( match != null ) { matchedNodes . add ( n . getSId ( ) ) ; initialCovered . put ( n , match ) ; } } SingleResultPanel . CoveredMatchesCalculator cmc = new SingleResultPanel . CoveredMatchesCalculator ( doc . getSDocumentGraph ( ) , initialCovered ) ; Map < SNode , Long > covered = cmc . getMatchedAndCovered ( ) ; if ( segmentationName != null ) { Map < SToken , Long > coveredToken = new HashMap < SToken , Long > ( ) ; for ( Map . Entry < SNode , Long > e : covered . entrySet ( ) ) { if ( e . getKey ( ) instanceof SToken ) { coveredToken . put ( ( SToken ) e . getKey ( ) , e . getValue ( ) ) ; } } for ( SNode segNode : segNodes ) { if ( segNode != null && ! covered . containsKey ( segNode ) ) { long leftTok = segNode . getSFeature ( ANNIS_NS , FEAT_LEFTTOKEN ) . getSValueSNUMERIC ( ) ; long rightTok = segNode . getSFeature ( ANNIS_NS , FEAT_RIGHTTOKEN ) . getSValueSNUMERIC ( ) ; for ( Map . Entry < SToken , Long > e : coveredToken . entrySet ( ) ) { long entryTokenIndex = e . getKey ( ) . getSFeature ( ANNIS_NS , FEAT_TOKENINDEX ) . getSValueSNUMERIC ( ) ; if ( entryTokenIndex <= rightTok && entryTokenIndex >= leftTok ) { covered . put ( segNode , e . getValue ( ) ) ; break ; } } } } } return covered ; } @ Override public void buttonClick ( ClickEvent event ) { if ( event . getButton ( ) == btInfo ) { Window infoWindow = new Window ( "<STR_LIT>" + result . getSId ( ) ) ; infoWindow . setModal ( false ) ; MetaDataPanel meta = new MetaDataPanel ( path . get ( <NUM_LIT:0> ) , path . get ( path . size ( ) - <NUM_LIT:1> ) ) ; infoWindow . setContent ( meta ) ; infoWindow . setWidth ( "<STR_LIT>" ) ; infoWindow . setHeight ( "<STR_LIT>" ) ; getWindow ( ) . addWindow ( infoWindow ) ; } } public static class CoveredMatchesCalculator implements SGraphTraverseHandler { private Map < SNode , Long > matchedAndCovered ; private long currentMatchPos ; public CoveredMatchesCalculator ( SDocumentGraph graph , Map < SNode , Long > initialMatches ) { this . matchedAndCovered = initialMatches ; currentMatchPos = <NUM_LIT:1> ; if ( initialMatches . size ( ) > <NUM_LIT:0> ) { graph . traverse ( new BasicEList < SNode > ( initialMatches . keySet ( ) ) , GRAPH_TRAVERSE_TYPE . TOP_DOWN_DEPTH_FIRST , "<STR_LIT>" , ( SGraphTraverseHandler ) this , true ) ; } } @ Override public void nodeReached ( GRAPH_TRAVERSE_TYPE traversalType , String traversalId , SNode currNode , SRelation edge , SNode fromNode , long order ) { if ( matchedAndCovered . containsKey ( fromNode ) && ! matchedAndCovered . containsKey ( currNode ) ) { currentMatchPos = matchedAndCovered . get ( fromNode ) ; matchedAndCovered . put ( currNode , currentMatchPos ) ; } } @ Override public void nodeLeft ( GRAPH_TRAVERSE_TYPE traversalType , String traversalId , SNode currNode , SRelation edge , SNode fromNode , long order ) { } @ Override public boolean checkConstraint ( GRAPH_TRAVERSE_TYPE traversalType , String traversalId , SRelation edge , SNode currNode , long order ) { if ( edge == null || edge instanceof SDominanceRelation || edge instanceof SSpanningRelation ) { return true ; } else { return false ; } } public Map < SNode , Long > getMatchedAndCovered ( ) { return matchedAndCovered ; } } } </s>
<s> package annis . gui . resultview ; import annis . resolver . ResolverEntry ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCommon . sCorpusStructure . SDocument ; public interface ResolverProvider { public ResolverEntry [ ] getResolverEntries ( SDocument result ) ; } </s>
<s> package annis . gui ; import annis . gui . beans . CorpusBrowserEntry ; import annis . gui . controlpanel . ControlPanel ; import annis . service . objects . AnnisAttribute ; import annis . service . objects . AnnisCorpus ; import com . sun . jersey . api . client . GenericType ; import com . sun . jersey . api . client . WebResource ; import com . vaadin . data . Item ; import com . vaadin . data . Property . ValueChangeEvent ; import com . vaadin . data . Property . ValueChangeListener ; import com . vaadin . data . util . BeanItemContainer ; import com . vaadin . data . util . DefaultItemSorter ; import com . vaadin . ui . Accordion ; import com . vaadin . ui . Panel ; import com . vaadin . ui . Table ; import com . vaadin . ui . Window . Notification ; import java . net . URLEncoder ; import java . util . * ; import org . slf4j . LoggerFactory ; public class CorpusBrowserPanel extends Panel { private static final org . slf4j . Logger log = LoggerFactory . getLogger ( CorpusBrowserPanel . class ) ; private static final long serialVersionUID = - <NUM_LIT> ; private AnnisCorpus corpus ; private Table tblNodeAnno ; private BeanItemContainer < CorpusBrowserEntry > containerNodeAnno ; private Table tblEdgeTypes ; private BeanItemContainer < CorpusBrowserEntry > containerEdgeType ; private Table tblEdgeAnno ; private BeanItemContainer < CorpusBrowserEntry > containerEdgeAnno ; private CitationLinkGenerator citationGenerator ; private ControlPanel controlPanel ; public CorpusBrowserPanel ( final AnnisCorpus corpus , ControlPanel controlPanel ) { super ( "<STR_LIT>" ) ; this . corpus = corpus ; this . controlPanel = controlPanel ; setSizeFull ( ) ; Accordion accordion = new Accordion ( ) ; setContent ( accordion ) ; accordion . setSizeFull ( ) ; containerNodeAnno = new BeanItemContainer < CorpusBrowserEntry > ( CorpusBrowserEntry . class ) ; containerNodeAnno . setItemSorter ( new ExampleSorter ( ) ) ; containerEdgeType = new BeanItemContainer < CorpusBrowserEntry > ( CorpusBrowserEntry . class ) ; containerEdgeType . setItemSorter ( new ExampleSorter ( ) ) ; containerEdgeAnno = new BeanItemContainer < CorpusBrowserEntry > ( CorpusBrowserEntry . class ) ; containerEdgeAnno . setItemSorter ( new ExampleSorter ( ) ) ; citationGenerator = new CitationLinkGenerator ( ) ; tblNodeAnno = new ExampleTable ( citationGenerator , containerNodeAnno ) ; tblNodeAnno . addListener ( new ExampleListener ( ) ) ; tblEdgeTypes = new ExampleTable ( citationGenerator , containerEdgeType ) ; tblEdgeTypes . addListener ( new ExampleListener ( ) ) ; tblEdgeAnno = new ExampleTable ( citationGenerator , containerEdgeAnno ) ; tblEdgeAnno . addListener ( new ExampleListener ( ) ) ; accordion . addTab ( tblNodeAnno , "<STR_LIT>" , null ) ; accordion . addTab ( tblEdgeTypes , "<STR_LIT>" , null ) ; accordion . addTab ( tblEdgeAnno , "<STR_LIT>" , null ) ; } @ Override public void attach ( ) { citationGenerator . setMainWindow ( getApplication ( ) . getMainWindow ( ) ) ; boolean stripNodeAnno = true ; boolean stripEdgeName = true ; boolean stripEdgeAnno = true ; HashSet < String > nodeAnnoNames = new HashSet < String > ( ) ; HashSet < String > edgeAnnoNames = new HashSet < String > ( ) ; HashSet < String > edgeNames = new HashSet < String > ( ) ; HashSet < String > fullEdgeNames = new HashSet < String > ( ) ; boolean hasDominance = false ; List < AnnisAttribute > attributes = fetchAnnos ( corpus . getName ( ) ) ; for ( AnnisAttribute a : attributes ) { if ( a . getType ( ) == AnnisAttribute . Type . node ) { String name = killNamespace ( a . getName ( ) ) ; if ( nodeAnnoNames . contains ( name ) ) { stripNodeAnno = false ; } nodeAnnoNames . add ( name ) ; } else if ( a . getType ( ) == AnnisAttribute . Type . edge ) { fullEdgeNames . add ( a . getEdgeName ( ) ) ; if ( a . getSubtype ( ) == AnnisAttribute . SubType . d ) { hasDominance = true ; } String annoName = killNamespace ( a . getName ( ) ) ; if ( edgeAnnoNames . contains ( annoName ) ) { stripEdgeAnno = false ; } edgeAnnoNames . add ( annoName ) ; } } for ( String edgeName : fullEdgeNames ) { String name = killNamespace ( edgeName ) ; if ( edgeNames . contains ( name ) ) { stripEdgeName = false ; } edgeNames . add ( name ) ; } if ( hasDominance ) { CorpusBrowserEntry cbe = new CorpusBrowserEntry ( ) ; cbe . setName ( "<STR_LIT>" ) ; cbe . setCorpus ( corpus ) ; cbe . setExample ( "<STR_LIT>" ) ; containerEdgeType . addBean ( cbe ) ; } for ( AnnisAttribute a : attributes ) { if ( a . getType ( ) == AnnisAttribute . Type . node ) { String name = stripNodeAnno ? killNamespace ( a . getName ( ) ) : a . getName ( ) ; CorpusBrowserEntry cbe = new CorpusBrowserEntry ( ) ; cbe . setName ( name ) ; cbe . setExample ( name + "<STR_LIT>" + getFirst ( a . getValueSet ( ) ) + "<STR_LIT:\">" ) ; cbe . setCorpus ( corpus ) ; containerNodeAnno . addBean ( cbe ) ; } else if ( a . getType ( ) == AnnisAttribute . Type . edge ) { CorpusBrowserEntry cbeEdgeType = new CorpusBrowserEntry ( ) ; String name = stripEdgeName ? killNamespace ( a . getEdgeName ( ) ) : a . getEdgeName ( ) ; cbeEdgeType . setName ( name ) ; cbeEdgeType . setCorpus ( corpus ) ; if ( a . getSubtype ( ) == AnnisAttribute . SubType . p ) { cbeEdgeType . setExample ( "<STR_LIT>" + killNamespace ( name ) + "<STR_LIT>" ) ; } else if ( a . getSubtype ( ) == AnnisAttribute . SubType . d ) { cbeEdgeType . setExample ( "<STR_LIT>" + killNamespace ( name ) + "<STR_LIT>" ) ; } containerEdgeType . addBean ( cbeEdgeType ) ; CorpusBrowserEntry cbeEdgeAnno = new CorpusBrowserEntry ( ) ; String edgeAnno = stripEdgeAnno ? killNamespace ( a . getName ( ) ) : a . getName ( ) ; cbeEdgeAnno . setName ( edgeAnno ) ; cbeEdgeAnno . setCorpus ( corpus ) ; if ( a . getSubtype ( ) == AnnisAttribute . SubType . p ) { cbeEdgeAnno . setExample ( "<STR_LIT>" + killNamespace ( a . getEdgeName ( ) ) + "<STR_LIT:[>" + killNamespace ( a . getName ( ) ) + "<STR_LIT>" + getFirst ( a . getValueSet ( ) ) + "<STR_LIT>" ) ; } else if ( a . getSubtype ( ) == AnnisAttribute . SubType . d ) { cbeEdgeAnno . setExample ( "<STR_LIT>" + killNamespace ( a . getName ( ) ) + "<STR_LIT>" + getFirst ( a . getValueSet ( ) ) + "<STR_LIT>" ) ; } containerEdgeAnno . addBean ( cbeEdgeAnno ) ; } } tblNodeAnno . setSortContainerPropertyId ( "<STR_LIT:name>" ) ; tblEdgeTypes . setSortContainerPropertyId ( "<STR_LIT:name>" ) ; tblEdgeAnno . setSortContainerPropertyId ( "<STR_LIT:name>" ) ; super . attach ( ) ; } private List < AnnisAttribute > fetchAnnos ( String toplevelCorpus ) { Collection < AnnisAttribute > result = new ArrayList < AnnisAttribute > ( ) ; try { WebResource service = Helper . getAnnisWebResource ( getApplication ( ) ) ; if ( service != null ) { WebResource query = service . path ( "<STR_LIT>" ) . path ( URLEncoder . encode ( toplevelCorpus , "<STR_LIT:UTF-8>" ) ) . path ( "<STR_LIT>" ) . queryParam ( "<STR_LIT>" , "<STR_LIT:true>" ) . queryParam ( "<STR_LIT>" , "<STR_LIT:true>" ) ; result = query . get ( new GenericType < List < AnnisAttribute > > ( ) { } ) ; } } catch ( Exception ex ) { log . error ( null , ex ) ; getWindow ( ) . showNotification ( "<STR_LIT>" + ex . getLocalizedMessage ( ) , Notification . TYPE_WARNING_MESSAGE ) ; } return new LinkedList < AnnisAttribute > ( result ) ; } public static class ExampleTable extends Table { public ExampleTable ( CitationLinkGenerator citationGenerator , BeanItemContainer < CorpusBrowserEntry > container ) { setContainerDataSource ( container ) ; addGeneratedColumn ( "<STR_LIT>" , citationGenerator ) ; setSizeFull ( ) ; setSelectable ( true ) ; setMultiSelect ( false ) ; setVisibleColumns ( new String [ ] { "<STR_LIT:name>" , "<STR_LIT>" , "<STR_LIT>" } ) ; setColumnHeaders ( new String [ ] { "<STR_LIT:Name>" , "<STR_LIT>" , "<STR_LIT>" } ) ; setColumnExpandRatio ( "<STR_LIT:name>" , <NUM_LIT> ) ; setColumnExpandRatio ( "<STR_LIT>" , <NUM_LIT> ) ; setImmediate ( true ) ; } } public class ExampleListener implements ValueChangeListener { @ Override public void valueChange ( ValueChangeEvent event ) { CorpusBrowserEntry cbe = ( CorpusBrowserEntry ) event . getProperty ( ) . getValue ( ) ; HashMap < String , AnnisCorpus > corpusMap = new HashMap < String , AnnisCorpus > ( ) ; corpusMap . put ( corpus . getName ( ) , corpus ) ; if ( controlPanel != null ) { controlPanel . setQuery ( cbe . getExample ( ) , corpusMap ) ; } } } public static class ExampleSorter extends DefaultItemSorter { @ Override protected int compareProperty ( Object propertyId , boolean sortDirection , Item item1 , Item item2 ) { if ( "<STR_LIT:name>" . equals ( propertyId ) ) { String val1 = ( String ) item1 . getItemProperty ( propertyId ) . getValue ( ) ; String val2 = ( String ) item2 . getItemProperty ( propertyId ) . getValue ( ) ; if ( sortDirection ) { return val1 . compareToIgnoreCase ( val2 ) ; } else { return val2 . compareToIgnoreCase ( val1 ) ; } } else { return super . compareProperty ( propertyId , sortDirection , item1 , item2 ) ; } } } private String killNamespace ( String qName ) { String [ ] splitted = qName . split ( "<STR_LIT::>" ) ; return splitted [ splitted . length - <NUM_LIT:1> ] ; } private String getFirst ( Collection < String > list ) { Iterator < String > it = list . iterator ( ) ; return it . hasNext ( ) ? it . next ( ) : null ; } } </s>
<s> package annis . gui . servlets ; import java . io . IOException ; import java . net . URI ; import java . net . URISyntaxException ; import javax . servlet . ServletException ; import javax . servlet . http . HttpServlet ; import javax . servlet . http . HttpServletRequest ; import javax . servlet . http . HttpServletResponse ; import org . slf4j . LoggerFactory ; public class CitationRedirectionServlet extends HttpServlet { private static final org . slf4j . Logger log = LoggerFactory . getLogger ( CitationRedirectionServlet . class ) ; @ Override protected void doGet ( HttpServletRequest req , HttpServletResponse resp ) throws ServletException , IOException { try { URI uri = new URI ( req . getRequestURI ( ) ) ; req . getSession ( ) . setAttribute ( "<STR_LIT>" , uri . getPath ( ) ) ; resp . sendRedirect ( req . getContextPath ( ) + "<STR_LIT>" ) ; } catch ( URISyntaxException ex ) { log . error ( null , ex ) ; resp . sendError ( <NUM_LIT> , ex . getMessage ( ) ) ; } } } </s>
<s> package annis . gui . servlets ; import annis . gui . visualizers . ResourcePlugin ; import java . io . * ; import java . net . URL ; import java . net . URLConnection ; import java . util . * ; import javax . servlet . ServletException ; import javax . servlet . http . HttpServlet ; import javax . servlet . http . HttpServletRequest ; import javax . servlet . http . HttpServletResponse ; import net . xeoh . plugins . base . Plugin ; import net . xeoh . plugins . base . annotations . PluginImplementation ; import net . xeoh . plugins . base . annotations . events . PluginLoaded ; import org . apache . commons . lang3 . StringUtils ; @ PluginImplementation public class ResourceServlet extends HttpServlet implements Plugin { private static final long serialVersionUID = - <NUM_LIT> ; private static final Map < String , ResourcePlugin > resourceRegistry = Collections . synchronizedMap ( new HashMap < String , ResourcePlugin > ( ) ) ; @ Override @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void doGet ( HttpServletRequest request , HttpServletResponse response ) throws ServletException , IOException { OutputStream outStream = response . getOutputStream ( ) ; String completePath = request . getPathInfo ( ) ; if ( completePath == null ) { response . sendError ( <NUM_LIT> , "<STR_LIT>" ) ; return ; } completePath = completePath . substring ( <NUM_LIT:1> ) ; String [ ] pathComponents = completePath . split ( "<STR_LIT:/>" ) ; String vistype = pathComponents [ <NUM_LIT:0> ] ; if ( pathComponents . length < <NUM_LIT:2> ) { response . sendError ( <NUM_LIT> , "<STR_LIT>" ) ; return ; } String path = StringUtils . join ( Arrays . copyOfRange ( pathComponents , <NUM_LIT:1> , pathComponents . length ) , "<STR_LIT:/>" ) ; ResourcePlugin vis = resourceRegistry . get ( vistype ) ; if ( vis == null ) { response . sendError ( <NUM_LIT> , "<STR_LIT>" + vistype ) ; } else if ( path . endsWith ( "<STR_LIT:.class>" ) ) { response . sendError ( <NUM_LIT> , "<STR_LIT>" ) ; } else { URL resource = vis . getClass ( ) . getResource ( path ) ; if ( resource == null ) { response . sendError ( <NUM_LIT> , path + "<STR_LIT>" ) ; } else { URLConnection resourceConnection = resource . openConnection ( ) ; long resourceLastModified = resourceConnection . getLastModified ( ) ; long requestLastModified = request . getDateHeader ( "<STR_LIT>" ) ; if ( requestLastModified != - <NUM_LIT:1> && resourceLastModified <= requestLastModified ) { response . setStatus ( HttpServletResponse . SC_NOT_MODIFIED ) ; } else { response . addDateHeader ( "<STR_LIT>" , resourceLastModified ) ; if ( "<STR_LIT:localhost>" . equals ( request . getServerName ( ) ) ) { response . addDateHeader ( "<STR_LIT>" , new Date ( ) . getTime ( ) ) ; } else { response . addDateHeader ( "<STR_LIT>" , new Date ( ) . getTime ( ) + <NUM_LIT> ) ; } String mimeType = getServletContext ( ) . getMimeType ( path ) ; response . setContentType ( mimeType ) ; if ( mimeType . startsWith ( "<STR_LIT>" ) ) { response . setCharacterEncoding ( "<STR_LIT:UTF-8>" ) ; } OutputStream bufferedOut = new BufferedOutputStream ( outStream ) ; InputStream resourceInStream = new BufferedInputStream ( resource . openStream ( ) ) ; try { int v = - <NUM_LIT:1> ; while ( ( v = resourceInStream . read ( ) ) != - <NUM_LIT:1> ) { bufferedOut . write ( v ) ; } } finally { resourceInStream . close ( ) ; bufferedOut . flush ( ) ; outStream . flush ( ) ; } } } } } @ PluginLoaded public void newResourceAdded ( ResourcePlugin vis ) { resourceRegistry . put ( vis . getShortName ( ) , vis ) ; } } </s>
<s> package annis . gui . servlets ; import annis . provider . SaltProjectProvider ; import annis . service . objects . AnnisBinary ; import annis . service . objects . AnnisBinaryMetaData ; import com . sun . jersey . api . client . Client ; import com . sun . jersey . api . client . ClientHandlerException ; import com . sun . jersey . api . client . UniformInterfaceException ; import com . sun . jersey . api . client . WebResource ; import com . sun . jersey . api . client . config . ClientConfig ; import com . sun . jersey . api . client . config . DefaultClientConfig ; import java . io . IOException ; import java . net . URLEncoder ; import java . rmi . RemoteException ; import java . util . Map ; import javax . servlet . ServletConfig ; import javax . servlet . ServletException ; import javax . servlet . ServletOutputStream ; import javax . servlet . http . HttpServlet ; import javax . servlet . http . HttpServletRequest ; import javax . servlet . http . HttpServletResponse ; import org . apache . commons . lang3 . Validate ; import org . slf4j . Logger ; import org . slf4j . LoggerFactory ; public class BinaryServlet extends HttpServlet { private final Logger log = LoggerFactory . getLogger ( BinaryServlet . class ) ; private static final int MAX_LENGTH = <NUM_LIT> * <NUM_LIT> ; private String toplevelCorpusName ; private String documentName ; private Client client ; @ Override public void init ( ServletConfig config ) throws ServletException { super . init ( config ) ; ClientConfig cc = new DefaultClientConfig ( SaltProjectProvider . class ) ; cc . getProperties ( ) . put ( ClientConfig . PROPERTY_THREADPOOL_SIZE , <NUM_LIT:10> ) ; cc . getProperties ( ) . put ( ClientConfig . PROPERTY_CONNECT_TIMEOUT , <NUM_LIT> ) ; client = Client . create ( cc ) ; } @ Override public void doGet ( HttpServletRequest request , HttpServletResponse response ) throws ServletException { Map < String , String [ ] > binaryParameter = request . getParameterMap ( ) ; toplevelCorpusName = binaryParameter . get ( "<STR_LIT>" ) [ <NUM_LIT:0> ] ; documentName = binaryParameter . get ( "<STR_LIT>" ) [ <NUM_LIT:0> ] ; ServletOutputStream out = null ; try { out = response . getOutputStream ( ) ; String range = request . getHeader ( "<STR_LIT>" ) ; String annisServiceURL = getServletContext ( ) . getInitParameter ( "<STR_LIT>" ) ; if ( annisServiceURL == null ) { throw new ServletException ( "<STR_LIT>" ) ; } WebResource annisRes = client . resource ( annisServiceURL ) ; WebResource binaryRes = annisRes . path ( "<STR_LIT>" ) . path ( URLEncoder . encode ( toplevelCorpusName , "<STR_LIT:UTF-8>" ) ) . path ( URLEncoder . encode ( documentName , "<STR_LIT:UTF-8>" ) ) . path ( "<STR_LIT>" ) ; if ( range != null ) { responseStatus206 ( binaryRes , out , response , range ) ; } else { responseStatus200 ( binaryRes , out , response ) ; } out . flush ( ) ; } catch ( IOException ex ) { log . debug ( "<STR_LIT>" , ex ) ; } catch ( ClientHandlerException ex ) { log . error ( null , ex ) ; response . setStatus ( <NUM_LIT> ) ; } catch ( UniformInterfaceException ex ) { log . error ( null , ex ) ; response . setStatus ( <NUM_LIT> ) ; } } private void responseStatus206 ( WebResource binaryRes , ServletOutputStream out , HttpServletResponse response , String range ) throws RemoteException , IOException { AnnisBinaryMetaData bm = binaryRes . path ( "<STR_LIT>" ) . get ( AnnisBinary . class ) ; String [ ] rangeTupel = range . split ( "<STR_LIT:->" ) ; int offset = Integer . parseInt ( rangeTupel [ <NUM_LIT:0> ] . split ( "<STR_LIT:=>" ) [ <NUM_LIT:1> ] ) ; int slice ; if ( rangeTupel . length > <NUM_LIT:1> ) { slice = Integer . parseInt ( rangeTupel [ <NUM_LIT:1> ] ) ; } else { slice = bm . getLength ( ) ; } int lengthToFetch = slice - offset ; response . setHeader ( "<STR_LIT>" , "<STR_LIT>" + offset + "<STR_LIT:->" + ( bm . getLength ( ) - <NUM_LIT:1> ) + "<STR_LIT:/>" + bm . getLength ( ) ) ; response . setContentType ( bm . getMimeType ( ) ) ; response . setStatus ( <NUM_LIT> ) ; response . setContentLength ( lengthToFetch ) ; writeStepByStep ( offset , lengthToFetch , binaryRes , out ) ; } private void responseStatus200 ( WebResource binaryRes , ServletOutputStream out , HttpServletResponse response ) throws RemoteException , IOException { AnnisBinaryMetaData binaryMeta = binaryRes . path ( "<STR_LIT>" ) . get ( AnnisBinary . class ) ; response . setStatus ( <NUM_LIT> ) ; response . setHeader ( "<STR_LIT>" , "<STR_LIT>" ) ; response . setContentType ( binaryMeta . getMimeType ( ) ) ; response . setHeader ( "<STR_LIT>" , "<STR_LIT>" + ( binaryMeta . getLength ( ) - <NUM_LIT:1> ) + "<STR_LIT:/>" + binaryMeta . getLength ( ) ) ; response . setContentLength ( binaryMeta . getLength ( ) ) ; getCompleteFile ( binaryRes , out ) ; } private void getCompleteFile ( WebResource binaryRes , ServletOutputStream out ) throws RemoteException , IOException { AnnisBinaryMetaData annisBinary = binaryRes . path ( "<STR_LIT>" ) . get ( AnnisBinary . class ) ; int offset = <NUM_LIT:0> ; int length = annisBinary . getLength ( ) ; writeStepByStep ( offset , length , binaryRes , out ) ; } private void writeStepByStep ( int offset , int completeLength , WebResource binaryRes , ServletOutputStream out ) throws IOException { int remaining = completeLength ; while ( remaining > <NUM_LIT:0> ) { int stepLength = Math . min ( MAX_LENGTH , remaining ) ; AnnisBinary bin = binaryRes . path ( "<STR_LIT>" + offset ) . path ( "<STR_LIT>" + stepLength ) . get ( AnnisBinary . class ) ; Validate . isTrue ( bin . getBytes ( ) . length == stepLength ) ; out . write ( bin . getBytes ( ) ) ; out . flush ( ) ; offset += stepLength ; remaining = remaining - stepLength ; } } } </s>
<s> package annis . gui ; import annis . gui . controlpanel . ControlPanel ; import annis . gui . media . MimeTypeErrorListener ; import annis . gui . querybuilder . TigerQueryBuilder ; import annis . gui . resultview . ResultViewPanel ; import annis . gui . tutorial . TutorialPanel ; import annis . security . AnnisSecurityManager ; import annis . security . AnnisUser ; import annis . security . SimpleSecurityManager ; import annis . service . objects . AnnisCorpus ; import com . vaadin . data . validator . EmailValidator ; import com . vaadin . event . ShortcutListener ; import com . vaadin . terminal . ParameterHandler ; import com . vaadin . terminal . ThemeResource ; import com . vaadin . terminal . gwt . server . WebApplicationContext ; import com . vaadin . terminal . gwt . server . WebBrowser ; import com . vaadin . ui . Button . ClickEvent ; import com . vaadin . ui . LoginForm . LoginEvent ; import com . vaadin . ui . * ; import com . vaadin . ui . themes . ChameleonTheme ; import java . util . * ; import java . util . regex . Matcher ; import java . util . regex . Pattern ; import javax . naming . AuthenticationException ; import javax . servlet . http . HttpSession ; import org . apache . commons . lang3 . StringUtils ; import org . netomi . vaadin . screenshot . Screenshot ; import org . slf4j . LoggerFactory ; public class SearchWindow extends Window implements LoginForm . LoginListener , Screenshot . ScreenshotListener , MimeTypeErrorListener { private static final org . slf4j . Logger log = LoggerFactory . getLogger ( SearchWindow . class ) ; private Pattern citationPattern = Pattern . compile ( "<STR_LIT>" , Pattern . MULTILINE | Pattern . DOTALL ) ; private Label lblUserName ; private Button btLoginLogout ; private Button btBugReport ; private ControlPanel control ; private TutorialPanel tutorial ; private TabSheet mainTab ; private Window windowLogin ; private ResultViewPanel resultView ; private AnnisSecurityManager securityManager ; private PluginSystem ps ; private TigerQueryBuilder queryBuilder ; private String bugEMailAddress ; private boolean warnedAboutMediaFormat = false ; public SearchWindow ( PluginSystem ps ) { super ( "<STR_LIT>" ) ; this . ps = ps ; setName ( "<STR_LIT>" ) ; getContent ( ) . setSizeFull ( ) ; ( ( VerticalLayout ) getContent ( ) ) . setMargin ( false ) ; HorizontalLayout layoutToolbar = new HorizontalLayout ( ) ; layoutToolbar . setWidth ( "<STR_LIT>" ) ; layoutToolbar . setHeight ( "<STR_LIT>" ) ; Panel panelToolbar = new Panel ( layoutToolbar ) ; panelToolbar . setWidth ( "<STR_LIT>" ) ; panelToolbar . setHeight ( "<STR_LIT>" ) ; addComponent ( panelToolbar ) ; panelToolbar . addStyleName ( "<STR_LIT>" ) ; Button btAboutAnnis = new Button ( "<STR_LIT>" ) ; btAboutAnnis . addStyleName ( ChameleonTheme . BUTTON_SMALL ) ; btAboutAnnis . setIcon ( new ThemeResource ( "<STR_LIT>" ) ) ; btAboutAnnis . addListener ( new Button . ClickListener ( ) { @ Override public void buttonClick ( ClickEvent event ) { Window w = new Window ( "<STR_LIT>" , new AboutPanel ( getApplication ( ) ) ) ; w . setModal ( true ) ; w . setResizable ( true ) ; w . setWidth ( "<STR_LIT>" ) ; w . setHeight ( "<STR_LIT>" ) ; addWindow ( w ) ; w . center ( ) ; } } ) ; final SearchWindow finalThis = this ; final Screenshot screenShot = new Screenshot ( ) ; screenShot . addListener ( finalThis ) ; addComponent ( screenShot ) ; btBugReport = new Button ( "<STR_LIT>" ) ; btBugReport . addStyleName ( ChameleonTheme . BUTTON_SMALL ) ; btBugReport . setDisableOnClick ( true ) ; btBugReport . setIcon ( new ThemeResource ( "<STR_LIT>" ) ) ; btBugReport . addListener ( new Button . ClickListener ( ) { @ Override public void buttonClick ( ClickEvent event ) { btBugReport . setCaption ( "<STR_LIT>" ) ; screenShot . makeScreenshot ( finalThis ) ; } } ) ; lblUserName = new Label ( "<STR_LIT>" ) ; lblUserName . setWidth ( "<STR_LIT>" ) ; lblUserName . setHeight ( "<STR_LIT>" ) ; lblUserName . addStyleName ( "<STR_LIT>" ) ; btLoginLogout = new Button ( "<STR_LIT>" , new Button . ClickListener ( ) { @ Override public void buttonClick ( ClickEvent event ) { if ( isLoggedIn ( ) ) { getApplication ( ) . setUser ( null ) ; showNotification ( "<STR_LIT>" , Window . Notification . TYPE_TRAY_NOTIFICATION ) ; } else { showLoginWindow ( ) ; } } } ) ; btLoginLogout . setSizeUndefined ( ) ; btLoginLogout . setStyleName ( ChameleonTheme . BUTTON_SMALL ) ; btLoginLogout . setIcon ( new ThemeResource ( "<STR_LIT>" ) ) ; layoutToolbar . addComponent ( btAboutAnnis ) ; layoutToolbar . addComponent ( btBugReport ) ; layoutToolbar . addComponent ( lblUserName ) ; layoutToolbar . addComponent ( btLoginLogout ) ; layoutToolbar . setSpacing ( true ) ; layoutToolbar . setComponentAlignment ( btAboutAnnis , Alignment . MIDDLE_LEFT ) ; layoutToolbar . setComponentAlignment ( lblUserName , Alignment . MIDDLE_RIGHT ) ; layoutToolbar . setComponentAlignment ( btLoginLogout , Alignment . MIDDLE_RIGHT ) ; layoutToolbar . setExpandRatio ( lblUserName , <NUM_LIT:1.0f> ) ; HorizontalLayout hLayout = new HorizontalLayout ( ) ; hLayout . setSizeFull ( ) ; Panel hPanel = new Panel ( hLayout ) ; hPanel . setSizeFull ( ) ; hPanel . setStyleName ( ChameleonTheme . PANEL_BORDERLESS ) ; addComponent ( hPanel ) ; ( ( VerticalLayout ) getContent ( ) ) . setExpandRatio ( hPanel , <NUM_LIT:1.0f> ) ; control = new ControlPanel ( this ) ; control . setWidth ( <NUM_LIT> , Layout . UNITS_EM ) ; control . setHeight ( <NUM_LIT> , Layout . UNITS_PERCENTAGE ) ; hLayout . addComponent ( control ) ; tutorial = new TutorialPanel ( ) ; mainTab = new TabSheet ( ) ; mainTab . setSizeFull ( ) ; mainTab . addTab ( tutorial , "<STR_LIT>" , null ) ; queryBuilder = new TigerQueryBuilder ( control ) ; mainTab . addTab ( queryBuilder , "<STR_LIT>" , null ) ; hLayout . addComponent ( mainTab ) ; hLayout . setExpandRatio ( mainTab , <NUM_LIT:1.0f> ) ; addAction ( new ShortcutListener ( "<STR_LIT>" ) { @ Override public void handleAction ( Object sender , Object target ) { mainTab . setSelectedTab ( queryBuilder ) ; } } ) ; addAction ( new ShortcutListener ( "<STR_LIT>" ) { @ Override public void handleAction ( Object sender , Object target ) { mainTab . setSelectedTab ( tutorial ) ; } } ) ; addParameterHandler ( new ParameterHandler ( ) { @ Override public void handleParameters ( Map < String , String [ ] > parameters ) { if ( parameters . containsKey ( "<STR_LIT>" ) ) { HttpSession session = ( ( WebApplicationContext ) getApplication ( ) . getContext ( ) ) . getHttpSession ( ) ; String citation = ( String ) session . getAttribute ( "<STR_LIT>" ) ; if ( citation != null ) { citation = StringUtils . removeStart ( citation , Helper . getContext ( getApplication ( ) ) + "<STR_LIT>" ) ; evaluateCitation ( citation ) ; session . removeAttribute ( "<STR_LIT>" ) ; } } } } ) ; } @ Override public void attach ( ) { super . attach ( ) ; String bugmail = getApplication ( ) . getProperty ( "<STR_LIT>" ) ; if ( bugmail != null && ! bugmail . isEmpty ( ) && ! bugmail . startsWith ( "<STR_LIT>" ) && new EmailValidator ( "<STR_LIT>" ) . isValid ( bugmail ) ) { this . bugEMailAddress = bugmail ; } btBugReport . setVisible ( this . bugEMailAddress != null ) ; initSecurityManager ( ) ; updateUserInformation ( ) ; } public void evaluateCitation ( String relativeUri ) { AnnisUser user = ( AnnisUser ) getApplication ( ) . getUser ( ) ; if ( user == null ) { return ; } Map < String , AnnisCorpus > userCorpora = user . getCorpusList ( ) ; Matcher m = citationPattern . matcher ( relativeUri ) ; if ( m . matches ( ) ) { String aql = "<STR_LIT>" ; if ( m . group ( <NUM_LIT:1> ) != null ) { aql = m . group ( <NUM_LIT:1> ) ; } HashMap < String , AnnisCorpus > selectedCorpora = new HashMap < String , AnnisCorpus > ( ) ; if ( m . group ( <NUM_LIT:2> ) != null ) { String [ ] cids = m . group ( <NUM_LIT:2> ) . split ( "<STR_LIT:U+002C>" ) ; for ( String name : cids ) { AnnisCorpus c = userCorpora . get ( name ) ; if ( c != null ) { selectedCorpora . put ( c . getName ( ) , c ) ; } } } if ( m . group ( <NUM_LIT:4> ) != null && m . group ( <NUM_LIT:6> ) != null ) { int cleft = <NUM_LIT:0> ; int cright = <NUM_LIT:0> ; try { cleft = Integer . parseInt ( m . group ( <NUM_LIT:4> ) ) ; cright = Integer . parseInt ( m . group ( <NUM_LIT:6> ) ) ; } catch ( NumberFormatException ex ) { log . error ( "<STR_LIT>" , ex ) ; } control . setQuery ( aql , selectedCorpora , cleft , cright ) ; } else { control . setQuery ( aql , selectedCorpora ) ; } Set < Window > all = new HashSet < Window > ( getChildWindows ( ) ) ; for ( Window w : all ) { removeWindow ( w ) ; } } else { showNotification ( "<STR_LIT>" , Notification . TYPE_WARNING_MESSAGE ) ; } } private void initSecurityManager ( ) { securityManager = new SimpleSecurityManager ( ) ; Enumeration < ? > parameterNames = getApplication ( ) . getPropertyNames ( ) ; Properties properties = new Properties ( ) ; while ( parameterNames . hasMoreElements ( ) ) { String name = ( String ) parameterNames . nextElement ( ) ; properties . put ( name , getApplication ( ) . getProperty ( name ) ) ; } securityManager . setProperties ( properties ) ; getApplication ( ) . setUser ( null ) ; } public void updateUserInformation ( ) { AnnisUser user = ( AnnisUser ) getApplication ( ) . getUser ( ) ; if ( btLoginLogout == null || lblUserName == null || user == null ) { return ; } if ( isLoggedIn ( ) ) { lblUserName . setValue ( "<STR_LIT>" + user . getUserName ( ) + "<STR_LIT:\">" ) ; btLoginLogout . setCaption ( "<STR_LIT>" ) ; } else { lblUserName . setValue ( "<STR_LIT>" ) ; btLoginLogout . setCaption ( "<STR_LIT>" ) ; } } public void showQueryResult ( String aql , Map < String , AnnisCorpus > corpora , int contextLeft , int contextRight , String segmentationLayer , int pageSize ) { warnedAboutMediaFormat = false ; if ( resultView != null ) { mainTab . removeComponent ( resultView ) ; } resultView = new ResultViewPanel ( aql , corpora , contextLeft , contextRight , segmentationLayer , pageSize , ps ) ; mainTab . addTab ( resultView , "<STR_LIT>" , null ) ; mainTab . setSelectedTab ( resultView ) ; } public void updateQueryCount ( int count ) { if ( resultView != null && count >= <NUM_LIT:0> ) { resultView . setCount ( count ) ; } } private void showLoginWindow ( ) { if ( windowLogin == null ) { LoginForm login = new LoginForm ( ) ; login . addListener ( ( LoginForm . LoginListener ) this ) ; windowLogin = new Window ( "<STR_LIT>" ) ; windowLogin . addComponent ( login ) ; windowLogin . setModal ( true ) ; windowLogin . setSizeUndefined ( ) ; login . setSizeUndefined ( ) ; ( ( VerticalLayout ) windowLogin . getContent ( ) ) . setSizeUndefined ( ) ; } addWindow ( windowLogin ) ; windowLogin . center ( ) ; } @ Override public void onLogin ( LoginEvent event ) { try { AnnisUser newUser = securityManager . login ( event . getLoginParameter ( "<STR_LIT:username>" ) , event . getLoginParameter ( "<STR_LIT:password>" ) , true ) ; getApplication ( ) . setUser ( newUser ) ; showNotification ( "<STR_LIT>" + newUser . getUserName ( ) + "<STR_LIT:\">" , Window . Notification . TYPE_TRAY_NOTIFICATION ) ; } catch ( AuthenticationException ex ) { showNotification ( "<STR_LIT>" + ex . getMessage ( ) , Window . Notification . TYPE_ERROR_MESSAGE ) ; } catch ( Exception ex ) { log . error ( null , ex ) ; showNotification ( "<STR_LIT>" + ex . getMessage ( ) , Window . Notification . TYPE_ERROR_MESSAGE ) ; } finally { removeWindow ( windowLogin ) ; } } public boolean isLoggedIn ( ) { AnnisUser u = ( AnnisUser ) getApplication ( ) . getUser ( ) ; if ( u == null || AnnisSecurityManager . FALLBACK_USER . equals ( u . getUserName ( ) ) ) { return false ; } else { return true ; } } @ Override public String getName ( ) { return "<STR_LIT>" ; } public AnnisSecurityManager getSecurityManager ( ) { return securityManager ; } public ControlPanel getControl ( ) { return control ; } @ Override public void screenshotReceived ( byte [ ] imageData ) { btBugReport . setEnabled ( true ) ; btBugReport . setCaption ( "<STR_LIT>" ) ; if ( bugEMailAddress != null ) { ReportBugPanel reportBugPanel = new ReportBugPanel ( getApplication ( ) , bugEMailAddress , imageData ) ; Window w = new Window ( "<STR_LIT>" , reportBugPanel ) ; w . setModal ( true ) ; w . setResizable ( true ) ; addWindow ( w ) ; w . center ( ) ; } } @ Override public void notifyCannotPlayMimeType ( String mimeType ) { if ( ! warnedAboutMediaFormat ) { String browserList = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; WebApplicationContext context = ( ( WebApplicationContext ) getApplication ( ) . getContext ( ) ) ; WebBrowser browser = context . getBrowser ( ) ; Set < String > supportedByIE9Plugin = new HashSet < String > ( ) ; supportedByIE9Plugin . add ( "<STR_LIT>" ) ; supportedByIE9Plugin . add ( "<STR_LIT>" ) ; supportedByIE9Plugin . add ( "<STR_LIT>" ) ; if ( browser . isIE ( ) && browser . getBrowserMajorVersion ( ) >= <NUM_LIT:9> && supportedByIE9Plugin . contains ( mimeType ) ) { getWindow ( ) . showNotification ( "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + browserList , Window . Notification . TYPE_ERROR_MESSAGE , true ) ; } else { getWindow ( ) . showNotification ( "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" + browserList , Window . Notification . TYPE_ERROR_MESSAGE , true ) ; } warnedAboutMediaFormat = true ; } } } </s>
<s> package annis . gui ; import annis . gui . beans . CitationProvider ; import com . vaadin . terminal . ThemeResource ; import com . vaadin . ui . Button ; import com . vaadin . ui . Button . ClickEvent ; import com . vaadin . ui . Table ; import com . vaadin . ui . Window ; import com . vaadin . ui . themes . BaseTheme ; public class CitationLinkGenerator implements Table . ColumnGenerator , Button . ClickListener { private Window mainWindow ; @ Override public Object generateCell ( Table source , Object itemId , Object columnId ) { Button btLink = new Button ( ) ; btLink . setStyleName ( BaseTheme . BUTTON_LINK ) ; btLink . setIcon ( new ThemeResource ( "<STR_LIT>" ) ) ; btLink . setDescription ( "<STR_LIT>" ) ; btLink . addListener ( this ) ; if ( itemId instanceof CitationProvider ) { final CitationProvider citationProvider = ( CitationProvider ) itemId ; btLink . addListener ( new Button . ClickListener ( ) { @ Override public void buttonClick ( ClickEvent event ) { if ( mainWindow == null ) { event . getButton ( ) . getWindow ( ) . showNotification ( "<STR_LIT>" , "<STR_LIT>" , Window . Notification . TYPE_ERROR_MESSAGE ) ; } else { if ( citationProvider != null ) { CitationWindow c = new CitationWindow ( mainWindow . getApplication ( ) , citationProvider . getQuery ( ) , citationProvider . getCorpora ( ) , citationProvider . getLeftContext ( ) , citationProvider . getRightContext ( ) ) ; mainWindow . addWindow ( c ) ; c . center ( ) ; } else { mainWindow . showNotification ( "<STR_LIT>" , "<STR_LIT>" , Window . Notification . TYPE_ERROR_MESSAGE ) ; } } } } ) ; } return btLink ; } public void setMainWindow ( Window mainWindow ) { this . mainWindow = mainWindow ; } @ Override public void buttonClick ( ClickEvent event ) { } } </s>
<s> package annis . gui . visualizers . iframe . tree ; import java . awt . geom . Rectangle2D ; public interface GraphicsItem { void setZValue ( int zValue ) ; void setParentItem ( GraphicsItem parent ) ; Rectangle2D getBounds ( ) ; } </s>
<s> package annis . gui . visualizers . iframe . tree ; public enum VerticalOrientation { TOP_ROOT ( <NUM_LIT:1> ) , BOTTOM_ROOT ( - <NUM_LIT:1> ) ; final int value ; private VerticalOrientation ( int v ) { value = v ; } } </s>
<s> package annis . gui . visualizers . iframe . tree ; class NodeStructureData { private int height ; private final NodeStructureData parent ; private boolean isContinuous ; private long leftCorner ; private long rightCorner ; private long leftmostImmediate = - <NUM_LIT:1> ; private long rightmostImmediate = - <NUM_LIT:1> ; private long arity = <NUM_LIT:0> ; private long tokenArity ; private int step = <NUM_LIT:0> ; public NodeStructureData ( NodeStructureData parent_ ) { parent = parent_ ; } public long getLeftCorner ( ) { return leftCorner ; } public void setLeftCorner ( long leftCorner ) { this . leftCorner = leftCorner ; } public long getRightCorner ( ) { return rightCorner ; } public void setRightCorner ( long rightCorner ) { this . rightCorner = rightCorner ; } public long getLeftmostImmediate ( ) { return leftmostImmediate ; } public void setLeftmostImmediate ( long leftmostImmediate ) { this . leftmostImmediate = leftmostImmediate ; } public long getRightmostImmediate ( ) { return rightmostImmediate ; } public void setRightmostImmediate ( long rightmostImmediate ) { this . rightmostImmediate = rightmostImmediate ; } public long getArity ( ) { return arity ; } public void setArity ( long arity ) { this . arity = arity ; } public long getTokenArity ( ) { return tokenArity ; } public void setTokenArity ( long tokenArity ) { this . tokenArity = tokenArity ; } public NodeStructureData getParent ( ) { return parent ; } public int getHeight ( ) { return height + step ; } public void setChildHeight ( int height ) { this . height = height ; } public boolean isContinuous ( ) { return isContinuous ; } public void setContinuous ( boolean isContinuous ) { this . isContinuous = isContinuous ; } public boolean encloses ( NodeStructureData other ) { return leftCorner < other . leftCorner && rightCorner > other . rightCorner ; } public void increaseStep ( ) { step += <NUM_LIT:1> ; parent . newChildHeight ( getHeight ( ) ) ; } public void setStep ( int newValue ) { step = newValue ; } private void newChildHeight ( int newHeight ) { if ( newHeight > this . height ) { setChildHeight ( newHeight ) ; if ( parent != null ) { parent . newChildHeight ( getHeight ( ) ) ; } } } public boolean canHaveVerticalOverlap ( ) { if ( arity == <NUM_LIT:0> ) { return getHeight ( ) + <NUM_LIT:1> < parent . getHeight ( ) ; } else { return isContinuous ; } } public boolean hasPredecessor ( NodeStructureData node ) { if ( node == parent ) { return true ; } else if ( parent == null ) { return false ; } else { return parent . hasPredecessor ( node ) ; } } public boolean hasVerticalEdgeConflict ( NodeStructureData other ) { return hasPredecessor ( other . parent ) ; } } </s>
<s> package annis . gui . visualizers . iframe . tree ; public class LayoutOptions { private final VerticalOrientation orientation ; private final HorizontalOrientation h_orientation ; public LayoutOptions ( VerticalOrientation vor , HorizontalOrientation hor ) { orientation = vor ; h_orientation = hor ; } public VerticalOrientation getOrientation ( ) { return orientation ; } public HorizontalOrientation getHorizontalOrientation ( ) { return h_orientation ; } } </s>
<s> package annis . gui . visualizers . iframe . tree ; public enum RectangleSide { TOP , LEFT , RIGHT , BOTTOM } </s>
<s> package annis . gui . visualizers . iframe . tree ; import annis . gui . visualizers . VisualizerInput ; import annis . gui . visualizers . iframe . tree . GraphicsBackend . Alignment ; import annis . model . AnnisNode ; import annis . model . Edge ; import edu . uci . ics . jung . graph . DirectedGraph ; import edu . uci . ics . jung . graph . util . Pair ; import java . awt . geom . CubicCurve2D ; import java . awt . geom . Line2D ; import java . awt . geom . Point2D ; import java . awt . geom . Rectangle2D ; import java . util . * ; public class ConstituentLayouter < T extends GraphicsItem > { private class TreeLayoutData { private double baseline ; private double ntStart ; private T parentItem ; private final Map < AnnisNode , Double > positions ; private final VerticalOrientation orientation ; private final List < Line2D > lines = new ArrayList < Line2D > ( ) ; private final OrderedNodeList nodeList = new OrderedNodeList ( styler . getVEdgeOverlapThreshold ( ) ) ; private final Map < AnnisNode , Rectangle2D > rectangles = new HashMap < AnnisNode , Rectangle2D > ( ) ; public void setBaseline ( double baseline ) { this . baseline = baseline ; } public TreeLayoutData ( VerticalOrientation orientation_ , Map < AnnisNode , Double > positions_ ) { positions = positions_ ; orientation = orientation_ ; } public VerticalOrientation getOrientation ( ) { return orientation ; } public double getYPosition ( AnnisNode node ) { return ntStart - orientation . value * dataMap . get ( node ) . getHeight ( ) * styler . getHeightStep ( ) ; } public Point2D getTokenPosition ( AnnisNode terminal ) { return new Point2D . Double ( positions . get ( terminal ) , baseline ) ; } public void addEdge ( Point2D from , Point2D to ) { getLines ( ) . add ( new Line2D . Double ( from , to ) ) ; } public void addNodeRect ( AnnisNode node , Rectangle2D nodeRect ) { rectangles . put ( node , nodeRect ) ; } public Point2D getDominanceConnector ( AnnisNode node , Rectangle2D bounds ) { if ( node . isToken ( ) ) { return new Point2D . Double ( bounds . getCenterX ( ) , ( orientation == VerticalOrientation . TOP_ROOT ) ? bounds . getMinY ( ) : bounds . getMaxY ( ) ) ; } else { return new Point2D . Double ( bounds . getCenterX ( ) , bounds . getCenterY ( ) ) ; } } public void setParentItem ( T parentItem ) { this . parentItem = parentItem ; } public T getParentItem ( ) { return parentItem ; } public void setNtStart ( double ntStart ) { this . ntStart = ntStart ; } public double getNtStart ( ) { return ntStart ; } public List < Line2D > getLines ( ) { return lines ; } public OrderedNodeList getNodeList ( ) { return nodeList ; } public Rectangle2D getRect ( AnnisNode source ) { return rectangles . get ( source ) ; } } private static final AnnisNode TOKEN_NODE = new AnnisNode ( ) ; static { TOKEN_NODE . setToken ( true ) ; } private final DirectedGraph < AnnisNode , Edge > graph ; private final AnnisNode root ; private final TreeElementLabeler labeler ; private final GraphicsBackend < T > backend ; private final Map < AnnisNode , NodeStructureData > dataMap ; private final TreeElementStyler styler ; private final VisualizerInput input ; public ConstituentLayouter ( DirectedGraph < AnnisNode , Edge > graph_ , GraphicsBackend < T > backend_ , TreeElementLabeler labeler_ , TreeElementStyler styler_ , VisualizerInput input_ ) { this . backend = backend_ ; this . labeler = labeler_ ; this . graph = graph_ ; this . styler = styler_ ; this . input = input_ ; root = findRoot ( ) ; dataMap = new HashMap < AnnisNode , NodeStructureData > ( ) ; fillHeightMap ( root , <NUM_LIT:0> , null ) ; adaptNodeHeights ( ) ; } private NodeStructureData fillHeightMap ( AnnisNode node , int height , NodeStructureData parent ) { if ( node . isToken ( ) ) { NodeStructureData structureData = new NodeStructureData ( parent ) ; structureData . setChildHeight ( <NUM_LIT:0> ) ; structureData . setTokenArity ( <NUM_LIT:1> ) ; structureData . setLeftCorner ( node . getTokenIndex ( ) . longValue ( ) ) ; structureData . setRightCorner ( node . getTokenIndex ( ) . longValue ( ) ) ; dataMap . put ( node , structureData ) ; return structureData ; } else { int maxH = <NUM_LIT:0> ; long leftCorner = Integer . MAX_VALUE ; long rightCorner = <NUM_LIT:0> ; boolean hasTokenChildren = false ; long leftmostImmediate = Integer . MAX_VALUE ; long rightmostImmediate = <NUM_LIT:0> ; int tokenArity = <NUM_LIT:0> ; int arity = <NUM_LIT:0> ; NodeStructureData structureData = new NodeStructureData ( parent ) ; for ( AnnisNode n : graph . getSuccessors ( node ) ) { NodeStructureData childData = fillHeightMap ( n , height + <NUM_LIT:1> , structureData ) ; maxH = Math . max ( childData . getHeight ( ) , maxH ) ; leftCorner = Math . min ( childData . getLeftCorner ( ) , leftCorner ) ; rightCorner = Math . max ( childData . getRightCorner ( ) , rightCorner ) ; tokenArity += childData . getTokenArity ( ) ; arity += <NUM_LIT:1> ; if ( n . isToken ( ) ) { hasTokenChildren = true ; leftmostImmediate = Math . min ( leftmostImmediate , childData . getLeftCorner ( ) ) ; rightmostImmediate = Math . max ( rightmostImmediate , childData . getLeftCorner ( ) ) ; } } structureData . setStep ( <NUM_LIT:1> ) ; structureData . setArity ( arity ) ; structureData . setTokenArity ( tokenArity ) ; structureData . setChildHeight ( maxH ) ; structureData . setLeftCorner ( leftCorner ) ; structureData . setRightCorner ( rightCorner ) ; structureData . setContinuous ( tokenArity == rightCorner - leftCorner + <NUM_LIT:1> ) ; if ( hasTokenChildren ) { structureData . setLeftmostImmediate ( leftmostImmediate ) ; structureData . setRightmostImmediate ( rightmostImmediate ) ; } dataMap . put ( node , structureData ) ; return structureData ; } } public void adaptNodeHeights ( ) { List < NodeStructureData > allNonterminals = new ArrayList < NodeStructureData > ( ) ; boolean allContinuous = true ; for ( AnnisNode n : this . graph . getVertices ( ) ) { if ( ! n . isToken ( ) ) { allNonterminals . add ( dataMap . get ( n ) ) ; allContinuous &= dataMap . get ( n ) . isContinuous ( ) ; } } if ( allContinuous ) { return ; } for ( int level = <NUM_LIT:1> ; ; level ++ ) { List < NodeStructureData > levelNodes = new ArrayList < NodeStructureData > ( ) ; for ( NodeStructureData n : allNonterminals ) { if ( n . getHeight ( ) == level ) { levelNodes . add ( n ) ; } } if ( levelNodes . isEmpty ( ) ) { return ; } Collections . sort ( levelNodes , new Comparator < NodeStructureData > ( ) { @ Override public int compare ( NodeStructureData o1 , NodeStructureData o2 ) { int o1k = o1 . isContinuous ( ) ? <NUM_LIT:1> : <NUM_LIT:0> ; int o2k = o2 . isContinuous ( ) ? <NUM_LIT:1> : <NUM_LIT:0> ; return o1k - o2k ; } } ) ; int d = findFirstContinuous ( levelNodes ) ; for ( int i = <NUM_LIT:0> ; i < d ; i ++ ) { NodeStructureData iNode = levelNodes . get ( i ) ; for ( int j = i + <NUM_LIT:1> ; j < levelNodes . size ( ) ; j ++ ) { NodeStructureData jNode = levelNodes . get ( j ) ; if ( iNode . getHeight ( ) != jNode . getHeight ( ) ) { continue ; } if ( jNode . isContinuous ( ) ) { if ( iNode . encloses ( jNode ) ) { iNode . increaseStep ( ) ; break ; } } else { bubbleNode ( iNode , jNode ) ; } } } } } private void bubbleNode ( NodeStructureData iNode , NodeStructureData jNode ) { if ( iNode . getLeftCorner ( ) < jNode . getLeftCorner ( ) && jNode . getLeftCorner ( ) < iNode . getRightCorner ( ) ) { if ( jNode . getRightCorner ( ) < iNode . getRightCorner ( ) ) { iNode . increaseStep ( ) ; } else if ( jNode . getLeftmostImmediate ( ) < iNode . getRightmostImmediate ( ) ) { NodeStructureData x = ( iNode . getArity ( ) < jNode . getArity ( ) ) ? iNode : jNode ; x . increaseStep ( ) ; } } else if ( jNode . getLeftCorner ( ) < iNode . getLeftCorner ( ) && jNode . getLeftCorner ( ) < jNode . getRightCorner ( ) ) { if ( iNode . getRightCorner ( ) < jNode . getRightCorner ( ) ) { jNode . increaseStep ( ) ; } else if ( iNode . getLeftmostImmediate ( ) < jNode . getRightmostImmediate ( ) ) { NodeStructureData x = ( iNode . getArity ( ) < jNode . getArity ( ) ) ? iNode : jNode ; x . increaseStep ( ) ; } } } private int findFirstContinuous ( List < NodeStructureData > levelNodes ) { for ( int d = <NUM_LIT:0> ; d < levelNodes . size ( ) ; d ++ ) { if ( levelNodes . get ( d ) . isContinuous ( ) ) { return d ; } } return levelNodes . size ( ) ; } private AnnisNode findRoot ( ) { for ( AnnisNode n : graph . getVertices ( ) ) { if ( graph . getInEdges ( n ) . isEmpty ( ) ) { return n ; } } throw new RuntimeException ( "<STR_LIT>" ) ; } private double computeTreeHeight ( ) { return ( dataMap . get ( root ) . getHeight ( ) ) * styler . getHeightStep ( ) + styler . getFont ( TOKEN_NODE ) . getLineHeight ( ) / <NUM_LIT:2> ; } private List < AnnisNode > getTokens ( LayoutOptions options ) { List < AnnisNode > tokens = new ArrayList < AnnisNode > ( ) ; for ( AnnisNode n : graph . getVertices ( ) ) { if ( n . isToken ( ) ) { tokens . add ( n ) ; } } Collections . sort ( tokens , options . getHorizontalOrientation ( ) . getComparator ( ) ) ; return tokens ; } private Map < AnnisNode , Double > computeTokenPositions ( LayoutOptions options , int padding ) { Map < AnnisNode , Double > positions = new HashMap < AnnisNode , Double > ( ) ; double x = <NUM_LIT:0> ; boolean first = true ; List < AnnisNode > leaves = getTokens ( options ) ; GraphicsBackend . Font tokenFont = styler . getFont ( leaves . get ( <NUM_LIT:0> ) ) ; for ( AnnisNode token : leaves ) { if ( first ) { first = false ; } else { x += styler . getTokenSpacing ( ) ; } positions . put ( token , x ) ; x += <NUM_LIT:2> * padding + tokenFont . extents ( labeler . getLabel ( token ) ) . getWidth ( ) ; } return positions ; } public T createLayout ( LayoutOptions options ) { TreeLayoutData treeLayout = new TreeLayoutData ( options . getOrientation ( ) , computeTokenPositions ( options , <NUM_LIT:5> ) ) ; treeLayout . setParentItem ( backend . group ( ) ) ; if ( options . getOrientation ( ) == VerticalOrientation . TOP_ROOT ) { treeLayout . setNtStart ( computeTreeHeight ( ) ) ; treeLayout . setBaseline ( treeLayout . getNtStart ( ) + styler . getFont ( TOKEN_NODE ) . getLineHeight ( ) ) ; } else { treeLayout . setBaseline ( styler . getFont ( TOKEN_NODE ) . getLineHeight ( ) ) ; treeLayout . setNtStart ( styler . getFont ( TOKEN_NODE ) . getLineHeight ( ) ) ; } calculateNodePosition ( root , treeLayout , options ) ; Edge e = getOutgoingEdges ( root ) . get ( <NUM_LIT:0> ) ; GraphicsItem edges = backend . makeLines ( treeLayout . getLines ( ) , styler . getEdgeColor ( e ) , styler . getStroke ( e ) ) ; edges . setZValue ( - <NUM_LIT:4> ) ; edges . setParentItem ( treeLayout . getParentItem ( ) ) ; addSecEdges ( treeLayout , options ) ; return treeLayout . getParentItem ( ) ; } private Point2D calculateNodePosition ( final AnnisNode current , TreeLayoutData treeLayout , LayoutOptions options ) { double y = treeLayout . getYPosition ( current ) ; List < Double > childPositions = new ArrayList < Double > ( ) ; for ( Edge e : getOutgoingEdges ( current ) ) { AnnisNode child = graph . getOpposite ( current , e ) ; Point2D childPos ; if ( child . isToken ( ) ) { childPos = addTerminalNode ( child , treeLayout ) ; } else { childPos = calculateNodePosition ( child , treeLayout , options ) ; } childPositions . add ( childPos . getX ( ) ) ; NodeStructureData childData = dataMap . get ( child ) ; if ( childData . canHaveVerticalOverlap ( ) ) { treeLayout . getNodeList ( ) . addVerticalEdgePosition ( childData , childPos ) ; } treeLayout . addEdge ( new Point2D . Double ( childPos . getX ( ) , y ) , childPos ) ; GraphicsItem label = backend . makeLabel ( labeler . getLabel ( e ) , new Point2D . Double ( childPos . getX ( ) , y + treeLayout . orientation . value * styler . getHeightStep ( ) * <NUM_LIT> ) , styler . getFont ( e ) , styler . getTextBrush ( e ) , Alignment . CENTERED , styler . getShape ( e ) ) ; label . setZValue ( <NUM_LIT:10> ) ; label . setParentItem ( treeLayout . parentItem ) ; } double xCenter = treeLayout . getNodeList ( ) . findBestPosition ( dataMap . get ( current ) , Collections . min ( childPositions ) , Collections . max ( childPositions ) ) ; GraphicsItem label = backend . makeLabel ( labeler . getLabel ( current ) , new Point2D . Double ( xCenter , y ) , styler . getFont ( current ) , styler . getTextBrush ( current ) , Alignment . CENTERED , styler . getShape ( current ) ) ; treeLayout . addNodeRect ( current , label . getBounds ( ) ) ; label . setZValue ( <NUM_LIT:11> ) ; label . setParentItem ( treeLayout . getParentItem ( ) ) ; treeLayout . addEdge ( new Point2D . Double ( Collections . min ( childPositions ) , y ) , new Point2D . Double ( Collections . max ( childPositions ) , y ) ) ; return treeLayout . getDominanceConnector ( current , label . getBounds ( ) ) ; } private Point2D addTerminalNode ( AnnisNode terminal , TreeLayoutData treeLayout ) { GraphicsItem label = backend . makeLabel ( labeler . getLabel ( terminal ) , treeLayout . getTokenPosition ( terminal ) , styler . getFont ( terminal ) , styler . getTextBrush ( terminal ) , Alignment . NONE , styler . getShape ( terminal ) ) ; label . setParentItem ( treeLayout . getParentItem ( ) ) ; treeLayout . addNodeRect ( terminal , label . getBounds ( ) ) ; return treeLayout . getDominanceConnector ( terminal , label . getBounds ( ) ) ; } private List < Edge > getOutgoingEdges ( final AnnisNode current ) { List < Edge > outEdges = new ArrayList < Edge > ( ) ; for ( Edge e : graph . getOutEdges ( current ) ) { if ( AnnisGraphTools . hasEdgeSubtype ( e , AnnisGraphTools . PRIMEDGE_SUBTYPE , input ) ) { outEdges . add ( e ) ; } } Collections . sort ( outEdges , new Comparator < Edge > ( ) { @ Override public int compare ( Edge o1 , Edge o2 ) { int h1 = dataMap . get ( graph . getOpposite ( current , o1 ) ) . getHeight ( ) ; int h2 = dataMap . get ( graph . getOpposite ( current , o2 ) ) . getHeight ( ) ; return h1 - h2 ; } } ) ; return outEdges ; } private CubicCurve2D secedgeCurve ( VerticalOrientation verticalOrientation , Rectangle2D sourceRect , Rectangle2D targetRect ) { Pair < RectangleSide > sidePair = findBestConnection ( sourceRect , targetRect ) ; Point2D startPoint = sideMidPoint ( sourceRect , sidePair . getFirst ( ) ) ; Point2D endPoint = sideMidPoint ( targetRect , sidePair . getSecond ( ) ) ; double middleX = ( startPoint . getX ( ) + endPoint . getX ( ) ) / <NUM_LIT> ; double middleY = <NUM_LIT> * - verticalOrientation . value + ( startPoint . getY ( ) + endPoint . getY ( ) ) / <NUM_LIT:2> ; return new CubicCurve2D . Double ( startPoint . getX ( ) , startPoint . getY ( ) , middleX , middleY , middleX , middleY , endPoint . getX ( ) , endPoint . getY ( ) ) ; } private Point2D sideMidPoint ( Rectangle2D rect , RectangleSide side ) { switch ( side ) { case TOP : return new Point2D . Double ( rect . getCenterX ( ) , rect . getMinY ( ) ) ; case BOTTOM : return new Point2D . Double ( rect . getCenterX ( ) , rect . getMaxY ( ) ) ; case LEFT : return new Point2D . Double ( rect . getMinX ( ) , rect . getCenterY ( ) ) ; case RIGHT : return new Point2D . Double ( rect . getMaxX ( ) , rect . getCenterY ( ) ) ; default : throw new RuntimeException ( ) ; } } private Pair < RectangleSide > findBestConnection ( Rectangle2D sourceRect , Rectangle2D targetRect ) { Pair < RectangleSide > result = null ; double minDist = Float . MAX_VALUE ; for ( RectangleSide orig : RectangleSide . values ( ) ) { for ( RectangleSide target : RectangleSide . values ( ) ) { Point2D o = sideMidPoint ( sourceRect , orig ) ; Point2D t = sideMidPoint ( targetRect , target ) ; double dist = Math . hypot ( o . getX ( ) - t . getX ( ) , t . getY ( ) - t . getY ( ) ) ; if ( dist < minDist ) { result = new Pair < RectangleSide > ( orig , target ) ; minDist = dist ; } } } return result ; } private void addSecEdges ( TreeLayoutData treeLayout , LayoutOptions options ) { for ( Edge e : graph . getEdges ( ) ) { if ( ! AnnisGraphTools . hasEdgeSubtype ( e , AnnisGraphTools . SECEDGE_SUBTYPE , input ) ) { continue ; } Rectangle2D sourceRect = treeLayout . getRect ( e . getSource ( ) ) ; Rectangle2D targetRect = treeLayout . getRect ( e . getDestination ( ) ) ; CubicCurve2D curveData = secedgeCurve ( treeLayout . getOrientation ( ) , sourceRect , targetRect ) ; T secedgeElem = backend . cubicCurve ( curveData , styler . getStroke ( e ) , styler . getEdgeColor ( e ) ) ; secedgeElem . setZValue ( - <NUM_LIT:2> ) ; T arrowElem = backend . arrow ( curveData . getP1 ( ) , curveData . getCtrlP1 ( ) , new Rectangle2D . Double ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:8> ) , styler . getEdgeColor ( e ) ) ; arrowElem . setZValue ( - <NUM_LIT:1> ) ; arrowElem . setParentItem ( secedgeElem ) ; Point2D labelPos = evaluate ( curveData , <NUM_LIT> ) ; T label = backend . makeLabel ( labeler . getLabel ( e ) , labelPos , styler . getFont ( e ) , styler . getTextBrush ( e ) , Alignment . CENTERED , styler . getShape ( e ) ) ; label . setParentItem ( secedgeElem ) ; secedgeElem . setParentItem ( treeLayout . getParentItem ( ) ) ; } } private Point2D evaluate ( CubicCurve2D curveData , double t ) { double u = <NUM_LIT:1> - t ; return new Point2D . Double ( curveData . getX1 ( ) * u * u * u + <NUM_LIT:3> * curveData . getCtrlX1 ( ) * t * u * u + <NUM_LIT:3> * curveData . getCtrlX2 ( ) * t * t * u + curveData . getX2 ( ) * t * t * t , curveData . getY1 ( ) * u * u * u + <NUM_LIT:3> * curveData . getCtrlY1 ( ) * t * u * u + <NUM_LIT:3> * curveData . getCtrlY2 ( ) * t * t * u + curveData . getY2 ( ) * t * t * t ) ; } } </s>
<s> package annis . gui . visualizers . iframe . tree ; import annis . model . AnnisNode ; import java . util . Comparator ; public enum HorizontalOrientation { LEFT_TO_RIGHT ( <NUM_LIT:1> ) , RIGHT_TO_LEFT ( - <NUM_LIT:1> ) ; private final int directionModifier ; HorizontalOrientation ( int directionModifier_ ) { directionModifier = directionModifier_ ; } Comparator < AnnisNode > getComparator ( ) { return new Comparator < AnnisNode > ( ) { @ Override public int compare ( AnnisNode o1 , AnnisNode o2 ) { return directionModifier * ( o1 . getTokenIndex ( ) . intValue ( ) - o2 . getTokenIndex ( ) . intValue ( ) ) ; } } ; } } </s>
<s> package annis . gui . visualizers . iframe . tree ; import annis . model . AnnisNode ; import annis . model . Edge ; public interface TreeElementLabeler { String getLabel ( AnnisNode n ) ; String getLabel ( Edge e ) ; } </s>
<s> package annis . gui . visualizers . iframe . tree ; import java . awt . Color ; import java . awt . Stroke ; import java . awt . geom . CubicCurve2D ; import java . awt . geom . Line2D ; import java . awt . geom . Point2D ; import java . awt . geom . Rectangle2D ; import java . util . Collection ; public interface GraphicsBackend < T extends GraphicsItem > { class Alignment { public static final Alignment NONE = new Alignment ( <NUM_LIT:0> , <NUM_LIT:0> ) ; public static final Alignment CENTERED = new Alignment ( <NUM_LIT> , <NUM_LIT> ) ; private final double x ; private final double y ; public Alignment ( double x , double y ) { super ( ) ; this . x = x ; this . y = y ; } public double getXAlign ( ) { return x ; } public double getYAlign ( ) { return y ; } } interface Font { Rectangle2D extents ( String string ) ; double getLineHeight ( ) ; public double getAscent ( ) ; } Font getFont ( String family , int pointSize , int style ) ; T group ( ) ; T makeLabel ( String label , Point2D pos , Font font , Color color , Alignment alignment , Shape shape ) ; T makeLines ( Collection < Line2D > lines , Color color , Stroke strokeStyle ) ; T cubicCurve ( CubicCurve2D curveData , Stroke strokeStyle , Color color ) ; T arrow ( Point2D tip , Point2D fromDirection , Rectangle2D dimensions , Color fillColor ) ; } </s>
<s> package annis . gui . visualizers . iframe . tree . backends . staticimg ; import annis . gui . visualizers . iframe . tree . GraphicsItem ; import java . awt . Graphics2D ; import java . util . ArrayList ; import java . util . Collection ; import java . util . List ; public abstract class AbstractImageGraphicsItem implements GraphicsItem { private List < AbstractImageGraphicsItem > children = new ArrayList < AbstractImageGraphicsItem > ( ) ; private int zValue ; public void addChildItem ( AbstractImageGraphicsItem childItem ) { children . add ( childItem ) ; } public abstract void draw ( Graphics2D canvas ) ; @ Override public void setParentItem ( GraphicsItem parent ) { ( ( AbstractImageGraphicsItem ) parent ) . addChildItem ( this ) ; } @ Override public void setZValue ( int newZValue ) { zValue = newZValue ; } public int getZValue ( ) { return zValue ; } public Collection < AbstractImageGraphicsItem > getChildren ( ) { return children ; } public void getAllChildren ( List < AbstractImageGraphicsItem > outputList ) { outputList . addAll ( children ) ; for ( AbstractImageGraphicsItem child : children ) { child . getAllChildren ( outputList ) ; } } } </s>
<s> package annis . gui . visualizers . iframe . tree . backends . staticimg ; import annis . gui . visualizers . iframe . tree . GraphicsBackend ; import annis . gui . visualizers . iframe . tree . Shape ; import java . awt . Color ; import java . awt . Graphics2D ; import java . awt . Stroke ; import java . awt . font . FontRenderContext ; import java . awt . font . LineMetrics ; import java . awt . font . TextLayout ; import java . awt . geom . * ; import java . util . Collection ; public class Java2dBackend implements GraphicsBackend < AbstractImageGraphicsItem > { public static final FontRenderContext FRC = new FontRenderContext ( new AffineTransform ( ) , true , true ) ; public static class Java2dFont implements GraphicsBackend . Font { private final java . awt . Font awtFont ; public Java2dFont ( String family , int pointSize , int style ) { awtFont = new java . awt . Font ( family , style , pointSize ) ; } @ Override public Rectangle2D extents ( String string ) { if ( string . isEmpty ( ) ) { return new Rectangle2D . Double ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) ; } else { TextLayout tl = new TextLayout ( string , awtFont , FRC ) ; return tl . getBounds ( ) ; } } public java . awt . Font getAwtFont ( ) { return awtFont ; } @ Override public double getLineHeight ( ) { return lineMetrics ( ) . getHeight ( ) ; } @ Override public double getAscent ( ) { return lineMetrics ( ) . getAscent ( ) ; } private LineMetrics lineMetrics ( ) { return awtFont . getLineMetrics ( "<STR_LIT>" , FRC ) ; } } ; @ Override public AbstractImageGraphicsItem group ( ) { return new GraphicsItemGroup ( ) ; } @ Override public AbstractImageGraphicsItem makeLabel ( String label , Point2D pos , Font font , Color color , Alignment alignment , Shape shape ) { return new LabelItem ( label , pos , ( Java2dFont ) font , color , alignment , shape ) ; } @ Override public Font getFont ( String family , int pointSize , int style ) { return new Java2dFont ( family , pointSize , style ) ; } @ Override public AbstractImageGraphicsItem makeLines ( final Collection < Line2D > lines , final Color color , final Stroke stroke ) { return new AbstractImageGraphicsItem ( ) { @ Override public Rectangle2D getBounds ( ) { return null ; } @ Override public void draw ( Graphics2D canvas ) { canvas . setColor ( color ) ; canvas . setStroke ( stroke ) ; for ( Line2D l : lines ) { canvas . draw ( l ) ; } } } ; } private double getRotationAngle ( Point2D origin , Point2D target ) { double l = Math . hypot ( origin . getX ( ) - target . getX ( ) , origin . getY ( ) - target . getY ( ) ) ; double x = Math . acos ( ( origin . getX ( ) - target . getX ( ) ) * Math . signum ( origin . getX ( ) - target . getX ( ) ) / l ) ; if ( origin . getX ( ) > target . getX ( ) ) { if ( origin . getY ( ) < target . getY ( ) ) { x = - x ; } x += Math . PI ; } else { if ( origin . getY ( ) > target . getY ( ) ) { x = - x ; } } return x ; } @ Override public AbstractImageGraphicsItem arrow ( final Point2D tip , Point2D fromPoint , Rectangle2D dimensions , final Color color ) { final GeneralPath path = new GeneralPath ( ) ; path . moveTo ( <NUM_LIT:0> , <NUM_LIT:0> ) ; path . lineTo ( dimensions . getHeight ( ) , dimensions . getWidth ( ) / <NUM_LIT:2> ) ; path . lineTo ( dimensions . getHeight ( ) , - dimensions . getWidth ( ) / <NUM_LIT:2> ) ; path . closePath ( ) ; final double angle = getRotationAngle ( tip , fromPoint ) ; return new AbstractImageGraphicsItem ( ) { @ Override public Rectangle2D getBounds ( ) { return new Rectangle2D . Double ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) ; } @ Override public void draw ( Graphics2D canvas ) { AffineTransform t = canvas . getTransform ( ) ; canvas . setColor ( color ) ; canvas . translate ( tip . getX ( ) , tip . getY ( ) ) ; canvas . rotate ( angle ) ; canvas . fill ( path ) ; canvas . setTransform ( t ) ; } } ; } @ Override public AbstractImageGraphicsItem cubicCurve ( final CubicCurve2D curveData , final Stroke strokeStyle , final Color color ) { return new AbstractImageGraphicsItem ( ) { @ Override public Rectangle2D getBounds ( ) { return curveData . getBounds2D ( ) ; } @ Override public void draw ( Graphics2D canvas ) { canvas . setStroke ( strokeStyle ) ; canvas . setColor ( color ) ; canvas . draw ( curveData ) ; } } ; } } </s>
<s> package annis . gui . visualizers . iframe . tree . backends . staticimg ; import annis . gui . visualizers . iframe . tree . GraphicsBackend . Alignment ; import annis . gui . visualizers . iframe . tree . Shape ; import annis . gui . visualizers . iframe . tree . backends . staticimg . Java2dBackend . Java2dFont ; import java . awt . Color ; import java . awt . Graphics2D ; import java . awt . font . GlyphMetrics ; import java . awt . geom . Point2D ; import java . awt . geom . Rectangle2D ; public class LabelItem extends AbstractImageGraphicsItem { private final java . awt . Font awtFont ; private final String label ; private final Point2D pos ; private final Color color ; private final Rectangle2D rect ; private Shape shape ; public LabelItem ( String label_ , Point2D pos_ , Java2dFont font , Color color_ , Alignment alignment , Shape shape_ ) { this . color = color_ ; this . label = label_ ; this . awtFont = font . getAwtFont ( ) ; GlyphMetrics gm = awtFont . createGlyphVector ( Java2dBackend . FRC , label . substring ( <NUM_LIT:0> , <NUM_LIT:1> ) ) . getGlyphMetrics ( <NUM_LIT:0> ) ; Rectangle2D size = font . extents ( label ) ; double text_x = pos_ . getX ( ) - size . getWidth ( ) * alignment . getXAlign ( ) ; double text_y = pos_ . getY ( ) + shape_ . getInternalYOffset ( label_ , font , alignment ) ; double rect_y = pos_ . getY ( ) + size . getHeight ( ) * alignment . getYAlign ( ) - ( font . getAscent ( ) + shape_ . getYPadding ( ) ) ; rect = new Rectangle2D . Double ( text_x + gm . getLSB ( ) - shape_ . getXPadding ( ) , rect_y , size . getWidth ( ) + <NUM_LIT:2> * shape_ . getXPadding ( ) , font . getLineHeight ( ) + <NUM_LIT:2> * shape_ . getYPadding ( ) ) ; this . pos = new Point2D . Double ( text_x - rect . getX ( ) , text_y - rect . getY ( ) ) ; this . shape = shape_ ; } @ Override public Rectangle2D getBounds ( ) { return rect ; } @ Override public void draw ( Graphics2D canvas ) { if ( shape instanceof Shape . Ellipse ) { canvas . setStroke ( shape . getPenStyle ( ) ) ; canvas . setColor ( shape . getFillColor ( ) ) ; canvas . fillOval ( ( int ) rect . getX ( ) , ( int ) rect . getY ( ) , ( int ) rect . getWidth ( ) , ( int ) rect . getHeight ( ) ) ; canvas . setColor ( shape . getStrokeColor ( ) ) ; canvas . drawOval ( ( int ) rect . getX ( ) , ( int ) rect . getY ( ) , ( int ) rect . getWidth ( ) , ( int ) rect . getHeight ( ) ) ; } else if ( shape instanceof Shape . Rectangle ) { canvas . setStroke ( shape . getPenStyle ( ) ) ; canvas . setColor ( shape . getFillColor ( ) ) ; canvas . fillRect ( ( int ) rect . getX ( ) , ( int ) rect . getY ( ) , ( int ) rect . getWidth ( ) , ( int ) rect . getHeight ( ) ) ; canvas . setColor ( shape . getStrokeColor ( ) ) ; canvas . drawRect ( ( int ) rect . getX ( ) , ( int ) rect . getY ( ) , ( int ) rect . getWidth ( ) , ( int ) rect . getHeight ( ) ) ; } canvas . setFont ( awtFont ) ; canvas . setColor ( color ) ; canvas . drawString ( this . label , ( float ) ( this . pos . getX ( ) + this . rect . getX ( ) ) , ( float ) ( this . pos . getY ( ) + this . rect . getY ( ) ) ) ; } } </s>
<s> package annis . gui . visualizers . iframe . tree . backends . staticimg ; import java . awt . Graphics2D ; import java . awt . geom . Rectangle2D ; public class GraphicsItemGroup extends AbstractImageGraphicsItem { @ Override public Rectangle2D getBounds ( ) { Rectangle2D r = new Rectangle2D . Double ( ) ; for ( AbstractImageGraphicsItem c : getChildren ( ) ) { Rectangle2D childBounds = c . getBounds ( ) ; if ( childBounds != null ) { r . add ( childBounds ) ; } } return r ; } @ Override public void draw ( Graphics2D canvas ) { } } </s>
<s> package annis . gui . visualizers . iframe . tree ; import java . awt . geom . Point2D ; import java . util . ArrayList ; import java . util . Collection ; import java . util . Collections ; import java . util . List ; public class OrderedNodeList { private final double minDistance ; private final List < NodeStructureData > nodes = new ArrayList < NodeStructureData > ( ) ; private final List < Double > points = new ArrayList < Double > ( ) ; public OrderedNodeList ( double minDistance_ ) { minDistance = minDistance_ ; } public void addVerticalEdgePosition ( NodeStructureData structData , Point2D pos ) { int idx = findInsertionIndex ( pos . getX ( ) ) ; nodes . add ( idx , structData ) ; points . add ( idx , pos . getX ( ) ) ; } private int findInsertionIndex ( double pos ) { int idx = Collections . binarySearch ( points , pos ) ; if ( idx < <NUM_LIT:0> ) { idx = - ( idx + <NUM_LIT:1> ) ; } return idx ; } public double findBestPosition ( NodeStructureData nodeStructureData , double minX , double maxX ) { double optimalPos = ( minX + maxX ) / <NUM_LIT:2> ; if ( nodeStructureData . isContinuous ( ) ) { return optimalPos ; } else if ( hasConflict ( nodeStructureData , optimalPos ) ) { double lastPos = minX ; double bestPos = minX + minDistance / <NUM_LIT:2> ; double bestDist = Integer . MAX_VALUE ; for ( double x : findConflicts ( nodeStructureData , minX , maxX ) ) { double space = Math . abs ( x - lastPos ) ; if ( space > <NUM_LIT:2> * minDistance ) { double regionOptimalPos = nearest ( optimalPos , lastPos + minDistance , x - minDistance ) ; double dist = Math . abs ( regionOptimalPos - optimalPos ) ; if ( dist < bestDist ) { bestPos = regionOptimalPos ; bestDist = dist ; } } lastPos = x ; } return bestPos ; } else { return optimalPos ; } } private double nearest ( double optimalPos , double min , double max ) { return Math . max ( min , Math . min ( max , optimalPos ) ) ; } private Collection < Double > findConflicts ( NodeStructureData nodeStructureData , double minX , double maxX ) { List < Double > result = new ArrayList < Double > ( ) ; for ( int pos : findInRegion ( minX , maxX ) ) { if ( nodeStructureData . hasVerticalEdgeConflict ( nodes . get ( pos ) ) ) { result . add ( points . get ( pos ) ) ; } } result . add ( maxX ) ; return result ; } private boolean hasConflict ( NodeStructureData nodeStructureData , double atPos ) { for ( int lower : findInRegion ( atPos - minDistance , atPos + minDistance ) ) { if ( nodeStructureData . hasVerticalEdgeConflict ( nodes . get ( lower ) ) ) { return true ; } } return false ; } private Collection < Integer > findInRegion ( double low , double high ) { int start = findInsertionIndex ( low ) ; int end = findInsertionIndex ( high ) ; List < Integer > l = new ArrayList < Integer > ( ) ; for ( int i = start ; i < end ; i ++ ) { l . add ( i ) ; } return l ; } } </s>
<s> package annis . gui . visualizers . iframe . tree ; import annis . gui . visualizers . iframe . tree . GraphicsBackend . Alignment ; import annis . gui . visualizers . iframe . tree . GraphicsBackend . Font ; import java . awt . Color ; import java . awt . Stroke ; public interface Shape { double getXPadding ( ) ; double getYPadding ( ) ; double getInternalYOffset ( String label , GraphicsBackend . Font font , GraphicsBackend . Alignment alignment ) ; Color getStrokeColor ( ) ; Color getFillColor ( ) ; Stroke getPenStyle ( ) ; abstract class AbstractShape implements Shape { private final double xPadding ; private final double yPadding ; private final Color stroke ; private final Color fill ; private final Stroke penStyle ; public AbstractShape ( double xPadding_ , double yPadding_ , Color stroke_ , Color fill_ , Stroke penStyle_ ) { this . xPadding = xPadding_ ; this . yPadding = yPadding_ ; this . stroke = stroke_ ; this . fill = fill_ ; this . penStyle = penStyle_ ; } @ Override public double getXPadding ( ) { return xPadding ; } @ Override public double getYPadding ( ) { return yPadding ; } public Color getStrokeColor ( ) { return stroke ; } public Color getFillColor ( ) { return fill ; } public Stroke getPenStyle ( ) { return penStyle ; } @ Override public double getInternalYOffset ( String label , Font font , Alignment alignment ) { return font . extents ( label ) . getHeight ( ) * alignment . getYAlign ( ) ; } } class Invisible extends AbstractShape { public Invisible ( double padding ) { super ( padding , padding , null , null , null ) ; } } class Rectangle extends AbstractShape { public Rectangle ( Color stroke , Color fill , Stroke penStyle , double padding ) { super ( padding , padding , stroke , fill , penStyle ) ; } } class Ellipse extends AbstractShape { public Ellipse ( Color stroke , Color fill , Stroke penStyle , double padding ) { super ( padding + <NUM_LIT:4> , padding , stroke , fill , penStyle ) ; } @ Override public double getInternalYOffset ( String label , Font font , Alignment alignment ) { return ( font . getLineHeight ( ) - font . getAscent ( ) * alignment . getYAlign ( ) ) * alignment . getYAlign ( ) ; } } } </s>
<s> package annis . gui . visualizers . iframe . tree ; import annis . gui . MatchedNodeColors ; import annis . gui . visualizers . AbstractIFrameVisualizer ; import annis . gui . visualizers . VisualizerInput ; import annis . gui . visualizers . iframe . tree . backends . staticimg . AbstractImageGraphicsItem ; import annis . gui . visualizers . iframe . tree . backends . staticimg . Java2dBackend ; import annis . model . AnnisNode ; import annis . model . Annotation ; import annis . model . Edge ; import annis . service . ifaces . AnnisResult ; import edu . uci . ics . jung . graph . DirectedGraph ; import java . awt . * ; import java . awt . geom . AffineTransform ; import java . awt . geom . Rectangle2D ; import java . awt . image . BufferedImage ; import java . io . IOException ; import java . io . OutputStream ; import java . util . List ; import java . util . * ; import javax . imageio . ImageIO ; import net . xeoh . plugins . base . annotations . PluginImplementation ; @ PluginImplementation public class TigerTreeVisualizer extends AbstractIFrameVisualizer { private VisualizerInput input = new VisualizerInput ( ) ; private static final int SIDE_MARGIN = <NUM_LIT:20> ; private static final int TOP_MARGIN = <NUM_LIT> ; private static final int TREE_DISTANCE = <NUM_LIT> ; private final Java2dBackend backend ; private final DefaultLabeler labeler ; private final DefaultStyler styler ; private final AnnisGraphTools graphtools ; public class DefaultStyler implements TreeElementStyler { private final BasicStroke DEFAULT_PEN_STYLE = new BasicStroke ( <NUM_LIT:1> ) ; public static final int LABEL_PADDING = <NUM_LIT:2> ; public static final int HEIGHT_STEP = <NUM_LIT> ; public static final int TOKEN_SPACING = <NUM_LIT:15> ; public static final int VEDGE_OVERLAP_THRESHOLD = <NUM_LIT:20> ; private final Java2dBackend backend ; public DefaultStyler ( Java2dBackend backend_ ) { backend = backend_ ; } public int getLabelPadding ( ) { return LABEL_PADDING ; } public GraphicsBackend . Font getFont ( AnnisNode n ) { if ( n . isToken ( ) ) { return backend . getFont ( Font . SANS_SERIF , <NUM_LIT:12> , java . awt . Font . PLAIN ) ; } else { return backend . getFont ( Font . SANS_SERIF , <NUM_LIT:15> , java . awt . Font . BOLD ) ; } } public GraphicsBackend . Font getFont ( Edge e ) { return backend . getFont ( Font . SANS_SERIF , <NUM_LIT:10> , java . awt . Font . PLAIN ) ; } @ Override public Shape getShape ( AnnisNode n ) { if ( isQueryMatch ( n ) ) { String backColorName = input . getMarkableMap ( ) . get ( "<STR_LIT>" + n . getId ( ) ) ; Color backColor = Color . RED ; try { backColor = MatchedNodeColors . valueOf ( backColorName ) . getColor ( ) ; } catch ( IllegalArgumentException ex ) { } if ( n . isToken ( ) ) { return new Shape . Rectangle ( Color . WHITE , backColor , DEFAULT_PEN_STYLE , getLabelPadding ( ) ) ; } else { return new Shape . Ellipse ( Color . WHITE , backColor , DEFAULT_PEN_STYLE , getLabelPadding ( ) ) ; } } else { if ( n . isToken ( ) ) { return new Shape . Invisible ( getLabelPadding ( ) ) ; } else { return new Shape . Ellipse ( Color . BLACK , Color . WHITE , DEFAULT_PEN_STYLE , getLabelPadding ( ) ) ; } } } private boolean isQueryMatch ( AnnisNode n ) { return input . getMarkableExactMap ( ) . containsKey ( Long . toString ( n . getId ( ) ) ) ; } @ Override public Shape getShape ( Edge e ) { if ( AnnisGraphTools . hasEdgeSubtype ( e , AnnisGraphTools . SECEDGE_SUBTYPE , input ) ) { return new Shape . Rectangle ( getEdgeColor ( e ) , Color . WHITE , DEFAULT_PEN_STYLE , getLabelPadding ( ) ) ; } else { return new Shape . Rectangle ( new Color ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) , Color . WHITE , DEFAULT_PEN_STYLE , getLabelPadding ( ) ) ; } } @ Override public Color getTextBrush ( AnnisNode n ) { if ( isQueryMatch ( n ) ) { return Color . WHITE ; } else { return Color . BLACK ; } } @ Override public Color getTextBrush ( Edge n ) { return Color . BLACK ; } @ Override public int getHeightStep ( ) { return HEIGHT_STEP ; } @ Override public Color getEdgeColor ( Edge e ) { if ( AnnisGraphTools . hasEdgeSubtype ( e , AnnisGraphTools . SECEDGE_SUBTYPE , input ) ) { return new Color ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) ; } else { return new Color ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) ; } } @ Override public int getTokenSpacing ( ) { return TOKEN_SPACING ; } @ Override public int getVEdgeOverlapThreshold ( ) { return VEDGE_OVERLAP_THRESHOLD ; } @ Override public Stroke getStroke ( Edge e ) { if ( AnnisGraphTools . hasEdgeSubtype ( e , AnnisGraphTools . SECEDGE_SUBTYPE , input ) ) { return new BasicStroke ( <NUM_LIT:2> , BasicStroke . CAP_BUTT , BasicStroke . JOIN_MITER , <NUM_LIT:10> , new float [ ] { <NUM_LIT:2> , <NUM_LIT:2> } , <NUM_LIT:0> ) ; } else { return new BasicStroke ( <NUM_LIT:2> ) ; } } } private class DefaultLabeler implements TreeElementLabeler { @ Override public String getLabel ( AnnisNode n ) { if ( n . isToken ( ) ) { String spannedText = n . getSpannedText ( ) ; if ( spannedText == null || "<STR_LIT>" . equals ( spannedText ) ) { spannedText = "<STR_LIT:U+0020>" ; } return spannedText ; } else { return extractAnnotation ( n . getNodeAnnotations ( ) , input . getMappings ( ) . getProperty ( "<STR_LIT>" , input . getNamespace ( ) ) , input . getMappings ( ) . getProperty ( "<STR_LIT>" , "<STR_LIT>" ) ) ; } } @ Override public String getLabel ( Edge e ) { return extractAnnotation ( e . getAnnotations ( ) , input . getMappings ( ) . getProperty ( "<STR_LIT>" , input . getNamespace ( ) ) , input . getMappings ( ) . getProperty ( "<STR_LIT>" , "<STR_LIT>" ) ) ; } private String extractAnnotation ( Set < Annotation > annotations , String namespace , String featureName ) { for ( Annotation a : annotations ) { if ( a . getNamespace ( ) . equals ( namespace ) && a . getName ( ) . equals ( featureName ) ) { return a . getValue ( ) ; } } return "<STR_LIT:-->" ; } } public TigerTreeVisualizer ( ) { backend = new Java2dBackend ( ) ; labeler = new DefaultLabeler ( ) ; styler = new DefaultStyler ( backend ) ; graphtools = new AnnisGraphTools ( ) ; } @ Override public String getShortName ( ) { return "<STR_LIT>" ; } @ Override public void writeOutput ( VisualizerInput input , OutputStream outstream ) { this . input = input ; AnnisResult result = input . getResult ( ) ; List < AbstractImageGraphicsItem > layouts = new LinkedList < AbstractImageGraphicsItem > ( ) ; double width = <NUM_LIT:0> ; double maxheight = <NUM_LIT:0> ; for ( DirectedGraph < AnnisNode , Edge > g : graphtools . getSyntaxGraphs ( input ) ) { ConstituentLayouter < AbstractImageGraphicsItem > cl = new ConstituentLayouter < AbstractImageGraphicsItem > ( g , backend , labeler , styler , input ) ; AbstractImageGraphicsItem item = cl . createLayout ( new LayoutOptions ( VerticalOrientation . TOP_ROOT , AnnisGraphTools . detectLayoutDirection ( result . getGraph ( ) ) ) ) ; Rectangle2D treeSize = item . getBounds ( ) ; maxheight = Math . max ( maxheight , treeSize . getHeight ( ) ) ; width += treeSize . getWidth ( ) ; layouts . add ( item ) ; } BufferedImage image = new BufferedImage ( ( int ) ( width + ( layouts . size ( ) - <NUM_LIT:1> ) * TREE_DISTANCE + <NUM_LIT:2> * SIDE_MARGIN ) , ( int ) ( maxheight + <NUM_LIT:2> * TOP_MARGIN ) , BufferedImage . TYPE_INT_ARGB ) ; Graphics2D canvas = createCanvas ( image ) ; double xOffset = SIDE_MARGIN ; for ( AbstractImageGraphicsItem item : layouts ) { AffineTransform t = canvas . getTransform ( ) ; Rectangle2D bounds = item . getBounds ( ) ; canvas . translate ( xOffset , TOP_MARGIN + maxheight - bounds . getHeight ( ) ) ; renderTree ( item , canvas ) ; xOffset += bounds . getWidth ( ) + TREE_DISTANCE ; canvas . setTransform ( t ) ; } try { ImageIO . write ( image , "<STR_LIT>" , outstream ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } private void renderTree ( AbstractImageGraphicsItem item , Graphics2D canvas ) { List < AbstractImageGraphicsItem > allItems = new ArrayList < AbstractImageGraphicsItem > ( ) ; item . getAllChildren ( allItems ) ; Collections . sort ( allItems , new Comparator < AbstractImageGraphicsItem > ( ) { @ Override public int compare ( AbstractImageGraphicsItem o1 , AbstractImageGraphicsItem o2 ) { return o1 . getZValue ( ) - o2 . getZValue ( ) ; } } ) ; for ( AbstractImageGraphicsItem c : allItems ) { c . draw ( canvas ) ; } } private Graphics2D createCanvas ( BufferedImage image ) { Graphics2D canvas = ( Graphics2D ) image . getGraphics ( ) ; canvas . setRenderingHint ( RenderingHints . KEY_TEXT_ANTIALIASING , RenderingHints . VALUE_TEXT_ANTIALIAS_ON ) ; canvas . setRenderingHint ( RenderingHints . KEY_ANTIALIASING , RenderingHints . VALUE_ANTIALIAS_ON ) ; canvas . setRenderingHint ( RenderingHints . KEY_RENDERING , RenderingHints . VALUE_RENDER_QUALITY ) ; canvas . setRenderingHint ( RenderingHints . KEY_STROKE_CONTROL , RenderingHints . VALUE_STROKE_PURE ) ; return canvas ; } @ Override public String getContentType ( ) { return "<STR_LIT>" ; } @ Override public String getCharacterEncoding ( ) { return "<STR_LIT>" ; } } </s>
<s> package annis . gui . visualizers . iframe . tree ; import annis . gui . visualizers . iframe . tree . GraphicsBackend . Font ; import annis . model . AnnisNode ; import annis . model . Edge ; import java . awt . Color ; import java . awt . Stroke ; public interface TreeElementStyler { Font getFont ( AnnisNode n ) ; Font getFont ( Edge e ) ; Color getTextBrush ( AnnisNode n ) ; Color getTextBrush ( Edge n ) ; Color getEdgeColor ( Edge n ) ; Stroke getStroke ( Edge n ) ; Shape getShape ( AnnisNode n ) ; Shape getShape ( Edge e ) ; int getLabelPadding ( ) ; int getHeightStep ( ) ; int getTokenSpacing ( ) ; int getVEdgeOverlapThreshold ( ) ; } </s>
<s> package annis . gui . visualizers . iframe . tree ; import annis . gui . visualizers . VisualizerInput ; import annis . model . AnnisNode ; import annis . model . AnnotationGraph ; import annis . model . Edge ; import edu . uci . ics . jung . graph . DirectedGraph ; import edu . uci . ics . jung . graph . DirectedSparseGraph ; import java . util . ArrayList ; import java . util . List ; class AnnisGraphTools { public static final String PRIMEDGE_SUBTYPE = "<STR_LIT>" ; public static final String SECEDGE_SUBTYPE = "<STR_LIT>" ; public List < DirectedGraph < AnnisNode , Edge > > getSyntaxGraphs ( VisualizerInput input ) { AnnotationGraph ag = input . getResult ( ) . getGraph ( ) ; String namespace = input . getMappings ( ) . getProperty ( "<STR_LIT>" , input . getNamespace ( ) ) ; List < DirectedGraph < AnnisNode , Edge > > resultGraphs = new ArrayList < DirectedGraph < AnnisNode , Edge > > ( ) ; for ( AnnisNode n : ag . getNodes ( ) ) { if ( isRootNode ( n , namespace , input ) ) { resultGraphs . add ( extractGraph ( ag , n , input ) ) ; } } return resultGraphs ; } private boolean copyNode ( DirectedGraph < AnnisNode , Edge > graph , AnnisNode n , VisualizerInput input ) { boolean addToGraph = n . isToken ( ) ; for ( Edge e : n . getOutgoingEdges ( ) ) { if ( includeEdge ( e , input ) && copyNode ( graph , e . getDestination ( ) , input ) ) { addToGraph |= true ; graph . addEdge ( e , n , e . getDestination ( ) ) ; } } if ( addToGraph ) { graph . addVertex ( n ) ; } return addToGraph ; } private boolean isRootNode ( AnnisNode n , String namespace , VisualizerInput input ) { if ( ! n . getNamespace ( ) . equals ( namespace ) ) { return false ; } for ( Edge e : n . getIncomingEdges ( ) ) { if ( hasEdgeSubtype ( e , AnnisGraphTools . PRIMEDGE_SUBTYPE , input ) && e . getSource ( ) != null ) { return false ; } } return true ; } private DirectedGraph < AnnisNode , Edge > extractGraph ( AnnotationGraph ag , AnnisNode n , VisualizerInput input ) { DirectedGraph < AnnisNode , Edge > graph = new DirectedSparseGraph < AnnisNode , Edge > ( ) ; copyNode ( graph , n , input ) ; for ( Edge e : ag . getEdges ( ) ) { if ( hasEdgeSubtype ( e , AnnisGraphTools . SECEDGE_SUBTYPE , input ) && graph . containsVertex ( e . getDestination ( ) ) && graph . containsVertex ( e . getSource ( ) ) ) { graph . addEdge ( e , e . getSource ( ) , e . getDestination ( ) ) ; } } return graph ; } private boolean includeEdge ( Edge e , VisualizerInput input ) { return hasEdgeSubtype ( e , AnnisGraphTools . PRIMEDGE_SUBTYPE , input ) ; } public static boolean hasEdgeSubtype ( Edge e , String edgeSubtype , VisualizerInput input ) { String name = e . getName ( ) ; if ( PRIMEDGE_SUBTYPE . equals ( edgeSubtype ) ) { edgeSubtype = input . getMappings ( ) . getProperty ( "<STR_LIT>" ) != null ? input . getMappings ( ) . getProperty ( "<STR_LIT>" ) : PRIMEDGE_SUBTYPE ; } if ( SECEDGE_SUBTYPE . equals ( edgeSubtype ) ) { edgeSubtype = input . getMappings ( ) . getProperty ( "<STR_LIT>" ) != null ? input . getMappings ( ) . getProperty ( "<STR_LIT>" ) : SECEDGE_SUBTYPE ; } return e . getEdgeType ( ) == Edge . EdgeType . DOMINANCE && name != null && name . equals ( edgeSubtype ) ; } public static HorizontalOrientation detectLayoutDirection ( AnnotationGraph ag ) { int withHebrew = <NUM_LIT:0> ; for ( AnnisNode token : ag . getTokens ( ) ) { if ( isHebrewToken ( token . getSpannedText ( ) ) ) { withHebrew += <NUM_LIT:1> ; } } return ( withHebrew > ag . getTokens ( ) . size ( ) / <NUM_LIT:3> ) ? HorizontalOrientation . RIGHT_TO_LEFT : HorizontalOrientation . LEFT_TO_RIGHT ; } private static boolean isHebrewToken ( String text ) { for ( int i = <NUM_LIT:0> ; i < text . length ( ) ; ++ i ) { char c = text . charAt ( i ) ; if ( ( c >= <NUM_LIT> && c <= <NUM_LIT> ) || ( c >= <NUM_LIT> && c <= <NUM_LIT> ) || ( c >= <NUM_LIT> && c <= <NUM_LIT> ) ) { return true ; } } return false ; } } </s>
<s> package annis . gui . visualizers . iframe . graph ; import annis . gui . MatchedNodeColors ; import annis . gui . visualizers . component . AbstractDotVisualizer ; import annis . gui . visualizers . VisualizerInput ; import annis . model . AnnisNode ; import annis . model . Annotation ; import annis . model . Edge ; import java . util . * ; import net . xeoh . plugins . base . annotations . PluginImplementation ; @ PluginImplementation public class DotGraphVisualizer extends AbstractDotVisualizer { private VisualizerInput input ; private int scale = <NUM_LIT> ; private StringBuilder dot ; private boolean displayAllNamespaces = false ; private String requiredNodeNS ; private String requiredEdgeNS ; @ Override public String getShortName ( ) { return "<STR_LIT>" ; } @ Override public void createDotContent ( VisualizerInput input , StringBuilder sb ) { this . input = input ; displayAllNamespaces = Boolean . parseBoolean ( input . getMappings ( ) . getProperty ( "<STR_LIT>" , "<STR_LIT:false>" ) ) ; requiredNodeNS = input . getMappings ( ) . getProperty ( "<STR_LIT>" , input . getNamespace ( ) ) ; requiredEdgeNS = input . getMappings ( ) . getProperty ( "<STR_LIT>" , input . getNamespace ( ) ) ; if ( requiredEdgeNS == null && requiredNodeNS == null ) { displayAllNamespaces = true ; } dot = sb ; internalCreateDot ( ) ; } private void internalCreateDot ( ) { w ( "<STR_LIT>" ) ; w ( "<STR_LIT>" ) ; List < AnnisNode > token = new LinkedList < AnnisNode > ( ) ; for ( AnnisNode n : input . getResult ( ) . getGraph ( ) . getNodes ( ) ) { if ( n . isToken ( ) ) { token . add ( n ) ; } else { if ( testNode ( n ) ) { writeNode ( n ) ; } } } w ( "<STR_LIT>" + "<STR_LIT>" ) ; for ( AnnisNode tok : token ) { w ( "<STR_LIT:t>" ) ; writeNode ( tok ) ; } writeInvisibleTokenEdges ( token ) ; w ( "<STR_LIT>" ) ; for ( Edge e : input . getResult ( ) . getGraph ( ) . getEdges ( ) ) { if ( e != null && testEdge ( e ) ) { writeEdge ( e ) ; } } w ( "<STR_LIT:}>" ) ; } private void w ( String s ) { dot . append ( s ) ; } private void w ( long l ) { dot . append ( l ) ; } private boolean testNode ( AnnisNode node ) { if ( displayAllNamespaces ) { return true ; } if ( requiredNodeNS == null ) { return false ; } for ( Annotation anno : node . getNodeAnnotations ( ) ) { if ( requiredNodeNS . equals ( anno . getNamespace ( ) ) ) { return true ; } } for ( Annotation anno : node . getEdgeAnnotations ( ) ) { if ( requiredNodeNS . equals ( anno . getNamespace ( ) ) ) { return false ; } } return false ; } private void writeNode ( AnnisNode node ) { w ( "<STR_LIT:t>" ) ; w ( node . getId ( ) ) ; w ( "<STR_LIT>" ) ; w ( "<STR_LIT>" ) ; appendLabel ( node ) ; appendNodeAnnotations ( node ) ; w ( "<STR_LIT>" ) ; w ( "<STR_LIT>" ) ; w ( "<STR_LIT>" ) ; String colorAsString = input . getMarkableExactMap ( ) . get ( Long . toString ( node . getId ( ) ) ) ; if ( colorAsString != null ) { MatchedNodeColors color = MatchedNodeColors . valueOf ( colorAsString ) ; w ( color . getHTMLColor ( ) ) ; } else { w ( "<STR_LIT>" ) ; } w ( "<STR_LIT>" ) ; w ( "<STR_LIT>" ) ; } private void writeInvisibleTokenEdges ( List < AnnisNode > token ) { Collections . sort ( token , new Comparator < AnnisNode > ( ) { @ Override public int compare ( AnnisNode o1 , AnnisNode o2 ) { return o1 . getTokenIndex ( ) . compareTo ( o2 . getTokenIndex ( ) ) ; } } ) ; AnnisNode lastTok = null ; for ( AnnisNode tok : token ) { if ( lastTok != null ) { w ( "<STR_LIT>" ) ; w ( lastTok . getId ( ) ) ; w ( "<STR_LIT>" ) ; w ( tok . getId ( ) ) ; w ( "<STR_LIT>" ) ; } lastTok = tok ; } } private void appendLabel ( AnnisNode node ) { if ( node . isToken ( ) ) { w ( node . getSpannedText ( ) . replace ( "<STR_LIT:\">" , "<STR_LIT>" ) ) ; } else { w ( node . getQualifiedName ( ) ) ; } w ( "<STR_LIT>" ) ; } private void appendNodeAnnotations ( AnnisNode node ) { for ( Annotation anno : node . getNodeAnnotations ( ) ) { if ( displayAllNamespaces || requiredNodeNS . equals ( anno . getNamespace ( ) ) ) { w ( "<STR_LIT>" ) ; w ( anno . getQualifiedName ( ) ) ; w ( "<STR_LIT:=>" ) ; w ( anno . getValue ( ) . replace ( "<STR_LIT:\">" , "<STR_LIT>" ) ) ; } } } private boolean testEdge ( Edge edge ) { if ( displayAllNamespaces ) { return true ; } if ( requiredEdgeNS == null ) { return false ; } for ( Annotation anno : edge . getAnnotations ( ) ) { if ( requiredEdgeNS . equals ( anno . getNamespace ( ) ) ) { return true ; } } return false ; } private void writeEdge ( Edge edge ) { w ( "<STR_LIT:t>" ) ; w ( "<STR_LIT>" + ( edge . getSource ( ) == null ? "<STR_LIT:null>" : edge . getSource ( ) . getId ( ) ) ) ; w ( "<STR_LIT>" ) ; w ( "<STR_LIT>" + ( edge . getDestination ( ) == null ? "<STR_LIT:null>" : edge . getDestination ( ) . getId ( ) ) ) ; w ( "<STR_LIT>" ) ; if ( edge . getEdgeType ( ) == Edge . EdgeType . POINTING_RELATION ) { w ( "<STR_LIT>" ) ; } else if ( edge . getEdgeType ( ) == Edge . EdgeType . COVERAGE ) { w ( "<STR_LIT>" ) ; } w ( "<STR_LIT>" ) ; w ( edge . getNamespace ( ) ) ; w ( "<STR_LIT:.>" ) ; w ( edge . getName ( ) ) ; w ( "<STR_LIT>" ) ; Iterator < Annotation > itAnno = edge . getAnnotations ( ) . iterator ( ) ; while ( itAnno . hasNext ( ) ) { Annotation anno = itAnno . next ( ) ; w ( anno . getQualifiedName ( ) ) ; w ( "<STR_LIT:=>" ) ; w ( anno . getValue ( ) ) ; if ( itAnno . hasNext ( ) ) { w ( "<STR_LIT>" ) ; } } w ( "<STR_LIT:\">" ) ; w ( "<STR_LIT>" ) ; } } </s>
<s> package annis . gui . visualizers . iframe . graph ; import annis . gui . visualizers . VisualizerInput ; import annis . gui . visualizers . component . AbstractDotVisualizer ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCommon . resources . dot . Salt2DOT ; import java . io . File ; import java . io . IOException ; import java . io . Serializable ; import net . xeoh . plugins . base . annotations . PluginImplementation ; import org . apache . commons . io . FileUtils ; import org . eclipse . emf . common . util . URI ; import org . slf4j . Logger ; import org . slf4j . LoggerFactory ; @ PluginImplementation public class DebugVisualizer extends AbstractDotVisualizer implements Serializable { private final Logger log = LoggerFactory . getLogger ( DebugVisualizer . class ) ; @ Override public void createDotContent ( VisualizerInput input , StringBuilder sb ) { try { File tmpFile = File . createTempFile ( "<STR_LIT>" , "<STR_LIT>" ) ; tmpFile . deleteOnExit ( ) ; Salt2DOT converter = new Salt2DOT ( ) ; converter . salt2Dot ( input . getDocument ( ) . getSDocumentGraph ( ) , URI . createFileURI ( tmpFile . getCanonicalPath ( ) ) ) ; sb . append ( FileUtils . readFileToString ( tmpFile ) ) ; if ( ! tmpFile . delete ( ) ) { log . warn ( "<STR_LIT>" + tmpFile . getAbsolutePath ( ) ) ; } } catch ( IOException ex ) { log . error ( "<STR_LIT>" , ex ) ; } } @ Override public String getShortName ( ) { return "<STR_LIT>" ; } } </s>
<s> package annis . gui . visualizers . iframe . gridtree ; import annis . gui . visualizers . VisualizerInput ; import annis . gui . visualizers . iframe . WriterVisualizer ; import annis . model . AnnisNode ; import annis . model . Annotation ; import annis . model . AnnotationGraph ; import annis . model . Edge ; import java . io . IOException ; import java . io . Writer ; import java . util . ArrayList ; import java . util . Collections ; import java . util . List ; import net . xeoh . plugins . base . annotations . PluginImplementation ; @ PluginImplementation public class GridTreeVisualizer extends WriterVisualizer { final private String PROPERTY_KEY = "<STR_LIT>" ; private VisualizerInput input ; private class Span implements Comparable < Span > { Long left ; Long right ; AnnisNode root ; String anno ; int height ; long offset ; public Span ( AnnisNode root , long offset , int length , String anno ) { this . root = root ; this . offset = offset ; this . anno = anno ; left = ( root . getLeftToken ( ) < offset ) ? offset : root . getLeftToken ( ) ; right = ( root . getRightToken ( ) > offset + length ) ? offset + length : root . getRightToken ( ) ; calculateHeight ( root , <NUM_LIT:0> ) ; } @ Override public int compareTo ( Span sp ) { if ( this . height > sp . height ) { return <NUM_LIT:1> ; } if ( this . height == sp . height ) { if ( this . left > sp . right ) { return <NUM_LIT:1> ; } else { return - <NUM_LIT:1> ; } } return - <NUM_LIT:1> ; } private void calculateHeight ( AnnisNode current , int height ) { if ( current != null ) { for ( Edge incoming : current . getIncomingEdges ( ) ) { AnnisNode tmp = incoming . getSource ( ) ; if ( hasAnno ( tmp , anno ) ) { calculateHeight ( tmp , height + <NUM_LIT:1> ) ; } calculateHeight ( tmp , height ) ; } } this . height = Math . max ( this . height , height ) ; } @ Override public boolean equals ( Object obj ) { return super . equals ( obj ) ; } @ Override public int hashCode ( ) { return super . hashCode ( ) ; } public void colspan ( StringBuilder sb , String anno ) { String annoValue = getAnnoValue ( this . root , anno ) ; sb . append ( "<STR_LIT>" ) ; sb . append ( Math . abs ( this . right - this . left ) + <NUM_LIT:1> ) ; sb . append ( "<STR_LIT>" ) ; sb . append ( this . hashCode ( ) ) ; sb . append ( "<STR_LIT::>" ) ; sb . append ( left + <NUM_LIT:1> - offset ) ; sb . append ( "<STR_LIT:->" ) ; sb . append ( right + <NUM_LIT:1> - offset ) ; sb . append ( "<STR_LIT>" ) ; sb . append ( anno ) ; sb . append ( "<STR_LIT:=>" ) ; sb . append ( annoValue ) ; sb . append ( "<STR_LIT>" ) ; sb . append ( "<STR_LIT>" ) . append ( input . getMarkableExactMap ( ) . get ( Long . toString ( this . root . getId ( ) ) ) ) . append ( "<STR_LIT>" ) ; sb . append ( annoValue ) ; sb . append ( "<STR_LIT>" ) ; } public boolean isInIntervall ( long l ) { if ( this . left <= l && l <= this . right ) { return true ; } return false ; } } @ Override public String getShortName ( ) { return "<STR_LIT>" ; } @ Override public void writeOutput ( VisualizerInput input , Writer writer ) { ArrayList < Span > spans = new ArrayList < GridTreeVisualizer . Span > ( ) ; this . input = input ; try { writer . append ( "<STR_LIT>" ) ; writer . append ( "<STR_LIT>" + input . getResourcePath ( "<STR_LIT>" ) + "<STR_LIT>" ) ; writer . append ( "<STR_LIT>" + input . getResourcePath ( "<STR_LIT>" ) + "<STR_LIT>" ) ; writer . append ( "<STR_LIT>" + input . getResourcePath ( "<STR_LIT>" ) + "<STR_LIT>" ) ; writer . append ( "<STR_LIT>" + input . getResourcePath ( "<STR_LIT>" ) + "<STR_LIT>" ) ; writer . append ( "<STR_LIT>" + input . getResourcePath ( "<STR_LIT>" ) + "<STR_LIT>" ) ; writer . append ( "<STR_LIT>" + input . getResourcePath ( "<STR_LIT>" ) + "<STR_LIT>" ) ; writer . append ( "<STR_LIT>" ) ; writer . append ( "<STR_LIT>" ) ; writer . append ( findAnnotation ( input . getResult ( ) . getGraph ( ) , input , spans ) ) ; writer . append ( "<STR_LIT>" ) ; writer . append ( "<STR_LIT>" ) ; } catch ( IOException e ) { } } private String findAnnotation ( AnnotationGraph graph , VisualizerInput input , ArrayList < Span > spans ) { List < AnnisNode > nodes = graph . getNodes ( ) ; List < AnnisNode > result = graph . getTokens ( ) ; StringBuilder sb = new StringBuilder ( ) ; String anno = input . getMappings ( ) . getProperty ( PROPERTY_KEY ) ; anno = ( anno == null ) ? "<STR_LIT>" : anno ; anno = input . getNamespace ( ) + "<STR_LIT::>" + anno ; for ( AnnisNode n : nodes ) { if ( hasAnno ( n , anno ) ) { Span tmp = new Span ( n , result . get ( <NUM_LIT:0> ) . getTokenIndex ( ) , result . size ( ) , anno ) ; spans . add ( tmp ) ; } } Collections . sort ( spans ) ; htmlTableRow ( sb , result , spans , anno ) ; htmlTableRow ( sb , result ) ; return sb . toString ( ) ; } ; private String getAnnoValue ( AnnisNode n , String anno ) { for ( Annotation a : n . getNodeAnnotations ( ) ) { if ( a . getQualifiedName ( ) . equals ( anno ) ) { return a . getValue ( ) ; } } return null ; } private boolean hasAnno ( AnnisNode n , String annotation ) { if ( n == null ) { return false ; } for ( Annotation x : n . getNodeAnnotations ( ) ) { if ( x . getQualifiedName ( ) . equals ( annotation ) ) { return true ; } } return false ; } private void htmlTableRow ( StringBuilder sb , List < AnnisNode > result , ArrayList < Span > spans , String anno ) { int j = <NUM_LIT:0> ; while ( j < spans . size ( ) ) { Span tmp = spans . get ( j ) ; int level = tmp . height ; sb . append ( "<STR_LIT>" ) ; sb . append ( level ) ; sb . append ( "<STR_LIT>" ) ; for ( int i = <NUM_LIT:0> ; i < result . size ( ) ; i ++ ) { if ( j < spans . size ( ) ) { tmp = spans . get ( j ) ; } long index = i + result . get ( <NUM_LIT:0> ) . getTokenIndex ( ) ; if ( tmp . isInIntervall ( index ) && level == tmp . height ) { tmp . colspan ( sb , anno ) ; i += Math . abs ( tmp . right - tmp . left ) ; j ++ ; } else { sb . append ( "<STR_LIT>" ) ; } } sb . append ( "<STR_LIT>" ) ; } } private void htmlTableRow ( StringBuilder sb , List < AnnisNode > result ) { sb . append ( "<STR_LIT>" ) ; sb . append ( "<STR_LIT>" ) ; for ( AnnisNode n : result ) { sb . append ( "<STR_LIT>" ) . append ( n . getSpannedText ( ) ) . append ( "<STR_LIT>" ) ; } sb . append ( "<STR_LIT>" ) ; } } </s>
<s> package annis . gui . visualizers . iframe . partitur ; import annis . model . AnnisNode ; import annis . model . Annotation ; import annis . model . AnnotationGraph ; import annis . model . Edge ; import java . io . Serializable ; import java . util . * ; public class PartiturParser implements Serializable { private List < Token > token ; private Set < String > knownTiers ; private HashMap < String , String > tier2ns ; private TreeSet < String > nameslist ; private List < List < ResultElement > > resultlist ; public PartiturParser ( AnnotationGraph graph , String namespace ) { resultlist = new LinkedList < List < ResultElement > > ( ) ; nameslist = new TreeSet < String > ( ) ; for ( AnnisNode n : graph . getTokens ( ) ) { List < ResultElement > helper = new LinkedList < ResultElement > ( ) ; for ( Edge edge : n . getIncomingEdges ( ) ) { if ( edge . getEdgeType ( ) == Edge . EdgeType . COVERAGE ) { AnnisNode parentNode = edge . getSource ( ) ; if ( parentNode . getNamespace ( ) . equals ( namespace ) ) { for ( Annotation anno : parentNode . getNodeAnnotations ( ) ) { String newId = "<STR_LIT>" + parentNode . getId ( ) + "<STR_LIT:_>" + anno . getNamespace ( ) + "<STR_LIT:_>" + anno . getName ( ) ; helper . add ( new ResultElement ( newId , parentNode . getId ( ) , anno . getName ( ) , anno . getValue ( ) ) ) ; if ( ! nameslist . contains ( anno . getName ( ) ) ) { nameslist . add ( anno . getName ( ) ) ; } } } } } resultlist . add ( helper ) ; } token = new LinkedList < Token > ( ) ; knownTiers = new HashSet < String > ( ) ; tier2ns = new HashMap < String , String > ( ) ; for ( AnnisNode n : graph . getTokens ( ) ) { long tokenID = n . getId ( ) ; Token currentToken = new Token ( tokenID , new Hashtable < String , Event > ( ) , n . getSpannedText ( ) ) ; token . add ( currentToken ) ; for ( Edge edge : n . getIncomingEdges ( ) ) { if ( edge . getEdgeType ( ) == Edge . EdgeType . COVERAGE ) { AnnisNode parentNode = edge . getSource ( ) ; if ( parentNode . getNamespace ( ) . equals ( namespace ) ) { for ( Annotation anno : parentNode . getNodeAnnotations ( ) ) { Event newEvent = new Event ( parentNode . getId ( ) , anno . getValue ( ) ) ; currentToken . getTier2Event ( ) . put ( anno . getName ( ) , newEvent ) ; knownTiers . add ( anno . getName ( ) ) ; tier2ns . put ( anno . getName ( ) , anno . getNamespace ( ) ) ; } } } } } Iterator < Token > it = token . iterator ( ) ; Token current = it . hasNext ( ) ? it . next ( ) : null ; Token next = it . hasNext ( ) ? it . next ( ) : null ; Token last = null ; while ( current != null ) { current . setBefore ( last ) ; current . setAfter ( next ) ; last = current ; current = next ; next = it . hasNext ( ) ? it . next ( ) : null ; } } public TreeSet < String > getNameslist ( ) { return nameslist ; } public List < List < ResultElement > > getResultlist ( ) { return resultlist ; } public Set < String > getKnownTiers ( ) { return knownTiers ; } public String namespaceForTier ( String tier ) { return tier2ns . get ( tier ) ; } public List < Token > getToken ( ) { return token ; } public static class Token implements Serializable { private Map < String , Event > tier2Event ; private long id ; private String value ; private Token before ; private Token after ; public Token ( long id , Map < String , Event > tier2Event , String value ) { this . tier2Event = tier2Event ; this . id = id ; this . value = value ; before = null ; after = null ; } public Map < String , Event > getTier2Event ( ) { return tier2Event ; } public long getId ( ) { return id ; } public Token getAfter ( ) { return after ; } public void setAfter ( Token after ) { this . after = after ; } public Token getBefore ( ) { return before ; } public void setBefore ( Token before ) { this . before = before ; } public String getValue ( ) { return value ; } } public static class Event implements Serializable { private long id ; private String value ; public Event ( long id , String value ) { this . id = id ; this . value = value ; } public long getId ( ) { return id ; } public String getValue ( ) { return value ; } } public static class ResultElement implements Serializable { private String id ; private long nodeId ; private String name , value ; public String getName ( ) { return name ; } public String getId ( ) { return id ; } public String getValue ( ) { return value ; } public long getNodeId ( ) { return nodeId ; } ResultElement ( String id , long nodeId , String name , String value ) { this . id = id ; this . nodeId = nodeId ; this . name = name ; this . value = value ; } } } </s>
<s> package annis . gui . visualizers . iframe . partitur ; import annis . CommonHelper ; import annis . gui . visualizers . VisualizerInput ; import annis . gui . visualizers . iframe . WriterVisualizer ; import annis . model . AnnisNode ; import annis . service . ifaces . AnnisToken ; import java . io . IOException ; import java . io . Writer ; import java . util . ArrayList ; import java . util . Collections ; import java . util . HashSet ; import java . util . Iterator ; import java . util . LinkedHashSet ; import java . util . LinkedList ; import java . util . List ; import net . xeoh . plugins . base . annotations . PluginImplementation ; import org . apache . commons . lang3 . StringEscapeUtils ; import org . slf4j . LoggerFactory ; @ PluginImplementation public class PartiturVisualizer extends WriterVisualizer { private static final org . slf4j . Logger log = LoggerFactory . getLogger ( PartiturVisualizer . class ) ; private List < AnnisNode > nodes ; private List < AnnisNode > token ; public enum ElementType { begin , end , middle , single , noEvent } @ Override public String getShortName ( ) { return "<STR_LIT>" ; } @ Override public void writeOutput ( VisualizerInput input , Writer writer ) { try { nodes = input . getResult ( ) . getGraph ( ) . getNodes ( ) ; token = input . getResult ( ) . getGraph ( ) . getTokens ( ) ; PartiturParser partitur = new PartiturParser ( input . getResult ( ) . getGraph ( ) , input . getNamespace ( ) ) ; boolean isRTL = checkRTL ( input . getResult ( ) . getTokenList ( ) ) ; List < String > tierNames = new LinkedList < String > ( partitur . getKnownTiers ( ) ) ; Collections . sort ( tierNames ) ; LinkedHashSet < String > keys = new LinkedHashSet < String > ( ) ; String mapping = input . getMappings ( ) . getProperty ( "<STR_LIT>" ) ; if ( mapping == null ) { keys . addAll ( partitur . getNameslist ( ) ) ; } else { String [ ] splitted = mapping . split ( "<STR_LIT:U+002C>" ) ; for ( int k = <NUM_LIT:0> ; k < splitted . length ; k ++ ) { String s = splitted [ k ] . trim ( ) ; if ( partitur . getNameslist ( ) . contains ( s ) ) { keys . add ( s ) ; } } } writer . append ( "<STR_LIT>" ) ; writer . append ( "<STR_LIT>" + input . getResourcePath ( "<STR_LIT>" ) + "<STR_LIT>" ) ; writer . append ( "<STR_LIT>" + input . getResourcePath ( "<STR_LIT>" ) + "<STR_LIT>" ) ; writer . append ( "<STR_LIT>" + input . getResourcePath ( "<STR_LIT>" ) + "<STR_LIT>" ) ; writer . append ( "<STR_LIT>" + input . getResourcePath ( "<STR_LIT>" ) + "<STR_LIT>" ) ; writer . append ( "<STR_LIT>" + input . getResourcePath ( "<STR_LIT>" ) + "<STR_LIT>" ) ; writer . append ( "<STR_LIT>" + input . getResourcePath ( "<STR_LIT>" ) + "<STR_LIT>" ) ; writer . append ( "<STR_LIT>" + input . getResourcePath ( "<STR_LIT>" ) + "<STR_LIT>" ) ; writer . append ( "<STR_LIT>" + input . getResourcePath ( "<STR_LIT>" ) + "<STR_LIT>" ) ; writer . append ( "<STR_LIT>" ) ; writer . append ( convertToJavacSriptArray ( new LinkedList < String > ( ) ) ) ; writer . append ( "<STR_LIT>" ) ; int i = <NUM_LIT:0> ; for ( String levelName : tierNames ) { if ( keys . contains ( levelName ) ) { writer . append ( ( i ++ > <NUM_LIT:0> ? "<STR_LIT:U+002CU+0020>" : "<STR_LIT>" ) + "<STR_LIT:\">" + levelName + "<STR_LIT:\">" ) ; } } writer . append ( "<STR_LIT>" ) ; writer . append ( "<STR_LIT>" + input . getResourcePath ( "<STR_LIT>" ) + "<STR_LIT>" ) ; writer . append ( "<STR_LIT>" ) ; writer . append ( "<STR_LIT>" ) ; writer . append ( "<STR_LIT>" ) ; writer . append ( "<STR_LIT>" ) ; if ( isRTL ) { writer . append ( "<STR_LIT>" ) ; } else { writer . append ( "<STR_LIT>" ) ; } for ( String tier : keys ) { List < String > indexlist = new ArrayList < String > ( ) ; for ( List < PartiturParser . ResultElement > span : partitur . getResultlist ( ) ) { for ( PartiturParser . ResultElement strr : span ) { if ( strr . getName ( ) . equals ( tier ) && ! indexlist . contains ( strr . getId ( ) ) ) { indexlist . add ( strr . getId ( ) ) ; } } } String [ ] currentarray ; while ( ! indexlist . isEmpty ( ) ) { List < String > currentdontuselist = new LinkedList < String > ( ) ; writer . append ( "<STR_LIT>" + tier + "<STR_LIT>" + tier + "<STR_LIT>" ) ; currentarray = new String [ partitur . getResultlist ( ) . size ( ) ] ; for ( int iterator3 = <NUM_LIT:0> ; iterator3 < partitur . getResultlist ( ) . size ( ) ; iterator3 ++ ) { currentarray [ iterator3 ] = null ; } int spanCounter = <NUM_LIT:0> ; for ( List < PartiturParser . ResultElement > span : partitur . getResultlist ( ) ) { for ( PartiturParser . ResultElement annotationelement : span ) { if ( indexlist . contains ( annotationelement . getId ( ) ) && ! currentdontuselist . contains ( annotationelement . getId ( ) ) ) { boolean neu = false ; if ( currentarray [ spanCounter ] == null ) { indexlist . remove ( annotationelement . getId ( ) ) ; currentarray [ spanCounter ] = annotationelement . getId ( ) ; neu = true ; } int span2Counter = <NUM_LIT:0> ; for ( List < PartiturParser . ResultElement > span2 : partitur . getResultlist ( ) ) { for ( PartiturParser . ResultElement strr2 : span2 ) { if ( strr2 . getId ( ) . equals ( annotationelement . getId ( ) ) && neu ) { if ( currentarray [ span2Counter ] == null ) { currentarray [ span2Counter ] = annotationelement . getId ( ) ; } } if ( span2Counter <= spanCounter && ! currentdontuselist . contains ( strr2 . getId ( ) ) ) { currentdontuselist . add ( strr2 . getId ( ) ) ; } } span2Counter ++ ; } } } spanCounter ++ ; } int length = <NUM_LIT:1> ; for ( int iterator5 = <NUM_LIT:0> ; iterator5 < currentarray . length ; iterator5 += length ) { StringBuffer tokenIdsArray = new StringBuffer ( ) ; StringBuffer eventIdsArray = new StringBuffer ( ) ; boolean unused = true ; length = <NUM_LIT:1> ; if ( currentarray [ iterator5 ] == null ) { writer . append ( "<STR_LIT>" ) ; } else { PartiturParser . ResultElement element = null ; HashSet < Integer > common = new HashSet < Integer > ( ) ; boolean found = false ; int outputSpanCounter = <NUM_LIT:0> ; for ( List < PartiturParser . ResultElement > outputSpan : partitur . getResultlist ( ) ) { for ( PartiturParser . ResultElement strr : outputSpan ) { if ( strr . getId ( ) . equals ( currentarray [ iterator5 ] ) ) { if ( ! found ) { element = strr ; } if ( ! common . contains ( outputSpanCounter ) ) { common . add ( outputSpanCounter ) ; } found = true ; if ( unused ) { tokenIdsArray . append ( "<STR_LIT>" + strr . getId ( ) + "<STR_LIT:_>" + outputSpanCounter ) ; eventIdsArray . append ( tier + "<STR_LIT:_>" + strr . getId ( ) + "<STR_LIT:_>" + outputSpanCounter ) ; unused = false ; } else { tokenIdsArray . append ( "<STR_LIT:U+002C>" + strr . getId ( ) + "<STR_LIT:_>" + outputSpanCounter ) ; eventIdsArray . append ( "<STR_LIT:U+002C>" + tier + "<STR_LIT:_>" + strr . getId ( ) + "<STR_LIT:_>" + outputSpanCounter ) ; } } } outputSpanCounter ++ ; } for ( int iterator7 = iterator5 + <NUM_LIT:1> ; iterator7 < currentarray . length ; iterator7 ++ ) { if ( common . contains ( iterator7 ) ) { length ++ ; } else { break ; } } for ( int iterator8 = <NUM_LIT:0> ; iterator8 < currentarray . length ; iterator8 ++ ) { if ( common . contains ( iterator8 ) ) { Long id = ( ( PartiturParser . Token ) partitur . getToken ( ) . toArray ( ) [ iterator8 ] ) . getId ( ) ; if ( unused ) { tokenIdsArray . append ( "<STR_LIT>" + id ) ; eventIdsArray . append ( tier + "<STR_LIT:_>" + id ) ; unused = false ; } else { tokenIdsArray . append ( "<STR_LIT:U+002C>" + id ) ; eventIdsArray . append ( "<STR_LIT:U+002C>" + tier + "<STR_LIT:_>" + id ) ; } } } String color = "<STR_LIT>" ; if ( input . getMarkableExactMap ( ) . containsKey ( "<STR_LIT>" + element . getNodeId ( ) ) ) { color = input . getMarkableExactMap ( ) . get ( "<STR_LIT>" + element . getNodeId ( ) ) ; } if ( found ) { writer . append ( "<STR_LIT>" + "<STR_LIT>" + tier + "<STR_LIT:_>" + element . getId ( ) + "<STR_LIT:_>" + iterator5 + "<STR_LIT>" + "<STR_LIT>" + color + "<STR_LIT>" + "<STR_LIT>" + length + "<STR_LIT:U+0020>" + "<STR_LIT>" + tokenIdsArray + "<STR_LIT>" + "<STR_LIT>" + eventIdsArray + "<STR_LIT>" + "<STR_LIT>" + partitur . namespaceForTier ( tier ) + "<STR_LIT::>" + tier + "<STR_LIT:U+0020=U+0020>" + StringEscapeUtils . escapeXml ( element . getValue ( ) ) + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + addTimeAttribute ( element . getNodeId ( ) ) + "<STR_LIT:>>" + element . getValue ( ) + "<STR_LIT>" ) ; } else { writer . append ( "<STR_LIT>" ) ; } } } writer . append ( "<STR_LIT>" ) ; } } writer . append ( "<STR_LIT>" ) ; for ( PartiturParser . Token token : partitur . getToken ( ) ) { String color = "<STR_LIT>" ; if ( input . getMarkableExactMap ( ) . containsKey ( "<STR_LIT>" + token . getId ( ) ) ) { color = input . getMarkableExactMap ( ) . get ( "<STR_LIT>" + token . getId ( ) ) ; } writer . append ( "<STR_LIT>" + color + "<STR_LIT>" + "<STR_LIT>" + token . getId ( ) + "<STR_LIT>" + "<STR_LIT:>>" + token . getValue ( ) + "<STR_LIT>" ) ; } writer . append ( "<STR_LIT>" ) ; writer . append ( "<STR_LIT>" ) ; writer . append ( "<STR_LIT>" ) ; writer . append ( "<STR_LIT>" ) ; } catch ( Exception ex ) { log . error ( null , ex ) ; try { String annisLine = "<STR_LIT>" ; for ( int i = <NUM_LIT:0> ; i < ex . getStackTrace ( ) . length ; i ++ ) { if ( ex . getStackTrace ( ) [ i ] . getClassName ( ) . startsWith ( "<STR_LIT>" ) ) { annisLine = ex . getStackTrace ( ) [ i ] . toString ( ) ; } } writer . append ( "<STR_LIT>" + ex . getClass ( ) . getName ( ) + "<STR_LIT>" + ex . getLocalizedMessage ( ) + "<STR_LIT>" + annisLine + "<STR_LIT>" ) ; } catch ( IOException ex1 ) { log . error ( null , ex1 ) ; } } } private ElementType getTypeForToken ( PartiturParser . Token token , String tier ) { PartiturParser . Token beforeToken = token . getBefore ( ) ; PartiturParser . Token afterToken = token . getAfter ( ) ; PartiturParser . Event event = token . getTier2Event ( ) . get ( tier ) ; if ( event != null ) { PartiturParser . Event beforeEvent = beforeToken == null ? null : beforeToken . getTier2Event ( ) . get ( tier ) ; PartiturParser . Event afterEvent = afterToken == null ? null : afterToken . getTier2Event ( ) . get ( tier ) ; boolean left = false ; boolean right = false ; if ( beforeEvent != null && beforeEvent . getId ( ) == event . getId ( ) ) { left = true ; } if ( afterEvent != null && afterEvent . getId ( ) == event . getId ( ) ) { right = true ; } if ( left && right ) { return ElementType . middle ; } else if ( left ) { return ElementType . end ; } else if ( right ) { return ElementType . begin ; } else { return ElementType . single ; } } return ElementType . noEvent ; } private boolean checkRTL ( List < AnnisToken > tokenList ) { Iterator < AnnisToken > itToken = tokenList . listIterator ( ) ; while ( itToken . hasNext ( ) ) { AnnisToken tok = itToken . next ( ) ; String tokText = tok . getText ( ) ; if ( CommonHelper . containsRTLText ( tokText ) ) { return true ; } } return false ; } private String convertToJavacSriptArray ( List < String > mediaIDs ) { if ( mediaIDs == null ) { return "<STR_LIT>" ; } StringBuilder sb = new StringBuilder ( "<STR_LIT>" ) ; int size = mediaIDs . size ( ) ; for ( int i = <NUM_LIT:0> ; i < size ; i ++ ) { sb . append ( "<STR_LIT:\">" ) ; sb . append ( mediaIDs . get ( i ) ) ; sb . append ( "<STR_LIT:\">" ) ; if ( ! ( size - <NUM_LIT:1> - i == <NUM_LIT:0> ) ) { sb . append ( "<STR_LIT:U+002CU+0020>" ) ; } } return sb . append ( "<STR_LIT>" ) . toString ( ) ; } private String addTimeAttribute ( long nodeId ) { DetectHoles detectHoles = new DetectHoles ( token ) ; AnnisNode root = null ; TimeHelper t = new TimeHelper ( token ) ; for ( AnnisNode n : nodes ) { if ( n . getId ( ) == nodeId ) { root = n ; break ; } } AnnisNode leftNode = detectHoles . getLeftBorder ( root ) ; AnnisNode rightNode = detectHoles . getRightBorder ( root ) ; return t . getTimeAnno ( leftNode , rightNode ) ; } } </s>
<s> package annis . gui . visualizers . iframe . partitur ; import annis . model . AnnisNode ; import java . util . List ; public class DetectHoles { private List < AnnisNode > token ; public DetectHoles ( List < AnnisNode > token ) { this . token = token ; } public AnnisNode getLeftBorder ( AnnisNode n ) { AnnisNode tmp = null ; for ( AnnisNode tok : token ) { if ( n . getLeftToken ( ) == tok . getTokenIndex ( ) ) { return tok ; } if ( n . getLeftToken ( ) <= tok . getTokenIndex ( ) && tmp == null ) { tmp = tok ; } } return tmp ; } public AnnisNode getRightBorder ( AnnisNode n ) { AnnisNode tmp = null ; for ( AnnisNode tok : token ) { if ( n . getRightToken ( ) == tok . getTokenIndex ( ) ) { return tok ; } if ( tok . getTokenIndex ( ) <= n . getRightToken ( ) ) { tmp = tok ; } } return tmp ; } } </s>
<s> package annis . gui . visualizers . iframe . partitur ; import annis . model . AnnisNode ; import annis . model . Annotation ; import java . util . List ; public class TimeHelper { private List < AnnisNode > token ; public TimeHelper ( ) { } public TimeHelper ( List < AnnisNode > token ) { this . token = token ; } public String getStartTime ( String time ) { return getTimePosition ( time , true ) ; } public String getEndTime ( String time ) { return getTimePosition ( time , false ) ; } private String getTimePosition ( String time , boolean first ) { if ( time == null ) { return "<STR_LIT>" ; } String [ ] splittedTimeAnno = time . split ( "<STR_LIT:->" ) ; if ( splittedTimeAnno . length > <NUM_LIT:1> ) { if ( first ) { return splittedTimeAnno [ <NUM_LIT:0> ] . equals ( "<STR_LIT>" ) ? "<STR_LIT>" : splittedTimeAnno [ <NUM_LIT:0> ] ; } else { return splittedTimeAnno [ <NUM_LIT:1> ] . equals ( "<STR_LIT>" ) ? "<STR_LIT>" : splittedTimeAnno [ <NUM_LIT:1> ] ; } } if ( first ) { return splittedTimeAnno [ <NUM_LIT:0> ] . equals ( "<STR_LIT>" ) ? "<STR_LIT>" : splittedTimeAnno [ <NUM_LIT:0> ] ; } return "<STR_LIT>" ; } String getTimeAnnotation ( AnnisNode node ) { for ( Annotation anno : node . getNodeAnnotations ( ) ) { if ( anno . getName ( ) . equals ( "<STR_LIT>" ) ) { return anno . getValue ( ) ; } } return "<STR_LIT>" ; } public String getTimeAnno ( AnnisNode leftNode , AnnisNode rightNode ) { String startTime = getStartTime ( getTimeAnnotation ( leftNode ) ) ; String endTime = getEndTime ( getTimeAnnotation ( rightNode ) ) ; if ( "<STR_LIT>" . equals ( startTime ) ) { return "<STR_LIT>" ; } if ( "<STR_LIT>" . equals ( endTime ) ) { endTime = getNextEndTime ( rightNode ) ; } return ( "<STR_LIT>" + startTime + "<STR_LIT:->" + endTime + "<STR_LIT:\">" ) ; } private String getNextEndTime ( AnnisNode rightNode ) { int offset = getOffset ( rightNode ) ; String time = null ; TimeHelper t = null ; for ( long i = offset + <NUM_LIT:1> ; i < token . size ( ) ; i ++ ) { for ( Annotation anno : token . get ( ( int ) i ) . getNodeAnnotations ( ) ) { if ( "<STR_LIT>" . equals ( anno . getName ( ) ) ) { time = anno . getValue ( ) ; break ; } } String startTime = getStartTime ( time ) ; String endTime = getEndTime ( time ) ; if ( startTime != null && ! "<STR_LIT>" . equals ( startTime ) ) { return startTime ; } if ( endTime != null && ! "<STR_LIT>" . equals ( endTime ) ) { return endTime ; } } return "<STR_LIT>" ; } private int getOffset ( AnnisNode rightNode ) { for ( int i = <NUM_LIT:0> ; i < token . size ( ) ; i ++ ) { if ( rightNode == token . get ( i ) ) { return i ; } } return <NUM_LIT:0> ; } } </s>
<s> package annis . gui . visualizers . iframe ; import annis . gui . visualizers . AbstractIFrameVisualizer ; import annis . gui . visualizers . VisualizerInput ; import java . io . * ; import java . util . logging . Level ; import java . util . logging . Logger ; import org . slf4j . LoggerFactory ; public abstract class WriterVisualizer extends AbstractIFrameVisualizer { private static final org . slf4j . Logger log = LoggerFactory . getLogger ( WriterVisualizer . class ) ; @ Override public void writeOutput ( VisualizerInput input , OutputStream outstream ) { try { OutputStreamWriter writer = new OutputStreamWriter ( outstream , getCharacterEncoding ( ) ) ; writeOutput ( input , writer ) ; writer . flush ( ) ; } catch ( IOException ex ) { log . error ( "<STR_LIT>" , ex ) ; StringWriter strWriter = new StringWriter ( ) ; ex . printStackTrace ( new PrintWriter ( strWriter ) ) ; try { outstream . write ( strWriter . toString ( ) . getBytes ( "<STR_LIT:UTF-8>" ) ) ; } catch ( IOException ex1 ) { log . error ( null , ex ) ; } } } public abstract void writeOutput ( VisualizerInput input , Writer writer ) ; } </s>
<s> package annis . gui . visualizers . iframe . dependency ; import annis . gui . visualizers . VisualizerInput ; import annis . gui . visualizers . iframe . WriterVisualizer ; import annis . model . AnnisNode ; import annis . model . Annotation ; import annis . model . Edge ; import annis . service . ifaces . AnnisResult ; import java . io . IOException ; import java . io . Writer ; import java . util . HashMap ; import java . util . Set ; import net . xeoh . plugins . base . annotations . PluginImplementation ; import org . json . JSONException ; import org . json . JSONObject ; import org . slf4j . LoggerFactory ; @ PluginImplementation public class VakyarthaDependencyTree extends WriterVisualizer { private static final org . slf4j . Logger log = LoggerFactory . getLogger ( VakyarthaDependencyTree . class ) ; private Writer theWriter ; @ Override public String getShortName ( ) { return "<STR_LIT>" ; } @ Override public void writeOutput ( VisualizerInput input , Writer writer ) { theWriter = writer ; try { AnnisResult result = input . getResult ( ) ; println ( "<STR_LIT>" ) ; println ( "<STR_LIT>" ) ; println ( "<STR_LIT>" + input . getResourcePath ( "<STR_LIT>" ) + "<STR_LIT>" ) ; println ( "<STR_LIT>" + input . getResourcePath ( "<STR_LIT>" ) + "<STR_LIT>" ) ; println ( "<STR_LIT>" + input . getResourcePath ( "<STR_LIT>" ) + "<STR_LIT>" ) ; println ( "<STR_LIT>" ) ; println ( "<STR_LIT>" ) ; println ( "<STR_LIT>" ) ; println ( "<STR_LIT>" ) ; HashMap < Long , Integer > id2pos = new HashMap < Long , Integer > ( ) ; int counter = <NUM_LIT:0> ; for ( AnnisNode tok : result . getGraph ( ) . getTokens ( ) ) { id2pos . put ( tok . getId ( ) , counter ) ; counter ++ ; } counter = <NUM_LIT:0> ; for ( AnnisNode tok : result . getGraph ( ) . getTokens ( ) ) { JSONObject o = new JSONObject ( ) ; o . put ( "<STR_LIT:t>" , tok . getSpannedText ( ) ) ; JSONObject govs = new JSONObject ( ) ; Set < Edge > edges = tok . getIncomingEdges ( ) ; for ( Edge e : edges ) { if ( e . getEdgeType ( ) == Edge . EdgeType . POINTING_RELATION ) { String label = "<STR_LIT>" ; for ( Annotation anno : e . getAnnotations ( ) ) { if ( anno . getNamespace ( ) != null && anno . getNamespace ( ) . equals ( anno . getNamespace ( ) ) ) { label = anno . getValue ( ) ; break ; } } if ( e . getSource ( ) == null ) { govs . put ( "<STR_LIT:root>" , label ) ; } else { govs . put ( "<STR_LIT>" + id2pos . get ( e . getSource ( ) . getId ( ) ) , label ) ; } } } o . put ( "<STR_LIT>" , govs ) ; JSONObject attris = new JSONObject ( ) ; JSONObject tAttris = new JSONObject ( ) ; String tokenColor = "<STR_LIT>" ; if ( input . getMarkableExactMap ( ) . containsKey ( "<STR_LIT>" + tok . getId ( ) ) ) { tokenColor = input . getMarkableExactMap ( ) . get ( "<STR_LIT>" + tok . getId ( ) ) ; } tAttris . put ( "<STR_LIT>" , tokenColor ) ; tAttris . put ( "<STR_LIT>" , "<STR_LIT>" ) ; attris . put ( "<STR_LIT:t>" , tAttris ) ; o . put ( "<STR_LIT>" , attris ) ; theWriter . append ( "<STR_LIT>" ) . append ( "<STR_LIT>" + counter ) . append ( "<STR_LIT>" ) ; theWriter . append ( o . toString ( ) . replaceAll ( "<STR_LIT:n>" , "<STR_LIT:U+0020>" ) ) ; theWriter . append ( "<STR_LIT>" ) ; counter ++ ; } println ( "<STR_LIT>" ) ; println ( "<STR_LIT>" ) ; println ( "<STR_LIT>" ) ; println ( "<STR_LIT>" ) ; println ( "<STR_LIT>" ) ; println ( "<STR_LIT>" ) ; } catch ( JSONException ex ) { log . error ( null , ex ) ; } catch ( IOException ex ) { log . error ( null , ex ) ; } } private void println ( String s ) throws IOException { println ( s , <NUM_LIT:0> ) ; } private void println ( String s , int indent ) throws IOException { for ( int i = <NUM_LIT:0> ; i < indent ; i ++ ) { theWriter . append ( "<STR_LIT:t>" ) ; } theWriter . append ( s ) ; theWriter . append ( "<STR_LIT:n>" ) ; } } </s>
<s> package annis . gui . visualizers . iframe . dependency ; import annis . gui . MatchedNodeColors ; import annis . gui . visualizers . component . AbstractDotVisualizer ; import annis . gui . visualizers . VisualizerInput ; import annis . model . AnnisNode ; import annis . model . Annotation ; import annis . model . Edge ; import java . util . * ; import net . xeoh . plugins . base . annotations . PluginImplementation ; @ PluginImplementation public class ProielRegularDependencyTree extends AbstractDotVisualizer { private VisualizerInput input ; private StringBuilder dot ; private List < AnnisNode > realToken ; private List < AnnisNode > pseudoToken ; private Set < String > alreadyWrittenEdge ; private Random rand = new Random ( ) ; @ Override public String getShortName ( ) { return "<STR_LIT>" ; } @ Override public void createDotContent ( VisualizerInput input , StringBuilder sb ) { this . dot = sb ; this . input = input ; w ( "<STR_LIT>" ) ; w ( "<STR_LIT>" ) ; w ( "<STR_LIT>" ) ; w ( "<STR_LIT>" ) ; realToken = new LinkedList < AnnisNode > ( ) ; pseudoToken = new LinkedList < AnnisNode > ( ) ; alreadyWrittenEdge = new HashSet < String > ( ) ; writeAllRealToken ( ) ; writeAllPseudoToken ( ) ; writeAllTokenConnections ( ) ; writeAllDepEdges ( ) ; w ( "<STR_LIT:}>" ) ; } private void writeAllRealToken ( ) { w ( "<STR_LIT>" ) ; for ( AnnisNode n : input . getResult ( ) . getGraph ( ) . getTokens ( ) ) { realToken . add ( n ) ; writeToken ( n ) ; } writeInvisibleTokenEdges ( realToken ) ; w ( "<STR_LIT>" ) ; } private void writeAllPseudoToken ( ) { for ( AnnisNode n : input . getResult ( ) . getGraph ( ) . getNodes ( ) ) { if ( ! n . isToken ( ) ) { boolean isDepNode = false ; String word = null ; for ( Annotation anno : n . getNodeAnnotations ( ) ) { if ( "<STR_LIT>" . equals ( anno . getNamespace ( ) ) && "<STR_LIT>" . equals ( anno . getName ( ) ) ) { isDepNode = true ; word = anno . getValue ( ) ; break ; } } if ( isDepNode ) { writeNode ( n ) ; pseudoToken . add ( n ) ; } } } } private void writeAllDepEdges ( ) { for ( Edge e : input . getResult ( ) . getGraph ( ) . getEdges ( ) ) { if ( e . getDestination ( ) != null && ! e . getDestination ( ) . isToken ( ) ) { boolean isDepEdge = false ; for ( Annotation anno : e . getAnnotations ( ) ) { if ( "<STR_LIT>" . equals ( anno . getNamespace ( ) ) && "<STR_LIT>" . equals ( anno . getName ( ) ) ) { isDepEdge = true ; break ; } } if ( isDepEdge ) { writeEdge ( e ) ; } } } } private void writeAllTokenConnections ( ) { for ( AnnisNode tok : pseudoToken ) { AnnisNode realTok = getCorrespondingRealToken ( tok ) ; if ( realTok != null ) { w ( "<STR_LIT>" + tok . getId ( ) + "<STR_LIT>" + realTok . getId ( ) + "<STR_LIT>" ) ; } } } private AnnisNode getCorrespondingRealToken ( AnnisNode n ) { if ( n == null ) { return null ; } for ( Edge e : n . getOutgoingEdges ( ) ) { if ( e . getDestination ( ) != null && e . getDestination ( ) . isToken ( ) ) { for ( Annotation anno : e . getAnnotations ( ) ) { if ( "<STR_LIT>" . equals ( anno . getNamespace ( ) ) && "<STR_LIT>" . equals ( anno . getName ( ) ) && "<STR_LIT:-->" . equals ( anno . getValue ( ) ) ) { return e . getDestination ( ) ; } } } } return null ; } private void writeInvisibleTokenEdges ( List < AnnisNode > token ) { Collections . sort ( token , new Comparator < AnnisNode > ( ) { @ Override public int compare ( AnnisNode o1 , AnnisNode o2 ) { return o1 . getTokenIndex ( ) . compareTo ( o2 . getTokenIndex ( ) ) ; } } ) ; AnnisNode lastTok = null ; for ( AnnisNode tok : token ) { if ( lastTok != null ) { w ( "<STR_LIT>" ) ; w ( lastTok . getId ( ) ) ; w ( "<STR_LIT>" ) ; w ( tok . getId ( ) ) ; w ( "<STR_LIT>" ) ; } lastTok = tok ; } } private void writeNode ( AnnisNode n ) { String color = "<STR_LIT>" ; String shape = "<STR_LIT>" ; String colorAsString = input . getMarkableExactMap ( ) . get ( Long . toString ( n . getId ( ) ) ) ; if ( colorAsString != null ) { MatchedNodeColors matchedColor = MatchedNodeColors . valueOf ( colorAsString ) ; color = matchedColor . getHTMLColor ( ) ; shape = "<STR_LIT>" ; } w ( "<STR_LIT:U+0020U+0020>" + n . getId ( ) + "<STR_LIT>" + shape + "<STR_LIT>" ) ; w ( "<STR_LIT>" ) ; w ( "<STR_LIT>" ) ; w ( color ) ; w ( "<STR_LIT>" ) ; w ( color ) ; w ( "<STR_LIT>" ) ; } private void writeToken ( AnnisNode n ) { w ( "<STR_LIT:U+0020U+0020>" + n . getId ( ) + "<STR_LIT>" + n . getSpannedText ( ) + "<STR_LIT>" ) ; w ( "<STR_LIT>" ) ; w ( "<STR_LIT>" ) ; String colorAsString = input . getMarkableExactMap ( ) . get ( Long . toString ( n . getId ( ) ) ) ; if ( colorAsString != null ) { MatchedNodeColors color = MatchedNodeColors . valueOf ( colorAsString ) ; w ( color . getHTMLColor ( ) ) ; } else { w ( "<STR_LIT>" ) ; } w ( "<STR_LIT>" ) ; } private void writeEdge ( Edge e ) { AnnisNode srcNode = e . getSource ( ) ; AnnisNode destNode = e . getDestination ( ) ; if ( e . getName ( ) == null || srcNode == null || destNode == null ) { return ; } else { String srcId = "<STR_LIT>" + srcNode . getId ( ) ; String destId = "<STR_LIT>" + destNode . getId ( ) ; StringBuilder sbAnno = new StringBuilder ( ) ; boolean first = true ; for ( Annotation anno : e . getAnnotations ( ) ) { if ( ! first ) { sbAnno . append ( "<STR_LIT>" ) ; } first = false ; sbAnno . append ( anno . getValue ( ) ) ; } String style = "<STR_LIT>" ; if ( "<STR_LIT>" . equals ( e . getName ( ) ) ) { style = "<STR_LIT>" ; } String edgeString = srcId + "<STR_LIT>" + destId + "<STR_LIT>" + sbAnno . toString ( ) + "<STR_LIT>" + style + "<STR_LIT>" ; if ( ! alreadyWrittenEdge . contains ( edgeString ) ) { w ( edgeString ) ; alreadyWrittenEdge . add ( edgeString ) ; } } } private void w ( String s ) { dot . append ( s ) ; } private void w ( long l ) { dot . append ( l ) ; } } </s>
<s> package annis . gui . visualizers . iframe . dependency ; import annis . gui . MatchedNodeColors ; import annis . gui . visualizers . component . AbstractDotVisualizer ; import annis . gui . visualizers . VisualizerInput ; import annis . model . AnnisNode ; import annis . model . Annotation ; import annis . model . Edge ; import java . util . HashSet ; import java . util . Set ; import net . xeoh . plugins . base . annotations . PluginImplementation ; @ PluginImplementation public class ProielDependecyTree extends AbstractDotVisualizer { @ Override public String getShortName ( ) { return "<STR_LIT>" ; } private VisualizerInput input ; private StringBuilder dot ; private Set < String > alreadyWrittenEdge ; @ Override public void createDotContent ( VisualizerInput input , StringBuilder sb ) { this . input = input ; this . dot = sb ; alreadyWrittenEdge = new HashSet < String > ( ) ; w ( "<STR_LIT>" ) ; w ( "<STR_LIT>" ) ; w ( "<STR_LIT>" ) ; writeAllNodes ( ) ; writeAllEdges ( ) ; w ( "<STR_LIT>" ) ; } private void writeAllNodes ( ) { for ( AnnisNode n : input . getResult ( ) . getGraph ( ) . getNodes ( ) ) { boolean isDepNode = false ; String word = null ; for ( Annotation anno : n . getNodeAnnotations ( ) ) { if ( "<STR_LIT>" . equals ( anno . getNamespace ( ) ) && "<STR_LIT>" . equals ( anno . getName ( ) ) ) { isDepNode = true ; word = anno . getValue ( ) ; break ; } } if ( isDepNode ) { writeNode ( n , word ) ; } } } private void writeAllEdges ( ) { for ( Edge e : input . getResult ( ) . getGraph ( ) . getEdges ( ) ) { boolean isDepEdge = false ; for ( Annotation anno : e . getAnnotations ( ) ) { if ( "<STR_LIT>" . equals ( anno . getNamespace ( ) ) && "<STR_LIT>" . equals ( anno . getName ( ) ) ) { isDepEdge = true ; break ; } } if ( isDepEdge ) { writeEdge ( e ) ; } } } private void writeEdge ( Edge e ) { AnnisNode srcNode = e . getSource ( ) ; AnnisNode destNode = e . getDestination ( ) ; if ( e . getName ( ) == null || srcNode == null || destNode == null ) { return ; } String srcId = "<STR_LIT>" + srcNode . getId ( ) ; String destId = "<STR_LIT>" + destNode . getId ( ) ; StringBuilder sbAnno = new StringBuilder ( ) ; for ( Annotation anno : e . getAnnotations ( ) ) { if ( "<STR_LIT>" . equals ( anno . getName ( ) ) ) { if ( "<STR_LIT:-->" . equals ( anno . getValue ( ) ) ) { return ; } sbAnno . append ( anno . getValue ( ) ) ; } break ; } String style = null ; if ( "<STR_LIT>" . equals ( e . getName ( ) ) ) { style = "<STR_LIT>" ; } else { style = "<STR_LIT>" ; } String edgeString = srcId + "<STR_LIT>" + destId + "<STR_LIT:[>" + style + "<STR_LIT>" + sbAnno . toString ( ) + "<STR_LIT>" ; if ( ! alreadyWrittenEdge . contains ( edgeString ) ) { w ( "<STR_LIT:U+0020U+0020>" + edgeString ) ; alreadyWrittenEdge . add ( edgeString ) ; } } private void writeNode ( AnnisNode n , String word ) { String shape = "<STR_LIT>" ; String id = "<STR_LIT>" + n . getId ( ) ; String fillcolor = "<STR_LIT>" ; String fontcolor = "<STR_LIT>" ; String style = "<STR_LIT>" ; String label = "<STR_LIT>" ; String posAnno = "<STR_LIT>" ; for ( Annotation anno : n . getNodeAnnotations ( ) ) { if ( "<STR_LIT>" . equals ( anno . getNamespace ( ) ) && "<STR_LIT>" . equals ( anno . getName ( ) ) && anno . getValue ( ) != null ) { posAnno = anno . getValue ( ) ; } } if ( isEmptyNode ( word ) ) { if ( isRootNode ( n ) ) { shape = "<STR_LIT>" ; } else { if ( posAnno . length ( ) > <NUM_LIT:0> ) { switch ( posAnno . charAt ( <NUM_LIT:0> ) ) { case '<CHAR_LIT>' : shape = "<STR_LIT>" ; label = posAnno ; break ; case '<CHAR_LIT>' : shape = "<STR_LIT>" ; label = posAnno ; break ; case '<CHAR_LIT>' : shape = "<STR_LIT>" ; label = posAnno ; break ; default : shape = "<STR_LIT>" ; label = posAnno ; break ; } } } } else { if ( "<STR_LIT>" . equals ( posAnno ) ) { shape = "<STR_LIT>" ; } label = word ; } String matchColorAsString = input . getMarkableExactMap ( ) . get ( Long . toString ( n . getId ( ) ) ) ; if ( matchColorAsString == null ) { AnnisNode token = getCorrespondingRealToken ( n ) ; if ( token != null ) { matchColorAsString = input . getMarkableExactMap ( ) . get ( Long . toString ( token . getId ( ) ) ) ; } } if ( matchColorAsString != null ) { MatchedNodeColors matchColor = MatchedNodeColors . valueOf ( matchColorAsString ) ; fillcolor = matchColor . getHTMLColor ( ) ; } w ( id ) ; w ( "<STR_LIT>" ) ; wAtt ( "<STR_LIT>" , fontcolor ) ; wAtt ( "<STR_LIT>" , shape ) ; wAtt ( "<STR_LIT>" , fillcolor ) ; wAtt ( "<STR_LIT>" , style ) ; wAtt ( "<STR_LIT:label>" , label ) ; w ( "<STR_LIT>" ) ; } private AnnisNode getCorrespondingRealToken ( AnnisNode n ) { if ( n == null ) { return null ; } for ( Edge e : n . getOutgoingEdges ( ) ) { if ( e . getDestination ( ) != null && e . getDestination ( ) . isToken ( ) ) { for ( Annotation anno : e . getAnnotations ( ) ) { if ( "<STR_LIT>" . equals ( anno . getNamespace ( ) ) && "<STR_LIT>" . equals ( anno . getName ( ) ) && "<STR_LIT:-->" . equals ( anno . getValue ( ) ) ) { return e . getDestination ( ) ; } } } } return null ; } private boolean isRootNode ( AnnisNode node ) { boolean result = true ; for ( Edge e : node . getIncomingEdges ( ) ) { if ( e . getSource ( ) != null ) { result = false ; break ; } } return result ; } private boolean isEmptyNode ( String word ) { if ( word == null || "<STR_LIT>" . equals ( word ) || "<STR_LIT:-->" . equals ( word ) ) { return true ; } else { return false ; } } private void w ( String s ) { dot . append ( s ) ; } private void w ( long l ) { dot . append ( l ) ; } private void wAtt ( String key , String value ) { w ( key ) ; w ( "<STR_LIT>" ) ; w ( value ) ; w ( "<STR_LIT:\">" ) ; } } </s>
<s> package annis . gui . visualizers . iframe . dependency ; import annis . model . AnnisNode ; public class Vector2 { private long x ; private long y ; public Vector2 ( AnnisNode n ) { this . x = n . getLeftToken ( ) ; this . y = n . getRightToken ( ) ; } public Vector2 ( long x , long y ) { this . x = x ; this . y = y ; } public long getX ( ) { return x ; } public void setX ( long x ) { this . x = x ; } public long getY ( ) { return y ; } public void setY ( long y ) { this . y = y ; } @ Override public boolean equals ( Object obj ) { if ( obj == null ) { return false ; } if ( getClass ( ) != obj . getClass ( ) ) { return false ; } final Vector2 other = ( Vector2 ) obj ; if ( this . x != other . x ) { return false ; } if ( this . y != other . y ) { return false ; } return true ; } @ Override public int hashCode ( ) { int hash = <NUM_LIT:7> ; hash = <NUM_LIT> * hash + ( int ) ( this . x ^ ( this . x > > > <NUM_LIT:32> ) ) ; hash = <NUM_LIT> * hash + ( int ) ( this . y ^ ( this . y > > > <NUM_LIT:32> ) ) ; return hash ; } } </s>
<s> package annis . gui . visualizers . iframe ; import annis . gui . visualizers . VisualizerInput ; import annis . model . AnnisNode ; import annis . model . Edge ; import annis . service . ifaces . AnnisToken ; import java . io . IOException ; import java . io . Writer ; import annis . model . Annotation ; import annis . model . AnnotationGraph ; import annis . service . ifaces . AnnisResult ; import java . util . HashMap ; import java . util . HashSet ; import java . util . LinkedList ; import java . util . List ; import java . util . Set ; import net . xeoh . plugins . base . annotations . PluginImplementation ; import org . slf4j . LoggerFactory ; @ PluginImplementation public class CorefVisualizer extends WriterVisualizer { private static final org . slf4j . Logger log = LoggerFactory . getLogger ( CorefVisualizer . class ) ; VisualizerInput theInput ; Writer theWriter ; long globalIndex ; List < TReferent > ReferentList ; List < TComponent > Komponent ; HashMap < Long , List < Long > > ComponentOfToken , TokensOfNode ; HashMap < Long , HashMap < Long , Integer > > ReferentOfToken ; List < Long > visitedNodes ; LinkedList < TComponenttype > Componenttype ; private HashMap < Integer , Integer > colorlist ; static class TComponenttype { String Type ; List < Long > NodeList ; TComponenttype ( ) { Type = "<STR_LIT>" ; NodeList = new LinkedList < Long > ( ) ; } } static class TComponent { List < Long > TokenList ; String Type ; TComponent ( ) { TokenList = new LinkedList < Long > ( ) ; Type = "<STR_LIT>" ; } TComponent ( List < Long > ll , String t ) { TokenList = ll ; Type = t ; } } static class TReferent { Set < Annotation > Annotations ; long Component ; TReferent ( ) { Component = - <NUM_LIT:1> ; Annotations = new HashSet < Annotation > ( ) ; } } @ Override public String getShortName ( ) { return "<STR_LIT>" ; } @ Override public boolean isUsingText ( ) { return true ; } @ Override public void writeOutput ( VisualizerInput input , Writer writer ) { this . theInput = input ; this . theWriter = writer ; try { println ( "<STR_LIT>" ) ; println ( "<STR_LIT>" ) ; println ( "<STR_LIT>" + theInput . getResourcePath ( "<STR_LIT>" ) + "<STR_LIT>" ) ; println ( "<STR_LIT>" + input . getResourcePath ( "<STR_LIT>" ) + "<STR_LIT>" ) ; println ( "<STR_LIT>" + input . getResourcePath ( "<STR_LIT>" ) + "<STR_LIT>" ) ; println ( "<STR_LIT>" + theInput . getResourcePath ( "<STR_LIT>" ) + "<STR_LIT>" ) ; println ( "<STR_LIT>" + theInput . getResourcePath ( "<STR_LIT>" ) + "<STR_LIT>" ) ; println ( "<STR_LIT>" ) ; println ( "<STR_LIT>" ) ; globalIndex = <NUM_LIT:0> ; int toolTipMaxLineCount = <NUM_LIT:1> ; TokensOfNode = new HashMap < Long , List < Long > > ( ) ; ReferentList = new LinkedList < TReferent > ( ) ; Komponent = new LinkedList < TComponent > ( ) ; ReferentOfToken = new HashMap < Long , HashMap < Long , Integer > > ( ) ; ComponentOfToken = new HashMap < Long , List < Long > > ( ) ; Componenttype = new LinkedList < TComponenttype > ( ) ; AnnisResult anResult = input . getResult ( ) ; AnnotationGraph anGraph = anResult . getGraph ( ) ; if ( anGraph == null ) { println ( "<STR_LIT>" ) ; return ; } List < Edge > edgeList = anGraph . getEdges ( ) ; if ( edgeList == null ) { return ; } for ( Edge e : edgeList ) { if ( includeEdge ( e ) ) { visitedNodes = new LinkedList < Long > ( ) ; boolean gotIt = false ; int Componentnr ; for ( Componentnr = <NUM_LIT:0> ; Componentnr < Componenttype . size ( ) ; Componentnr ++ ) { if ( Componenttype . get ( Componentnr ) != null && Componenttype . get ( Componentnr ) . Type != null && Componenttype . get ( Componentnr ) . NodeList != null && Componenttype . get ( Componentnr ) . Type . equals ( e . getName ( ) ) && Componenttype . get ( Componentnr ) . NodeList . contains ( e . getSource ( ) . getId ( ) ) ) { gotIt = true ; break ; } } TComponent currentComponent ; TComponenttype currentComponenttype ; if ( gotIt ) { currentComponent = Komponent . get ( Componentnr ) ; currentComponenttype = Componenttype . get ( Componentnr ) ; } else { currentComponenttype = new TComponenttype ( ) ; currentComponenttype . Type = e . getName ( ) ; Componenttype . add ( currentComponenttype ) ; Componentnr = Komponent . size ( ) ; currentComponent = new TComponent ( ) ; currentComponent . Type = e . getName ( ) ; currentComponent . TokenList = new LinkedList < Long > ( ) ; Komponent . add ( currentComponent ) ; currentComponenttype . NodeList . add ( e . getSource ( ) . getId ( ) ) ; } TReferent Ref = new TReferent ( ) ; Ref . Annotations = e . getAnnotations ( ) ; Ref . Component = Componentnr ; ReferentList . add ( Ref ) ; List < Long > currentTokens = getAllTokens ( e . getSource ( ) , e . getName ( ) , currentComponenttype , Componentnr ) ; setReferent ( e . getDestination ( ) , globalIndex , <NUM_LIT:0> ) ; setReferent ( e . getSource ( ) , globalIndex , <NUM_LIT:1> ) ; for ( Long l : currentTokens ) { if ( ! currentComponent . TokenList . contains ( l ) ) { currentComponent . TokenList . add ( l ) ; } } globalIndex ++ ; } } colorlist = new HashMap < Integer , Integer > ( ) ; List < Long > prevpositions , listpositions ; List < Long > finalpositions = null ; int maxlinkcount = <NUM_LIT:0> ; Long lastId = null , currentId = null ; for ( AnnisToken tok : input . getResult ( ) . getTokenList ( ) ) { prevpositions = finalpositions ; if ( prevpositions != null && prevpositions . size ( ) < <NUM_LIT:1> ) { prevpositions = null ; } lastId = currentId ; currentId = tok . getId ( ) ; listpositions = ComponentOfToken . get ( currentId ) ; List < Boolean > checklist = null ; if ( prevpositions == null && listpositions != null ) { finalpositions = listpositions ; } else if ( listpositions == null ) { finalpositions = new LinkedList < Long > ( ) ; } else { checklist = new LinkedList < Boolean > ( ) ; for ( int i = <NUM_LIT:0> ; i < prevpositions . size ( ) ; i ++ ) { if ( listpositions . contains ( prevpositions . get ( i ) ) ) { checklist . add ( true ) ; } else { checklist . add ( false ) ; } } List < Long > remains = new LinkedList < Long > ( ) ; for ( int i = <NUM_LIT:0> ; i < listpositions . size ( ) ; i ++ ) { if ( ! prevpositions . contains ( listpositions . get ( i ) ) ) { remains . add ( listpositions . get ( i ) ) ; } } int minsize = checklist . size ( ) + remains . size ( ) ; int number = <NUM_LIT:0> ; finalpositions = new LinkedList < Long > ( ) ; for ( int i = <NUM_LIT:0> ; i < minsize ; i ++ ) { if ( checklist . size ( ) > i && checklist . get ( i ) . booleanValue ( ) ) { finalpositions . add ( prevpositions . get ( i ) ) ; } else { if ( remains . size ( ) > number ) { Long ll = remains . get ( number ) ; finalpositions . add ( ll ) ; number ++ ; minsize -- ; } else { finalpositions . add ( Long . MIN_VALUE ) ; } } } } String onclick = "<STR_LIT>" , style = "<STR_LIT>" ; if ( input . getMarkableMap ( ) . containsKey ( "<STR_LIT>" + tok . getId ( ) ) ) { style += "<STR_LIT>" ; } boolean underline = false ; if ( ! finalpositions . isEmpty ( ) ) { style += "<STR_LIT>" ; underline = true ; onclick = "<STR_LIT>" ; } println ( "<STR_LIT>" ) ; int currentlinkcount = <NUM_LIT:0> ; if ( underline ) { boolean firstone = true ; int index = - <NUM_LIT:1> ; String tooltip = "<STR_LIT>" ; if ( ! finalpositions . isEmpty ( ) ) { for ( Long currentPositionComponent : finalpositions ) { index ++ ; String left = "<STR_LIT>" , right = "<STR_LIT>" ; List < Long > pi ; TComponent currentWriteComponent = null ; String currentType = "<STR_LIT>" ; if ( ! currentPositionComponent . equals ( Long . MIN_VALUE ) && Komponent . size ( ) > currentPositionComponent ) { currentWriteComponent = Komponent . get ( ( int ) ( long ) currentPositionComponent ) ; pi = currentWriteComponent . TokenList ; currentType = currentWriteComponent . Type ; left = ListToString ( pi ) ; right = "<STR_LIT>" + currentPositionComponent + <NUM_LIT:1> ; } String Annotations = getAnnotations ( tok . getId ( ) , currentPositionComponent ) ; if ( firstone ) { firstone = false ; if ( currentWriteComponent == null ) { String left2 = "<STR_LIT>" , right2 = "<STR_LIT>" ; List < Long > pi2 ; long pr = <NUM_LIT:0> ; TComponent currentWriteComponent2 = null ; String currentType2 = "<STR_LIT>" ; String Annotations2 = "<STR_LIT>" ; for ( Long currentPositionComponent2 : finalpositions ) { if ( ! currentPositionComponent2 . equals ( Long . MIN_VALUE ) && Komponent . size ( ) > currentPositionComponent2 ) { currentWriteComponent2 = Komponent . get ( ( int ) ( long ) currentPositionComponent2 ) ; pi2 = currentWriteComponent2 . TokenList ; currentType2 = currentWriteComponent2 . Type ; left2 = ListToString ( pi2 ) ; right2 = "<STR_LIT>" + currentPositionComponent2 + <NUM_LIT:1> ; Annotations2 = getAnnotations ( tok . getId ( ) , currentPositionComponent2 ) ; pr = currentPositionComponent2 ; break ; } } tooltip = "<STR_LIT>" + ( pr + <NUM_LIT:1> ) + "<STR_LIT>" + currentType2 + Annotations2 + "<STR_LIT:\">" ; if ( tooltip . length ( ) / <NUM_LIT> + <NUM_LIT:1> > toolTipMaxLineCount ) { toolTipMaxLineCount = tooltip . length ( ) / <NUM_LIT> + <NUM_LIT:1> ; } println ( "<STR_LIT>" + tok . getId ( ) + "<STR_LIT>" + tooltip + "<STR_LIT>" + style + "<STR_LIT>" + onclick + "<STR_LIT>" + left2 + "<STR_LIT>" + right2 + "<STR_LIT>" + tok . getText ( ) + "<STR_LIT>" ) ; } else { tooltip = "<STR_LIT>" + ( currentPositionComponent + <NUM_LIT:1> ) + "<STR_LIT>" + currentType + Annotations + "<STR_LIT:\">" ; if ( tooltip . length ( ) / <NUM_LIT> + <NUM_LIT:1> > toolTipMaxLineCount ) { toolTipMaxLineCount = tooltip . length ( ) / <NUM_LIT> + <NUM_LIT:1> ; } println ( "<STR_LIT>" + tok . getId ( ) + "<STR_LIT>" + tooltip + "<STR_LIT>" + style + "<STR_LIT>" + onclick + "<STR_LIT>" + left + "<STR_LIT>" + right + "<STR_LIT>" + tok . getText ( ) + "<STR_LIT>" ) ; } } currentlinkcount ++ ; if ( currentPositionComponent . equals ( Long . MIN_VALUE ) ) { println ( "<STR_LIT>" ) ; } else { int color = <NUM_LIT:0> ; if ( colorlist . containsKey ( ( int ) ( long ) currentPositionComponent ) ) { color = colorlist . get ( ( int ) ( long ) currentPositionComponent ) ; } else { color = getNewColor ( ( int ) ( long ) currentPositionComponent ) ; colorlist . put ( ( int ) ( long ) currentPositionComponent , color ) ; } if ( color > <NUM_LIT> ) { color = <NUM_LIT> ; } String addition = "<STR_LIT>" ; if ( lastId != null && currentId != null && checklist != null && checklist . size ( ) > index && checklist . get ( index ) . booleanValue ( ) == true ) { if ( connectionOf ( lastId , currentId , currentPositionComponent ) ) { addition = "<STR_LIT>" ; } } tooltip = "<STR_LIT>" + ( currentPositionComponent + <NUM_LIT:1> ) + "<STR_LIT>" + currentType + Annotations + "<STR_LIT:\">" ; if ( tooltip . length ( ) / <NUM_LIT> + <NUM_LIT:1> > toolTipMaxLineCount ) { toolTipMaxLineCount = tooltip . length ( ) / <NUM_LIT> + <NUM_LIT:1> ; } println ( "<STR_LIT>" ) ; println ( "<STR_LIT>" + "<STR_LIT>" + style + addition + "<STR_LIT>" + onclick + "<STR_LIT>" + left + "<STR_LIT>" + right + "<STR_LIT>" + tooltip + "<STR_LIT>" + Integer . toHexString ( color ) + "<STR_LIT>" ) ; println ( "<STR_LIT>" ) ; println ( "<STR_LIT>" ) ; } } } if ( currentlinkcount > maxlinkcount ) { maxlinkcount = currentlinkcount ; } else { if ( currentlinkcount < maxlinkcount ) { println ( "<STR_LIT>" + ( maxlinkcount - currentlinkcount ) * <NUM_LIT:5> + "<STR_LIT>" ) ; } } println ( "<STR_LIT>" ) ; } else { println ( "<STR_LIT>" + tok . getId ( ) + "<STR_LIT>" + "<STR_LIT>" + style + "<STR_LIT>" + onclick + "<STR_LIT>" + tok . getText ( ) + "<STR_LIT>" ) ; if ( maxlinkcount > <NUM_LIT:0> ) { println ( "<STR_LIT>" ) ; println ( "<STR_LIT>" + maxlinkcount * <NUM_LIT:5> + "<STR_LIT>" ) ; println ( "<STR_LIT>" ) ; } } println ( "<STR_LIT>" ) ; } println ( "<STR_LIT>" ) ; println ( "<STR_LIT>" ) ; if ( toolTipMaxLineCount > <NUM_LIT:10> ) { toolTipMaxLineCount = <NUM_LIT:10> ; } println ( "<STR_LIT>" + ( toolTipMaxLineCount * <NUM_LIT:15> + <NUM_LIT:15> ) + "<STR_LIT>" ) ; println ( "<STR_LIT>" ) ; println ( "<STR_LIT>" ) ; } catch ( IOException ex ) { log . error ( null , ex ) ; } } private List < Long > getAllTokens ( AnnisNode a , String name , TComponenttype c , long cnr ) { List < Long > result = null ; if ( ! visitedNodes . contains ( a . getId ( ) ) ) { result = new LinkedList < Long > ( ) ; visitedNodes . add ( a . getId ( ) ) ; if ( TokensOfNode . containsKey ( a . getId ( ) ) ) { for ( Long l : TokensOfNode . get ( a . getId ( ) ) ) { result . add ( l ) ; if ( ComponentOfToken . get ( l ) == null ) { List < Long > newlist = new LinkedList < Long > ( ) ; newlist . add ( cnr ) ; ComponentOfToken . put ( l , newlist ) ; } else { if ( ! ComponentOfToken . get ( l ) . contains ( cnr ) ) { ComponentOfToken . get ( l ) . add ( cnr ) ; } } } } else { result = searchTokens ( a , cnr ) ; if ( result != null ) { TokensOfNode . put ( a . getId ( ) , result ) ; } } for ( Edge e : a . getOutgoingEdges ( ) ) { if ( includeEdge ( e ) && name . equals ( e . getName ( ) ) && ! visitedNodes . contains ( e . getDestination ( ) . getId ( ) ) ) { c . NodeList . add ( e . getDestination ( ) . getId ( ) ) ; List < Long > Med = getAllTokens ( e . getDestination ( ) , name , c , cnr ) ; for ( Long l : Med ) { if ( ! result . contains ( l ) ) { result . add ( l ) ; } } } } for ( Edge e : a . getIncomingEdges ( ) ) { if ( includeEdge ( e ) && name . equals ( e . getName ( ) ) && ! visitedNodes . contains ( e . getSource ( ) . getId ( ) ) ) { c . NodeList . add ( e . getSource ( ) . getId ( ) ) ; List < Long > Med = getAllTokens ( e . getSource ( ) , name , c , cnr ) ; for ( Long l : Med ) { if ( ! result . contains ( l ) ) { result . add ( l ) ; } } } } } return result ; } private void setReferent ( AnnisNode a , long index , int value ) { if ( a . isToken ( ) ) { if ( ! ReferentOfToken . containsKey ( a . getId ( ) ) ) { HashMap < Long , Integer > newlist = new HashMap < Long , Integer > ( ) ; newlist . put ( index , value ) ; ReferentOfToken . put ( a . getId ( ) , newlist ) ; } else { ReferentOfToken . get ( a . getId ( ) ) . put ( globalIndex , value ) ; } } else { for ( Edge e : a . getOutgoingEdges ( ) ) { if ( e . getEdgeType ( ) != Edge . EdgeType . POINTING_RELATION && e . getSource ( ) != null && e . getDestination ( ) != null ) { setReferent ( e . getDestination ( ) , index , value ) ; } } } } private List < Long > searchTokens ( AnnisNode a , long cnr ) { List < Long > result = new LinkedList < Long > ( ) ; if ( a . isToken ( ) ) { result . add ( a . getId ( ) ) ; if ( ComponentOfToken . get ( a . getId ( ) ) == null ) { List < Long > newlist = new LinkedList < Long > ( ) ; newlist . add ( cnr ) ; ComponentOfToken . put ( a . getId ( ) , newlist ) ; } else { List < Long > newlist = ComponentOfToken . get ( a . getId ( ) ) ; if ( ! newlist . contains ( cnr ) ) { newlist . add ( cnr ) ; } } } else { for ( Edge e : a . getOutgoingEdges ( ) ) { if ( e . getEdgeType ( ) != Edge . EdgeType . POINTING_RELATION && e . getSource ( ) != null && e . getDestination ( ) != null ) { List < Long > Med = searchTokens ( e . getDestination ( ) , cnr ) ; for ( Long l : Med ) { if ( ! result . contains ( l ) ) { result . add ( l ) ; } } } } } return result ; } private String getAnnotations ( Long id , long component ) { String result = "<STR_LIT>" ; String incoming = "<STR_LIT>" , outgoing = "<STR_LIT>" ; int nri = <NUM_LIT:1> , nro = <NUM_LIT:1> ; if ( ReferentOfToken . get ( id ) != null ) { for ( long l : ReferentOfToken . get ( id ) . keySet ( ) ) { if ( ReferentList . get ( ( int ) ( long ) l ) != null && ReferentList . get ( ( int ) ( long ) l ) . Component == component && ReferentList . get ( ( int ) ( long ) l ) . Annotations != null && ReferentList . get ( ( int ) ( long ) l ) . Annotations . size ( ) > <NUM_LIT:0> ) { int num = ReferentOfToken . get ( id ) . get ( l ) ; if ( num == <NUM_LIT:0> || num == <NUM_LIT:2> ) { for ( Annotation an : ReferentList . get ( ( int ) ( long ) l ) . Annotations ) { if ( nri == <NUM_LIT:1> ) { incoming = "<STR_LIT>" + an . getName ( ) + "<STR_LIT:=>" + an . getValue ( ) ; nri -- ; } else { incoming += "<STR_LIT:U+002CU+0020>" + an . getName ( ) + "<STR_LIT:=>" + an . getValue ( ) ; } } } if ( num == <NUM_LIT:1> || num == <NUM_LIT:2> ) { for ( Annotation an : ReferentList . get ( ( int ) ( long ) l ) . Annotations ) { if ( nro == <NUM_LIT:1> ) { outgoing = "<STR_LIT>" + an . getName ( ) + "<STR_LIT:=>" + an . getValue ( ) ; nro -- ; } else { outgoing += "<STR_LIT:U+002CU+0020>" + an . getName ( ) + "<STR_LIT:=>" + an . getValue ( ) ; } } } } } } if ( nro < <NUM_LIT:1> ) { result += outgoing ; } if ( nri < <NUM_LIT:1> ) { result += incoming ; } return result ; } private boolean connectionOf ( long pre , long now , long currentComponent ) { List < Long > prel = new LinkedList < Long > ( ) , nowl = new LinkedList < Long > ( ) ; if ( pre != now && ReferentOfToken . get ( pre ) != null && ReferentOfToken . get ( now ) != null ) { for ( long l : ReferentOfToken . get ( pre ) . keySet ( ) ) { if ( ReferentList . get ( ( int ) l ) != null && ReferentList . get ( ( int ) l ) . Component == currentComponent && ReferentOfToken . get ( pre ) . get ( l ) . equals ( <NUM_LIT:0> ) ) { prel . add ( l ) ; } } for ( long l : ReferentOfToken . get ( now ) . keySet ( ) ) { if ( ReferentList . get ( ( int ) l ) != null && ReferentList . get ( ( int ) l ) . Component == currentComponent && ReferentOfToken . get ( now ) . get ( l ) . equals ( <NUM_LIT:0> ) ) { nowl . add ( l ) ; } } for ( long l : nowl ) { if ( prel . contains ( l ) ) { return true ; } } } prel = new LinkedList < Long > ( ) ; nowl = new LinkedList < Long > ( ) ; if ( pre != now && ReferentOfToken . get ( pre ) != null && ReferentOfToken . get ( now ) != null ) { for ( long l : ReferentOfToken . get ( pre ) . keySet ( ) ) { if ( ReferentList . get ( ( int ) l ) != null && ReferentList . get ( ( int ) l ) . Component == currentComponent && ReferentOfToken . get ( pre ) . get ( l ) . equals ( <NUM_LIT:1> ) ) { prel . add ( l ) ; } } for ( long l : ReferentOfToken . get ( now ) . keySet ( ) ) { if ( ReferentList . get ( ( int ) l ) != null && ReferentList . get ( ( int ) l ) . Component == currentComponent && ReferentOfToken . get ( now ) . get ( l ) . equals ( <NUM_LIT:1> ) ) { nowl . add ( l ) ; } } for ( long l : nowl ) { if ( prel . contains ( l ) ) { return true ; } } } return false ; } private String ListToString ( List < Long > ll ) { StringBuilder result = new StringBuilder ( ) ; int i = <NUM_LIT:1> ; for ( Long l : ll ) { if ( i == <NUM_LIT:1> ) { i = <NUM_LIT:0> ; result . append ( l ) ; } else { result . append ( "<STR_LIT:U+002C>" ) ; result . append ( l ) ; } } return result . toString ( ) ; } private int getNewColor ( int i ) { int r = ( ( ( i ) * <NUM_LIT> ) % <NUM_LIT:255> ) ; int g = ( ( ( i + <NUM_LIT> ) * <NUM_LIT> ) % <NUM_LIT:255> ) ; int b = ( ( ( i + <NUM_LIT> ) * <NUM_LIT> ) % <NUM_LIT:255> ) ; if ( ( ( r + b + g ) / <NUM_LIT:3> ) < <NUM_LIT:100> ) { r = <NUM_LIT:255> - r ; g = <NUM_LIT:255> - g ; b = <NUM_LIT:255> - b ; } else if ( ( ( r + b + g ) / <NUM_LIT:3> ) > <NUM_LIT> ) { r = <NUM_LIT:1> * ( r / <NUM_LIT:2> ) ; g = <NUM_LIT:1> * ( g / <NUM_LIT:2> ) ; b = <NUM_LIT:1> * ( b / <NUM_LIT:2> ) ; } if ( r == <NUM_LIT:255> && g == <NUM_LIT:255> && b == <NUM_LIT:255> ) { r = <NUM_LIT:255> ; g = <NUM_LIT:255> ; b = <NUM_LIT:0> ; } return ( r * <NUM_LIT> + g * <NUM_LIT> + b ) ; } private void println ( String s ) throws IOException { println ( s , <NUM_LIT:0> ) ; } private void println ( String s , int indent ) throws IOException { for ( int i = <NUM_LIT:0> ; i < indent ; i ++ ) { theWriter . append ( "<STR_LIT:t>" ) ; } theWriter . append ( s ) ; theWriter . append ( "<STR_LIT:n>" ) ; } private boolean includeEdge ( Edge e ) { if ( e != null && e . getName ( ) != null && e . getEdgeType ( ) == Edge . EdgeType . POINTING_RELATION && e . getSource ( ) != null && e . getDestination ( ) != null && e . getNamespace ( ) != null && e . getNamespace ( ) . equals ( theInput . getNamespace ( ) ) ) { return true ; } else { return false ; } } } </s>
<s> package annis . gui . visualizers . iframe . media ; import net . xeoh . plugins . base . annotations . PluginImplementation ; @ PluginImplementation public class VideoVisualizer extends MediaVisualizer { @ Override public String getTag ( ) { return "<STR_LIT>" ; } @ Override public String getMediaMime ( ) { return "<STR_LIT>" ; } @ Override public String getShortName ( ) { return "<STR_LIT>" ; } } </s>
<s> package annis . gui . visualizers . iframe . media ; import net . xeoh . plugins . base . annotations . PluginImplementation ; @ PluginImplementation public class AudioVisualizer extends MediaVisualizer { @ Override public String getTag ( ) { return "<STR_LIT>" ; } @ Override public String getMediaMime ( ) { return "<STR_LIT>" ; } @ Override public String getShortName ( ) { return "<STR_LIT>" ; } } </s>
<s> package annis . gui . visualizers . iframe . media ; import annis . CommonHelper ; import annis . gui . visualizers . VisualizerInput ; import annis . gui . visualizers . iframe . WriterVisualizer ; import annis . model . AnnisNode ; import annis . model . Annotation ; import annis . model . AnnotationGraph ; import java . io . IOException ; import java . io . Writer ; import java . net . URI ; import java . net . URLEncoder ; import java . util . List ; import java . util . Set ; public abstract class MediaVisualizer extends WriterVisualizer { @ Override public void writeOutput ( VisualizerInput input , Writer writer ) { List < String > corpusPath = CommonHelper . getCorpusPath ( input . getDocument ( ) . getSCorpusGraph ( ) , input . getDocument ( ) ) ; try { String binaryServletPath = input . getContextPath ( ) + "<STR_LIT>" + "<STR_LIT>" + URLEncoder . encode ( corpusPath . get ( <NUM_LIT:0> ) , "<STR_LIT:UTF-8>" ) + "<STR_LIT>" + URLEncoder . encode ( corpusPath . get ( corpusPath . size ( ) - <NUM_LIT:1> ) , "<STR_LIT:UTF-8>" ) ; writer . append ( "<STR_LIT>" ) ; writer . append ( "<STR_LIT>" ) ; writer . append ( "<STR_LIT>" ) ; writer . append ( "<STR_LIT>" ) ; writer . append ( "<STR_LIT>" ) ; writer . append ( input . getResourcePath ( "<STR_LIT>" ) ) ; writer . append ( "<STR_LIT>" ) ; writer . append ( "<STR_LIT>" ) ; writer . append ( input . getResourcePath ( "<STR_LIT>" ) ) ; writer . append ( "<STR_LIT>" ) ; writer . append ( "<STR_LIT>" ) ; writer . append ( "<STR_LIT>" ) ; writer . append ( "<STR_LIT:<>" + getTag ( ) + "<STR_LIT>" ) ; writer . append ( "<STR_LIT>" ) ; writer . append ( binaryServletPath ) ; writer . append ( "<STR_LIT>" + getMediaMime ( ) + "<STR_LIT>" ) ; writer . append ( "<STR_LIT>" ) ; writer . append ( "<STR_LIT>" + getTag ( ) + "<STR_LIT:>>" ) ; writer . append ( "<STR_LIT>" ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } private String getTimeRange ( VisualizerInput input ) { AnnotationGraph g = input . getResult ( ) . getGraph ( ) ; List < AnnisNode > resultList = g . getNodes ( ) ; AnnisNode n = resultList . get ( <NUM_LIT:0> ) ; Set < Annotation > nodeAnnotations = n . getNodeAnnotations ( ) ; StringBuffer ret ; for ( Annotation annotation : nodeAnnotations ) { if ( "<STR_LIT>" . equals ( annotation . getName ( ) ) ) { ret = new StringBuffer ( "<STR_LIT>" ) ; ret . append ( annotation . getValue ( ) . split ( "<STR_LIT:->" ) [ <NUM_LIT:0> ] ) ; ret . append ( "<STR_LIT:;>" ) ; return ret . toString ( ) ; } } return "<STR_LIT>" ; } public abstract String getTag ( ) ; public abstract String getMediaMime ( ) ; } </s>
<s> package annis . gui . visualizers ; import annis . gui . MainApp ; import annis . gui . visualizers . component . KWICPanel ; import com . vaadin . Application ; import com . vaadin . ui . Component ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCore . SNode ; import java . util . Map ; import java . util . Set ; import net . xeoh . plugins . base . Plugin ; public interface VisualizerPlugin < I extends Component > extends Plugin { public String getShortName ( ) ; public I createComponent ( VisualizerInput visInput , Application application ) ; public boolean isUsingText ( ) ; public void setVisibleTokenAnnosVisible ( I visualizerImplementation , Set < String > annos ) ; public void setSegmentationLayer ( I visualizerImplementation , String segmentationName , Map < SNode , Long > markedAndCovered ) ; } </s>
<s> package annis . gui . visualizers ; import annis . gui . MatchedNodeColors ; import annis . gui . resultview . VisualizerPanel ; import annis . service . ifaces . AnnisResult ; import annis . service . objects . AnnisResultImpl ; import annis . utils . LegacyGraphConverter ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCommon . sCorpusStructure . SDocument ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCommon . sDocumentStructure . STextualDS ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCommon . sDocumentStructure . SToken ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCore . SNode ; import java . io . Writer ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; import java . util . Properties ; import java . util . Set ; public class VisualizerInput { private SDocument document ; private String namespace = "<STR_LIT>" ; private Map < SNode , Long > markedAndCovered ; private Map < String , String > markableMap = new HashMap < String , String > ( ) ; private Map < String , String > markableExactMap = new HashMap < String , String > ( ) ; private String id = "<STR_LIT>" ; private String contextPath ; private String annisWebServiceURL ; private String dotPath ; private AnnisResult result ; private Properties mappings ; private String resourcePathTemplate = "<STR_LIT:%s>" ; private List < SToken > token ; private Set < String > tokenAnnos ; private STextualDS text ; private String segmentationName ; private VisualizerPanel visPanel ; public String getAnnisWebServiceURL ( ) { return annisWebServiceURL ; } public void setAnnisWebServiceURL ( String annisRemoteServiceURL ) { this . annisWebServiceURL = annisRemoteServiceURL ; } public String getContextPath ( ) { return contextPath ; } public void setContextPath ( String contextPath ) { this . contextPath = contextPath ; } @ Deprecated public String getDotPath ( ) { return dotPath ; } @ Deprecated public void setDotPath ( String dotPath ) { this . dotPath = dotPath ; } public String getId ( ) { return id ; } public void setId ( String id ) { this . id = id ; } public Properties getMappings ( ) { return mappings ; } public void setMappings ( Properties mappings ) { this . mappings = mappings ; } @ Deprecated public Map < String , String > getMarkableExactMap ( ) { return markableExactMap ; } @ Deprecated public void setMarkableExactMap ( Map < String , String > markableExactMap ) { this . markableExactMap = markableExactMap ; } @ Deprecated public Map < String , String > getMarkableMap ( ) { return markableMap ; } @ Deprecated public void setMarkableMap ( Map < String , String > markableMap ) { this . markableMap = markableMap ; } public void setMarkedAndCovered ( Map < SNode , Long > markedAndCovered ) { this . markedAndCovered = markedAndCovered ; } public Map < SNode , Long > getMarkedAndCovered ( ) { return markedAndCovered ; } public String getNamespace ( ) { return namespace ; } public void setNamespace ( String namespace ) { this . namespace = namespace ; } @ Deprecated public AnnisResult getResult ( ) { if ( result == null ) { result = new AnnisResultImpl ( LegacyGraphConverter . convertToAnnotationGraph ( document ) ) ; } return result ; } public SDocument getDocument ( ) { return document ; } public void setDocument ( SDocument document ) { this . document = document ; } public void setResult ( SDocument document ) { setDocument ( document ) ; } public SDocument getSResult ( ) { return getDocument ( ) ; } public String getResourcePathTemplate ( ) { return resourcePathTemplate ; } public void setResourcePathTemplate ( String resourcePathTemplate ) { this . resourcePathTemplate = resourcePathTemplate ; } public String getResourcePath ( String resource ) { return String . format ( resourcePathTemplate , resource ) ; } public void setToken ( List < SToken > token ) { this . token = token ; } public List < SToken > getToken ( ) { return this . token ; } public void setVisibleTokenAnnos ( Set < String > tokenAnnos ) { this . tokenAnnos = tokenAnnos ; } public Set < String > getVisibleTokenAnnos ( ) { return this . tokenAnnos ; } public void setText ( STextualDS text ) { this . text = text ; } public STextualDS getText ( ) { return this . text ; } public void setSegmentationName ( String segmentationName ) { this . segmentationName = segmentationName ; } public String getSegmentationName ( ) { return segmentationName ; } public VisualizerPanel getVisPanel ( ) { return visPanel ; } public void setVisPanel ( VisualizerPanel visPanel ) { this . visPanel = visPanel ; } } </s>
<s> package annis . gui . visualizers ; import net . xeoh . plugins . base . Plugin ; public interface ResourcePlugin extends Plugin { public String getShortName ( ) ; } </s>
<s> package annis . gui . visualizers ; import annis . gui . widgets . AutoHeightIFrame ; import com . vaadin . Application ; import com . vaadin . terminal . ApplicationResource ; import com . vaadin . ui . Component ; import java . io . ByteArrayOutputStream ; import java . io . OutputStream ; public abstract class AbstractIFrameVisualizer extends AbstractVisualizer implements ResourcePlugin { public String getCharacterEncoding ( ) { return "<STR_LIT:utf-8>" ; } public String getContentType ( ) { return "<STR_LIT:text/html>" ; } public abstract void writeOutput ( VisualizerInput input , OutputStream outstream ) ; @ Override public Component createComponent ( VisualizerInput vis , Application application ) { AutoHeightIFrame iframe ; ApplicationResource resource ; ByteArrayOutputStream outStream = new ByteArrayOutputStream ( ) ; writeOutput ( vis , outStream ) ; resource = vis . getVisPanel ( ) . createResource ( outStream , getContentType ( ) ) ; String url = vis . getVisPanel ( ) . getApplication ( ) . getRelativeLocation ( resource ) ; iframe = new AutoHeightIFrame ( url == null ? "<STR_LIT>" : url ) ; return iframe ; } } </s>
<s> package annis . gui . visualizers ; import com . vaadin . ui . Component ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCore . SNode ; import java . util . List ; import java . util . Map ; import java . util . Set ; public abstract class AbstractVisualizer < I extends Component > implements VisualizerPlugin < I > { @ Override public boolean isUsingText ( ) { return false ; } @ Override public void setSegmentationLayer ( I visualizerImplementation , String segmentationName , Map < SNode , Long > markedAndCovered ) { } @ Override public void setVisibleTokenAnnosVisible ( I visualizerImplementation , Set < String > annos ) { } } </s>
<s> package annis . gui . visualizers . component ; import annis . CommonHelper ; import annis . gui . MatchedNodeColors ; import annis . gui . media . MediaController ; import annis . gui . media . MediaControllerFactory ; import annis . gui . media . MediaControllerHolder ; import annis . gui . visualizers . AbstractVisualizer ; import annis . gui . visualizers . VisualizerInput ; import annis . model . AnnisConstants ; import com . vaadin . Application ; import com . vaadin . data . util . BeanItemContainer ; import com . vaadin . event . ItemClickEvent ; import com . vaadin . ui . AbstractSelect ; import com . vaadin . ui . Component ; import com . vaadin . ui . Table ; import com . vaadin . ui . themes . ChameleonTheme ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCommon . sCorpusStructure . SDocument ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCommon . sDocumentStructure . * ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCore . SAnnotation ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCore . SFeature ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCore . SNode ; import java . util . * ; import net . xeoh . plugins . base . annotations . PluginImplementation ; import net . xeoh . plugins . base . annotations . injections . InjectPlugin ; import org . eclipse . emf . common . util . BasicEList ; import org . eclipse . emf . common . util . EList ; import org . slf4j . LoggerFactory ; @ PluginImplementation public class KWICPanel extends AbstractVisualizer < KWICPanel . KWICPanelImpl > { @ InjectPlugin public MediaControllerFactory mcFactory ; @ Override public String getShortName ( ) { return "<STR_LIT>" ; } @ Override public KWICPanelImpl createComponent ( VisualizerInput visInput , Application application ) { MediaController mediaController = null ; if ( mcFactory != null && application instanceof MediaControllerHolder ) { mediaController = mcFactory . getOrCreate ( ( MediaControllerHolder ) application ) ; } return new KWICPanelImpl ( visInput , mediaController ) ; } @ Override public void setVisibleTokenAnnosVisible ( KWICPanelImpl visualizerImplementation , Set < String > annos ) { visualizerImplementation . setVisibleTokenAnnosVisible ( annos ) ; } @ Override public void setSegmentationLayer ( KWICPanelImpl visualizerImplementation , String segmentationName , Map < SNode , Long > markedAndCovered ) { visualizerImplementation . setSegmentationLayer ( segmentationName , markedAndCovered ) ; } public static class KWICPanelImpl extends Table implements ItemClickEvent . ItemClickListener { private final org . slf4j . Logger log = LoggerFactory . getLogger ( KWICPanelImpl . class ) ; private SDocument result ; private static final String DUMMY_COLUMN = "<STR_LIT>" ; private BeanItemContainer < String > containerAnnos ; private Map < SNode , Long > markedAndCovered ; private MediaController mediaController ; private String [ ] media_annotations = { "<STR_LIT>" } ; private List < Object > generatedColumns ; private VisualizerInput visInput ; public KWICPanelImpl ( VisualizerInput visInput , MediaController mediaController ) { this . generatedColumns = new LinkedList < Object > ( ) ; this . visInput = visInput ; this . mediaController = mediaController ; } @ Override public void attach ( ) { if ( visInput != null ) { initKWICPanel ( visInput . getSResult ( ) , visInput . getVisibleTokenAnnos ( ) , visInput . getMarkedAndCovered ( ) , visInput . getText ( ) , visInput . getSegmentationName ( ) ) ; } } private void initKWICPanel ( SDocument result , Set < String > tokenAnnos , Map < SNode , Long > markedAndCovered , STextualDS text , String segmentationName ) { this . result = result ; this . markedAndCovered = markedAndCovered ; this . addListener ( ( ItemClickEvent . ItemClickListener ) this ) ; this . addStyleName ( "<STR_LIT>" ) ; setSizeFull ( ) ; setHeight ( "<STR_LIT>" ) ; addStyleName ( ChameleonTheme . PANEL_BORDERLESS ) ; containerAnnos = new BeanItemContainer < String > ( String . class ) ; containerAnnos . addItem ( "<STR_LIT>" ) ; setColumnHeaderMode ( Table . COLUMN_HEADER_MODE_HIDDEN ) ; addStyleName ( ChameleonTheme . TABLE_BORDERLESS ) ; setWidth ( "<STR_LIT>" ) ; setHeight ( "<STR_LIT>" ) ; setPageLength ( <NUM_LIT:0> ) ; addStyleName ( "<STR_LIT>" ) ; if ( CommonHelper . containsRTLText ( text . getSText ( ) ) ) { addStyleName ( "<STR_LIT>" ) ; } SDocumentGraph graph = result . getSDocumentGraph ( ) ; ArrayList < Object > visible = new ArrayList < Object > ( <NUM_LIT:10> ) ; Long lastTokenIndex = null ; List < SNode > token = CommonHelper . getSortedSegmentationNodes ( segmentationName , graph ) ; for ( SNode t : token ) { STextualDS tokenText = null ; EList < STYPE_NAME > types = new BasicEList < STYPE_NAME > ( ) ; types . add ( STYPE_NAME . STEXT_OVERLAPPING_RELATION ) ; EList < SDataSourceSequence > dataSources = graph . getOverlappedDSSequences ( t , types ) ; if ( dataSources != null ) { for ( SDataSourceSequence seq : dataSources ) { if ( seq . getSSequentialDS ( ) instanceof STextualDS ) { tokenText = ( STextualDS ) seq . getSSequentialDS ( ) ; break ; } } } SFeature featTokenIndex = t . getSFeature ( AnnisConstants . ANNIS_NS , segmentationName == null ? AnnisConstants . FEAT_TOKENINDEX : AnnisConstants . FEAT_SEGLEFT ) ; if ( tokenText == text ) { if ( lastTokenIndex != null && featTokenIndex != null && featTokenIndex . getSValueSNUMERIC ( ) . longValue ( ) > ( lastTokenIndex . longValue ( ) + <NUM_LIT:1> ) ) { Long gapColumnID = featTokenIndex . getSValueSNUMERIC ( ) ; addGeneratedColumn ( gapColumnID , new KWICPanelImpl . GapColumnGenerator ( ) ) ; generatedColumns . add ( gapColumnID ) ; setColumnExpandRatio ( gapColumnID , <NUM_LIT:0.0f> ) ; visible . add ( gapColumnID ) ; } try { addGeneratedColumn ( t , new KWICPanelImpl . TokenColumnGenerator ( t , segmentationName ) ) ; generatedColumns . add ( t ) ; setColumnExpandRatio ( t , <NUM_LIT:0.0f> ) ; } catch ( IllegalArgumentException ex ) { log . error ( "<STR_LIT:unknown>" , ex ) ; } visible . add ( t ) ; if ( featTokenIndex != null ) { lastTokenIndex = featTokenIndex . getSValueSNUMERIC ( ) ; } } } addGeneratedColumn ( DUMMY_COLUMN , new Table . ColumnGenerator ( ) { @ Override public Object generateCell ( Table source , Object itemId , Object columnId ) { return "<STR_LIT>" ; } } ) ; generatedColumns . add ( DUMMY_COLUMN ) ; setColumnWidth ( DUMMY_COLUMN , <NUM_LIT:0> ) ; setColumnExpandRatio ( DUMMY_COLUMN , <NUM_LIT:1.0f> ) ; visible . add ( DUMMY_COLUMN ) ; containerAnnos . addAll ( tokenAnnos ) ; setContainerDataSource ( containerAnnos ) ; setVisibleColumns ( visible . toArray ( ) ) ; setCellStyleGenerator ( new KWICPanelImpl . KWICStyleGenerator ( ) ) ; setItemDescriptionGenerator ( new KWICPanelImpl . TooltipGenerator ( ) ) ; } public void setVisibleTokenAnnosVisible ( Set < String > annos ) { if ( containerAnnos != null ) { containerAnnos . removeAllItems ( ) ; containerAnnos . addItem ( "<STR_LIT>" ) ; containerAnnos . addAll ( annos ) ; } } public void setSegmentationLayer ( String segmentationName , Map < SNode , Long > markedAndCovered ) { if ( generatedColumns != null ) { for ( Object o : generatedColumns ) { removeGeneratedColumn ( o ) ; } } generatedColumns = new LinkedList < Object > ( ) ; if ( visInput != null ) { initKWICPanel ( visInput . getSResult ( ) , visInput . getVisibleTokenAnnos ( ) , markedAndCovered , visInput . getText ( ) , segmentationName ) ; } } public static class TooltipGenerator implements AbstractSelect . ItemDescriptionGenerator { public String generateDescription ( String layer , SToken token ) { SAnnotation a = token . getSAnnotation ( layer ) ; if ( a != null ) { return a . getQName ( ) ; } return null ; } @ Override public String generateDescription ( Component source , Object itemId , Object propertyId ) { if ( propertyId != null && propertyId instanceof SToken ) { return generateDescription ( ( String ) itemId , ( SToken ) propertyId ) ; } else { return null ; } } } public class KWICStyleGenerator implements Table . CellStyleGenerator { public String getStyle ( String layer , SNode token ) { if ( "<STR_LIT>" . equals ( layer ) ) { if ( markedAndCovered . containsKey ( token ) ) { return MatchedNodeColors . colorClassByMatch ( markedAndCovered . get ( token ) ) ; } else { return null ; } } else { SAnnotation a = token . getSAnnotation ( layer ) ; if ( a != null ) { for ( String media_anno : media_annotations ) { if ( media_anno . equals ( a . getName ( ) ) ) { if ( ! a . getValueString ( ) . matches ( "<STR_LIT>" ) ) { return "<STR_LIT>" ; } } } } } return "<STR_LIT>" ; } @ Override public String getStyle ( Object itemId , Object propertyId ) { if ( propertyId != null && propertyId instanceof SNode ) { return getStyle ( ( String ) itemId , ( SNode ) propertyId ) ; } else { return null ; } } } public static class GapColumnGenerator implements Table . ColumnGenerator { public Object generateCell ( String layer ) { if ( "<STR_LIT>" . equals ( layer ) ) { return "<STR_LIT>" ; } return "<STR_LIT>" ; } @ Override public Object generateCell ( Table source , Object itemId , Object columnId ) { return generateCell ( ( String ) itemId ) ; } } public class TokenColumnGenerator implements Table . ColumnGenerator { private Map < String , SAnnotation > annotationsByQName ; private SNode token ; private String segmentationName ; public TokenColumnGenerator ( SNode token , String segmentationName ) { this . token = token ; this . segmentationName = segmentationName ; annotationsByQName = new HashMap < String , SAnnotation > ( ) ; for ( SAnnotation a : token . getSAnnotations ( ) ) { annotationsByQName . put ( a . getQName ( ) , a ) ; if ( a . getSName ( ) . equals ( segmentationName ) ) { annotationsByQName . put ( a . getSName ( ) , a ) ; } } } public Object generateCell ( String layer ) { BasicEList < STYPE_NAME > textualRelation = new BasicEList < STYPE_NAME > ( ) ; textualRelation . add ( STYPE_NAME . STEXT_OVERLAPPING_RELATION ) ; SDocumentGraph docGraph = result . getSDocumentGraph ( ) ; if ( "<STR_LIT>" . equals ( layer ) ) { if ( segmentationName == null ) { SDataSourceSequence seq = docGraph . getOverlappedDSSequences ( token , textualRelation ) . get ( <NUM_LIT:0> ) ; return ( ( String ) seq . getSSequentialDS ( ) . getSData ( ) ) . substring ( seq . getSStart ( ) , seq . getSEnd ( ) ) ; } else { SAnnotation a = annotationsByQName . get ( segmentationName ) ; if ( a != null ) { return a . getValueString ( ) ; } } } else { SAnnotation a = annotationsByQName . get ( layer ) ; if ( a != null ) { for ( String media_anno : media_annotations ) { if ( media_anno . equals ( a . getName ( ) ) ) { return a . getSValueSTEXT ( ) ; } } return a . getValueString ( ) ; } } return "<STR_LIT>" ; } @ Override public Object generateCell ( Table source , Object itemId , Object columnId ) { return generateCell ( ( String ) itemId ) ; } } @ Override public void itemClick ( ItemClickEvent event ) { String buttonName = ( String ) event . getItemId ( ) ; if ( buttonName == null ) { return ; } if ( ! buttonName . matches ( "<STR_LIT>" ) ) { return ; } String time = null ; SToken token = ( SToken ) event . getPropertyId ( ) ; for ( SAnnotation anno : token . getSAnnotations ( ) ) { for ( String media_anno : media_annotations ) { if ( media_anno . equals ( anno . getName ( ) ) ) { time = anno . getValueString ( ) ; } } } if ( time != null && time . matches ( "<STR_LIT>" ) ) { return ; } if ( time != null ) { startMediaVisualizers ( time ) ; } } public void startMediaVisualizers ( String time ) { if ( mediaController != null ) { String [ ] split = time . split ( "<STR_LIT:->" ) ; if ( split . length == <NUM_LIT:1> ) { mediaController . play ( visInput . getId ( ) , Double . parseDouble ( split [ <NUM_LIT:0> ] ) ) ; } else if ( split . length == <NUM_LIT:2> ) { mediaController . play ( visInput . getId ( ) , Double . parseDouble ( split [ <NUM_LIT:0> ] ) , Double . parseDouble ( split [ <NUM_LIT:1> ] ) ) ; } } } } } </s>
<s> package annis . gui . visualizers . component ; import annis . CommonHelper ; import annis . gui . media . MediaController ; import annis . gui . media . MediaControllerFactory ; import annis . gui . media . MediaControllerHolder ; import annis . gui . visualizers . AbstractVisualizer ; import annis . gui . visualizers . VisualizerInput ; import annis . gui . widgets . VideoPlayer ; import com . vaadin . Application ; import com . vaadin . terminal . gwt . server . WebApplicationContext ; import java . io . UnsupportedEncodingException ; import java . net . URLEncoder ; import java . util . List ; import net . xeoh . plugins . base . annotations . PluginImplementation ; import net . xeoh . plugins . base . annotations . injections . InjectPlugin ; import org . slf4j . Logger ; import org . slf4j . LoggerFactory ; @ PluginImplementation public class VideoVisualizer extends AbstractVisualizer < VideoPlayer > { private Logger log = LoggerFactory . getLogger ( VideoVisualizer . class ) ; @ InjectPlugin public MediaControllerFactory mcFactory ; @ Override public String getShortName ( ) { return "<STR_LIT>" ; } @ Override public VideoPlayer createComponent ( VisualizerInput input , Application application ) { List < String > corpusPath = CommonHelper . getCorpusPath ( input . getDocument ( ) . getSCorpusGraph ( ) , input . getDocument ( ) ) ; String binaryServletPath = "<STR_LIT>" ; try { binaryServletPath = input . getContextPath ( ) + "<STR_LIT>" + "<STR_LIT>" + URLEncoder . encode ( corpusPath . get ( <NUM_LIT:0> ) , "<STR_LIT:UTF-8>" ) + "<STR_LIT>" + URLEncoder . encode ( corpusPath . get ( corpusPath . size ( ) - <NUM_LIT:1> ) , "<STR_LIT:UTF-8>" ) ; } catch ( UnsupportedEncodingException ex ) { log . error ( "<STR_LIT>" , ex ) ; } VideoPlayer player = new VideoPlayer ( binaryServletPath , "<STR_LIT>" ) ; if ( mcFactory != null && application instanceof MediaControllerHolder ) { mcFactory . getOrCreate ( ( MediaControllerHolder ) application ) . addMediaPlayer ( player , input . getId ( ) , input . getVisPanel ( ) ) ; } return player ; } } </s>
<s> package annis . gui . visualizers . component ; import annis . CommonHelper ; import annis . gui . media . MediaControllerFactory ; import annis . gui . media . MediaControllerHolder ; import annis . gui . visualizers . AbstractVisualizer ; import annis . gui . visualizers . VisualizerInput ; import annis . gui . widgets . AudioPlayer ; import com . vaadin . Application ; import java . io . UnsupportedEncodingException ; import java . net . URLEncoder ; import java . util . List ; import net . xeoh . plugins . base . annotations . PluginImplementation ; import net . xeoh . plugins . base . annotations . injections . InjectPlugin ; import org . slf4j . Logger ; import org . slf4j . LoggerFactory ; @ PluginImplementation public class AudioVisualizer extends AbstractVisualizer < AudioPlayer > { private Logger log = LoggerFactory . getLogger ( AudioVisualizer . class ) ; @ InjectPlugin public MediaControllerFactory mcFactory ; @ Override public String getShortName ( ) { return "<STR_LIT>" ; } @ Override public AudioPlayer createComponent ( VisualizerInput input , Application application ) { List < String > corpusPath = CommonHelper . getCorpusPath ( input . getDocument ( ) . getSCorpusGraph ( ) , input . getDocument ( ) ) ; String binaryServletPath = "<STR_LIT>" ; try { binaryServletPath = input . getContextPath ( ) + "<STR_LIT>" + "<STR_LIT>" + URLEncoder . encode ( corpusPath . get ( <NUM_LIT:0> ) , "<STR_LIT:UTF-8>" ) + "<STR_LIT>" + URLEncoder . encode ( corpusPath . get ( corpusPath . size ( ) - <NUM_LIT:1> ) , "<STR_LIT:UTF-8>" ) ; } catch ( UnsupportedEncodingException ex ) { log . error ( "<STR_LIT>" , ex ) ; } AudioPlayer player = new AudioPlayer ( binaryServletPath , "<STR_LIT>" ) ; if ( mcFactory != null && application instanceof MediaControllerHolder ) { mcFactory . getOrCreate ( ( MediaControllerHolder ) application ) . addMediaPlayer ( player , input . getId ( ) , input . getVisPanel ( ) ) ; } return player ; } } </s>
<s> package annis . gui . visualizers . component . grid ; import annis . gui . widgets . grid . GridEvent ; import annis . gui . widgets . grid . Row ; import annis . CommonHelper ; import annis . gui . media . MediaController ; import annis . gui . media . MediaControllerFactory ; import annis . gui . media . MediaControllerHolder ; import annis . gui . media . impl . TimeHelper ; import static annis . model . AnnisConstants . * ; import annis . gui . visualizers . AbstractVisualizer ; import annis . gui . visualizers . VisualizerInput ; import annis . gui . widgets . grid . AnnotationGrid ; import com . vaadin . Application ; import com . vaadin . ui . Panel ; import com . vaadin . ui . VerticalLayout ; import com . vaadin . ui . themes . ChameleonTheme ; import de . hu_berlin . german . korpling . saltnpepper . salt . graph . Edge ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCommon . sDocumentStructure . SDocumentGraph ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCommon . sDocumentStructure . SSpan ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCommon . sDocumentStructure . SSpanningRelation ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCommon . sDocumentStructure . STYPE_NAME ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCommon . sDocumentStructure . SToken ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCore . SAnnotation ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCore . SFeature ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCore . SLayer ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCore . SNode ; import java . util . ArrayList ; import java . util . Collections ; import java . util . Comparator ; import java . util . LinkedHashMap ; import java . util . LinkedList ; import java . util . List ; import java . util . ListIterator ; import java . util . Map ; import java . util . Random ; import java . util . Set ; import java . util . TreeSet ; import net . xeoh . plugins . base . annotations . PluginImplementation ; import net . xeoh . plugins . base . annotations . injections . InjectPlugin ; import org . apache . commons . lang3 . builder . CompareToBuilder ; import org . eclipse . emf . common . util . BasicEList ; import org . eclipse . emf . common . util . EList ; import org . slf4j . LoggerFactory ; @ PluginImplementation public class GridVisualizer extends AbstractVisualizer < GridVisualizer . GridVisualizerComponent > { @ InjectPlugin public MediaControllerFactory mcFactory ; @ Override public String getShortName ( ) { return "<STR_LIT>" ; } @ Override public GridVisualizerComponent createComponent ( VisualizerInput visInput , Application application ) { MediaController mediaController = null ; if ( mcFactory != null && application instanceof MediaControllerHolder ) { mediaController = mcFactory . getOrCreate ( ( MediaControllerHolder ) application ) ; } GridVisualizerComponent component = new GridVisualizerComponent ( visInput , mediaController ) ; return component ; } public static class GridVisualizerComponent extends Panel { private static final org . slf4j . Logger log = LoggerFactory . getLogger ( GridVisualizerComponent . class ) ; public static final String MAPPING_ANNOS_KEY = "<STR_LIT>" ; public static final String MAPPING_HIDE_TOK_KEY = "<STR_LIT>" ; private AnnotationGrid grid ; private VisualizerInput input ; private MediaController mediaController ; public enum ElementType { begin , end , middle , single , noEvent } public GridVisualizerComponent ( VisualizerInput input , MediaController mediaController ) { this . input = input ; this . mediaController = mediaController ; setWidth ( "<STR_LIT>" ) ; setHeight ( "<STR_LIT:-1>" ) ; ( ( VerticalLayout ) getContent ( ) ) . setSizeUndefined ( ) ; addStyleName ( ChameleonTheme . PANEL_BORDERLESS ) ; } @ Override public void attach ( ) { String resultID = input . getId ( ) ; grid = new AnnotationGrid ( mediaController , resultID ) ; grid . addStyleName ( "<STR_LIT>" ) ; addComponent ( grid ) ; SDocumentGraph graph = input . getDocument ( ) . getSDocumentGraph ( ) ; List < String > annos = new LinkedList < String > ( getAnnotationLevelSet ( graph , input . getNamespace ( ) ) ) ; String annosConfiguration = input . getMappings ( ) . getProperty ( MAPPING_ANNOS_KEY ) ; if ( annosConfiguration != null && annosConfiguration . trim ( ) . length ( ) > <NUM_LIT:0> ) { String [ ] split = annosConfiguration . split ( "<STR_LIT:U+002C>" ) ; annos . clear ( ) ; for ( String s : split ) { annos . add ( s . trim ( ) ) ; } } EList < SToken > token = graph . getSortedSTokenByText ( ) ; long startIndex = token . get ( <NUM_LIT:0> ) . getSFeature ( ANNIS_NS , FEAT_TOKENINDEX ) . getSValueSNUMERIC ( ) ; long endIndex = token . get ( token . size ( ) - <NUM_LIT:1> ) . getSFeature ( ANNIS_NS , FEAT_TOKENINDEX ) . getSValueSNUMERIC ( ) ; LinkedHashMap < String , ArrayList < Row > > rowsByAnnotation = parseSalt ( input . getDocument ( ) . getSDocumentGraph ( ) , annos , ( int ) startIndex , ( int ) endIndex ) ; Row tokenRow = new Row ( ) ; for ( SToken t : token ) { long idx = t . getSFeature ( ANNIS_NS , FEAT_TOKENINDEX ) . getSValueSNUMERIC ( ) - startIndex ; String text = CommonHelper . getSpannedText ( t ) ; GridEvent event = new GridEvent ( t . getSId ( ) , ( int ) idx , ( int ) idx , text ) ; SFeature featMatched = t . getSFeature ( ANNIS_NS , FEAT_MATCHEDNODE ) ; Long match = featMatched == null ? null : featMatched . getSValueSNUMERIC ( ) ; event . setMatch ( match ) ; tokenRow . addEvent ( event ) ; } ArrayList < Row > tokenRowList = new ArrayList < Row > ( ) ; tokenRowList . add ( tokenRow ) ; if ( Boolean . parseBoolean ( input . getMappings ( ) . getProperty ( MAPPING_HIDE_TOK_KEY , "<STR_LIT:false>" ) ) == false ) { rowsByAnnotation . put ( "<STR_LIT>" , tokenRowList ) ; } grid . setRowsByAnnotation ( rowsByAnnotation ) ; } private long clip ( long value , long min , long max ) { if ( value > max ) { return max ; } else if ( value < min ) { return min ; } else { return value ; } } private Set < String > getAnnotationLevelSet ( SDocumentGraph graph , String namespace ) { Set < String > result = new TreeSet < String > ( ) ; if ( graph != null ) { for ( SSpan n : graph . getSSpans ( ) ) { for ( SLayer layer : n . getSLayers ( ) ) { if ( namespace . equals ( layer . getSName ( ) ) ) { for ( SAnnotation anno : n . getSAnnotations ( ) ) { result . add ( anno . getQName ( ) ) ; } break ; } } } } return result ; } private LinkedHashMap < String , ArrayList < Row > > parseSalt ( SDocumentGraph graph , List < String > annotationNames , long startTokenIndex , long endTokenIndex ) { LinkedHashMap < String , ArrayList < Row > > rowsByAnnotation = new LinkedHashMap < String , ArrayList < Row > > ( ) ; for ( String anno : annotationNames ) { rowsByAnnotation . put ( anno , new ArrayList < Row > ( ) ) ; } EList < STYPE_NAME > types = new BasicEList < STYPE_NAME > ( ) ; types . add ( STYPE_NAME . SSPANNING_RELATION ) ; types . add ( STYPE_NAME . STEXTUAL_RELATION ) ; types . add ( STYPE_NAME . STEXT_OVERLAPPING_RELATION ) ; types . add ( STYPE_NAME . SSEQUENTIAL_RELATION ) ; int eventCounter = <NUM_LIT:0> ; for ( SSpan span : graph . getSSpans ( ) ) { long leftLong = span . getSFeature ( ANNIS_NS , FEAT_LEFTTOKEN ) . getSValueSNUMERIC ( ) ; long rightLong = span . getSFeature ( ANNIS_NS , FEAT_RIGHTTOKEN ) . getSValueSNUMERIC ( ) ; leftLong = clip ( leftLong , startTokenIndex , endTokenIndex ) ; rightLong = clip ( rightLong , startTokenIndex , endTokenIndex ) ; int left = ( int ) ( leftLong - startTokenIndex ) ; int right = ( int ) ( rightLong - startTokenIndex ) ; for ( SAnnotation anno : span . getSAnnotations ( ) ) { ArrayList < Row > rows = rowsByAnnotation . get ( anno . getQName ( ) ) ; if ( rows == null ) { rows = rowsByAnnotation . get ( anno . getSName ( ) ) ; } if ( rows != null ) { Row r = new Row ( ) ; String id = "<STR_LIT>" + eventCounter ++ ; GridEvent event = new GridEvent ( id , left , right , anno . getSValueSTEXT ( ) ) ; SFeature featMatched = span . getSFeature ( ANNIS_NS , FEAT_MATCHEDNODE ) ; Long match = featMatched == null ? null : featMatched . getSValueSNUMERIC ( ) ; event . setMatch ( match ) ; EList < Edge > outEdges = graph . getOutEdges ( span . getSId ( ) ) ; if ( outEdges != null ) { for ( Edge e : outEdges ) { if ( e instanceof SSpanningRelation ) { SSpanningRelation spanRel = ( SSpanningRelation ) e ; event . getCoveredIDs ( ) . add ( spanRel . getSTarget ( ) . getSId ( ) ) ; } } } double [ ] startEndTime = TimeHelper . getOverlappedTime ( span ) ; if ( startEndTime . length == <NUM_LIT:1> ) { event . setStartTime ( startEndTime [ <NUM_LIT:0> ] ) ; } else if ( startEndTime . length == <NUM_LIT:2> ) { event . setStartTime ( startEndTime [ <NUM_LIT:0> ] ) ; event . setEndTime ( startEndTime [ <NUM_LIT:1> ] ) ; } r . addEvent ( event ) ; rows . add ( r ) ; } } } for ( Map . Entry < String , ArrayList < Row > > e : rowsByAnnotation . entrySet ( ) ) { mergeAllRowsIfPossible ( e . getValue ( ) ) ; } for ( Map . Entry < String , ArrayList < Row > > e : rowsByAnnotation . entrySet ( ) ) { for ( Row r : e . getValue ( ) ) { sortEventsByTokenIndex ( r ) ; } } for ( Map . Entry < String , ArrayList < Row > > e : rowsByAnnotation . entrySet ( ) ) { for ( Row r : e . getValue ( ) ) { splitRowsOnGaps ( r , graph , startTokenIndex , endTokenIndex ) ; } } return rowsByAnnotation ; } private void splitRowsOnGaps ( Row row , final SDocumentGraph graph , long startTokenIndex , long endTokenIndex ) { ListIterator < GridEvent > itEvents = row . getEvents ( ) . listIterator ( ) ; while ( itEvents . hasNext ( ) ) { GridEvent event = itEvents . next ( ) ; int lastTokenIndex = Integer . MIN_VALUE ; LinkedList < String > sortedCoveredToken = new LinkedList < String > ( event . getCoveredIDs ( ) ) ; Collections . sort ( sortedCoveredToken , new Comparator < String > ( ) { @ Override public int compare ( String o1 , String o2 ) { SNode node1 = graph . getSNode ( o1 ) ; SNode node2 = graph . getSNode ( o2 ) ; if ( node1 == node2 ) { return <NUM_LIT:0> ; } if ( node1 == null ) { return - <NUM_LIT:1> ; } if ( node2 == null ) { return + <NUM_LIT:1> ; } long tokenIndex1 = node1 . getSFeature ( ANNIS_NS , FEAT_TOKENINDEX ) . getSValueSNUMERIC ( ) ; long tokenIndex2 = node2 . getSFeature ( ANNIS_NS , FEAT_TOKENINDEX ) . getSValueSNUMERIC ( ) ; return ( ( Long ) ( tokenIndex1 ) ) . compareTo ( tokenIndex2 ) ; } } ) ; List < GridEvent > gaps = new LinkedList < GridEvent > ( ) ; for ( String id : sortedCoveredToken ) { SNode node = graph . getSNode ( id ) ; long tokenIndexRaw = node . getSFeature ( ANNIS_NS , FEAT_TOKENINDEX ) . getSValueSNUMERIC ( ) ; tokenIndexRaw = clip ( tokenIndexRaw , startTokenIndex , endTokenIndex ) ; int tokenIndex = ( int ) ( tokenIndexRaw - startTokenIndex ) ; int diff = tokenIndex - lastTokenIndex ; if ( lastTokenIndex >= <NUM_LIT:0> && diff > <NUM_LIT:1> ) { GridEvent gap = new GridEvent ( event . getId ( ) + "<STR_LIT>" , lastTokenIndex + <NUM_LIT:1> , tokenIndex - <NUM_LIT:1> , "<STR_LIT>" ) ; gap . setGap ( true ) ; gaps . add ( gap ) ; } lastTokenIndex = tokenIndex ; } for ( GridEvent gap : gaps ) { int oldRight = event . getRight ( ) ; event . setRight ( gap . getLeft ( ) - <NUM_LIT:1> ) ; itEvents . add ( gap ) ; GridEvent after = new GridEvent ( event . getId ( ) + "<STR_LIT>" , gap . getRight ( ) + <NUM_LIT:1> , oldRight , event . getValue ( ) ) ; after . getCoveredIDs ( ) . addAll ( event . getCoveredIDs ( ) ) ; itEvents . add ( after ) ; } } } private void sortEventsByTokenIndex ( Row row ) { Collections . sort ( row . getEvents ( ) , new Comparator < GridEvent > ( ) { @ Override public int compare ( GridEvent o1 , GridEvent o2 ) { if ( o1 == o2 ) { return <NUM_LIT:0> ; } if ( o1 == null ) { return - <NUM_LIT:1> ; } if ( o2 == null ) { return + <NUM_LIT:1> ; } return ( ( Integer ) o1 . getLeft ( ) ) . compareTo ( o2 . getLeft ( ) ) ; } } ) ; } private void mergeAllRowsIfPossible ( ArrayList < Row > rows ) { Random rand = new Random ( <NUM_LIT> ) ; int tries = <NUM_LIT:0> ; final int maxTries = rows . size ( ) * <NUM_LIT:2> ; while ( rows . size ( ) > <NUM_LIT:1> && tries < maxTries ) { int oneIdx = rand . nextInt ( rows . size ( ) ) ; int secondIdx = rand . nextInt ( rows . size ( ) ) ; if ( oneIdx == secondIdx ) { continue ; } Row one = rows . get ( oneIdx ) ; Row second = rows . get ( secondIdx ) ; if ( one . merge ( second ) ) { rows . remove ( secondIdx ) ; tries = <NUM_LIT:0> ; } else { tries ++ ; } } } } } </s>
<s> package annis . gui . visualizers . component ; import annis . gui . ImagePanel ; import annis . gui . visualizers . AbstractVisualizer ; import annis . gui . visualizers . VisualizerInput ; import com . vaadin . Application ; import com . vaadin . terminal . StreamResource ; import com . vaadin . ui . Embedded ; import com . vaadin . ui . Panel ; import java . io . File ; import java . io . FileInputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . OutputStream ; import java . io . PipedInputStream ; import java . io . PipedOutputStream ; import java . util . Random ; import org . apache . commons . io . FileUtils ; import org . apache . commons . lang3 . StringUtils ; import org . slf4j . LoggerFactory ; public abstract class AbstractDotVisualizer extends AbstractVisualizer < ImagePanel > { private static final org . slf4j . Logger log = LoggerFactory . getLogger ( AbstractDotVisualizer . class ) ; @ Override public ImagePanel createComponent ( final VisualizerInput visInput , Application application ) { try { final PipedOutputStream out = new PipedOutputStream ( ) ; final PipedInputStream in = new PipedInputStream ( out ) ; new Thread ( new Runnable ( ) { @ Override public void run ( ) { writeOutput ( visInput , out ) ; } } ) . start ( ) ; String fileName = "<STR_LIT>" + new Random ( ) . nextInt ( Integer . MAX_VALUE ) + "<STR_LIT>" ; StreamResource resource = new StreamResource ( new StreamResource . StreamSource ( ) { @ Override public InputStream getStream ( ) { return in ; } } , fileName , application ) ; Embedded emb = new Embedded ( "<STR_LIT>" , resource ) ; emb . setMimeType ( "<STR_LIT>" ) ; emb . setSizeFull ( ) ; emb . setStandby ( "<STR_LIT>" ) ; emb . setAlternateText ( "<STR_LIT>" ) ; return new ImagePanel ( emb ) ; } catch ( IOException ex ) { log . error ( null , ex ) ; } return new ImagePanel ( new Embedded ( ) ) ; } public void writeOutput ( VisualizerInput input , OutputStream outstream ) { StringBuilder dot = new StringBuilder ( ) ; try { File tmpInput = File . createTempFile ( "<STR_LIT>" , "<STR_LIT>" ) ; tmpInput . deleteOnExit ( ) ; StringBuilder dotContent = new StringBuilder ( ) ; createDotContent ( input , dotContent ) ; FileUtils . writeStringToFile ( tmpInput , dotContent . toString ( ) ) ; ProcessBuilder pBuilder = new ProcessBuilder ( input . getMappings ( ) . getProperty ( "<STR_LIT>" , "<STR_LIT>" ) , "<STR_LIT>" , tmpInput . getCanonicalPath ( ) ) ; pBuilder . redirectErrorStream ( false ) ; Process process = pBuilder . start ( ) ; int resultCode = process . waitFor ( ) ; if ( resultCode != <NUM_LIT:0> ) { InputStream stderr = process . getErrorStream ( ) ; StringBuilder errorMessage = new StringBuilder ( ) ; for ( int chr = stderr . read ( ) ; chr != - <NUM_LIT:1> ; chr = stderr . read ( ) ) { errorMessage . append ( ( char ) chr ) ; } if ( ! "<STR_LIT>" . equals ( errorMessage . toString ( ) ) ) { log . error ( "<STR_LIT>" , new Object [ ] { StringUtils . join ( pBuilder . command ( ) , "<STR_LIT:U+0020>" ) , errorMessage . toString ( ) , dot . toString ( ) } ) ; } } InputStream fileInput = process . getInputStream ( ) ; for ( int chr = fileInput . read ( ) ; chr != - <NUM_LIT:1> ; chr = fileInput . read ( ) ) { outstream . write ( chr ) ; } fileInput . close ( ) ; if ( ! tmpInput . delete ( ) ) { log . warn ( "<STR_LIT>" + tmpInput . getAbsolutePath ( ) ) ; } } catch ( Exception ex ) { log . error ( null , ex ) ; } } public abstract void createDotContent ( VisualizerInput input , StringBuilder sb ) ; } </s>
<s> package annis . gui ; import annis . service . objects . AnnisCorpus ; import com . vaadin . Application ; import com . vaadin . ui . Button . ClickEvent ; import com . vaadin . ui . * ; import com . vaadin . ui . themes . ChameleonTheme ; import java . util . LinkedList ; import java . util . List ; import java . util . Map ; public class CitationWindow extends Window implements Button . ClickListener { public CitationWindow ( Application app , String query , Map < String , AnnisCorpus > corpora , int contextLeft , int contextRight ) { super ( "<STR_LIT>" ) ; VerticalLayout wLayout = ( VerticalLayout ) getContent ( ) ; wLayout . setSizeFull ( ) ; List < String > corpusNames = new LinkedList < String > ( corpora . keySet ( ) ) ; String url = Helper . generateCitation ( app , query , corpusNames , contextLeft , contextRight ) ; TextArea txtCitation = new TextArea ( ) ; txtCitation . setWidth ( "<STR_LIT>" ) ; txtCitation . setHeight ( "<STR_LIT>" ) ; txtCitation . addStyleName ( ChameleonTheme . TEXTFIELD_BIG ) ; txtCitation . addStyleName ( "<STR_LIT>" ) ; txtCitation . setValue ( url ) ; txtCitation . setWordwrap ( true ) ; txtCitation . setReadOnly ( true ) ; addComponent ( txtCitation ) ; Button btOk = new Button ( "<STR_LIT:OK>" ) ; btOk . addListener ( ( Button . ClickListener ) this ) ; btOk . setSizeUndefined ( ) ; addComponent ( btOk ) ; wLayout . setExpandRatio ( txtCitation , <NUM_LIT:1.0f> ) ; wLayout . setComponentAlignment ( btOk , Alignment . BOTTOM_CENTER ) ; setWidth ( "<STR_LIT>" ) ; setHeight ( "<STR_LIT>" ) ; } @ Override public void buttonClick ( ClickEvent event ) { this . getParent ( ) . removeWindow ( this ) ; } } </s>
<s> package annis . gui . querybuilder ; import annis . gui . controlpanel . ControlPanel ; import com . vaadin . ui . Button ; import com . vaadin . ui . Button . ClickEvent ; import com . vaadin . ui . HorizontalLayout ; import com . vaadin . ui . Panel ; import com . vaadin . ui . VerticalLayout ; import com . vaadin . ui . themes . ChameleonTheme ; public class TigerQueryBuilder extends Panel implements Button . ClickListener { private Button btAddNode ; private Button btClearAll ; private TigerQueryBuilderCanvas queryBuilder ; public TigerQueryBuilder ( ControlPanel controlPanel ) { VerticalLayout layout = ( VerticalLayout ) getContent ( ) ; layout . setSizeFull ( ) ; setSizeFull ( ) ; HorizontalLayout toolbar = new HorizontalLayout ( ) ; toolbar . addStyleName ( "<STR_LIT>" ) ; btAddNode = new Button ( "<STR_LIT>" , ( Button . ClickListener ) this ) ; btAddNode . setStyleName ( ChameleonTheme . BUTTON_SMALL ) ; btAddNode . setDescription ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; toolbar . addComponent ( btAddNode ) ; btClearAll = new Button ( "<STR_LIT>" , ( Button . ClickListener ) this ) ; btClearAll . setStyleName ( ChameleonTheme . BUTTON_SMALL ) ; btClearAll . setDescription ( "<STR_LIT>" + "<STR_LIT>" ) ; toolbar . addComponent ( btClearAll ) ; toolbar . setWidth ( "<STR_LIT>" ) ; toolbar . setHeight ( "<STR_LIT>" ) ; addComponent ( toolbar ) ; queryBuilder = new TigerQueryBuilderCanvas ( controlPanel ) ; addComponent ( queryBuilder ) ; layout . setExpandRatio ( queryBuilder , <NUM_LIT:1.0f> ) ; } @ Override public void buttonClick ( ClickEvent event ) { if ( event . getButton ( ) == btAddNode ) { queryBuilder . addNode ( ) ; } else if ( event . getButton ( ) == btClearAll ) { queryBuilder . clearAll ( ) ; } } } </s>
<s> package annis . gui . querybuilder ; import annis . gui . querybuilder . NodeWindow . SimpleNewItemHandler ; import com . vaadin . data . Property . ValueChangeEvent ; import com . vaadin . data . Property . ValueChangeListener ; import com . vaadin . ui . Button . ClickEvent ; import com . vaadin . ui . * ; import com . vaadin . ui . themes . ChameleonTheme ; public class EdgeWindow extends Panel implements Button . ClickListener { private static final String [ ] EDGE_OPERATORS = new String [ ] { "<STR_LIT:.>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:>>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:$>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ; private TigerQueryBuilderCanvas parent ; private ComboBox cbOperator ; private Button btClose ; private NodeWindow source ; private NodeWindow target ; public EdgeWindow ( final TigerQueryBuilderCanvas parent , NodeWindow source , NodeWindow target ) { this . parent = parent ; this . source = source ; this . target = target ; setSizeFull ( ) ; VerticalLayout vLayout = ( VerticalLayout ) getContent ( ) ; vLayout . setMargin ( false ) ; HorizontalLayout toolbar = new HorizontalLayout ( ) ; toolbar . addStyleName ( "<STR_LIT>" ) ; toolbar . setWidth ( "<STR_LIT>" ) ; toolbar . setHeight ( "<STR_LIT>" ) ; addComponent ( toolbar ) ; btClose = new Button ( "<STR_LIT:X>" ) ; btClose . setStyleName ( ChameleonTheme . BUTTON_SMALL ) ; btClose . addListener ( ( Button . ClickListener ) this ) ; toolbar . addComponent ( btClose ) ; toolbar . setComponentAlignment ( btClose , Alignment . MIDDLE_RIGHT ) ; cbOperator = new ComboBox ( ) ; cbOperator . setNewItemsAllowed ( true ) ; cbOperator . setNewItemHandler ( new SimpleNewItemHandler ( cbOperator ) ) ; cbOperator . setImmediate ( true ) ; addComponent ( cbOperator ) ; for ( String o : EDGE_OPERATORS ) { cbOperator . addItem ( o ) ; } cbOperator . setValue ( EDGE_OPERATORS [ <NUM_LIT:0> ] ) ; cbOperator . addListener ( new ValueChangeListener ( ) { @ Override public void valueChange ( ValueChangeEvent event ) { if ( parent != null ) { parent . updateQuery ( ) ; } } } ) ; cbOperator . setWidth ( "<STR_LIT>" ) ; cbOperator . setHeight ( "<STR_LIT>" ) ; vLayout . setExpandRatio ( cbOperator , <NUM_LIT:1.0f> ) ; } @ Override public void buttonClick ( ClickEvent event ) { if ( event . getButton ( ) == btClose ) { parent . deleteEdge ( this ) ; } } public NodeWindow getSource ( ) { return source ; } public NodeWindow getTarget ( ) { return target ; } public String getOperator ( ) { return ( String ) cbOperator . getValue ( ) ; } } </s>
<s> package annis . gui . querybuilder ; import annis . gui . Helper ; import annis . gui . controlpanel . ControlPanel ; import annis . gui . widgets . SimpleCanvas ; import annis . service . objects . AnnisAttribute ; import annis . service . objects . AnnisCorpus ; import com . sun . jersey . api . client . GenericType ; import com . sun . jersey . api . client . WebResource ; import com . vaadin . event . dd . DragAndDropEvent ; import com . vaadin . event . dd . DropHandler ; import com . vaadin . event . dd . acceptcriteria . AcceptAll ; import com . vaadin . event . dd . acceptcriteria . AcceptCriterion ; import com . vaadin . ui . AbsoluteLayout ; import com . vaadin . ui . AbsoluteLayout . ComponentPosition ; import com . vaadin . ui . DragAndDropWrapper ; import com . vaadin . ui . DragAndDropWrapper . WrapperTargetDetails ; import com . vaadin . ui . DragAndDropWrapper . WrapperTransferable ; import com . vaadin . ui . Layout ; import com . vaadin . ui . Panel ; import com . vaadin . ui . Window . Notification ; import java . awt . geom . Line2D ; import java . util . ArrayList ; import java . util . HashMap ; import java . util . LinkedList ; import java . util . List ; import java . util . Map ; import java . util . Set ; import java . util . TreeSet ; import org . slf4j . LoggerFactory ; public class TigerQueryBuilderCanvas extends Panel { private static final org . slf4j . Logger log = LoggerFactory . getLogger ( TigerQueryBuilderCanvas . class ) ; private SimpleCanvas canvas ; private Map < NodeWindow , DragAndDropWrapper > nodes ; private List < EdgeWindow > edges ; private AbsoluteLayout area ; private AbsoluteDropHandler handler ; private int number = <NUM_LIT:0> ; private NodeWindow preparedEdgeSource = null ; private ControlPanel controlPanel ; public TigerQueryBuilderCanvas ( ControlPanel controlPanel ) { this . controlPanel = controlPanel ; nodes = new HashMap < NodeWindow , DragAndDropWrapper > ( ) ; edges = new ArrayList < EdgeWindow > ( ) ; setSizeFull ( ) ; area = new AbsoluteLayout ( ) ; area . setWidth ( "<STR_LIT>" ) ; area . setHeight ( "<STR_LIT>" ) ; area . addStyleName ( "<STR_LIT>" ) ; area . addStyleName ( "<STR_LIT>" ) ; area . addStyleName ( "<STR_LIT>" ) ; canvas = new SimpleCanvas ( ) ; canvas . setWidth ( "<STR_LIT>" ) ; canvas . setHeight ( "<STR_LIT>" ) ; handler = new AbsoluteDropHandler ( this , area ) ; DragAndDropWrapper areaPane = new DragAndDropWrapper ( area ) ; areaPane . setSizeFull ( ) ; areaPane . setDropHandler ( handler ) ; area . addComponent ( canvas , "<STR_LIT>" ) ; setContent ( areaPane ) ; addStyleName ( "<STR_LIT>" ) ; addStyleName ( "<STR_LIT>" ) ; addStyleName ( "<STR_LIT>" ) ; } public void updateQuery ( ) { controlPanel . setQuery ( getAQLQuery ( ) , null ) ; } public Set < String > getAvailableAnnotationNames ( ) { Set < String > result = new TreeSet < String > ( ) ; WebResource service = Helper . getAnnisWebResource ( getApplication ( ) ) ; Map < String , AnnisCorpus > corpusSelection = controlPanel . getSelectedCorpora ( ) ; if ( service != null ) { try { List < AnnisAttribute > atts = new LinkedList < AnnisAttribute > ( ) ; for ( String corpus : corpusSelection . keySet ( ) ) { atts . addAll ( service . path ( "<STR_LIT>" ) . path ( corpus ) . path ( "<STR_LIT>" ) . queryParam ( "<STR_LIT>" , "<STR_LIT:false>" ) . queryParam ( "<STR_LIT>" , "<STR_LIT:true>" ) . get ( new GenericType < List < AnnisAttribute > > ( ) { } ) ) ; } for ( AnnisAttribute a : atts ) { if ( a . getType ( ) == AnnisAttribute . Type . node ) { result . add ( a . getName ( ) ) ; } } } catch ( Exception ex ) { log . error ( null , ex ) ; } } return result ; } public void updateLinesAndEdgePositions ( ) { canvas . getLines ( ) . clear ( ) ; for ( EdgeWindow e : edges ) { DragAndDropWrapper w1 = nodes . get ( e . getSource ( ) ) ; DragAndDropWrapper w2 = nodes . get ( e . getTarget ( ) ) ; ComponentPosition p1 = area . getPosition ( w1 ) ; ComponentPosition p2 = area . getPosition ( w2 ) ; float x1 = p1 . getLeftValue ( ) + ( w1 . getWidth ( ) / <NUM_LIT:2> ) ; float y1 = p1 . getTopValue ( ) + ( w1 . getHeight ( ) / <NUM_LIT:2> ) ; float x2 = p2 . getLeftValue ( ) + ( w2 . getWidth ( ) / <NUM_LIT:2> ) ; float y2 = p2 . getTopValue ( ) + ( w2 . getHeight ( ) / <NUM_LIT:2> ) ; float v_x = x2 - x1 ; float v_y = y2 - y1 ; canvas . getLines ( ) . add ( new Line2D . Float ( x1 , y1 , x2 , y2 ) ) ; ComponentPosition posEdge = area . getPosition ( e ) ; float vectorLength = ( float ) Math . sqrt ( Math . pow ( x2 - x1 , <NUM_LIT:2> ) + Math . pow ( y2 - y1 , <NUM_LIT:2> ) ) ; float xM = x1 + ( vectorLength / <NUM_LIT> ) * ( ( x2 - x1 ) / vectorLength ) ; float yM = y1 + ( vectorLength / <NUM_LIT> ) * ( ( y2 - y1 ) / vectorLength ) ; double normV_x = v_x / vectorLength ; double normV_y = v_y / vectorLength ; double pos1_x = ( <NUM_LIT> * vectorLength / <NUM_LIT:3> ) * normV_x + x1 ; double pos1_y = ( <NUM_LIT> * vectorLength / <NUM_LIT:3> ) * normV_y + y1 ; double origDir = Math . atan2 ( normV_y , normV_x ) ; double pos2_x = ( ( <NUM_LIT:1> * vectorLength ) / <NUM_LIT:3> ) * normV_x + x1 ; double pos2_y = ( ( <NUM_LIT:1> * vectorLength ) / <NUM_LIT:3> ) * normV_y + y1 ; canvas . getLines ( ) . addAll ( createArrow ( pos1_x , pos1_y , origDir , <NUM_LIT> ) ) ; canvas . getLines ( ) . addAll ( createArrow ( pos2_x , pos2_y , origDir , <NUM_LIT> ) ) ; posEdge . setLeftValue ( xM - e . getWidth ( ) / <NUM_LIT> ) ; posEdge . setTopValue ( yM - e . getHeight ( ) / <NUM_LIT> ) ; } canvas . requestRepaint ( ) ; } private List < Line2D > createArrow ( double x , double y , double direction , double arrowLength ) { LinkedList < Line2D > result = new LinkedList < Line2D > ( ) ; double dir1 = direction + Math . PI / <NUM_LIT> ; double dir2 = direction - Math . PI / <NUM_LIT> ; double end1_x = x - arrowLength * Math . cos ( dir1 ) ; double end1_y = y - arrowLength * Math . sin ( dir1 ) ; double end2_x = x - arrowLength * Math . cos ( dir2 ) ; double end2_y = y - arrowLength * Math . sin ( dir2 ) ; result . add ( new Line2D . Double ( x , y , end1_x , end1_y ) ) ; result . add ( new Line2D . Double ( x , y , end2_x , end2_y ) ) ; return result ; } public void prepareAddingEdge ( NodeWindow sourceNode ) { preparedEdgeSource = sourceNode ; for ( NodeWindow w : nodes . keySet ( ) ) { if ( w != sourceNode ) { w . setPrepareEdgeDock ( true ) ; } } } public void addEdge ( NodeWindow target ) { for ( NodeWindow w : nodes . keySet ( ) ) { w . setPrepareEdgeDock ( false ) ; } if ( preparedEdgeSource != target ) { boolean valid = true ; for ( EdgeWindow e : edges ) { if ( e . getSource ( ) == preparedEdgeSource && e . getTarget ( ) == target ) { valid = false ; break ; } } if ( valid ) { EdgeWindow e = new EdgeWindow ( this , preparedEdgeSource , target ) ; e . setWidth ( "<STR_LIT>" ) ; e . setHeight ( "<STR_LIT>" ) ; edges . add ( e ) ; area . addComponent ( e ) ; updateLinesAndEdgePositions ( ) ; updateQuery ( ) ; } else { getWindow ( ) . showNotification ( "<STR_LIT>" , Notification . TYPE_WARNING_MESSAGE ) ; } } } public void deleteEdge ( EdgeWindow e ) { area . removeComponent ( e ) ; edges . remove ( e ) ; updateLinesAndEdgePositions ( ) ; updateQuery ( ) ; } public void addNode ( ) { final NodeWindow n = new NodeWindow ( number ++ , this ) ; DragAndDropWrapper wrapper = new DragAndDropWrapper ( n ) ; nodes . put ( n , wrapper ) ; wrapper . setDragStartMode ( DragAndDropWrapper . DragStartMode . WRAPPER ) ; wrapper . setWidth ( NodeWindow . WIDTH , Layout . UNITS_PIXELS ) ; wrapper . setHeight ( NodeWindow . HEIGHT , Layout . UNITS_PIXELS ) ; area . addComponent ( wrapper , "<STR_LIT>" + ( <NUM_LIT> * ( number + <NUM_LIT:1> ) ) + "<STR_LIT>" ) ; updateQuery ( ) ; } public void deleteNode ( NodeWindow n ) { LinkedList < EdgeWindow > edgesToRemove = new LinkedList < EdgeWindow > ( ) ; for ( EdgeWindow e : edges ) { if ( e . getSource ( ) == n || e . getTarget ( ) == n ) { edgesToRemove . add ( e ) ; area . removeComponent ( e ) ; } } edges . removeAll ( edgesToRemove ) ; area . removeComponent ( nodes . get ( n ) ) ; nodes . remove ( n ) ; updateLinesAndEdgePositions ( ) ; updateQuery ( ) ; } public void clearAll ( ) { for ( EdgeWindow w : edges ) { area . removeComponent ( w ) ; } edges . clear ( ) ; for ( DragAndDropWrapper w : nodes . values ( ) ) { area . removeComponent ( w ) ; } nodes . clear ( ) ; number = <NUM_LIT:0> ; updateLinesAndEdgePositions ( ) ; updateQuery ( ) ; } private static class AbsoluteDropHandler implements DropHandler { private AbsoluteLayout layout ; private TigerQueryBuilderCanvas parent ; public AbsoluteDropHandler ( TigerQueryBuilderCanvas parent , AbsoluteLayout layout ) { this . layout = layout ; this . parent = parent ; } @ Override public void drop ( DragAndDropEvent event ) { WrapperTransferable t = ( WrapperTransferable ) event . getTransferable ( ) ; WrapperTargetDetails details = ( WrapperTargetDetails ) event . getTargetDetails ( ) ; if ( t == null || details == null ) { return ; } int xChange = details . getMouseEvent ( ) . getClientX ( ) - t . getMouseDownEvent ( ) . getClientX ( ) ; int yChange = details . getMouseEvent ( ) . getClientY ( ) - t . getMouseDownEvent ( ) . getClientY ( ) ; ComponentPosition pos = layout . getPosition ( t . getSourceComponent ( ) ) ; pos . setLeftValue ( pos . getLeftValue ( ) + xChange ) ; pos . setTopValue ( pos . getTopValue ( ) + yChange ) ; if ( parent != null ) { parent . updateLinesAndEdgePositions ( ) ; } } @ Override public AcceptCriterion getAcceptCriterion ( ) { return AcceptAll . get ( ) ; } } public String getAQLQuery ( ) { StringBuilder query = new StringBuilder ( ) ; StringBuffer nodeIdentityOperations = new StringBuffer ( ) ; Map < NodeWindow , Integer > nodeComponentMap = new HashMap < NodeWindow , Integer > ( ) ; int componentCount = <NUM_LIT:0> ; int nodeID = <NUM_LIT:1> ; for ( NodeWindow nodeWindow : nodes . keySet ( ) ) { List < NodeWindow . ConstraintLayout > constraints = nodeWindow . getConstraints ( ) ; if ( componentCount ++ > <NUM_LIT:0> ) { query . append ( "<STR_LIT>" ) ; } if ( constraints . size ( ) > <NUM_LIT:0> ) { int nodeComponentCount = <NUM_LIT:0> ; for ( NodeWindow . ConstraintLayout c : constraints ) { if ( nodeComponentCount ++ > <NUM_LIT:0> ) { nodeIdentityOperations . append ( "<STR_LIT>" ) . append ( componentCount ) . append ( "<STR_LIT>" ) . append ( componentCount + <NUM_LIT:1> ) ; query . append ( "<STR_LIT>" ) ; componentCount ++ ; } String operator = c . getOperator ( ) . replace ( "<STR_LIT>" , "<STR_LIT:=>" ) ; String quotes = c . getOperator ( ) . equals ( "<STR_LIT:=>" ) || c . getOperator ( ) . equals ( "<STR_LIT>" ) ? "<STR_LIT:\">" : "<STR_LIT:/>" ; String prefix = "<STR_LIT>" ; if ( c . getName ( ) . trim ( ) . isEmpty ( ) || c . getName ( ) . trim ( ) . equals ( "<STR_LIT>" ) ) { if ( operator . equals ( "<STR_LIT>" ) ) { prefix = "<STR_LIT>" + c . getName ( ) + operator ; } } else { prefix = c . getName ( ) + operator ; } if ( "<STR_LIT>" . equals ( c . getValue ( ) ) ) { query . append ( c . getName ( ) ) ; } else { query . append ( prefix ) . append ( quotes ) . append ( c . getValue ( ) ) . append ( quotes ) ; } } } else { query . append ( "<STR_LIT>" ) ; } nodeComponentMap . put ( nodeWindow , componentCount ) ; nodeID ++ ; } query . append ( nodeIdentityOperations ) ; for ( EdgeWindow edgeWindow : edges ) { query . append ( "<STR_LIT>" ) ; query . append ( '<CHAR_LIT>' ) . append ( nodeComponentMap . get ( edgeWindow . getSource ( ) ) ) . append ( "<STR_LIT:U+0020>" ) . append ( edgeWindow . getOperator ( ) ) . append ( "<STR_LIT:U+0020>" ) . append ( "<STR_LIT:#>" ) . append ( nodeComponentMap . get ( edgeWindow . getTarget ( ) ) ) ; } return query . toString ( ) ; } } </s>
<s> package annis . gui . querybuilder ; import com . vaadin . data . Property . ValueChangeEvent ; import com . vaadin . data . Property . ValueChangeListener ; import com . vaadin . event . LayoutEvents . LayoutClickEvent ; import com . vaadin . event . LayoutEvents . LayoutClickListener ; import com . vaadin . ui . AbstractSelect . NewItemHandler ; import com . vaadin . ui . Button . ClickEvent ; import com . vaadin . ui . * ; import com . vaadin . ui . themes . ChameleonTheme ; import java . util . ArrayList ; import java . util . List ; import java . util . Set ; import java . util . TreeSet ; public class NodeWindow extends Panel implements Button . ClickListener { public static final int HEIGHT = <NUM_LIT:100> ; public static final int WIDTH = <NUM_LIT> ; private static final String [ ] NODE_OPERATORS = new String [ ] { "<STR_LIT:=>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ; private Set < String > annoNames ; private TigerQueryBuilderCanvas parent ; private Button btEdge ; private Button btAdd ; private Button btClear ; private Button btClose ; private HorizontalLayout toolbar ; private List < ConstraintLayout > constraints ; private boolean prepareEdgeDock ; private int id ; public NodeWindow ( int id , TigerQueryBuilderCanvas parent ) { this . parent = parent ; this . id = id ; this . annoNames = new TreeSet < String > ( ) ; for ( String a : parent . getAvailableAnnotationNames ( ) ) { annoNames . add ( a . replaceFirst ( "<STR_LIT>" , "<STR_LIT>" ) ) ; } constraints = new ArrayList < ConstraintLayout > ( ) ; setWidth ( "<STR_LIT>" ) ; setHeight ( "<STR_LIT>" ) ; prepareEdgeDock = false ; VerticalLayout vLayout = ( VerticalLayout ) getContent ( ) ; vLayout . setMargin ( false ) ; toolbar = new HorizontalLayout ( ) ; toolbar . addStyleName ( "<STR_LIT>" ) ; toolbar . setWidth ( "<STR_LIT>" ) ; toolbar . setHeight ( "<STR_LIT>" ) ; addComponent ( toolbar ) ; btEdge = new Button ( "<STR_LIT>" ) ; btEdge . setStyleName ( ChameleonTheme . BUTTON_SMALL ) ; btEdge . addListener ( ( Button . ClickListener ) this ) ; btEdge . setDescription ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; toolbar . addComponent ( btEdge ) ; btAdd = new Button ( "<STR_LIT>" ) ; btAdd . setStyleName ( ChameleonTheme . BUTTON_SMALL ) ; btAdd . addListener ( ( Button . ClickListener ) this ) ; btAdd . setDescription ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; toolbar . addComponent ( btAdd ) ; btClear = new Button ( "<STR_LIT>" ) ; btClear . setStyleName ( ChameleonTheme . BUTTON_SMALL ) ; btClear . addListener ( ( Button . ClickListener ) this ) ; btClear . setDescription ( "<STR_LIT>" ) ; toolbar . addComponent ( btClear ) ; btClose = new Button ( "<STR_LIT:X>" ) ; btClose . setStyleName ( ChameleonTheme . BUTTON_SMALL ) ; btClose . addListener ( ( Button . ClickListener ) this ) ; toolbar . addComponent ( btClose ) ; toolbar . setComponentAlignment ( btClose , Alignment . MIDDLE_RIGHT ) ; } public void setPrepareEdgeDock ( boolean prepare ) { this . prepareEdgeDock = prepare ; btClear . setVisible ( ! prepare ) ; btClose . setVisible ( ! prepare ) ; btAdd . setVisible ( ! prepare ) ; if ( prepare ) { btEdge . setCaption ( "<STR_LIT>" ) ; } else { btEdge . setCaption ( "<STR_LIT>" ) ; } } @ Override public void buttonClick ( ClickEvent event ) { if ( event . getButton ( ) == btEdge ) { if ( prepareEdgeDock ) { setPrepareEdgeDock ( false ) ; parent . addEdge ( this ) ; } else { parent . prepareAddingEdge ( this ) ; setPrepareEdgeDock ( true ) ; btEdge . setCaption ( "<STR_LIT>" ) ; } } else if ( event . getButton ( ) == btClose ) { parent . deleteNode ( this ) ; } else if ( event . getButton ( ) == btAdd ) { ConstraintLayout c = new ConstraintLayout ( parent , annoNames ) ; c . setWidth ( "<STR_LIT>" ) ; c . setHeight ( "<STR_LIT>" ) ; constraints . add ( c ) ; addComponent ( c ) ; if ( parent != null ) { parent . updateQuery ( ) ; } } else if ( event . getButton ( ) == btClear ) { for ( ConstraintLayout c : constraints ) { removeComponent ( c ) ; } constraints . clear ( ) ; if ( parent != null ) { parent . updateQuery ( ) ; } } } public int getID ( ) { return id ; } @ Override public boolean equals ( Object obj ) { if ( obj == null ) { return false ; } if ( getClass ( ) != obj . getClass ( ) ) { return false ; } final NodeWindow other = ( NodeWindow ) obj ; return other . getID ( ) == getID ( ) ; } @ Override public int hashCode ( ) { int hash = <NUM_LIT:5> ; hash = <NUM_LIT> * hash + this . id ; return hash ; } public List < ConstraintLayout > getConstraints ( ) { return constraints ; } public static class ConstraintLayout extends HorizontalLayout implements LayoutClickListener , ValueChangeListener { private TigerQueryBuilderCanvas parent ; private ComboBox cbName ; private ComboBox cbOperator ; private TextField txtValue ; public ConstraintLayout ( TigerQueryBuilderCanvas parent , Set < String > annoNames ) { this . parent = parent ; setWidth ( "<STR_LIT>" ) ; cbName = new ComboBox ( ) ; cbName . setNewItemsAllowed ( true ) ; cbName . setNewItemHandler ( new SimpleNewItemHandler ( cbName ) ) ; cbName . setImmediate ( true ) ; cbName . setNullSelectionAllowed ( true ) ; cbName . setNullSelectionItemId ( "<STR_LIT>" ) ; cbName . addItem ( "<STR_LIT>" ) ; for ( String n : annoNames ) { cbName . addItem ( n ) ; } cbName . setValue ( "<STR_LIT>" ) ; cbName . addListener ( ( ValueChangeListener ) this ) ; cbOperator = new ComboBox ( ) ; cbOperator . setNewItemsAllowed ( false ) ; cbOperator . setImmediate ( true ) ; for ( String o : NODE_OPERATORS ) { cbOperator . addItem ( o ) ; } cbOperator . setValue ( NODE_OPERATORS [ <NUM_LIT:0> ] ) ; cbOperator . addListener ( ( ValueChangeListener ) this ) ; txtValue = new TextField ( ) ; txtValue . setImmediate ( true ) ; txtValue . addListener ( ( ValueChangeListener ) this ) ; cbOperator . setWidth ( "<STR_LIT>" ) ; cbName . setWidth ( "<STR_LIT>" ) ; txtValue . setWidth ( "<STR_LIT>" ) ; addComponent ( cbName ) ; addComponent ( cbOperator ) ; addComponent ( txtValue ) ; setExpandRatio ( cbName , <NUM_LIT> ) ; setExpandRatio ( txtValue , <NUM_LIT:1.0f> ) ; addListener ( ( LayoutClickListener ) this ) ; } @ Override public void layoutClick ( LayoutClickEvent event ) { Component c = event . getClickedComponent ( ) ; if ( c != null && c instanceof AbstractField ) { AbstractField f = ( AbstractField ) c ; f . focus ( ) ; if ( event . isDoubleClick ( ) ) { if ( f instanceof AbstractTextField ) { ( ( AbstractTextField ) f ) . selectAll ( ) ; } } } } public String getOperator ( ) { if ( cbOperator . getValue ( ) == null ) { return "<STR_LIT>" ; } else { return ( String ) cbOperator . getValue ( ) ; } } public String getName ( ) { if ( cbName . getValue ( ) == null ) { return "<STR_LIT>" ; } else { return ( String ) cbName . getValue ( ) ; } } public String getValue ( ) { if ( txtValue . getValue ( ) == null ) { return "<STR_LIT>" ; } else { return ( String ) txtValue . getValue ( ) ; } } @ Override public void valueChange ( ValueChangeEvent event ) { if ( parent != null ) { parent . updateQuery ( ) ; } } } public static class SimpleNewItemHandler implements NewItemHandler { private ComboBox comboBox ; public SimpleNewItemHandler ( ComboBox comboBox ) { this . comboBox = comboBox ; } @ Override public void addNewItem ( String newItemCaption ) { if ( comboBox != null ) { comboBox . addItem ( newItemCaption ) ; comboBox . setValue ( newItemCaption ) ; } } } } </s>
<s> package annis . gui . controlpanel ; import annis . gui . CorpusBrowserPanel ; import annis . gui . MetaDataPanel ; import annis . gui . Helper ; import annis . gui . MainApp ; import annis . security . AnnisSecurityManager ; import annis . security . AnnisUser ; import annis . service . objects . AnnisCorpus ; import com . sun . jersey . api . client . ClientHandlerException ; import com . sun . jersey . api . client . GenericType ; import com . sun . jersey . api . client . UniformInterfaceException ; import com . sun . jersey . api . client . WebResource ; import com . vaadin . Application ; import com . vaadin . Application . UserChangeEvent ; import com . vaadin . Application . UserChangeListener ; import com . vaadin . data . Item ; import com . vaadin . data . Property . ValueChangeEvent ; import com . vaadin . data . Property . ValueChangeListener ; import com . vaadin . data . util . BeanContainer ; import com . vaadin . data . util . DefaultItemSorter ; import com . vaadin . event . Action ; import com . vaadin . terminal . ThemeResource ; import com . vaadin . ui . AbstractSelect ; import com . vaadin . ui . Alignment ; import com . vaadin . ui . Button ; import com . vaadin . ui . Button . ClickEvent ; import com . vaadin . ui . ComboBox ; import com . vaadin . ui . Component ; import com . vaadin . ui . HorizontalLayout ; import com . vaadin . ui . Label ; import com . vaadin . ui . Panel ; import com . vaadin . ui . Table ; import com . vaadin . ui . VerticalLayout ; import com . vaadin . ui . Window ; import com . vaadin . ui . Window . Notification ; import com . vaadin . ui . themes . BaseTheme ; import com . vaadin . ui . themes . ChameleonTheme ; import java . util . HashMap ; import java . util . LinkedList ; import java . util . List ; import java . util . Map ; import java . util . TreeMap ; import javax . naming . AuthenticationException ; import org . apache . commons . lang3 . StringUtils ; import org . slf4j . LoggerFactory ; public class CorpusListPanel extends Panel implements UserChangeListener , AbstractSelect . NewItemHandler , ValueChangeListener , Action . Handler { private static final org . slf4j . Logger log = LoggerFactory . getLogger ( CorpusListPanel . class ) ; private static final ThemeResource INFO_ICON = new ThemeResource ( "<STR_LIT>" ) ; public static final String ALL_CORPORA = "<STR_LIT>" ; public static final String CORPUSSET_PREFIX = "<STR_LIT>" ; public enum ActionType { Add , Remove } ; BeanContainer < String , AnnisCorpus > corpusContainer ; private Table tblCorpora ; private ControlPanel controlPanel ; private ComboBox cbSelection ; private Map < String , Map < String , AnnisCorpus > > corpusSets = new TreeMap < String , Map < String , AnnisCorpus > > ( ) ; public CorpusListPanel ( ControlPanel controlPanel ) { this . controlPanel = controlPanel ; final CorpusListPanel finalThis = this ; setSizeFull ( ) ; VerticalLayout layout = ( VerticalLayout ) getContent ( ) ; layout . setSizeFull ( ) ; HorizontalLayout selectionLayout = new HorizontalLayout ( ) ; selectionLayout . setWidth ( "<STR_LIT>" ) ; selectionLayout . setHeight ( "<STR_LIT>" ) ; Label lblVisible = new Label ( "<STR_LIT>" ) ; lblVisible . setSizeUndefined ( ) ; selectionLayout . addComponent ( lblVisible ) ; cbSelection = new ComboBox ( ) ; cbSelection . setDescription ( "<STR_LIT>" ) ; cbSelection . setWidth ( "<STR_LIT>" ) ; cbSelection . setHeight ( "<STR_LIT>" ) ; cbSelection . setInputPrompt ( "<STR_LIT>" ) ; cbSelection . setNullSelectionAllowed ( false ) ; cbSelection . setNewItemsAllowed ( true ) ; cbSelection . setNewItemHandler ( ( AbstractSelect . NewItemHandler ) this ) ; cbSelection . setImmediate ( true ) ; cbSelection . addListener ( ( ValueChangeListener ) this ) ; selectionLayout . addComponent ( cbSelection ) ; selectionLayout . setExpandRatio ( cbSelection , <NUM_LIT:1.0f> ) ; selectionLayout . setSpacing ( true ) ; selectionLayout . setComponentAlignment ( cbSelection , Alignment . MIDDLE_RIGHT ) ; selectionLayout . setComponentAlignment ( lblVisible , Alignment . MIDDLE_LEFT ) ; layout . addComponent ( selectionLayout ) ; tblCorpora = new Table ( ) ; addComponent ( tblCorpora ) ; corpusContainer = new BeanContainer < String , AnnisCorpus > ( AnnisCorpus . class ) ; corpusContainer . setBeanIdProperty ( "<STR_LIT:name>" ) ; corpusContainer . setItemSorter ( new CorpusSorter ( ) ) ; tblCorpora . setContainerDataSource ( corpusContainer ) ; tblCorpora . addGeneratedColumn ( "<STR_LIT>" , new InfoGenerator ( ) ) ; tblCorpora . setVisibleColumns ( new String [ ] { "<STR_LIT:name>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ) ; tblCorpora . setColumnHeaders ( new String [ ] { "<STR_LIT:Name>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ) ; tblCorpora . setHeight ( <NUM_LIT> , UNITS_PERCENTAGE ) ; tblCorpora . setWidth ( <NUM_LIT> , UNITS_PERCENTAGE ) ; tblCorpora . setSelectable ( true ) ; tblCorpora . setMultiSelect ( true ) ; tblCorpora . setNullSelectionAllowed ( false ) ; tblCorpora . setColumnExpandRatio ( "<STR_LIT:name>" , <NUM_LIT> ) ; tblCorpora . setColumnExpandRatio ( "<STR_LIT>" , <NUM_LIT> ) ; tblCorpora . setColumnExpandRatio ( "<STR_LIT>" , <NUM_LIT> ) ; tblCorpora . addActionHandler ( ( Action . Handler ) this ) ; tblCorpora . setImmediate ( true ) ; tblCorpora . addListener ( new ValueChangeListener ( ) { @ Override public void valueChange ( ValueChangeEvent event ) { finalThis . controlPanel . corpusSelectionChanged ( ) ; } } ) ; layout . setExpandRatio ( tblCorpora , <NUM_LIT:1.0f> ) ; Button btReload = new Button ( ) ; btReload . addListener ( new Button . ClickListener ( ) { @ Override public void buttonClick ( ClickEvent event ) { MainApp app = ( MainApp ) getApplication ( ) ; try { app . getWindowSearch ( ) . getSecurityManager ( ) . updateUserCorpusList ( app . getUser ( ) , true ) ; } catch ( AuthenticationException ex ) { log . error ( null , ex ) ; } updateCorpusSetList ( false ) ; getWindow ( ) . showNotification ( "<STR_LIT>" , Notification . TYPE_HUMANIZED_MESSAGE ) ; } } ) ; btReload . setIcon ( new ThemeResource ( "<STR_LIT>" ) ) ; btReload . setDescription ( "<STR_LIT>" ) ; btReload . addStyleName ( ChameleonTheme . BUTTON_ICON_ONLY ) ; selectionLayout . addComponent ( btReload ) ; selectionLayout . setComponentAlignment ( btReload , Alignment . MIDDLE_RIGHT ) ; } @ Override public void attach ( ) { super . attach ( ) ; getApplication ( ) . addListener ( ( UserChangeListener ) this ) ; tblCorpora . setSortContainerPropertyId ( "<STR_LIT:name>" ) ; updateCorpusSetList ( ) ; } private void updateCorpusSetList ( ) { updateCorpusSetList ( true ) ; } private void updateCorpusSetList ( boolean showLoginMessage ) { corpusSets . clear ( ) ; AnnisUser user = ( AnnisUser ) getApplication ( ) . getUser ( ) ; Map < String , AnnisCorpus > allCorpora = getCorpusList ( user ) ; corpusSets . put ( ALL_CORPORA , allCorpora ) ; if ( user != null ) { if ( user . getUserName ( ) . equals ( AnnisSecurityManager . FALLBACK_USER ) ) { if ( corpusSets . get ( ALL_CORPORA ) . isEmpty ( ) ) { getWindow ( ) . showNotification ( "<STR_LIT>" + "<STR_LIT>" , Notification . TYPE_HUMANIZED_MESSAGE ) ; } else if ( showLoginMessage ) { getWindow ( ) . showNotification ( "<STR_LIT>" , Notification . TYPE_TRAY_NOTIFICATION ) ; } } for ( String p : user . stringPropertyNames ( ) ) { if ( p . startsWith ( CORPUSSET_PREFIX ) ) { String setName = p . substring ( CORPUSSET_PREFIX . length ( ) ) ; Map < String , AnnisCorpus > corpora = new TreeMap < String , AnnisCorpus > ( ) ; String corpusString = user . getProperty ( p ) ; if ( ! ALL_CORPORA . equals ( setName ) && corpusString != null ) { String [ ] splitted = corpusString . split ( "<STR_LIT:U+002C>" ) ; for ( String s : splitted ) { if ( ! "<STR_LIT>" . equals ( s ) ) { try { AnnisCorpus c = allCorpora . get ( s ) ; if ( c != null ) { corpora . put ( c . getName ( ) , c ) ; } } catch ( NumberFormatException ex ) { log . warn ( "<STR_LIT>" + setName , ex ) ; } } } corpusSets . put ( setName , corpora ) ; } } } } Object oldSelection = cbSelection . getValue ( ) ; cbSelection . removeAllItems ( ) ; for ( String n : corpusSets . keySet ( ) ) { cbSelection . addItem ( n ) ; } if ( oldSelection != null && cbSelection . containsId ( oldSelection ) ) { cbSelection . select ( oldSelection ) ; } else { cbSelection . select ( ALL_CORPORA ) ; } updateCorpusList ( ) ; } private void updateCorpusList ( ) { corpusContainer . removeAllItems ( ) ; String selectedCorpusSet = ( String ) cbSelection . getValue ( ) ; if ( selectedCorpusSet == null ) { selectedCorpusSet = ALL_CORPORA ; } if ( corpusSets . containsKey ( selectedCorpusSet ) ) { corpusContainer . addAll ( corpusSets . get ( selectedCorpusSet ) . values ( ) ) ; } tblCorpora . sort ( ) ; } private Map < String , AnnisCorpus > getCorpusList ( AnnisUser user ) { Map < String , AnnisCorpus > result = new TreeMap < String , AnnisCorpus > ( ) ; try { WebResource res = Helper . getAnnisWebResource ( getApplication ( ) ) ; List < AnnisCorpus > corpora = res . path ( "<STR_LIT>" ) . get ( new GenericType < List < AnnisCorpus > > ( ) { } ) ; for ( AnnisCorpus c : corpora ) { if ( user == null || user . getCorpusNameList ( ) . contains ( c . getName ( ) ) ) { result . put ( c . getName ( ) , c ) ; } } } catch ( ClientHandlerException ex ) { log . error ( null , ex ) ; getWindow ( ) . showNotification ( "<STR_LIT>" + ex . getLocalizedMessage ( ) , Notification . TYPE_TRAY_NOTIFICATION ) ; } catch ( UniformInterfaceException ex ) { log . error ( null , ex ) ; getWindow ( ) . showNotification ( "<STR_LIT>" + ex . getLocalizedMessage ( ) , Notification . TYPE_TRAY_NOTIFICATION ) ; } catch ( Exception ex ) { log . error ( null , ex ) ; getWindow ( ) . showNotification ( "<STR_LIT>" + ex . getLocalizedMessage ( ) , Notification . TYPE_TRAY_NOTIFICATION ) ; } return result ; } @ Override public void applicationUserChanged ( UserChangeEvent event ) { updateCorpusSetList ( ) ; } @ Override public void addNewItem ( String newItemCaption ) { if ( ! cbSelection . containsId ( newItemCaption ) ) { cbSelection . addItem ( newItemCaption ) ; cbSelection . setValue ( newItemCaption ) ; corpusSets . put ( newItemCaption , new TreeMap < String , AnnisCorpus > ( ) ) ; updateCorpusList ( ) ; Application app = getApplication ( ) ; if ( app instanceof MainApp ) { AnnisSecurityManager sm = ( ( MainApp ) app ) . getSecurityManager ( ) ; AnnisUser user = ( AnnisUser ) app . getUser ( ) ; if ( sm != null && ! AnnisSecurityManager . FALLBACK_USER . equals ( user . getUserName ( ) ) ) { user . put ( CORPUSSET_PREFIX + newItemCaption , "<STR_LIT>" ) ; try { sm . storeUserProperties ( user ) ; } catch ( Exception ex ) { log . error ( "<STR_LIT>" , ex ) ; getWindow ( ) . showNotification ( "<STR_LIT>" + ex . getLocalizedMessage ( ) , Notification . TYPE_ERROR_MESSAGE ) ; } } } } } @ Override public void valueChange ( ValueChangeEvent event ) { updateCorpusList ( ) ; } @ Override public Action [ ] getActions ( Object target , Object sender ) { String corpusName = ( String ) target ; LinkedList < Action > result = new LinkedList < Action > ( ) ; AnnisUser user = ( AnnisUser ) getApplication ( ) . getUser ( ) ; if ( user == null || AnnisSecurityManager . FALLBACK_USER . equals ( user . getUserName ( ) ) ) { return new Action [ <NUM_LIT:0> ] ; } for ( Map . Entry < String , Map < String , AnnisCorpus > > entry : corpusSets . entrySet ( ) ) { if ( entry . getValue ( ) != null && ! ALL_CORPORA . equals ( entry . getKey ( ) ) && corpusName != null ) { if ( entry . getValue ( ) . containsKey ( corpusName ) ) { result . add ( new AddRemoveAction ( ActionType . Remove , entry . getKey ( ) , corpusName , "<STR_LIT>" + entry . getKey ( ) ) ) ; } else { result . add ( new AddRemoveAction ( ActionType . Add , entry . getKey ( ) , corpusName , "<STR_LIT>" + entry . getKey ( ) ) ) ; } } } return result . toArray ( new Action [ <NUM_LIT:0> ] ) ; } @ Override public void handleAction ( Action action , Object sender , Object target ) { if ( action instanceof AddRemoveAction ) { AddRemoveAction a = ( AddRemoveAction ) action ; Map < String , AnnisCorpus > set = corpusSets . get ( a . getCorpusSet ( ) ) ; Map < String , AnnisCorpus > allCorpora = corpusSets . get ( ALL_CORPORA ) ; if ( a . type == ActionType . Remove ) { set . remove ( a . getCorpusId ( ) ) ; if ( set . isEmpty ( ) ) { corpusSets . remove ( a . getCorpusSet ( ) ) ; cbSelection . removeItem ( a . getCorpusSet ( ) ) ; cbSelection . select ( ALL_CORPORA ) ; } } else if ( a . type == ActionType . Add ) { set . put ( a . getCorpusId ( ) , allCorpora . get ( a . getCorpusId ( ) ) ) ; } Application app = getApplication ( ) ; if ( app instanceof MainApp ) { AnnisSecurityManager sm = ( ( MainApp ) app ) . getSecurityManager ( ) ; AnnisUser user = ( AnnisUser ) app . getUser ( ) ; LinkedList < String > keys = new LinkedList < String > ( user . stringPropertyNames ( ) ) ; for ( String key : keys ) { if ( key . startsWith ( CORPUSSET_PREFIX ) ) { user . remove ( key ) ; } } for ( Map . Entry < String , Map < String , AnnisCorpus > > entry : corpusSets . entrySet ( ) ) { if ( ! ALL_CORPORA . equals ( entry . getKey ( ) ) ) { String key = CORPUSSET_PREFIX + entry . getKey ( ) ; String value = StringUtils . join ( entry . getValue ( ) . keySet ( ) , "<STR_LIT:U+002C>" ) ; user . setProperty ( key , value ) ; } } try { sm . storeUserProperties ( user ) ; } catch ( Exception ex ) { log . error ( null , ex ) ; } } updateCorpusList ( ) ; } } public static class CorpusSorter extends DefaultItemSorter { @ Override protected int compareProperty ( Object propertyId , boolean sortDirection , Item item1 , Item item2 ) { if ( "<STR_LIT:name>" . equals ( propertyId ) ) { String val1 = ( String ) item1 . getItemProperty ( propertyId ) . getValue ( ) ; String val2 = ( String ) item2 . getItemProperty ( propertyId ) . getValue ( ) ; if ( sortDirection ) { return val1 . compareToIgnoreCase ( val2 ) ; } else { return val2 . compareToIgnoreCase ( val1 ) ; } } else { return super . compareProperty ( propertyId , sortDirection , item1 , item2 ) ; } } } protected void selectCorpora ( Map < String , AnnisCorpus > corpora ) { if ( tblCorpora != null ) { tblCorpora . setValue ( corpora . keySet ( ) ) ; } } protected Map < String , AnnisCorpus > getSelectedCorpora ( ) { HashMap < String , AnnisCorpus > result = new HashMap < String , AnnisCorpus > ( ) ; for ( String id : corpusContainer . getItemIds ( ) ) { if ( tblCorpora . isSelected ( id ) ) { AnnisCorpus c = ( AnnisCorpus ) corpusContainer . getItem ( id ) . getBean ( ) ; result . put ( id , c ) ; } } return result ; } public class InfoGenerator implements Table . ColumnGenerator { @ Override public Component generateCell ( Table source , Object itemId , Object columnId ) { final AnnisCorpus c = corpusContainer . getItem ( itemId ) . getBean ( ) ; Button l = new Button ( ) ; l . setStyleName ( BaseTheme . BUTTON_LINK ) ; l . setIcon ( INFO_ICON ) ; l . setDescription ( c . getName ( ) ) ; l . addListener ( new Button . ClickListener ( ) { @ Override public void buttonClick ( ClickEvent event ) { MetaDataPanel meta = new MetaDataPanel ( c . getName ( ) ) ; if ( controlPanel != null ) { CorpusBrowserPanel browse = new CorpusBrowserPanel ( c , controlPanel ) ; HorizontalLayout layout = new HorizontalLayout ( ) ; layout . addComponent ( meta ) ; layout . addComponent ( browse ) ; layout . setSizeFull ( ) ; layout . setExpandRatio ( meta , <NUM_LIT> ) ; layout . setExpandRatio ( browse , <NUM_LIT> ) ; Window window = new Window ( "<STR_LIT>" + c . getName ( ) + "<STR_LIT>" + c . getId ( ) + "<STR_LIT:)>" , layout ) ; window . setWidth ( <NUM_LIT> , UNITS_EM ) ; window . setHeight ( <NUM_LIT> , UNITS_EM ) ; window . setResizable ( false ) ; window . setModal ( false ) ; getWindow ( ) . addWindow ( window ) ; window . center ( ) ; } } } ) ; return l ; } } public static class AddRemoveAction extends Action { private ActionType type ; private String corpusSet ; private String corpusId ; public AddRemoveAction ( ActionType type , String corpusSet , String corpusId , String caption ) { super ( caption ) ; this . type = type ; this . corpusSet = corpusSet ; this . corpusId = corpusId ; } public ActionType getType ( ) { return type ; } public String getCorpusId ( ) { return corpusId ; } public String getCorpusSet ( ) { return corpusSet ; } } } </s>
<s> package annis . gui . controlpanel ; import annis . gui . Helper ; import annis . gui . SearchWindow ; import annis . gui . beans . HistoryEntry ; import annis . security . AnnisUser ; import annis . service . objects . AnnisCorpus ; import com . sun . jersey . api . client . UniformInterfaceException ; import com . sun . jersey . api . client . WebResource ; import com . vaadin . terminal . PaintException ; import com . vaadin . terminal . PaintTarget ; import com . vaadin . ui . * ; import com . vaadin . ui . themes . ChameleonTheme ; import java . util . Map ; import java . util . Set ; import java . util . TreeMap ; import java . util . TreeSet ; import org . apache . commons . collections15 . set . ListOrderedSet ; import org . apache . commons . lang3 . StringUtils ; public class ControlPanel extends Panel { private static final long serialVersionUID = - <NUM_LIT> ; private QueryPanel queryPanel ; private CorpusListPanel corpusList ; private SearchWindow searchWindow ; private Window window ; private String lastQuery ; private Map < String , AnnisCorpus > lastCorpusSelection ; private SearchOptionsPanel searchOptions ; private ListOrderedSet < HistoryEntry > history ; public ControlPanel ( SearchWindow searchWindow ) { super ( "<STR_LIT>" ) ; this . searchWindow = searchWindow ; this . history = new ListOrderedSet < HistoryEntry > ( ) ; setStyleName ( ChameleonTheme . PANEL_BORDERLESS ) ; addStyleName ( "<STR_LIT>" ) ; VerticalLayout layout = ( VerticalLayout ) getContent ( ) ; layout . setHeight ( <NUM_LIT> , UNITS_PERCENTAGE ) ; Accordion accordion = new Accordion ( ) ; accordion . setHeight ( <NUM_LIT> , Layout . UNITS_PERCENTAGE ) ; corpusList = new CorpusListPanel ( this ) ; searchOptions = new SearchOptionsPanel ( ) ; queryPanel = new QueryPanel ( this ) ; queryPanel . setHeight ( <NUM_LIT> , Layout . UNITS_EM ) ; accordion . addTab ( corpusList , "<STR_LIT>" , null ) ; accordion . addTab ( searchOptions , "<STR_LIT>" , null ) ; accordion . addTab ( new ExportPanel ( queryPanel , corpusList ) , "<STR_LIT>" , null ) ; addComponent ( queryPanel ) ; addComponent ( accordion ) ; layout . setExpandRatio ( accordion , <NUM_LIT:1.0f> ) ; } @ Override public void attach ( ) { super . attach ( ) ; this . window = getWindow ( ) ; } public void setQuery ( String query , Map < String , AnnisCorpus > corpora ) { if ( queryPanel != null && corpusList != null ) { queryPanel . setQuery ( query ) ; if ( corpora != null ) { corpusList . selectCorpora ( corpora ) ; } } } public void setQuery ( String query , Map < String , AnnisCorpus > corpora , int contextLeft , int contextRight ) { setQuery ( query , corpora ) ; searchOptions . setLeftContext ( contextLeft ) ; searchOptions . setRightContext ( contextRight ) ; } public Map < String , AnnisCorpus > getSelectedCorpora ( ) { return corpusList . getSelectedCorpora ( ) ; } @ Override public void paintContent ( PaintTarget target ) throws PaintException { super . paintContent ( target ) ; } public void executeQuery ( ) { if ( getApplication ( ) != null && getApplication ( ) . getUser ( ) == null ) { getWindow ( ) . showNotification ( "<STR_LIT>" , Window . Notification . TYPE_WARNING_MESSAGE ) ; } else if ( getApplication ( ) != null && corpusList != null && queryPanel != null ) { Map < String , AnnisCorpus > rawCorpusSelection = corpusList . getSelectedCorpora ( ) ; lastCorpusSelection = new TreeMap < String , AnnisCorpus > ( rawCorpusSelection ) ; AnnisUser user = ( AnnisUser ) getApplication ( ) . getUser ( ) ; if ( user != null ) { lastCorpusSelection . keySet ( ) . retainAll ( user . getCorpusNameList ( ) ) ; } lastQuery = queryPanel . getQuery ( ) ; if ( lastCorpusSelection . isEmpty ( ) ) { getWindow ( ) . showNotification ( "<STR_LIT>" , Window . Notification . TYPE_WARNING_MESSAGE ) ; return ; } if ( "<STR_LIT>" . equals ( lastQuery ) ) { getWindow ( ) . showNotification ( "<STR_LIT>" , Window . Notification . TYPE_WARNING_MESSAGE ) ; return ; } HistoryEntry e = new HistoryEntry ( ) ; e . setQuery ( lastQuery ) ; e . setCorpora ( getSelectedCorpora ( ) ) ; history . remove ( e ) ; history . add ( <NUM_LIT:0> , e ) ; queryPanel . updateShortHistory ( history . asList ( ) ) ; queryPanel . setCountIndicatorEnabled ( true ) ; CountThread countThread = new CountThread ( ) ; countThread . start ( ) ; searchWindow . showQueryResult ( lastQuery , lastCorpusSelection , searchOptions . getLeftContext ( ) , searchOptions . getRightContext ( ) , searchOptions . getSegmentationLayer ( ) , searchOptions . getResultsPerPage ( ) ) ; } } public Set < HistoryEntry > getHistory ( ) { return history ; } public void corpusSelectionChanged ( ) { searchOptions . updateSegmentationList ( corpusList . getSelectedCorpora ( ) . keySet ( ) ) ; } private class CountThread extends Thread { private int count = - <NUM_LIT:1> ; @ Override public void run ( ) { WebResource res = null ; synchronized ( getApplication ( ) ) { res = Helper . getAnnisWebResource ( getApplication ( ) ) ; } if ( res != null ) { try { Set < String > corpusNames = new TreeSet < String > ( ) ; for ( AnnisCorpus c : lastCorpusSelection . values ( ) ) { corpusNames . add ( c . getName ( ) ) ; } count = Integer . parseInt ( res . path ( "<STR_LIT>" ) . path ( "<STR_LIT:count>" ) . queryParam ( "<STR_LIT:q>" , lastQuery ) . queryParam ( "<STR_LIT>" , StringUtils . join ( corpusNames , "<STR_LIT:U+002C>" ) ) . get ( String . class ) ) ; } catch ( UniformInterfaceException ex ) { synchronized ( getApplication ( ) ) { if ( ex . getResponse ( ) . getStatus ( ) == <NUM_LIT> ) { window . showNotification ( ex . getResponse ( ) . getEntity ( String . class ) , "<STR_LIT>" , Window . Notification . TYPE_ERROR_MESSAGE ) ; } else { window . showNotification ( ex . getResponse ( ) . getEntity ( String . class ) , "<STR_LIT>" + ex . getResponse ( ) . getStatus ( ) , Window . Notification . TYPE_ERROR_MESSAGE ) ; } } } } synchronized ( getApplication ( ) ) { queryPanel . setStatus ( "<STR_LIT>" + count + "<STR_LIT>" ) ; searchWindow . updateQueryCount ( count ) ; } queryPanel . setCountIndicatorEnabled ( false ) ; } public int getCount ( ) { return count ; } } } </s>
<s> package annis . gui . controlpanel ; import annis . gui . Helper ; import annis . service . objects . AnnisAttribute ; import annis . service . objects . CorpusConfig ; import com . sun . jersey . api . client . GenericType ; import com . sun . jersey . api . client . WebResource ; import com . vaadin . data . validator . IntegerValidator ; import com . vaadin . ui . ComboBox ; import com . vaadin . ui . FormLayout ; import com . vaadin . ui . Panel ; import java . io . UnsupportedEncodingException ; import java . net . URLEncoder ; import java . util . LinkedList ; import java . util . List ; import java . util . Set ; import org . slf4j . Logger ; import org . slf4j . LoggerFactory ; public class SearchOptionsPanel extends Panel { public static final String DEFAULT_SEGMENTATION = "<STR_LIT>" ; private static final Logger log = LoggerFactory . getLogger ( SearchOptionsPanel . class ) ; private ComboBox cbLeftContext ; private ComboBox cbRightContext ; private ComboBox cbResultsPerPage ; private ComboBox cbSegmentation ; private static final String [ ] PREDEFINED_PAGE_SIZES = new String [ ] { "<STR_LIT:1>" , "<STR_LIT:2>" , "<STR_LIT:5>" , "<STR_LIT:10>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ; static final String [ ] PREDEFINED_CONTEXTS = new String [ ] { "<STR_LIT:0>" , "<STR_LIT:1>" , "<STR_LIT:2>" , "<STR_LIT:5>" , "<STR_LIT:10>" } ; public SearchOptionsPanel ( ) { setSizeFull ( ) ; FormLayout layout = new FormLayout ( ) ; setContent ( layout ) ; cbLeftContext = new ComboBox ( "<STR_LIT>" ) ; cbRightContext = new ComboBox ( "<STR_LIT>" ) ; cbResultsPerPage = new ComboBox ( "<STR_LIT>" ) ; cbLeftContext . setNullSelectionAllowed ( false ) ; cbRightContext . setNullSelectionAllowed ( false ) ; cbResultsPerPage . setNullSelectionAllowed ( false ) ; cbLeftContext . setNewItemsAllowed ( true ) ; cbRightContext . setNewItemsAllowed ( true ) ; cbResultsPerPage . setNewItemsAllowed ( true ) ; cbLeftContext . addValidator ( new IntegerValidator ( "<STR_LIT>" ) ) ; cbRightContext . addValidator ( new IntegerValidator ( "<STR_LIT>" ) ) ; cbResultsPerPage . addValidator ( new IntegerValidator ( "<STR_LIT>" ) ) ; for ( String s : PREDEFINED_CONTEXTS ) { cbLeftContext . addItem ( s ) ; cbRightContext . addItem ( s ) ; } for ( String s : PREDEFINED_PAGE_SIZES ) { cbResultsPerPage . addItem ( s ) ; } cbSegmentation = new ComboBox ( "<STR_LIT>" ) ; cbSegmentation . setTextInputAllowed ( false ) ; cbSegmentation . setNullSelectionAllowed ( true ) ; cbSegmentation . setValue ( "<STR_LIT>" ) ; cbLeftContext . setValue ( "<STR_LIT:5>" ) ; cbRightContext . setValue ( "<STR_LIT:5>" ) ; cbResultsPerPage . setValue ( "<STR_LIT:10>" ) ; layout . addComponent ( cbLeftContext ) ; layout . addComponent ( cbRightContext ) ; layout . addComponent ( cbResultsPerPage ) ; layout . addComponent ( cbSegmentation ) ; } public void updateSegmentationList ( Set < String > corpora ) { WebResource service = Helper . getAnnisWebResource ( getApplication ( ) ) ; if ( service != null ) { List < AnnisAttribute > attributes = new LinkedList < AnnisAttribute > ( ) ; String lastSelection = ( String ) cbSegmentation . getValue ( ) ; cbSegmentation . removeAllItems ( ) ; for ( String corpus : corpora ) { try { attributes . addAll ( service . path ( "<STR_LIT>" ) . path ( URLEncoder . encode ( corpus , "<STR_LIT:UTF-8>" ) ) . path ( "<STR_LIT>" ) . queryParam ( "<STR_LIT>" , "<STR_LIT:true>" ) . queryParam ( "<STR_LIT>" , "<STR_LIT:true>" ) . get ( new GenericType < List < AnnisAttribute > > ( ) { } ) ) ; } catch ( UnsupportedEncodingException ex ) { log . error ( null , ex ) ; } CorpusConfig config = Helper . getCorpusConfig ( corpus , getApplication ( ) , getWindow ( ) ) ; if ( config . getConfig ( ) . containsKey ( DEFAULT_SEGMENTATION ) ) { lastSelection = config . getConfig ( ) . get ( DEFAULT_SEGMENTATION ) ; } } for ( AnnisAttribute att : attributes ) { if ( AnnisAttribute . Type . segmentation == att . getType ( ) && att . getName ( ) != null ) { cbSegmentation . addItem ( att . getName ( ) ) ; } } cbSegmentation . setValue ( lastSelection ) ; } } public void setLeftContext ( int context ) { cbLeftContext . setValue ( "<STR_LIT>" + context ) ; } public int getLeftContext ( ) { int result = <NUM_LIT:5> ; try { result = Integer . parseInt ( ( String ) cbLeftContext . getValue ( ) ) ; } catch ( Exception ex ) { } return Math . max ( <NUM_LIT:0> , result ) ; } public int getRightContext ( ) { int result = <NUM_LIT:5> ; try { result = Integer . parseInt ( ( String ) cbRightContext . getValue ( ) ) ; } catch ( Exception ex ) { } return Math . max ( <NUM_LIT:0> , result ) ; } public void setRightContext ( int context ) { cbRightContext . setValue ( "<STR_LIT>" + context ) ; } public int getResultsPerPage ( ) { int result = <NUM_LIT:10> ; try { result = Integer . parseInt ( ( String ) cbResultsPerPage . getValue ( ) ) ; } catch ( Exception ex ) { } return Math . max ( <NUM_LIT:0> , result ) ; } public String getSegmentationLayer ( ) { return ( String ) cbSegmentation . getValue ( ) ; } } </s>
<s> package annis . gui . controlpanel ; import annis . gui . Helper ; import annis . gui . exporter . Exporter ; import annis . gui . exporter . GridExporter ; import annis . gui . exporter . TextExporter ; import annis . gui . exporter . WekaExporter ; import annis . security . AnnisUser ; import com . vaadin . data . validator . IntegerValidator ; import com . vaadin . terminal . ExternalResource ; import com . vaadin . terminal . StreamResource ; import com . vaadin . ui . Button . ClickEvent ; import com . vaadin . ui . * ; import com . vaadin . ui . Window . Notification ; import java . io . * ; import java . util . HashMap ; import java . util . Map ; import java . util . Random ; import java . util . logging . Level ; import java . util . logging . Logger ; import org . slf4j . LoggerFactory ; public class ExportPanel extends Panel implements Button . ClickListener { private static final org . slf4j . Logger log = LoggerFactory . getLogger ( ExportPanel . class ) ; private static final Exporter [ ] EXPORTER = new Exporter [ ] { new WekaExporter ( ) , new TextExporter ( ) , new GridExporter ( ) } ; private ComboBox cbExporter ; private ComboBox cbLeftContext ; private ComboBox cbRightContext ; private TextField txtParameters ; private Button btExport ; private Map < String , Exporter > exporterMap ; private QueryPanel queryPanel ; private CorpusListPanel corpusListPanel ; private final static Random rand = new Random ( ) ; public ExportPanel ( QueryPanel queryPanel , CorpusListPanel corpusListPanel ) { this . queryPanel = queryPanel ; this . corpusListPanel = corpusListPanel ; setSizeFull ( ) ; FormLayout layout = new FormLayout ( ) ; layout . setSizeFull ( ) ; setContent ( layout ) ; cbExporter = new ComboBox ( "<STR_LIT>" ) ; cbExporter . setNewItemsAllowed ( false ) ; cbExporter . setNullSelectionAllowed ( false ) ; exporterMap = new HashMap < String , Exporter > ( ) ; for ( Exporter e : EXPORTER ) { String name = e . getClass ( ) . getSimpleName ( ) ; exporterMap . put ( name , e ) ; cbExporter . addItem ( name ) ; } cbExporter . setValue ( EXPORTER [ <NUM_LIT:0> ] . getClass ( ) . getSimpleName ( ) ) ; layout . addComponent ( cbExporter ) ; cbLeftContext = new ComboBox ( "<STR_LIT>" ) ; cbRightContext = new ComboBox ( "<STR_LIT>" ) ; cbLeftContext . setNullSelectionAllowed ( false ) ; cbRightContext . setNullSelectionAllowed ( false ) ; cbLeftContext . setNewItemsAllowed ( true ) ; cbRightContext . setNewItemsAllowed ( true ) ; cbLeftContext . addValidator ( new IntegerValidator ( "<STR_LIT>" ) ) ; cbRightContext . addValidator ( new IntegerValidator ( "<STR_LIT>" ) ) ; for ( String s : SearchOptionsPanel . PREDEFINED_CONTEXTS ) { cbLeftContext . addItem ( s ) ; cbRightContext . addItem ( s ) ; } cbLeftContext . setValue ( "<STR_LIT:5>" ) ; cbRightContext . setValue ( "<STR_LIT:5>" ) ; layout . addComponent ( cbLeftContext ) ; layout . addComponent ( cbRightContext ) ; txtParameters = new TextField ( "<STR_LIT>" ) ; layout . addComponent ( txtParameters ) ; btExport = new Button ( "<STR_LIT>" ) ; btExport . addListener ( ( Button . ClickListener ) this ) ; layout . addComponent ( btExport ) ; } @ Override public void buttonClick ( ClickEvent event ) { try { String exporterName = ( String ) cbExporter . getValue ( ) ; final Exporter exporter = exporterMap . get ( exporterName ) ; if ( exporter != null ) { if ( corpusListPanel . getSelectedCorpora ( ) . isEmpty ( ) ) { getWindow ( ) . showNotification ( "<STR_LIT>" , Notification . TYPE_WARNING_MESSAGE ) ; return ; } AnnisUser user = ( AnnisUser ) getApplication ( ) . getUser ( ) ; if ( user == null || ! user . getCorpusNameList ( ) . containsAll ( corpusListPanel . getSelectedCorpora ( ) . keySet ( ) ) ) { getWindow ( ) . showNotification ( "<STR_LIT>" , Notification . TYPE_ERROR_MESSAGE ) ; return ; } final PipedOutputStream out = new PipedOutputStream ( ) ; final PipedInputStream in = new PipedInputStream ( out ) ; new Thread ( new Runnable ( ) { @ Override public void run ( ) { try { exporter . convertText ( queryPanel . getQuery ( ) , Integer . parseInt ( ( String ) cbLeftContext . getValue ( ) ) , Integer . parseInt ( ( String ) cbRightContext . getValue ( ) ) , corpusListPanel . getSelectedCorpora ( ) , null , ( String ) txtParameters . getValue ( ) , Helper . getAnnisWebResource ( getApplication ( ) ) , new OutputStreamWriter ( out , "<STR_LIT:UTF-8>" ) ) ; } catch ( UnsupportedEncodingException ex ) { log . error ( null , ex ) ; } } } ) . start ( ) ; StreamResource resource = new StreamResource ( new StreamResource . StreamSource ( ) { @ Override public InputStream getStream ( ) { return in ; } } , exporterName + "<STR_LIT:_>" + rand . nextInt ( Integer . MAX_VALUE ) , getApplication ( ) ) ; getWindow ( ) . open ( new ExternalResource ( getApplication ( ) . getRelativeLocation ( resource ) , "<STR_LIT>" ) ) ; } } catch ( IOException ex ) { log . error ( null , ex ) ; } } } </s>
<s> package annis . gui . controlpanel ; import annis . gui . Helper ; import annis . gui . HistoryPanel ; import annis . gui . beans . HistoryEntry ; import com . sun . jersey . api . client . ClientHandlerException ; import com . sun . jersey . api . client . UniformInterfaceException ; import com . sun . jersey . api . client . WebResource ; import com . vaadin . data . Property . ValueChangeEvent ; import com . vaadin . data . Property . ValueChangeListener ; import com . vaadin . event . FieldEvents . TextChangeEvent ; import com . vaadin . event . FieldEvents . TextChangeListener ; import com . vaadin . event . ShortcutAction . KeyCode ; import com . vaadin . event . ShortcutAction . ModifierKey ; import com . vaadin . ui . Button . ClickEvent ; import com . vaadin . ui . * ; import com . vaadin . ui . Window . Notification ; import java . util . LinkedList ; import java . util . List ; import org . slf4j . LoggerFactory ; import org . vaadin . hene . splitbutton . SplitButton ; import org . vaadin . hene . splitbutton . SplitButton . SplitButtonClickEvent ; public class QueryPanel extends Panel implements TextChangeListener , ValueChangeListener { private static final org . slf4j . Logger log = LoggerFactory . getLogger ( QueryPanel . class ) ; public static final int MAX_HISTORY_MENU_ITEMS = <NUM_LIT:5> ; private TextArea txtQuery ; private Label lblStatus ; private Button btShowResult ; private SplitButton btHistory ; private ListSelect lstHistory ; private ControlPanel controlPanel ; private ProgressIndicator piCount ; private HorizontalLayout buttonPanelLayout ; private GridLayout mainLayout ; private Panel panelStatus ; private String lastPublicStatus ; private List < HistoryEntry > history ; private Window historyWindow ; public QueryPanel ( final ControlPanel controlPanel ) { this . controlPanel = controlPanel ; this . lastPublicStatus = "<STR_LIT>" ; this . history = new LinkedList < HistoryEntry > ( ) ; setSizeFull ( ) ; mainLayout = new GridLayout ( <NUM_LIT:2> , <NUM_LIT:3> ) ; setContent ( mainLayout ) ; mainLayout . setSizeFull ( ) ; mainLayout . setSpacing ( true ) ; mainLayout . setMargin ( true ) ; mainLayout . addComponent ( new Label ( "<STR_LIT>" ) , <NUM_LIT:0> , <NUM_LIT:0> ) ; mainLayout . addComponent ( new Label ( "<STR_LIT>" ) , <NUM_LIT:0> , <NUM_LIT:2> ) ; mainLayout . setRowExpandRatio ( <NUM_LIT:0> , <NUM_LIT:1.0f> ) ; mainLayout . setColumnExpandRatio ( <NUM_LIT:0> , <NUM_LIT> ) ; mainLayout . setColumnExpandRatio ( <NUM_LIT:1> , <NUM_LIT> ) ; txtQuery = new TextArea ( ) ; txtQuery . addStyleName ( "<STR_LIT:query>" ) ; txtQuery . setSizeFull ( ) ; txtQuery . setTextChangeTimeout ( <NUM_LIT:1000> ) ; txtQuery . addListener ( ( TextChangeListener ) this ) ; mainLayout . addComponent ( txtQuery , <NUM_LIT:1> , <NUM_LIT:0> ) ; panelStatus = new Panel ( ) ; panelStatus . setWidth ( <NUM_LIT> , UNITS_PERCENTAGE ) ; panelStatus . setHeight ( <NUM_LIT> , UNITS_EM ) ; ( ( VerticalLayout ) panelStatus . getContent ( ) ) . setMargin ( false ) ; ( ( VerticalLayout ) panelStatus . getContent ( ) ) . setSpacing ( false ) ; ( ( VerticalLayout ) panelStatus . getContent ( ) ) . setSizeFull ( ) ; lblStatus = new Label ( ) ; lblStatus . setContentMode ( Label . CONTENT_TEXT ) ; lblStatus . setValue ( this . lastPublicStatus ) ; lblStatus . setWidth ( "<STR_LIT>" ) ; lblStatus . setHeight ( "<STR_LIT>" ) ; panelStatus . addComponent ( lblStatus ) ; mainLayout . addComponent ( panelStatus , <NUM_LIT:1> , <NUM_LIT:2> ) ; setScrollable ( true ) ; Panel buttonPanel = new Panel ( ) ; buttonPanelLayout = new HorizontalLayout ( ) ; buttonPanel . setContent ( buttonPanelLayout ) ; buttonPanelLayout . setWidth ( <NUM_LIT> , UNITS_PERCENTAGE ) ; mainLayout . addComponent ( buttonPanel , <NUM_LIT:1> , <NUM_LIT:1> ) ; piCount = new ProgressIndicator ( ) ; piCount . setIndeterminate ( true ) ; piCount . setEnabled ( false ) ; piCount . setVisible ( false ) ; piCount . setPollingInterval ( <NUM_LIT> ) ; panelStatus . addComponent ( piCount ) ; btShowResult = new Button ( "<STR_LIT>" ) ; btShowResult . setWidth ( <NUM_LIT> , UNITS_PERCENTAGE ) ; btShowResult . addListener ( new ShowResultClickListener ( ) ) ; btShowResult . setDescription ( "<STR_LIT>" ) ; btShowResult . setClickShortcut ( KeyCode . ENTER , ModifierKey . CTRL ) ; buttonPanel . addComponent ( btShowResult ) ; lstHistory = new ListSelect ( ) ; lstHistory . setNullSelectionAllowed ( false ) ; lstHistory . setValue ( null ) ; lstHistory . addListener ( ( ValueChangeListener ) this ) ; lstHistory . setImmediate ( true ) ; btHistory = new SplitButton ( "<STR_LIT>" ) ; btHistory . addStyleName ( SplitButton . STYLE_CHAMELEON ) ; btHistory . setWidth ( <NUM_LIT> , UNITS_PERCENTAGE ) ; btHistory . setComponent ( lstHistory ) ; btHistory . setButtonDescription ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; buttonPanel . addComponent ( btHistory ) ; btHistory . addClickListener ( new SplitButton . SplitButtonClickListener ( ) { @ Override public void splitButtonClick ( SplitButtonClickEvent event ) { if ( historyWindow == null ) { historyWindow = new Window ( "<STR_LIT>" ) ; historyWindow . setModal ( false ) ; historyWindow . setWidth ( "<STR_LIT>" ) ; historyWindow . setHeight ( "<STR_LIT>" ) ; } historyWindow . setContent ( new HistoryPanel ( history , controlPanel ) ) ; if ( getWindow ( ) . getChildWindows ( ) . contains ( historyWindow ) ) { historyWindow . bringToFront ( ) ; } else { getWindow ( ) . addWindow ( historyWindow ) ; } } } ) ; } public void updateShortHistory ( List < HistoryEntry > history ) { this . history = history ; lstHistory . removeAllItems ( ) ; int counter = <NUM_LIT:0> ; for ( HistoryEntry e : history ) { if ( counter >= MAX_HISTORY_MENU_ITEMS ) { break ; } else { lstHistory . addItem ( e ) ; } counter ++ ; } } public void setQuery ( String query ) { if ( txtQuery != null ) { txtQuery . setValue ( query ) ; } validateQuery ( query ) ; } public String getQuery ( ) { if ( txtQuery != null ) { return ( String ) txtQuery . getValue ( ) ; } return "<STR_LIT>" ; } @ Override public void textChange ( TextChangeEvent event ) { validateQuery ( event . getText ( ) ) ; } private void validateQuery ( String query ) { try { WebResource annisResource = Helper . getAnnisWebResource ( getApplication ( ) ) ; String result = annisResource . path ( "<STR_LIT>" ) . queryParam ( "<STR_LIT:q>" , query ) . get ( String . class ) ; if ( "<STR_LIT>" . equalsIgnoreCase ( result ) ) { lblStatus . setValue ( lastPublicStatus ) ; } else { lblStatus . setValue ( result ) ; } } catch ( UniformInterfaceException ex ) { if ( ex . getResponse ( ) . getStatus ( ) == <NUM_LIT> ) { lblStatus . setValue ( ex . getResponse ( ) . getEntity ( String . class ) ) ; } else { log . error ( "<STR_LIT>" , ex ) ; getWindow ( ) . showNotification ( "<STR_LIT>" + ex . getMessage ( ) , Notification . TYPE_TRAY_NOTIFICATION ) ; } } catch ( ClientHandlerException ex ) { log . error ( "<STR_LIT>" , ex ) ; getWindow ( ) . showNotification ( "<STR_LIT>" + ex . getMessage ( ) , Notification . TYPE_TRAY_NOTIFICATION ) ; } } @ Override public void valueChange ( ValueChangeEvent event ) { btHistory . setPopupVisible ( false ) ; HistoryEntry e = ( HistoryEntry ) event . getProperty ( ) . getValue ( ) ; if ( controlPanel != null & e != null ) { controlPanel . setQuery ( e . getQuery ( ) , e . getCorpora ( ) ) ; } } public class ShowResultClickListener implements Button . ClickListener { @ Override public void buttonClick ( ClickEvent event ) { if ( controlPanel != null ) { controlPanel . executeQuery ( ) ; } } } public void setCountIndicatorEnabled ( boolean enabled ) { if ( piCount != null && btShowResult != null ) { lblStatus . setVisible ( ! enabled ) ; piCount . setVisible ( enabled ) ; piCount . setEnabled ( enabled ) ; } } protected void setStatus ( String status ) { if ( lblStatus != null ) { lblStatus . setValue ( status ) ; lastPublicStatus = status ; } } } </s>
<s> package annis . gui ; import annis . provider . SaltProjectProvider ; import annis . service . objects . AnnisCorpus ; import annis . service . objects . CorpusConfig ; import com . sun . jersey . api . client . Client ; import com . sun . jersey . api . client . UniformInterfaceException ; import com . sun . jersey . api . client . WebResource ; import com . sun . jersey . api . client . config . ClientConfig ; import com . sun . jersey . api . client . config . DefaultClientConfig ; import com . vaadin . Application ; import com . vaadin . terminal . gwt . server . WebApplicationContext ; import com . vaadin . ui . Window ; import java . io . UnsupportedEncodingException ; import java . net . URI ; import java . net . URISyntaxException ; import java . net . URLEncoder ; import java . util . List ; import java . util . Map ; import java . util . TreeMap ; import org . apache . commons . lang3 . StringUtils ; import org . slf4j . LoggerFactory ; public class Helper { private static final org . slf4j . Logger log = LoggerFactory . getLogger ( Helper . class ) ; private static ThreadLocal < WebResource > annisWebResource = new ThreadLocal < WebResource > ( ) ; public static WebResource createAnnisWebResource ( String uri ) { ClientConfig rc = new DefaultClientConfig ( ) ; rc . getClasses ( ) . add ( SaltProjectProvider . class ) ; Client c = Client . create ( rc ) ; return c . resource ( uri ) ; } public static WebResource getAnnisWebResource ( Application app ) { if ( annisWebResource . get ( ) == null ) { annisWebResource . set ( createAnnisWebResource ( app . getProperty ( "<STR_LIT>" ) ) ) ; } return annisWebResource . get ( ) ; } public static String getContext ( Application app ) { WebApplicationContext context = ( WebApplicationContext ) app . getContext ( ) ; return context . getHttpSession ( ) . getServletContext ( ) . getContextPath ( ) ; } public static String generateCitation ( Application app , String aql , List < String > corpora , int contextLeft , int contextRight ) { try { StringBuilder sb = new StringBuilder ( ) ; URI appURI = app . getURL ( ) . toURI ( ) ; sb . append ( getContext ( app ) ) ; sb . append ( "<STR_LIT>" ) ; sb . append ( aql ) ; sb . append ( "<STR_LIT>" ) ; sb . append ( StringUtils . join ( corpora , "<STR_LIT:U+002C>" ) ) ; sb . append ( "<STR_LIT>" ) ; sb . append ( contextLeft ) ; sb . append ( "<STR_LIT>" ) ; sb . append ( contextRight ) ; sb . append ( "<STR_LIT:)>" ) ; try { return new URI ( appURI . getScheme ( ) , null , appURI . getHost ( ) , appURI . getPort ( ) , sb . toString ( ) , null , null ) . toASCIIString ( ) ; } catch ( URISyntaxException ex ) { log . error ( null , ex ) ; } return "<STR_LIT>" ; } catch ( URISyntaxException ex ) { log . error ( null , ex ) ; } return "<STR_LIT>" ; } public static Map < Long , AnnisCorpus > calculateID2Corpus ( Map < String , AnnisCorpus > corpusMap ) { TreeMap < Long , AnnisCorpus > result = new TreeMap < Long , AnnisCorpus > ( ) ; for ( AnnisCorpus c : corpusMap . values ( ) ) { result . put ( c . getId ( ) , c ) ; } return result ; } public static CorpusConfig getCorpusConfig ( String corpus , Application app , Window window ) { CorpusConfig corpusConfig = new CorpusConfig ( ) ; corpusConfig . setConfig ( new TreeMap < String , String > ( ) ) ; try { corpusConfig = Helper . getAnnisWebResource ( app ) . path ( "<STR_LIT>" ) . path ( URLEncoder . encode ( corpus , "<STR_LIT:UTF-8>" ) ) . path ( "<STR_LIT>" ) . get ( CorpusConfig . class ) ; } catch ( UnsupportedEncodingException ex ) { window . showNotification ( "<STR_LIT>" , ex . getLocalizedMessage ( ) , Window . Notification . TYPE_TRAY_NOTIFICATION ) ; } catch ( UniformInterfaceException ex ) { window . showNotification ( "<STR_LIT>" , ex . getLocalizedMessage ( ) , Window . Notification . TYPE_WARNING_MESSAGE ) ; } return corpusConfig ; } } </s>
<s> package annis . gui ; import com . vaadin . Application ; import com . vaadin . data . Validator ; import com . vaadin . data . validator . EmailValidator ; import com . vaadin . terminal . gwt . server . WebApplicationContext ; import com . vaadin . ui . * ; import com . vaadin . ui . Button . ClickEvent ; import java . io . File ; import java . io . IOException ; import javax . activation . FileDataSource ; import org . apache . commons . mail . * ; import org . slf4j . LoggerFactory ; public class ReportBugPanel extends Panel { private static final org . slf4j . Logger log = LoggerFactory . getLogger ( MetaDataPanel . class ) ; private Form form ; private TextField txtSummary ; private TextArea txtDescription ; private TextField txtName ; private TextField txtMail ; private Button btSubmit ; private Button btCancel ; public ReportBugPanel ( Application app , final String bugEMailAddress , final byte [ ] screenImage ) { setSizeUndefined ( ) ; FormLayout layout = new FormLayout ( ) ; layout . setSizeUndefined ( ) ; form = new Form ( layout ) ; form . setCaption ( "<STR_LIT>" ) ; form . setSizeUndefined ( ) ; form . setInvalidCommitted ( false ) ; form . setWriteThrough ( false ) ; getContent ( ) . setSizeFull ( ) ; getContent ( ) . addComponent ( form ) ; txtSummary = new TextField ( "<STR_LIT>" ) ; txtSummary . setRequired ( true ) ; txtSummary . setRequiredError ( "<STR_LIT>" ) ; txtSummary . setColumns ( <NUM_LIT> ) ; txtDescription = new TextArea ( "<STR_LIT>" ) ; txtDescription . setRequired ( true ) ; txtDescription . setRequiredError ( "<STR_LIT>" ) ; txtDescription . setRows ( <NUM_LIT:10> ) ; txtDescription . setColumns ( <NUM_LIT> ) ; txtDescription . setValue ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:n>" + "<STR_LIT>" + "<STR_LIT:n>" + "<STR_LIT:n>" + "<STR_LIT>" + "<STR_LIT:n>" + "<STR_LIT:n>" + "<STR_LIT>" ) ; txtName = new TextField ( "<STR_LIT>" ) ; txtName . setRequired ( true ) ; txtName . setRequiredError ( "<STR_LIT>" ) ; txtName . setColumns ( <NUM_LIT> ) ; txtMail = new TextField ( "<STR_LIT>" ) ; txtMail . setRequired ( true ) ; txtMail . setRequiredError ( "<STR_LIT>" ) ; txtMail . addValidator ( new EmailValidator ( "<STR_LIT>" ) ) ; txtMail . setColumns ( <NUM_LIT> ) ; form . addField ( "<STR_LIT>" , txtSummary ) ; form . addField ( "<STR_LIT:description>" , txtDescription ) ; form . addField ( "<STR_LIT:name>" , txtName ) ; form . addField ( "<STR_LIT:email>" , txtMail ) ; btSubmit = new Button ( "<STR_LIT>" , new Button . ClickListener ( ) { @ Override public void buttonClick ( ClickEvent event ) { try { form . commit ( ) ; sendBugReport ( bugEMailAddress , screenImage ) ; Window subwindow = getWindow ( ) ; Window parent = subwindow . getParent ( ) ; parent . removeWindow ( subwindow ) ; parent . showNotification ( "<STR_LIT>" , "<STR_LIT>" , Window . Notification . TYPE_HUMANIZED_MESSAGE ) ; } catch ( Validator . InvalidValueException ex ) { } catch ( Exception ex ) { getWindow ( ) . showNotification ( "<STR_LIT>" , ex . getMessage ( ) , Window . Notification . TYPE_ERROR_MESSAGE ) ; } } } ) ; btCancel = new Button ( "<STR_LIT>" , new Button . ClickListener ( ) { @ Override public void buttonClick ( ClickEvent event ) { form . discard ( ) ; Window subwindow = getWindow ( ) ; subwindow . getParent ( ) . removeWindow ( subwindow ) ; } } ) ; HorizontalLayout buttons = new HorizontalLayout ( ) ; buttons . addComponent ( btSubmit ) ; buttons . addComponent ( btCancel ) ; form . getFooter ( ) . addComponent ( buttons ) ; } private void sendBugReport ( String bugEMailAddress , byte [ ] screenImage ) { MultiPartEmail mail = new MultiPartEmail ( ) ; try { mail . setHostName ( "<STR_LIT:localhost>" ) ; mail . addReplyTo ( form . getField ( "<STR_LIT:email>" ) . getValue ( ) . toString ( ) , form . getField ( "<STR_LIT:name>" ) . getValue ( ) . toString ( ) ) ; mail . setFrom ( bugEMailAddress ) ; mail . addTo ( bugEMailAddress ) ; mail . setSubject ( "<STR_LIT>" + form . getField ( "<STR_LIT>" ) . getValue ( ) . toString ( ) ) ; StringBuilder sbMsg = new StringBuilder ( ) ; sbMsg . append ( "<STR_LIT>" ) . append ( form . getField ( "<STR_LIT:name>" ) . getValue ( ) . toString ( ) ) . append ( "<STR_LIT:U+0020(>" ) . append ( form . getField ( "<STR_LIT:email>" ) . getValue ( ) . toString ( ) ) . append ( "<STR_LIT>" ) ; sbMsg . append ( "<STR_LIT>" ) . append ( getApplication ( ) . getVersion ( ) ) . append ( "<STR_LIT:n>" ) ; sbMsg . append ( "<STR_LIT>" ) . append ( getApplication ( ) . getURL ( ) . toString ( ) ) . append ( "<STR_LIT:n>" ) ; sbMsg . append ( "<STR_LIT:n>" ) ; sbMsg . append ( form . getField ( "<STR_LIT:description>" ) . getValue ( ) . toString ( ) ) ; mail . setMsg ( sbMsg . toString ( ) ) ; if ( screenImage != null ) { try { mail . attach ( new ByteArrayDataSource ( screenImage , "<STR_LIT>" ) , "<STR_LIT>" , "<STR_LIT>" ) ; } catch ( IOException ex ) { log . error ( null , ex ) ; } WebApplicationContext context = ( WebApplicationContext ) getApplication ( ) . getContext ( ) ; File logfile = new File ( context . getHttpSession ( ) . getServletContext ( ) . getRealPath ( "<STR_LIT>" ) ) ; if ( logfile . exists ( ) && logfile . isFile ( ) && logfile . canRead ( ) ) { mail . attach ( new FileDataSource ( logfile ) , "<STR_LIT>" , "<STR_LIT>" ) ; } } mail . send ( ) ; } catch ( EmailException ex ) { getWindow ( ) . showNotification ( "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" , Window . Notification . TYPE_ERROR_MESSAGE ) ; log . error ( null , ex ) ; } } } </s>
<s> package annis . gui ; import com . vaadin . Application ; import com . vaadin . terminal . ApplicationResource ; import com . vaadin . terminal . ClassResource ; import com . vaadin . terminal . FileResource ; import com . vaadin . ui . Button . ClickEvent ; import com . vaadin . ui . * ; import java . io . File ; import java . io . FileFilter ; import java . io . IOException ; import org . apache . commons . io . FileUtils ; import org . apache . commons . io . filefilter . WildcardFileFilter ; import org . slf4j . Logger ; import org . slf4j . LoggerFactory ; public class AboutPanel extends Panel { private static final Logger log = LoggerFactory . getLogger ( AboutPanel . class ) ; private static ClassResource logo_sfb_res ; private static ClassResource logo_annis_res ; private VerticalLayout layout ; public AboutPanel ( Application app ) { if ( logo_sfb_res == null ) { logo_sfb_res = new ClassResource ( AboutPanel . class , "<STR_LIT>" , app ) ; } if ( logo_annis_res == null ) { logo_annis_res = new ClassResource ( AboutPanel . class , "<STR_LIT>" , app ) ; } setSizeFull ( ) ; layout = ( VerticalLayout ) getContent ( ) ; layout . setSizeFull ( ) ; } @ Override public void attach ( ) { super . attach ( ) ; HorizontalLayout hLayout = new HorizontalLayout ( ) ; Embedded logoAnnis = new Embedded ( ) ; logoAnnis . setSource ( logo_annis_res ) ; logoAnnis . setType ( Embedded . TYPE_IMAGE ) ; hLayout . addComponent ( logoAnnis ) ; Embedded logoSfb = new Embedded ( ) ; logoSfb . setSource ( logo_sfb_res ) ; logoSfb . setType ( Embedded . TYPE_IMAGE ) ; hLayout . addComponent ( logoSfb ) ; hLayout . setComponentAlignment ( logoAnnis , Alignment . MIDDLE_LEFT ) ; hLayout . setComponentAlignment ( logoSfb , Alignment . MIDDLE_RIGHT ) ; addComponent ( hLayout ) ; addComponent ( new Label ( "<STR_LIT>" + "<STR_LIT>" , Label . CONTENT_XHTML ) ) ; addComponent ( new Label ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" , Label . CONTENT_XHTML ) ) ; addComponent ( new Label ( "<STR_LIT>" + getApplication ( ) . getVersion ( ) ) ) ; TextArea txtThirdParty = new TextArea ( ) ; txtThirdParty . setSizeFull ( ) ; StringBuilder sb = new StringBuilder ( ) ; sb . append ( "<STR_LIT>" + "<STR_LIT>" ) ; File thirdPartyFolder = new File ( getApplication ( ) . getContext ( ) . getBaseDirectory ( ) , "<STR_LIT>" ) ; if ( thirdPartyFolder . isDirectory ( ) ) { for ( File c : thirdPartyFolder . listFiles ( ( FileFilter ) new WildcardFileFilter ( "<STR_LIT>" ) ) ) { if ( c . isFile ( ) ) { try { sb . append ( FileUtils . readFileToString ( c ) ) . append ( "<STR_LIT:n>" ) ; } catch ( IOException ex ) { log . error ( "<STR_LIT>" , ex ) ; } } } } txtThirdParty . setValue ( sb . toString ( ) ) ; txtThirdParty . setReadOnly ( true ) ; txtThirdParty . addStyleName ( "<STR_LIT>" ) ; txtThirdParty . setWordwrap ( false ) ; addComponent ( txtThirdParty ) ; Button btOK = new Button ( "<STR_LIT:OK>" ) ; btOK . addListener ( new Button . ClickListener ( ) { @ Override public void buttonClick ( ClickEvent event ) { Window subwindow = getWindow ( ) ; subwindow . getParent ( ) . removeWindow ( subwindow ) ; } } ) ; addComponent ( btOK ) ; layout . setComponentAlignment ( hLayout , Alignment . MIDDLE_CENTER ) ; layout . setComponentAlignment ( btOK , Alignment . MIDDLE_CENTER ) ; layout . setExpandRatio ( txtThirdParty , <NUM_LIT:1.0f> ) ; } } </s>
<s> package annis . gui . tutorial ; import com . vaadin . terminal . ExternalResource ; import com . vaadin . terminal . PaintException ; import com . vaadin . terminal . PaintTarget ; import com . vaadin . terminal . gwt . server . WebApplicationContext ; import com . vaadin . ui . Embedded ; import com . vaadin . ui . HorizontalLayout ; import com . vaadin . ui . Panel ; import javax . servlet . http . HttpSession ; public class TutorialPanel extends Panel { private Embedded embedded ; public TutorialPanel ( ) { setSizeFull ( ) ; HorizontalLayout layout = new HorizontalLayout ( ) ; layout . setSizeFull ( ) ; setContent ( layout ) ; embedded = new Embedded ( ) ; embedded . setSizeFull ( ) ; addComponent ( embedded ) ; } @ Override public void attach ( ) { WebApplicationContext webappcontext = ( WebApplicationContext ) getApplication ( ) . getContext ( ) ; HttpSession session = webappcontext . getHttpSession ( ) ; String contextPath = session . getServletContext ( ) . getContextPath ( ) ; embedded . setType ( Embedded . TYPE_BROWSER ) ; embedded . setSource ( new ExternalResource ( contextPath + "<STR_LIT>" ) ) ; super . attach ( ) ; } @ Override public void paintContent ( PaintTarget target ) throws PaintException { super . paintContent ( target ) ; } } </s>
<s> package annis . gui ; import com . vaadin . ui . Embedded ; import com . vaadin . ui . Panel ; import com . vaadin . ui . VerticalLayout ; import com . vaadin . ui . themes . ChameleonTheme ; public class ImagePanel extends Panel { public ImagePanel ( Embedded image ) { setWidth ( "<STR_LIT>" ) ; setHeight ( "<STR_LIT>" ) ; ( ( VerticalLayout ) getContent ( ) ) . setSizeUndefined ( ) ; addStyleName ( ChameleonTheme . PANEL_BORDERLESS ) ; addComponent ( image ) ; } } </s>
<s> package annis . gui ; import annis . gui . visualizers . VisualizerPlugin ; import net . xeoh . plugins . base . PluginManager ; public interface PluginSystem { public final static String DEFAULT_VISUALIZER = "<STR_LIT>" ; public PluginManager getPluginManager ( ) ; public VisualizerPlugin getVisualizer ( String shortName ) ; } </s>
<s> package annis . gui . beans ; import annis . service . objects . AnnisCorpus ; import java . util . Map ; public interface CitationProvider { public String getQuery ( ) ; public Map < String , AnnisCorpus > getCorpora ( ) ; public int getLeftContext ( ) ; public int getRightContext ( ) ; } </s>
<s> package annis . gui . beans ; import annis . service . objects . AnnisCorpus ; import java . io . Serializable ; import java . util . HashMap ; import java . util . Map ; import org . apache . commons . lang3 . StringUtils ; public class HistoryEntry implements CitationProvider , Serializable { private Map < String , AnnisCorpus > corpora ; private String query ; public HistoryEntry ( ) { corpora = new HashMap < String , AnnisCorpus > ( ) ; } @ Override public Map < String , AnnisCorpus > getCorpora ( ) { return corpora ; } public void setCorpora ( Map < String , AnnisCorpus > corpora ) { this . corpora = corpora ; } @ Override public String getQuery ( ) { return query ; } public void setQuery ( String query ) { this . query = query ; } @ Override public int getLeftContext ( ) { return <NUM_LIT:5> ; } @ Override public int getRightContext ( ) { return <NUM_LIT:5> ; } @ Override public String toString ( ) { return StringUtils . replaceChars ( query , "<STR_LIT>" , "<STR_LIT:U+0020U+0020>" ) ; } @ Override public boolean equals ( Object obj ) { if ( obj == null ) { return false ; } if ( getClass ( ) != obj . getClass ( ) ) { return false ; } final HistoryEntry other = ( HistoryEntry ) obj ; if ( this . corpora != other . corpora && ( this . corpora == null || ! this . corpora . equals ( other . corpora ) ) ) { return false ; } if ( ( this . query == null ) ? ( other . query != null ) : ! this . query . equals ( other . query ) ) { return false ; } return true ; } @ Override public int hashCode ( ) { int hash = <NUM_LIT:5> ; hash = <NUM_LIT:11> * hash + ( this . corpora != null ? this . corpora . hashCode ( ) : <NUM_LIT:0> ) ; hash = <NUM_LIT:11> * hash + ( this . query != null ? this . query . hashCode ( ) : <NUM_LIT:0> ) ; return hash ; } } </s>
<s> package annis . gui . beans ; import annis . service . objects . AnnisCorpus ; import java . io . Serializable ; import java . util . HashMap ; import java . util . Map ; public class CorpusBrowserEntry implements CitationProvider , Serializable { private String name ; private String example ; private AnnisCorpus corpus ; public String getExample ( ) { return example ; } public void setExample ( String example ) { this . example = example ; } public String getName ( ) { return name ; } public void setName ( String name ) { this . name = name ; } public AnnisCorpus getCorpus ( ) { return corpus ; } public void setCorpus ( AnnisCorpus corpus ) { this . corpus = corpus ; } @ Override public boolean equals ( Object obj ) { if ( obj == null ) { return false ; } if ( getClass ( ) != obj . getClass ( ) ) { return false ; } final CorpusBrowserEntry other = ( CorpusBrowserEntry ) obj ; if ( ( this . name == null ) ? ( other . name != null ) : ! this . name . equals ( other . name ) ) { return false ; } if ( this . corpus != other . corpus && ( this . corpus == null || ! this . corpus . equals ( other . corpus ) ) ) { return false ; } return true ; } @ Override public int hashCode ( ) { int hash = <NUM_LIT:5> ; hash = <NUM_LIT> * hash + ( this . name != null ? this . name . hashCode ( ) : <NUM_LIT:0> ) ; hash = <NUM_LIT> * hash + ( this . corpus != null ? this . corpus . hashCode ( ) : <NUM_LIT:0> ) ; return hash ; } @ Override public String getQuery ( ) { return example ; } @ Override public Map < String , AnnisCorpus > getCorpora ( ) { Map < String , AnnisCorpus > result = new HashMap < String , AnnisCorpus > ( ) ; result . put ( corpus . getName ( ) , corpus ) ; return result ; } @ Override public int getLeftContext ( ) { return <NUM_LIT:5> ; } @ Override public int getRightContext ( ) { return <NUM_LIT:5> ; } } </s>
<s> package annis . gui ; import annis . gui . media . MediaController ; import annis . gui . media . MediaControllerHolder ; import annis . gui . media . impl . MediaControllerFactoryImpl ; import annis . gui . servlets . ResourceServlet ; import annis . gui . visualizers . VisualizerPlugin ; import annis . gui . visualizers . component . grid . GridVisualizer ; import annis . gui . visualizers . iframe . CorefVisualizer ; import annis . gui . visualizers . iframe . dependency . ProielDependecyTree ; import annis . gui . visualizers . iframe . dependency . ProielRegularDependencyTree ; import annis . gui . visualizers . iframe . dependency . VakyarthaDependencyTree ; import annis . gui . visualizers . iframe . graph . DebugVisualizer ; import annis . gui . visualizers . iframe . graph . DotGraphVisualizer ; import annis . gui . visualizers . iframe . gridtree . GridTreeVisualizer ; import annis . gui . visualizers . component . AudioVisualizer ; import annis . gui . visualizers . component . KWICPanel ; import annis . gui . visualizers . component . VideoVisualizer ; import annis . gui . visualizers . iframe . partitur . PartiturVisualizer ; import annis . gui . visualizers . iframe . tree . TigerTreeVisualizer ; import annis . security . AnnisSecurityManager ; import annis . security . AnnisUser ; import ch . qos . logback . classic . LoggerContext ; import ch . qos . logback . classic . joran . JoranConfigurator ; import ch . qos . logback . core . joran . spi . JoranException ; import com . vaadin . Application ; import com . vaadin . Application . UserChangeListener ; import com . vaadin . terminal . ClassResource ; import com . vaadin . terminal . gwt . server . HttpServletRequestListener ; import com . vaadin . terminal . gwt . server . WebApplicationContext ; import com . vaadin . ui . Label ; import com . vaadin . ui . Window ; import java . io . * ; import java . net . URLDecoder ; import java . text . DateFormat ; import java . text . SimpleDateFormat ; import java . util . Collection ; import java . util . Collections ; import java . util . Date ; import java . util . HashMap ; import java . util . Map ; import java . util . Properties ; import javax . servlet . http . HttpServletRequest ; import javax . servlet . http . HttpServletResponse ; import javax . servlet . http . HttpSession ; import net . xeoh . plugins . base . Plugin ; import net . xeoh . plugins . base . PluginManager ; import net . xeoh . plugins . base . impl . PluginManagerFactory ; import net . xeoh . plugins . base . util . PluginManagerUtil ; import net . xeoh . plugins . base . util . uri . ClassURI ; import org . slf4j . LoggerFactory ; import org . slf4j . bridge . SLF4JBridgeHandler ; @ SuppressWarnings ( "<STR_LIT:serial>" ) public class MainApp extends Application implements PluginSystem , UserChangeListener , HttpServletRequestListener , Serializable , MediaControllerHolder { private static final org . slf4j . Logger log = LoggerFactory . getLogger ( MainApp . class ) ; public final static String USER_KEY = "<STR_LIT>" ; public final static String CITATION_KEY = "<STR_LIT>" ; private transient SearchWindow windowSearch ; private transient PluginManager pluginManager ; private static final Map < String , VisualizerPlugin > visualizerRegistry = Collections . synchronizedMap ( new HashMap < String , VisualizerPlugin > ( ) ) ; private static final Map < String , Date > resourceAddedDate = Collections . synchronizedMap ( new HashMap < String , Date > ( ) ) ; private Properties versionProperties ; private transient MediaController mediaController ; @ Override public void init ( ) { initLogging ( ) ; ClassResource res = new ClassResource ( "<STR_LIT>" , this ) ; versionProperties = new Properties ( ) ; try { versionProperties . load ( res . getStream ( ) . getStream ( ) ) ; } catch ( Exception ex ) { log . error ( null , ex ) ; } addListener ( ( UserChangeListener ) this ) ; initPlugins ( ) ; setTheme ( "<STR_LIT>" ) ; initWindow ( ) ; } protected void initLogging ( ) { SLF4JBridgeHandler . removeHandlersForRootLogger ( ) ; SLF4JBridgeHandler . install ( ) ; try { ClassResource res = new ClassResource ( "<STR_LIT>" , this ) ; if ( res != null ) { LoggerContext context = ( LoggerContext ) LoggerFactory . getILoggerFactory ( ) ; JoranConfigurator jc = new JoranConfigurator ( ) ; jc . setContext ( context ) ; context . reset ( ) ; context . putProperty ( "<STR_LIT>" , getContext ( ) . getBaseDirectory ( ) . getAbsolutePath ( ) ) ; jc . doConfigure ( res . getStream ( ) . getStream ( ) ) ; } } catch ( JoranException ex ) { log . error ( "<STR_LIT>" , ex ) ; } } public void initWindow ( ) { try { windowSearch = new SearchWindow ( ( PluginSystem ) this ) ; setMainWindow ( windowSearch ) ; } catch ( Exception e ) { log . error ( "<STR_LIT>" + "<STR_LIT>" , e ) ; Window debugWindow = new Window ( ) ; Label lblError = new Label ( ) ; lblError . setValue ( "<STR_LIT>" + e . getClass ( ) . getSimpleName ( ) + "<STR_LIT>" + e . getMessage ( ) + "<STR_LIT>" + e . getStackTrace ( ) [ <NUM_LIT:0> ] . toString ( ) ) ; lblError . setContentMode ( Label . CONTENT_PREFORMATTED ) ; debugWindow . addComponent ( lblError ) ; setMainWindow ( debugWindow ) ; } } public SearchWindow getWindowSearch ( ) { if ( windowSearch == null ) { initWindow ( ) ; } return windowSearch ; } public String getBuildRevision ( ) { String result = versionProperties . getProperty ( "<STR_LIT>" , "<STR_LIT>" ) ; return result ; } @ Override public String getVersion ( ) { String rev = getBuildRevision ( ) ; Date date = getBuildDate ( ) ; StringBuilder result = new StringBuilder ( ) ; result . append ( getVersionNumber ( ) ) ; if ( ! "<STR_LIT>" . equals ( rev ) || date != null ) { result . append ( "<STR_LIT:U+0020(>" ) ; boolean added = false ; if ( ! "<STR_LIT>" . equals ( rev ) ) { result . append ( "<STR_LIT>" ) ; result . append ( rev ) ; added = true ; } if ( date != null ) { result . append ( added ? "<STR_LIT>" : "<STR_LIT>" ) ; SimpleDateFormat d = new SimpleDateFormat ( "<STR_LIT>" ) ; result . append ( d . format ( date ) ) ; } result . append ( "<STR_LIT:)>" ) ; } return result . toString ( ) ; } public String getVersionNumber ( ) { return versionProperties . getProperty ( "<STR_LIT:version>" , "<STR_LIT>" ) ; } public Date getBuildDate ( ) { Date result = null ; try { DateFormat format = new SimpleDateFormat ( "<STR_LIT>" ) ; result = format . parse ( versionProperties . getProperty ( "<STR_LIT>" ) ) ; } catch ( Exception ex ) { log . debug ( null , ex ) ; } return result ; } @ Override public void setUser ( Object user ) { if ( user == null || ! ( user instanceof AnnisUser ) ) { try { user = getWindowSearch ( ) . getSecurityManager ( ) . login ( AnnisSecurityManager . FALLBACK_USER , AnnisSecurityManager . FALLBACK_USER , true ) ; } catch ( Exception ex ) { log . error ( null , ex ) ; } } super . setUser ( user ) ; getWindowSearch ( ) . updateUserInformation ( ) ; } @ Override public AnnisUser getUser ( ) { Object u = super . getUser ( ) ; return ( AnnisUser ) u ; } private void initPlugins ( ) { log . info ( "<STR_LIT>" ) ; pluginManager = PluginManagerFactory . createPluginManager ( ) ; pluginManager . addPluginsFrom ( new ClassURI ( CorefVisualizer . class ) . toURI ( ) ) ; pluginManager . addPluginsFrom ( new ClassURI ( DotGraphVisualizer . class ) . toURI ( ) ) ; pluginManager . addPluginsFrom ( new ClassURI ( DebugVisualizer . class ) . toURI ( ) ) ; pluginManager . addPluginsFrom ( new ClassURI ( GridTreeVisualizer . class ) . toURI ( ) ) ; pluginManager . addPluginsFrom ( new ClassURI ( GridVisualizer . class ) . toURI ( ) ) ; pluginManager . addPluginsFrom ( new ClassURI ( PartiturVisualizer . class ) . toURI ( ) ) ; pluginManager . addPluginsFrom ( new ClassURI ( ProielDependecyTree . class ) . toURI ( ) ) ; pluginManager . addPluginsFrom ( new ClassURI ( ProielRegularDependencyTree . class ) . toURI ( ) ) ; pluginManager . addPluginsFrom ( new ClassURI ( ResourceServlet . class ) . toURI ( ) ) ; pluginManager . addPluginsFrom ( new ClassURI ( TigerTreeVisualizer . class ) . toURI ( ) ) ; pluginManager . addPluginsFrom ( new ClassURI ( VakyarthaDependencyTree . class ) . toURI ( ) ) ; pluginManager . addPluginsFrom ( new ClassURI ( AudioVisualizer . class ) . toURI ( ) ) ; pluginManager . addPluginsFrom ( new ClassURI ( VideoVisualizer . class ) . toURI ( ) ) ; pluginManager . addPluginsFrom ( new ClassURI ( KWICPanel . class ) . toURI ( ) ) ; pluginManager . addPluginsFrom ( new ClassURI ( MediaControllerFactoryImpl . class ) . toURI ( ) ) ; File baseDir = this . getContext ( ) . getBaseDirectory ( ) ; File basicPlugins = new File ( baseDir , "<STR_LIT>" ) ; if ( basicPlugins . isDirectory ( ) ) { pluginManager . addPluginsFrom ( basicPlugins . toURI ( ) ) ; log . info ( "<STR_LIT>" , basicPlugins . getPath ( ) ) ; } String globalPlugins = System . getenv ( "<STR_LIT>" ) ; if ( globalPlugins != null ) { pluginManager . addPluginsFrom ( new File ( globalPlugins ) . toURI ( ) ) ; log . info ( "<STR_LIT>" , globalPlugins ) ; } StringBuilder listOfPlugins = new StringBuilder ( ) ; listOfPlugins . append ( "<STR_LIT>" ) ; PluginManagerUtil util = new PluginManagerUtil ( pluginManager ) ; for ( Plugin p : util . getPlugins ( ) ) { listOfPlugins . append ( p . getClass ( ) . getName ( ) ) . append ( "<STR_LIT:n>" ) ; } log . info ( listOfPlugins . toString ( ) ) ; Collection < VisualizerPlugin > visualizers = util . getPlugins ( VisualizerPlugin . class ) ; for ( VisualizerPlugin vis : visualizers ) { visualizerRegistry . put ( vis . getShortName ( ) , vis ) ; resourceAddedDate . put ( vis . getShortName ( ) , new Date ( ) ) ; } } @ Override public void close ( ) { if ( pluginManager != null ) { pluginManager . shutdown ( ) ; } super . close ( ) ; } @ Override public PluginManager getPluginManager ( ) { if ( pluginManager == null ) { initPlugins ( ) ; } return pluginManager ; } @ Override public VisualizerPlugin getVisualizer ( String shortName ) { return visualizerRegistry . get ( shortName ) ; } @ Override public void applicationUserChanged ( UserChangeEvent event ) { HttpSession session = ( ( WebApplicationContext ) getContext ( ) ) . getHttpSession ( ) ; session . setAttribute ( USER_KEY , event . getNewUser ( ) ) ; } public AnnisSecurityManager getSecurityManager ( ) { return getWindowSearch ( ) . getSecurityManager ( ) ; } @ Override public void onRequestStart ( HttpServletRequest request , HttpServletResponse response ) { String origURI = request . getRequestURI ( ) ; String parameters = origURI . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) ; if ( ! "<STR_LIT>" . equals ( parameters ) && ! origURI . equals ( parameters ) ) { try { String decoded = URLDecoder . decode ( parameters , "<STR_LIT:UTF-8>" ) ; getWindowSearch ( ) . evaluateCitation ( decoded ) ; try { response . sendRedirect ( getURL ( ) . toString ( ) ) ; } catch ( IOException ex ) { log . error ( null , ex ) ; } } catch ( UnsupportedEncodingException ex ) { log . error ( null , ex ) ; } } } @ Override public void onRequestEnd ( HttpServletRequest request , HttpServletResponse response ) { } @ Override public MediaController getMediaController ( ) { return mediaController ; } @ Override public void setMediaController ( MediaController mediaController ) { this . mediaController = mediaController ; } } </s>
<s> package annis . gui . paging ; import com . vaadin . ui . themes . ChameleonTheme ; import com . vaadin . data . Validator ; import com . vaadin . data . validator . AbstractStringValidator ; import com . vaadin . event . ShortcutAction . KeyCode ; import com . vaadin . event . ShortcutListener ; import com . vaadin . terminal . ThemeResource ; import com . vaadin . ui . Alignment ; import com . vaadin . ui . Button ; import com . vaadin . ui . Button . ClickEvent ; import com . vaadin . ui . CustomComponent ; import com . vaadin . ui . HorizontalLayout ; import com . vaadin . ui . Label ; import com . vaadin . ui . Panel ; import com . vaadin . ui . TextField ; import java . util . HashSet ; import java . util . Set ; import java . util . concurrent . atomic . AtomicInteger ; import org . slf4j . LoggerFactory ; public class PagingComponent extends CustomComponent implements Button . ClickListener { private static final org . slf4j . Logger log = LoggerFactory . getLogger ( PagingComponent . class ) ; public static final ThemeResource LEFT_ARROW = new ThemeResource ( "<STR_LIT>" ) ; public static final ThemeResource RIGHT_ARROW = new ThemeResource ( "<STR_LIT>" ) ; public static final ThemeResource FIRST = new ThemeResource ( "<STR_LIT>" ) ; public static final ThemeResource LAST = new ThemeResource ( "<STR_LIT>" ) ; private HorizontalLayout layout ; private Button btFirst ; private Button btLast ; private Button btNext ; private Button btPrevious ; private TextField txtPage ; private Label lblMaxPages ; private Label lblStatus ; private Set < PagingCallback > callbacks ; private AtomicInteger count ; private int pageSize ; private int currentPage ; private Label lblInfo ; public PagingComponent ( int count , int pageSize ) { if ( pageSize <= <NUM_LIT:0> ) { pageSize = <NUM_LIT:1> ; } if ( count < <NUM_LIT:0> ) { count = <NUM_LIT:0> ; } currentPage = <NUM_LIT:1> ; this . count = new AtomicInteger ( pageSize ) ; this . pageSize = pageSize ; setWidth ( "<STR_LIT>" ) ; setHeight ( "<STR_LIT>" ) ; addStyleName ( "<STR_LIT>" ) ; callbacks = new HashSet < PagingCallback > ( ) ; layout = new HorizontalLayout ( ) ; layout . setSpacing ( true ) ; layout . setMargin ( false , true , false , true ) ; Panel root = new Panel ( layout ) ; root . setStyleName ( ChameleonTheme . PANEL_BORDERLESS ) ; setCompositionRoot ( root ) ; lblInfo = new Label ( ) ; lblInfo . addStyleName ( "<STR_LIT>" ) ; layout . setWidth ( "<STR_LIT>" ) ; layout . setHeight ( "<STR_LIT>" ) ; btFirst = new Button ( ) ; btFirst . setIcon ( FIRST ) ; btFirst . setDescription ( "<STR_LIT>" ) ; btFirst . addListener ( ( Button . ClickListener ) this ) ; btFirst . addStyleName ( ChameleonTheme . BUTTON_ICON_ONLY ) ; btLast = new Button ( ) ; btLast . setIcon ( LAST ) ; btLast . setDescription ( "<STR_LIT>" ) ; btLast . addListener ( ( Button . ClickListener ) this ) ; btLast . addStyleName ( ChameleonTheme . BUTTON_ICON_ONLY ) ; btNext = new Button ( ) ; btNext . setIcon ( RIGHT_ARROW ) ; btNext . setDescription ( "<STR_LIT>" ) ; btNext . addListener ( ( Button . ClickListener ) this ) ; btNext . addStyleName ( ChameleonTheme . BUTTON_ICON_ONLY ) ; btPrevious = new Button ( ) ; btPrevious . setIcon ( LEFT_ARROW ) ; btPrevious . setDescription ( "<STR_LIT>" ) ; btPrevious . addListener ( ( Button . ClickListener ) this ) ; btPrevious . addStyleName ( ChameleonTheme . BUTTON_ICON_ONLY ) ; txtPage = new TextField ( ) ; txtPage . setDescription ( "<STR_LIT>" ) ; txtPage . setHeight ( "<STR_LIT>" ) ; txtPage . setWidth ( <NUM_LIT> , UNITS_EM ) ; Validator pageValidator = new AbstractStringValidator ( "<STR_LIT>" ) { @ Override protected boolean isValidString ( String value ) { try { int v = Integer . parseInt ( value ) ; if ( v > <NUM_LIT:0> ) { return true ; } else { return false ; } } catch ( Exception ex ) { return false ; } } } ; txtPage . addValidator ( pageValidator ) ; root . addAction ( new EnterListener ( txtPage ) ) ; lblMaxPages = new Label ( ) ; lblMaxPages . setDescription ( "<STR_LIT>" ) ; lblMaxPages . setSizeUndefined ( ) ; lblStatus = new Label ( ) ; lblStatus . setSizeUndefined ( ) ; layout . addComponent ( btFirst ) ; layout . addComponent ( btPrevious ) ; layout . addComponent ( txtPage ) ; layout . addComponent ( lblMaxPages ) ; layout . addComponent ( btNext ) ; layout . addComponent ( btLast ) ; layout . addComponent ( lblStatus ) ; layout . addComponent ( lblInfo ) ; layout . setComponentAlignment ( lblStatus , Alignment . MIDDLE_LEFT ) ; layout . setComponentAlignment ( lblMaxPages , Alignment . MIDDLE_CENTER ) ; layout . setComponentAlignment ( txtPage , Alignment . MIDDLE_RIGHT ) ; layout . setExpandRatio ( lblStatus , <NUM_LIT:1.0f> ) ; layout . setComponentAlignment ( lblInfo , Alignment . MIDDLE_RIGHT ) ; layout . setExpandRatio ( lblInfo , <NUM_LIT> ) ; update ( false ) ; } private void update ( boolean informCallbacks ) { int myCount = count . get ( ) ; txtPage . setValue ( "<STR_LIT>" + currentPage ) ; lblMaxPages . setValue ( "<STR_LIT>" + getMaxPage ( ) ) ; lblStatus . setValue ( "<STR_LIT>" + ( getStartNumber ( ) + <NUM_LIT:1> ) + "<STR_LIT:U+0020-U+0020>" + Math . min ( getStartNumber ( ) + pageSize , myCount ) + "<STR_LIT>" + myCount ) ; btFirst . setEnabled ( currentPage > <NUM_LIT:1> ) ; btPrevious . setEnabled ( currentPage > <NUM_LIT:1> ) ; btLast . setEnabled ( currentPage < getMaxPage ( ) ) ; btNext . setEnabled ( currentPage < getMaxPage ( ) ) ; if ( informCallbacks ) { for ( PagingCallback c : callbacks ) { c . createPage ( getStartNumber ( ) , pageSize ) ; } } } public void addCallback ( PagingCallback callback ) { callbacks . add ( callback ) ; } public boolean removeCallback ( PagingCallback callback ) { return callbacks . remove ( callback ) ; } public int getMaxPage ( ) { int mycount = Math . max ( <NUM_LIT:0> , count . get ( ) - <NUM_LIT:1> ) ; return ( <NUM_LIT:1> + ( mycount / pageSize ) ) ; } public int getStartNumber ( ) { return ( currentPage - <NUM_LIT:1> ) * pageSize ; } public int getCount ( ) { return count . get ( ) ; } public void setCount ( int count , boolean update ) { if ( count < <NUM_LIT:0> ) { count = <NUM_LIT:0> ; } this . count . set ( count ) ; update ( update ) ; } public int getPageSize ( ) { return pageSize ; } public void setPageSize ( int pageSize ) { if ( pageSize <= <NUM_LIT:0> ) { pageSize = <NUM_LIT:1> ; } this . pageSize = pageSize ; update ( true ) ; } @ Override public void buttonClick ( ClickEvent event ) { if ( event . getButton ( ) == btFirst ) { currentPage = <NUM_LIT:1> ; } else if ( event . getButton ( ) == btLast ) { currentPage = getMaxPage ( ) ; } else if ( event . getButton ( ) == btNext ) { currentPage ++ ; } else if ( event . getButton ( ) == btPrevious ) { currentPage -- ; } currentPage = sanitizePage ( currentPage ) ; String clearglobalMediaList = "<STR_LIT>" + "<STR_LIT:{>" + "<STR_LIT>" + "<STR_LIT:}>" ; getWindow ( ) . executeJavaScript ( clearglobalMediaList ) ; update ( true ) ; } private int sanitizePage ( int page ) { int val = Math . max ( <NUM_LIT:1> , page ) ; val = Math . min ( <NUM_LIT:1> + ( count . get ( ) / pageSize ) , page ) ; return val ; } public class EnterListener extends ShortcutListener { private Object registeredTarget ; public EnterListener ( Object registeredTarget ) { super ( "<STR_LIT>" , KeyCode . ENTER , null ) ; this . registeredTarget = registeredTarget ; } @ Override public void handleAction ( Object sender , Object target ) { if ( target != registeredTarget ) { return ; } try { int newPage = Integer . parseInt ( ( String ) txtPage . getValue ( ) ) ; currentPage = sanitizePage ( newPage ) ; update ( true ) ; } catch ( Exception ex ) { log . error ( null , ex ) ; } } } public void setInfo ( String text ) { lblInfo . setValue ( text ) ; } } </s>
<s> package annis . gui . paging ; import java . io . Serializable ; public interface PagingCallback extends Serializable { public void createPage ( int start , int limit ) ; } </s>
<s> package annis . gui ; import annis . gui . beans . HistoryEntry ; import annis . gui . controlpanel . ControlPanel ; import com . vaadin . data . Property . ValueChangeEvent ; import com . vaadin . data . Property . ValueChangeListener ; import com . vaadin . data . util . BeanItemContainer ; import com . vaadin . ui . Label ; import com . vaadin . ui . Panel ; import com . vaadin . ui . Table ; import com . vaadin . ui . VerticalLayout ; import java . util . List ; public class HistoryPanel extends Panel implements ValueChangeListener { private Table tblHistory ; private BeanItemContainer < HistoryEntry > containerHistory ; private ControlPanel parent ; private CitationLinkGenerator citationGenerator ; public HistoryPanel ( List < HistoryEntry > history , ControlPanel parent ) { this . parent = parent ; setSizeFull ( ) ; ( ( VerticalLayout ) getContent ( ) ) . setSizeFull ( ) ; containerHistory = new BeanItemContainer ( HistoryEntry . class ) ; containerHistory . addAll ( history ) ; tblHistory = new Table ( ) ; addComponent ( tblHistory ) ; tblHistory . setSizeFull ( ) ; tblHistory . setSelectable ( true ) ; tblHistory . setMultiSelect ( false ) ; tblHistory . setContainerDataSource ( containerHistory ) ; tblHistory . addGeneratedColumn ( "<STR_LIT>" , new Table . ColumnGenerator ( ) { @ Override public Object generateCell ( Table source , Object itemId , Object columnId ) { return new Label ( "<STR_LIT>" + ( containerHistory . indexOfId ( itemId ) + <NUM_LIT:1> ) ) ; } } ) ; citationGenerator = new CitationLinkGenerator ( ) ; tblHistory . addGeneratedColumn ( "<STR_LIT>" , citationGenerator ) ; tblHistory . setVisibleColumns ( new String [ ] { "<STR_LIT>" , "<STR_LIT:query>" , "<STR_LIT>" } ) ; tblHistory . setColumnHeader ( "<STR_LIT>" , "<STR_LIT:#>" ) ; tblHistory . setColumnHeader ( "<STR_LIT:query>" , "<STR_LIT>" ) ; tblHistory . setColumnHeader ( "<STR_LIT>" , "<STR_LIT>" ) ; tblHistory . setColumnExpandRatio ( "<STR_LIT:query>" , <NUM_LIT:1.0f> ) ; tblHistory . setImmediate ( true ) ; tblHistory . addListener ( ( ValueChangeListener ) this ) ; } @ Override public void attach ( ) { super . attach ( ) ; citationGenerator . setMainWindow ( getApplication ( ) . getMainWindow ( ) ) ; } @ Override public void valueChange ( ValueChangeEvent event ) { HistoryEntry e = ( HistoryEntry ) event . getProperty ( ) . getValue ( ) ; if ( parent != null ) { parent . setQuery ( e . getQuery ( ) , e . getCorpora ( ) ) ; } } } </s>
<s> package de . hu_berlin . german . korpling . annis . kickstarter ; import java . awt . Dialog ; public class ExceptionDialog extends javax . swing . JDialog { public ExceptionDialog ( Exception exception ) { super ( ( Dialog ) null , true ) ; init ( exception , null ) ; } public ExceptionDialog ( Exception exception , String caption ) { super ( ( Dialog ) null , true ) ; init ( exception , caption ) ; } public ExceptionDialog ( java . awt . Dialog parent , Exception exception ) { super ( parent , true ) ; init ( exception , null ) ; } public ExceptionDialog ( java . awt . Frame parent , Exception exception ) { super ( parent , true ) ; init ( exception , null ) ; } private void init ( Exception exception , String caption ) { initComponents ( ) ; if ( caption != null ) { lblCaption . setText ( caption + "<STR_LIT::>" ) ; } if ( exception != null ) { lblType . setText ( exception . getClass ( ) . getName ( ) ) ; txtMessage . setText ( exception . getLocalizedMessage ( ) ) ; txtMessage . setCaretPosition ( <NUM_LIT:0> ) ; StringBuilder details = new StringBuilder ( ) ; details . append ( exception . getLocalizedMessage ( ) ) ; details . append ( "<STR_LIT>" ) ; StackTraceElement [ ] st = exception . getStackTrace ( ) ; for ( int i = <NUM_LIT:0> ; i < st . length ; i ++ ) { details . append ( st [ i ] . toString ( ) ) ; details . append ( "<STR_LIT:n>" ) ; } txtDetails . setText ( details . toString ( ) ) ; } } @ SuppressWarnings ( "<STR_LIT:unchecked>" ) private void initComponents ( ) { lblCaption = new javax . swing . JLabel ( ) ; btClose = new javax . swing . JButton ( ) ; spDetails = new javax . swing . JScrollPane ( ) ; txtDetails = new javax . swing . JTextArea ( ) ; btDetails = new javax . swing . JToggleButton ( ) ; spMessage = new javax . swing . JScrollPane ( ) ; txtMessage = new javax . swing . JTextArea ( ) ; lblTypeCaption = new javax . swing . JLabel ( ) ; lblType = new javax . swing . JLabel ( ) ; setDefaultCloseOperation ( javax . swing . WindowConstants . DISPOSE_ON_CLOSE ) ; setTitle ( "<STR_LIT>" ) ; setLocationByPlatform ( true ) ; addWindowListener ( new java . awt . event . WindowAdapter ( ) { public void windowOpened ( java . awt . event . WindowEvent evt ) { formWindowOpened ( evt ) ; } } ) ; lblCaption . setFont ( new java . awt . Font ( "<STR_LIT>" , <NUM_LIT:1> , <NUM_LIT> ) ) ; lblCaption . setText ( "<STR_LIT>" ) ; btClose . setMnemonic ( '<CHAR_LIT>' ) ; btClose . setText ( "<STR_LIT>" ) ; btClose . addActionListener ( new java . awt . event . ActionListener ( ) { public void actionPerformed ( java . awt . event . ActionEvent evt ) { btCloseActionPerformed ( evt ) ; } } ) ; txtDetails . setColumns ( <NUM_LIT:20> ) ; txtDetails . setRows ( <NUM_LIT:5> ) ; txtDetails . setText ( "<STR_LIT>" ) ; spDetails . setViewportView ( txtDetails ) ; btDetails . setMnemonic ( '<CHAR_LIT>' ) ; btDetails . setText ( "<STR_LIT>" ) ; btDetails . addActionListener ( new java . awt . event . ActionListener ( ) { public void actionPerformed ( java . awt . event . ActionEvent evt ) { btDetailsActionPerformed ( evt ) ; } } ) ; txtMessage . setColumns ( <NUM_LIT:20> ) ; txtMessage . setEditable ( false ) ; txtMessage . setLineWrap ( true ) ; txtMessage . setRows ( <NUM_LIT:5> ) ; txtMessage . setText ( "<STR_LIT>" ) ; txtMessage . setWrapStyleWord ( true ) ; spMessage . setViewportView ( txtMessage ) ; lblTypeCaption . setText ( "<STR_LIT>" ) ; lblType . setText ( "<STR_LIT>" ) ; javax . swing . GroupLayout layout = new javax . swing . GroupLayout ( getContentPane ( ) ) ; getContentPane ( ) . setLayout ( layout ) ; layout . setHorizontalGroup ( layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . LEADING ) . addGroup ( layout . createSequentialGroup ( ) . addGap ( <NUM_LIT:24> , <NUM_LIT:24> , <NUM_LIT:24> ) . addGroup ( layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . LEADING ) . addComponent ( spDetails , javax . swing . GroupLayout . Alignment . TRAILING , javax . swing . GroupLayout . DEFAULT_SIZE , <NUM_LIT> , Short . MAX_VALUE ) . addComponent ( lblCaption , javax . swing . GroupLayout . DEFAULT_SIZE , <NUM_LIT> , Short . MAX_VALUE ) . addComponent ( spMessage , javax . swing . GroupLayout . DEFAULT_SIZE , <NUM_LIT> , Short . MAX_VALUE ) . addGroup ( layout . createSequentialGroup ( ) . addComponent ( btDetails ) . addPreferredGap ( javax . swing . LayoutStyle . ComponentPlacement . RELATED , javax . swing . GroupLayout . DEFAULT_SIZE , Short . MAX_VALUE ) . addComponent ( btClose ) ) . addGroup ( layout . createSequentialGroup ( ) . addComponent ( lblTypeCaption ) . addPreferredGap ( javax . swing . LayoutStyle . ComponentPlacement . RELATED ) . addComponent ( lblType , javax . swing . GroupLayout . DEFAULT_SIZE , javax . swing . GroupLayout . DEFAULT_SIZE , Short . MAX_VALUE ) ) ) . addContainerGap ( ) ) ) ; layout . setVerticalGroup ( layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . LEADING ) . addGroup ( layout . createSequentialGroup ( ) . addContainerGap ( ) . addComponent ( lblCaption ) . addPreferredGap ( javax . swing . LayoutStyle . ComponentPlacement . RELATED ) . addComponent ( spMessage ) . addPreferredGap ( javax . swing . LayoutStyle . ComponentPlacement . RELATED ) . addGroup ( layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . BASELINE ) . addComponent ( lblTypeCaption ) . addComponent ( lblType ) ) . addPreferredGap ( javax . swing . LayoutStyle . ComponentPlacement . RELATED ) . addComponent ( spDetails , javax . swing . GroupLayout . PREFERRED_SIZE , <NUM_LIT> , javax . swing . GroupLayout . PREFERRED_SIZE ) . addPreferredGap ( javax . swing . LayoutStyle . ComponentPlacement . RELATED ) . addGroup ( layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . BASELINE ) . addComponent ( btDetails ) . addComponent ( btClose ) ) . addContainerGap ( ) ) ) ; pack ( ) ; } private void btDetailsActionPerformed ( java . awt . event . ActionEvent evt ) { spDetails . setVisible ( btDetails . isSelected ( ) ) ; pack ( ) ; validate ( ) ; } private void btCloseActionPerformed ( java . awt . event . ActionEvent evt ) { this . setVisible ( false ) ; this . dispose ( ) ; } private void formWindowOpened ( java . awt . event . WindowEvent evt ) { spDetails . setVisible ( false ) ; pack ( ) ; validate ( ) ; } public static void main ( String args [ ] ) { java . awt . EventQueue . invokeLater ( new Runnable ( ) { @ Override public void run ( ) { ExceptionDialog dialog = new ExceptionDialog ( new javax . swing . JFrame ( ) , null ) ; dialog . addWindowListener ( new java . awt . event . WindowAdapter ( ) { @ Override public void windowClosing ( java . awt . event . WindowEvent e ) { System . exit ( <NUM_LIT:0> ) ; } } ) ; dialog . setVisible ( true ) ; } } ) ; } private javax . swing . JButton btClose ; private javax . swing . JToggleButton btDetails ; private javax . swing . JLabel lblCaption ; private javax . swing . JLabel lblType ; private javax . swing . JLabel lblTypeCaption ; private javax . swing . JScrollPane spDetails ; private javax . swing . JScrollPane spMessage ; private javax . swing . JTextArea txtDetails ; private javax . swing . JTextArea txtMessage ; } </s>
<s> package de . hu_berlin . german . korpling . annis . kickstarter ; import annis . administration . CorpusAdministration ; import java . util . LinkedList ; import java . util . List ; import java . util . Map ; import javax . swing . SwingWorker ; import javax . swing . table . DefaultTableModel ; public class ListDialog extends javax . swing . JDialog { private DefaultTableModel tableModel ; private CorpusAdministration corpusAdmin ; public ListDialog ( java . awt . Frame parent , boolean modal , CorpusAdministration corpusAdmin ) { super ( parent , modal ) ; this . corpusAdmin = corpusAdmin ; initComponents ( ) ; updateTable ( ) ; } @ SuppressWarnings ( "<STR_LIT:unchecked>" ) private void initComponents ( ) { jScrollPane1 = new javax . swing . JScrollPane ( ) ; tableList = new javax . swing . JTable ( ) ; btClose = new javax . swing . JButton ( ) ; btDelete = new javax . swing . JButton ( ) ; pbDelete = new javax . swing . JProgressBar ( ) ; setDefaultCloseOperation ( javax . swing . WindowConstants . DISPOSE_ON_CLOSE ) ; setTitle ( "<STR_LIT>" ) ; setLocationByPlatform ( true ) ; tableList . setModel ( new javax . swing . table . DefaultTableModel ( new Object [ ] [ ] { } , new String [ ] { } ) ) ; jScrollPane1 . setViewportView ( tableList ) ; btClose . setMnemonic ( '<CHAR_LIT:c>' ) ; btClose . setText ( "<STR_LIT>" ) ; btClose . addActionListener ( new java . awt . event . ActionListener ( ) { public void actionPerformed ( java . awt . event . ActionEvent evt ) { btCloseActionPerformed ( evt ) ; } } ) ; btDelete . setIcon ( new javax . swing . ImageIcon ( getClass ( ) . getResource ( "<STR_LIT>" ) ) ) ; btDelete . setText ( "<STR_LIT>" ) ; btDelete . addActionListener ( new java . awt . event . ActionListener ( ) { public void actionPerformed ( java . awt . event . ActionEvent evt ) { btDeleteActionPerformed ( evt ) ; } } ) ; javax . swing . GroupLayout layout = new javax . swing . GroupLayout ( getContentPane ( ) ) ; getContentPane ( ) . setLayout ( layout ) ; layout . setHorizontalGroup ( layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . LEADING ) . addComponent ( jScrollPane1 , javax . swing . GroupLayout . DEFAULT_SIZE , <NUM_LIT> , Short . MAX_VALUE ) . addGroup ( layout . createSequentialGroup ( ) . addContainerGap ( ) . addGroup ( layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . LEADING ) . addGroup ( javax . swing . GroupLayout . Alignment . TRAILING , layout . createSequentialGroup ( ) . addComponent ( btDelete , javax . swing . GroupLayout . PREFERRED_SIZE , <NUM_LIT> , Short . MAX_VALUE ) . addGap ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) . addComponent ( btClose ) . addContainerGap ( ) ) . addGroup ( layout . createSequentialGroup ( ) . addComponent ( pbDelete , javax . swing . GroupLayout . DEFAULT_SIZE , <NUM_LIT> , Short . MAX_VALUE ) . addGap ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) ) ) ) ) ; layout . setVerticalGroup ( layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . LEADING ) . addGroup ( layout . createSequentialGroup ( ) . addComponent ( jScrollPane1 , javax . swing . GroupLayout . PREFERRED_SIZE , <NUM_LIT> , javax . swing . GroupLayout . PREFERRED_SIZE ) . addGap ( <NUM_LIT:7> , <NUM_LIT:7> , <NUM_LIT:7> ) . addComponent ( pbDelete , javax . swing . GroupLayout . PREFERRED_SIZE , javax . swing . GroupLayout . DEFAULT_SIZE , javax . swing . GroupLayout . PREFERRED_SIZE ) . addPreferredGap ( javax . swing . LayoutStyle . ComponentPlacement . RELATED ) . addGroup ( layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . BASELINE ) . addComponent ( btDelete ) . addComponent ( btClose , javax . swing . GroupLayout . PREFERRED_SIZE , <NUM_LIT> , javax . swing . GroupLayout . PREFERRED_SIZE ) ) . addContainerGap ( javax . swing . GroupLayout . DEFAULT_SIZE , Short . MAX_VALUE ) ) ) ; pack ( ) ; } private void btCloseActionPerformed ( java . awt . event . ActionEvent evt ) { setVisible ( false ) ; } private void btDeleteActionPerformed ( java . awt . event . ActionEvent evt ) { int row = tableList . getSelectedRow ( ) ; int col = tableModel . findColumn ( "<STR_LIT:id>" ) ; if ( row > - <NUM_LIT:1> && col > - <NUM_LIT:1> ) { Object value = tableModel . getValueAt ( row , col ) ; final LinkedList < Long > corpusListToDelete = new LinkedList < Long > ( ) ; long l = Long . parseLong ( value . toString ( ) ) ; corpusListToDelete . add ( l ) ; pbDelete . setIndeterminate ( true ) ; btClose . setEnabled ( false ) ; btDelete . setEnabled ( false ) ; SwingWorker < String , Void > worker = new SwingWorker < String , Void > ( ) { @ Override protected String doInBackground ( ) throws Exception { corpusAdmin . deleteCorpora ( corpusListToDelete ) ; updateTable ( ) ; return "<STR_LIT>" ; } @ Override protected void done ( ) { pbDelete . setIndeterminate ( false ) ; pbDelete . setValue ( <NUM_LIT:100> ) ; btClose . setEnabled ( true ) ; btDelete . setEnabled ( true ) ; } } ; worker . execute ( ) ; } } private void updateTable ( ) { try { tableModel = new DefaultTableModel ( new String [ ] { "<STR_LIT:name>" , "<STR_LIT:id>" , "<STR_LIT:text>" , "<STR_LIT>" , "<STR_LIT>" } , <NUM_LIT:0> ) ; tableList . setModel ( tableModel ) ; List < Map < String , Object > > stats = corpusAdmin . listCorpusStats ( ) ; int row = <NUM_LIT:0> ; for ( Map < String , Object > map : stats ) { String [ ] rowData = new String [ tableModel . getColumnCount ( ) ] ; for ( int j = <NUM_LIT:0> ; j < rowData . length ; j ++ ) { String cName = tableList . getColumnName ( j ) ; if ( map . containsKey ( cName ) ) { rowData [ j ] = map . get ( cName ) . toString ( ) ; } else { rowData [ j ] = "<STR_LIT>" ; } } tableModel . addRow ( rowData ) ; row ++ ; } } catch ( Exception ex ) { new ExceptionDialog ( ex ) . setVisible ( true ) ; } } private javax . swing . JButton btClose ; private javax . swing . JButton btDelete ; private javax . swing . JScrollPane jScrollPane1 ; private javax . swing . JProgressBar pbDelete ; private javax . swing . JTable tableList ; } </s>
<s> package de . hu_berlin . german . korpling . annis . kickstarter ; import annis . administration . CorpusAdministration ; import java . awt . Frame ; import java . io . File ; import java . io . Serializable ; import java . util . LinkedList ; import java . util . List ; import java . util . Map ; import java . util . concurrent . ExecutionException ; import javax . swing . JFileChooser ; import javax . swing . JOptionPane ; import javax . swing . SwingWorker ; import org . slf4j . LoggerFactory ; public class InitDialog extends javax . swing . JDialog { private static final org . slf4j . Logger log = LoggerFactory . getLogger ( InitDialog . class ) ; private CorpusAdministration corpusAdministration ; private SwingWorker < String , Void > initWorker ; private Frame parentFrame ; private class InitDialogWorker extends SwingWorker < String , Void > implements Serializable { private InitDialog parent ; private List < Map < String , Object > > corpora ; public InitDialogWorker ( InitDialog parent , List < Map < String , Object > > corpora ) { this . parent = parent ; this . corpora = corpora ; } @ Override protected String doInBackground ( ) throws Exception { try { corpusAdministration . initializeDatabase ( "<STR_LIT:localhost>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , txtAdminUsername . getText ( ) , new String ( txtAdminPassword . getPassword ( ) ) ) ; return "<STR_LIT>" ; } catch ( Exception ex ) { parent . setVisible ( false ) ; ExceptionDialog dlg = new ExceptionDialog ( parent , ex ) ; dlg . setVisible ( true ) ; } return "<STR_LIT>" ; } @ Override protected void done ( ) { pbInit . setIndeterminate ( false ) ; btOk . setEnabled ( true ) ; btCancel . setEnabled ( true ) ; try { if ( "<STR_LIT>" . equals ( this . get ( ) ) ) { pbInit . setValue ( <NUM_LIT:100> ) ; if ( corpora != null && corpora . size ( ) > <NUM_LIT:0> ) { setVisible ( false ) ; ImportDialog importDlg = new ImportDialog ( parentFrame , true , corpusAdministration , corpora ) ; importDlg . setVisible ( true ) ; } else { JOptionPane . showMessageDialog ( null , "<STR_LIT>" , "<STR_LIT>" , JOptionPane . INFORMATION_MESSAGE ) ; setVisible ( false ) ; } } else { pbInit . setValue ( <NUM_LIT:0> ) ; } } catch ( InterruptedException ex ) { log . error ( null , ex ) ; } catch ( ExecutionException ex ) { log . error ( null , ex ) ; } } } public InitDialog ( java . awt . Frame parent , boolean modal , final CorpusAdministration corpusAdministration ) { super ( parent , modal ) ; this . parentFrame = parent ; initComponents ( ) ; getRootPane ( ) . setDefaultButton ( btOk ) ; this . corpusAdministration = corpusAdministration ; } @ SuppressWarnings ( "<STR_LIT:unchecked>" ) private void initComponents ( ) { fileChooser = new javax . swing . JFileChooser ( ) ; jLabel1 = new javax . swing . JLabel ( ) ; jLabel2 = new javax . swing . JLabel ( ) ; btOk = new javax . swing . JButton ( ) ; btCancel = new javax . swing . JButton ( ) ; txtAdminUsername = new javax . swing . JTextField ( ) ; txtAdminPassword = new javax . swing . JPasswordField ( ) ; pbInit = new javax . swing . JProgressBar ( ) ; cbMigrate = new javax . swing . JCheckBox ( ) ; fileChooser . setFileSelectionMode ( javax . swing . JFileChooser . DIRECTORIES_ONLY ) ; setDefaultCloseOperation ( javax . swing . WindowConstants . DISPOSE_ON_CLOSE ) ; setTitle ( "<STR_LIT>" ) ; setLocationByPlatform ( true ) ; jLabel1 . setText ( "<STR_LIT>" ) ; jLabel2 . setText ( "<STR_LIT>" ) ; btOk . setMnemonic ( '<CHAR_LIT>' ) ; btOk . setText ( "<STR_LIT>" ) ; btOk . addActionListener ( new java . awt . event . ActionListener ( ) { public void actionPerformed ( java . awt . event . ActionEvent evt ) { btOkActionPerformed ( evt ) ; } } ) ; btCancel . setMnemonic ( '<CHAR_LIT:c>' ) ; btCancel . setText ( "<STR_LIT>" ) ; btCancel . addActionListener ( new java . awt . event . ActionListener ( ) { public void actionPerformed ( java . awt . event . ActionEvent evt ) { btCancelActionPerformed ( evt ) ; } } ) ; txtAdminUsername . setText ( "<STR_LIT>" ) ; cbMigrate . setSelected ( true ) ; cbMigrate . setText ( "<STR_LIT>" ) ; cbMigrate . addActionListener ( new java . awt . event . ActionListener ( ) { public void actionPerformed ( java . awt . event . ActionEvent evt ) { cbMigrateActionPerformed ( evt ) ; } } ) ; javax . swing . GroupLayout layout = new javax . swing . GroupLayout ( getContentPane ( ) ) ; getContentPane ( ) . setLayout ( layout ) ; layout . setHorizontalGroup ( layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . LEADING ) . addGroup ( layout . createSequentialGroup ( ) . addContainerGap ( ) . addGroup ( layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . LEADING ) . addComponent ( pbInit , javax . swing . GroupLayout . DEFAULT_SIZE , javax . swing . GroupLayout . DEFAULT_SIZE , Short . MAX_VALUE ) . addGroup ( layout . createSequentialGroup ( ) . addComponent ( jLabel1 ) . addPreferredGap ( javax . swing . LayoutStyle . ComponentPlacement . RELATED ) . addComponent ( txtAdminUsername ) ) . addGroup ( layout . createSequentialGroup ( ) . addComponent ( jLabel2 ) . addGap ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) . addComponent ( txtAdminPassword ) ) . addGroup ( javax . swing . GroupLayout . Alignment . TRAILING , layout . createSequentialGroup ( ) . addComponent ( btCancel , javax . swing . GroupLayout . PREFERRED_SIZE , <NUM_LIT> , javax . swing . GroupLayout . PREFERRED_SIZE ) . addPreferredGap ( javax . swing . LayoutStyle . ComponentPlacement . RELATED , javax . swing . GroupLayout . DEFAULT_SIZE , Short . MAX_VALUE ) . addComponent ( btOk , javax . swing . GroupLayout . PREFERRED_SIZE , <NUM_LIT> , javax . swing . GroupLayout . PREFERRED_SIZE ) ) . addComponent ( cbMigrate , javax . swing . GroupLayout . DEFAULT_SIZE , javax . swing . GroupLayout . DEFAULT_SIZE , Short . MAX_VALUE ) ) . addContainerGap ( ) ) ) ; layout . setVerticalGroup ( layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . LEADING ) . addGroup ( layout . createSequentialGroup ( ) . addContainerGap ( ) . addGroup ( layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . BASELINE ) . addComponent ( jLabel1 ) . addComponent ( txtAdminUsername , javax . swing . GroupLayout . PREFERRED_SIZE , javax . swing . GroupLayout . DEFAULT_SIZE , javax . swing . GroupLayout . PREFERRED_SIZE ) ) . addPreferredGap ( javax . swing . LayoutStyle . ComponentPlacement . RELATED ) . addGroup ( layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . BASELINE ) . addComponent ( jLabel2 ) . addComponent ( txtAdminPassword , javax . swing . GroupLayout . PREFERRED_SIZE , javax . swing . GroupLayout . DEFAULT_SIZE , javax . swing . GroupLayout . PREFERRED_SIZE ) ) . addPreferredGap ( javax . swing . LayoutStyle . ComponentPlacement . UNRELATED ) . addComponent ( cbMigrate ) . addPreferredGap ( javax . swing . LayoutStyle . ComponentPlacement . RELATED , <NUM_LIT:4> , Short . MAX_VALUE ) . addComponent ( pbInit , javax . swing . GroupLayout . PREFERRED_SIZE , javax . swing . GroupLayout . DEFAULT_SIZE , javax . swing . GroupLayout . PREFERRED_SIZE ) . addPreferredGap ( javax . swing . LayoutStyle . ComponentPlacement . UNRELATED ) . addGroup ( layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . BASELINE ) . addComponent ( btOk ) . addComponent ( btCancel ) ) . addContainerGap ( ) ) ) ; pack ( ) ; } private void btCancelActionPerformed ( java . awt . event . ActionEvent evt ) { setVisible ( false ) ; } private void checkCorpusSourcePathExists ( Map < String , Object > corpus ) { if ( ! corpus . containsKey ( "<STR_LIT>" ) ) { int result = JOptionPane . showConfirmDialog ( this , "<STR_LIT>" + "<STR_LIT>" + corpus . get ( "<STR_LIT:name>" ) + "<STR_LIT>" , "<STR_LIT>" + corpus . get ( "<STR_LIT:name>" ) + "<STR_LIT:\">" , JOptionPane . YES_NO_OPTION ) ; if ( result == JOptionPane . YES_OPTION ) { int fileChooseResult = fileChooser . showDialog ( this , "<STR_LIT>" ) ; if ( fileChooseResult == JFileChooser . APPROVE_OPTION ) { corpus . put ( "<STR_LIT>" , fileChooser . getSelectedFile ( ) . getAbsolutePath ( ) ) ; } } } } private void btOkActionPerformed ( java . awt . event . ActionEvent evt ) { pbInit . setIndeterminate ( true ) ; btOk . setEnabled ( false ) ; btCancel . setEnabled ( false ) ; List < Map < String , Object > > existingCorpora = new LinkedList < Map < String , Object > > ( ) ; if ( cbMigrate . isSelected ( ) ) { try { existingCorpora = corpusAdministration . listCorpusStats ( ) ; } catch ( Exception ex ) { log . warn ( "<STR_LIT>" + "<STR_LIT>" , ex ) ; JOptionPane . showMessageDialog ( parentFrame , "<STR_LIT>" + "<STR_LIT>" ) ; } for ( Map < String , Object > corpus : existingCorpora ) { checkCorpusSourcePathExists ( corpus ) ; } } initWorker = new InitDialogWorker ( this , existingCorpora ) ; initWorker . execute ( ) ; } private void cbMigrateActionPerformed ( java . awt . event . ActionEvent evt ) { } private javax . swing . JButton btCancel ; private javax . swing . JButton btOk ; private javax . swing . JCheckBox cbMigrate ; private javax . swing . JFileChooser fileChooser ; private javax . swing . JLabel jLabel1 ; private javax . swing . JLabel jLabel2 ; private javax . swing . JProgressBar pbInit ; private javax . swing . JPasswordField txtAdminPassword ; private javax . swing . JTextField txtAdminUsername ; } </s>
<s> package de . hu_berlin . german . korpling . annis . kickstarter ; import annis . AnnisBaseRunner ; import annis . administration . CorpusAdministration ; import annis . service . internal . AnnisServiceRunner ; import annis . utils . Utils ; import java . awt . Color ; import java . awt . Cursor ; import java . awt . Desktop ; import java . awt . Image ; import java . awt . image . BufferedImage ; import java . beans . PropertyChangeEvent ; import java . beans . PropertyChangeListener ; import java . io . IOException ; import java . io . Serializable ; import java . net . URI ; import java . util . LinkedList ; import java . util . List ; import javax . imageio . ImageIO ; import javax . swing . SwingWorker ; import javax . swing . UIManager ; import org . eclipse . jetty . server . Server ; import org . eclipse . jetty . webapp . WebAppContext ; import org . slf4j . LoggerFactory ; public class MainFrame extends javax . swing . JFrame { private static final org . slf4j . Logger log = LoggerFactory . getLogger ( MainFrame . class ) ; private class MainFrameWorker extends SwingWorker < String , String > implements Serializable { @ Override protected String doInBackground ( ) throws Exception { setProgress ( <NUM_LIT:1> ) ; try { startService ( ) ; setProgress ( <NUM_LIT:2> ) ; startJetty ( ) ; } catch ( Exception ex ) { return ex . getLocalizedMessage ( ) ; } return "<STR_LIT>" ; } @ Override protected void done ( ) { try { wasStarted = true ; pbStart . setIndeterminate ( false ) ; pbStart . setValue ( <NUM_LIT:100> ) ; if ( "<STR_LIT>" . equals ( this . get ( ) ) ) { lblStatusService . setText ( "<STR_LIT>" ) ; lblStatusService . setIcon ( new javax . swing . ImageIcon ( getClass ( ) . getResource ( "<STR_LIT>" ) ) ) ; btLaunch . setEnabled ( true ) ; btLaunch . setForeground ( Color . blue ) ; } else { lblStatusService . setText ( "<STR_LIT>" + this . get ( ) + "<STR_LIT>" ) ; lblStatusService . setIcon ( new javax . swing . ImageIcon ( getClass ( ) . getResource ( "<STR_LIT>" ) ) ) ; } } catch ( Exception ex ) { new ExceptionDialog ( ex ) . setVisible ( true ) ; } } } private CorpusAdministration corpusAdministration ; private SwingWorker < String , String > serviceWorker ; private boolean wasStarted = false ; public MainFrame ( ) { Integer [ ] sizes = new Integer [ ] { <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:32> , <NUM_LIT:16> , <NUM_LIT> } ; List < Image > allImages = new LinkedList < Image > ( ) ; for ( int s : sizes ) { try { BufferedImage imgIcon = ImageIO . read ( MainFrame . class . getResource ( "<STR_LIT>" + s + "<STR_LIT>" ) ) ; allImages . add ( imgIcon ) ; } catch ( IOException ex ) { log . error ( null , ex ) ; } } this . setIconImages ( allImages ) ; System . setProperty ( "<STR_LIT>" , "<STR_LIT:.>" ) ; this . corpusAdministration = ( CorpusAdministration ) AnnisBaseRunner . getBean ( "<STR_LIT>" , true , "<STR_LIT>" + Utils . getAnnisFile ( "<STR_LIT>" ) . getAbsolutePath ( ) ) ; try { UIManager . setLookAndFeel ( UIManager . getSystemLookAndFeelClassName ( ) ) ; } catch ( Exception ex ) { log . error ( null , ex ) ; } initComponents ( ) ; serviceWorker = new MainFrameWorker ( ) ; serviceWorker . addPropertyChangeListener ( new PropertyChangeListener ( ) { public void propertyChange ( PropertyChangeEvent evt ) { if ( serviceWorker . getProgress ( ) == <NUM_LIT:1> ) { pbStart . setIndeterminate ( true ) ; lblStatusService . setText ( "<STR_LIT>" ) ; lblStatusService . setIcon ( new javax . swing . ImageIcon ( getClass ( ) . getResource ( "<STR_LIT>" ) ) ) ; } } } ) ; if ( isInitialized ( ) ) { btImport . setEnabled ( true ) ; btList . setEnabled ( true ) ; serviceWorker . execute ( ) ; } } @ SuppressWarnings ( "<STR_LIT:unchecked>" ) private void initComponents ( ) { btInit = new javax . swing . JButton ( ) ; btImport = new javax . swing . JButton ( ) ; btList = new javax . swing . JButton ( ) ; lblStatusService = new javax . swing . JLabel ( ) ; btLaunch = new javax . swing . JButton ( ) ; pbStart = new javax . swing . JProgressBar ( ) ; btExit = new javax . swing . JButton ( ) ; setDefaultCloseOperation ( javax . swing . WindowConstants . EXIT_ON_CLOSE ) ; setTitle ( "<STR_LIT>" ) ; setLocationByPlatform ( true ) ; btInit . setIcon ( new javax . swing . ImageIcon ( getClass ( ) . getResource ( "<STR_LIT>" ) ) ) ; btInit . setMnemonic ( '<CHAR_LIT>' ) ; btInit . setText ( "<STR_LIT>" ) ; btInit . setToolTipText ( "<STR_LIT>" ) ; btInit . setName ( "<STR_LIT>" ) ; btInit . addActionListener ( new java . awt . event . ActionListener ( ) { public void actionPerformed ( java . awt . event . ActionEvent evt ) { btInitActionPerformed ( evt ) ; } } ) ; btImport . setIcon ( new javax . swing . ImageIcon ( getClass ( ) . getResource ( "<STR_LIT>" ) ) ) ; btImport . setMnemonic ( '<CHAR_LIT>' ) ; btImport . setText ( "<STR_LIT>" ) ; btImport . setToolTipText ( "<STR_LIT>" ) ; btImport . setEnabled ( false ) ; btImport . setName ( "<STR_LIT>" ) ; btImport . addActionListener ( new java . awt . event . ActionListener ( ) { public void actionPerformed ( java . awt . event . ActionEvent evt ) { btImportActionPerformed ( evt ) ; } } ) ; btList . setIcon ( new javax . swing . ImageIcon ( getClass ( ) . getResource ( "<STR_LIT>" ) ) ) ; btList . setMnemonic ( '<CHAR_LIT>' ) ; btList . setText ( "<STR_LIT>" ) ; btList . setToolTipText ( "<STR_LIT>" ) ; btList . setEnabled ( false ) ; btList . setName ( "<STR_LIT>" ) ; btList . addActionListener ( new java . awt . event . ActionListener ( ) { public void actionPerformed ( java . awt . event . ActionEvent evt ) { btListActionPerformed ( evt ) ; } } ) ; lblStatusService . setFont ( new java . awt . Font ( "<STR_LIT>" , <NUM_LIT:0> , <NUM_LIT> ) ) ; lblStatusService . setHorizontalAlignment ( javax . swing . SwingConstants . CENTER ) ; lblStatusService . setIcon ( new javax . swing . ImageIcon ( getClass ( ) . getResource ( "<STR_LIT>" ) ) ) ; lblStatusService . setText ( "<STR_LIT>" ) ; lblStatusService . setName ( "<STR_LIT>" ) ; btLaunch . setForeground ( java . awt . Color . lightGray ) ; btLaunch . setMnemonic ( '<CHAR_LIT>' ) ; btLaunch . setText ( "<STR_LIT>" ) ; btLaunch . setActionCommand ( "<STR_LIT>" ) ; btLaunch . setEnabled ( false ) ; btLaunch . setName ( "<STR_LIT>" ) ; btLaunch . addMouseListener ( new java . awt . event . MouseAdapter ( ) { public void mouseEntered ( java . awt . event . MouseEvent evt ) { btLaunchMouseEntered ( evt ) ; } public void mouseExited ( java . awt . event . MouseEvent evt ) { btLaunchMouseExited ( evt ) ; } } ) ; btLaunch . addActionListener ( new java . awt . event . ActionListener ( ) { public void actionPerformed ( java . awt . event . ActionEvent evt ) { btLaunchActionPerformed ( evt ) ; } } ) ; pbStart . setName ( "<STR_LIT>" ) ; btExit . setIcon ( new javax . swing . ImageIcon ( getClass ( ) . getResource ( "<STR_LIT>" ) ) ) ; btExit . setMnemonic ( '<CHAR_LIT:e>' ) ; btExit . setText ( "<STR_LIT>" ) ; btExit . setToolTipText ( "<STR_LIT>" ) ; btExit . setName ( "<STR_LIT>" ) ; btExit . addActionListener ( new java . awt . event . ActionListener ( ) { public void actionPerformed ( java . awt . event . ActionEvent evt ) { btExitActionPerformed ( evt ) ; } } ) ; javax . swing . GroupLayout layout = new javax . swing . GroupLayout ( getContentPane ( ) ) ; getContentPane ( ) . setLayout ( layout ) ; layout . setHorizontalGroup ( layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . LEADING ) . addGroup ( layout . createSequentialGroup ( ) . addContainerGap ( ) . addGroup ( layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . LEADING ) . addComponent ( btInit , javax . swing . GroupLayout . Alignment . TRAILING , javax . swing . GroupLayout . DEFAULT_SIZE , <NUM_LIT> , Short . MAX_VALUE ) . addComponent ( btImport , javax . swing . GroupLayout . Alignment . TRAILING , javax . swing . GroupLayout . DEFAULT_SIZE , <NUM_LIT> , Short . MAX_VALUE ) . addComponent ( btList , javax . swing . GroupLayout . DEFAULT_SIZE , <NUM_LIT> , Short . MAX_VALUE ) . addComponent ( lblStatusService , javax . swing . GroupLayout . Alignment . TRAILING , javax . swing . GroupLayout . DEFAULT_SIZE , <NUM_LIT> , Short . MAX_VALUE ) . addComponent ( pbStart , javax . swing . GroupLayout . DEFAULT_SIZE , <NUM_LIT> , Short . MAX_VALUE ) . addComponent ( btLaunch , javax . swing . GroupLayout . DEFAULT_SIZE , <NUM_LIT> , Short . MAX_VALUE ) . addComponent ( btExit , javax . swing . GroupLayout . Alignment . TRAILING ) ) . addContainerGap ( ) ) ) ; layout . setVerticalGroup ( layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . LEADING ) . addGroup ( layout . createSequentialGroup ( ) . addContainerGap ( ) . addComponent ( btInit ) . addPreferredGap ( javax . swing . LayoutStyle . ComponentPlacement . RELATED ) . addComponent ( btImport ) . addPreferredGap ( javax . swing . LayoutStyle . ComponentPlacement . RELATED ) . addComponent ( btList ) . addGap ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) . addComponent ( lblStatusService , javax . swing . GroupLayout . PREFERRED_SIZE , javax . swing . GroupLayout . DEFAULT_SIZE , javax . swing . GroupLayout . PREFERRED_SIZE ) . addPreferredGap ( javax . swing . LayoutStyle . ComponentPlacement . RELATED ) . addComponent ( pbStart , javax . swing . GroupLayout . PREFERRED_SIZE , javax . swing . GroupLayout . DEFAULT_SIZE , javax . swing . GroupLayout . PREFERRED_SIZE ) . addPreferredGap ( javax . swing . LayoutStyle . ComponentPlacement . RELATED ) . addComponent ( btLaunch , javax . swing . GroupLayout . PREFERRED_SIZE , javax . swing . GroupLayout . DEFAULT_SIZE , javax . swing . GroupLayout . PREFERRED_SIZE ) . addPreferredGap ( javax . swing . LayoutStyle . ComponentPlacement . RELATED , <NUM_LIT> , Short . MAX_VALUE ) . addComponent ( btExit ) . addContainerGap ( ) ) ) ; pack ( ) ; } private void btInitActionPerformed ( java . awt . event . ActionEvent evt ) { InitDialog dlg = new InitDialog ( this , true , corpusAdministration ) ; dlg . setVisible ( true ) ; if ( ! wasStarted && isInitialized ( ) ) { btImport . setEnabled ( true ) ; btList . setEnabled ( true ) ; serviceWorker . execute ( ) ; } } private void btImportActionPerformed ( java . awt . event . ActionEvent evt ) { ImportDialog dlg = new ImportDialog ( this , true , corpusAdministration ) ; dlg . setVisible ( true ) ; } private void btListActionPerformed ( java . awt . event . ActionEvent evt ) { ListDialog dlg = new ListDialog ( this , true , corpusAdministration ) ; dlg . setVisible ( true ) ; } private void btLaunchActionPerformed ( java . awt . event . ActionEvent evt ) { try { Desktop . getDesktop ( ) . browse ( new URI ( "<STR_LIT>" ) ) ; } catch ( Exception ex ) { new ExceptionDialog ( this , ex ) . setVisible ( true ) ; } } private void btExitActionPerformed ( java . awt . event . ActionEvent evt ) { System . exit ( <NUM_LIT:0> ) ; } private void btLaunchMouseEntered ( java . awt . event . MouseEvent evt ) { this . setCursor ( new Cursor ( Cursor . HAND_CURSOR ) ) ; } private void btLaunchMouseExited ( java . awt . event . MouseEvent evt ) { this . setCursor ( new Cursor ( Cursor . DEFAULT_CURSOR ) ) ; } private void startService ( ) throws Exception { AnnisServiceRunner runner = new AnnisServiceRunner ( ) ; runner . createWebServer ( ) ; } private void startJetty ( ) throws Exception { Server jetty = new Server ( <NUM_LIT> ) ; WebAppContext context = new WebAppContext ( "<STR_LIT>" , "<STR_LIT>" ) ; context . setInitParameter ( "<STR_LIT>" , "<STR_LIT>" ) ; String webxmlOverrride = System . getProperty ( "<STR_LIT>" ) + "<STR_LIT>" ; context . setOverrideDescriptor ( webxmlOverrride ) ; jetty . setHandler ( context ) ; jetty . start ( ) ; } private boolean isInitialized ( ) { if ( corpusAdministration . checkDatabaseSchemaVersion ( ) == false ) { btInit . setText ( "<STR_LIT>" ) ; return false ; } try { corpusAdministration . listCorpusStats ( ) ; } catch ( Exception ex ) { return false ; } return true ; } public static void main ( String args [ ] ) { java . awt . EventQueue . invokeLater ( new Runnable ( ) { public void run ( ) { MainFrame frame = new MainFrame ( ) ; frame . setVisible ( true ) ; } } ) ; } private javax . swing . JButton btExit ; private javax . swing . JButton btImport ; private javax . swing . JButton btInit ; private javax . swing . JButton btLaunch ; private javax . swing . JButton btList ; private javax . swing . JLabel lblStatusService ; private javax . swing . JProgressBar pbStart ; } </s>
<s> package de . hu_berlin . german . korpling . annis . kickstarter ; import annis . administration . CorpusAdministration ; import ch . qos . logback . classic . Level ; import ch . qos . logback . classic . LoggerContext ; import ch . qos . logback . classic . joran . JoranConfigurator ; import ch . qos . logback . classic . spi . ILoggingEvent ; import ch . qos . logback . core . Appender ; import ch . qos . logback . core . AppenderBase ; import java . io . * ; import java . util . List ; import java . util . Map ; import java . util . Properties ; import javax . swing . JFileChooser ; import javax . swing . JOptionPane ; import javax . swing . SwingUtilities ; import javax . swing . SwingWorker ; import org . apache . commons . lang3 . StringUtils ; import org . slf4j . Logger ; import org . slf4j . LoggerFactory ; public class ImportDialog extends javax . swing . JDialog { private static final org . slf4j . Logger log = LoggerFactory . getLogger ( ImportDialog . class ) ; private File confFile ; private Properties confProps ; private static class Status { public boolean ok = true ; public Exception ex = new Exception ( ) ; } private class ImportDialogWorker extends SwingWorker < Status , Void > implements Serializable { @ Override protected Status doInBackground ( ) throws Exception { Status status = new Status ( ) ; StringBuilder errorMessages = new StringBuilder ( ) ; if ( corpora == null ) { try { SwingUtilities . invokeLater ( new Runnable ( ) { @ Override public void run ( ) { lblCurrentCorpus . setText ( "<STR_LIT>" + StringUtils . abbreviateMiddle ( txtInputDir . getText ( ) , "<STR_LIT:...>" , <NUM_LIT> ) ) ; pbCorpus . setMaximum ( <NUM_LIT:1> ) ; pbCorpus . setMinimum ( <NUM_LIT:0> ) ; pbCorpus . setValue ( <NUM_LIT:0> ) ; } } ) ; corpusAdministration . importCorpora ( txtInputDir . getText ( ) ) ; } catch ( Exception ex ) { status . ok = false ; status . ex = ex ; return status ; } } else { SwingUtilities . invokeLater ( new Runnable ( ) { @ Override public void run ( ) { pbCorpus . setMaximum ( corpora . size ( ) ) ; pbCorpus . setMinimum ( <NUM_LIT:0> ) ; pbCorpus . setValue ( <NUM_LIT:0> ) ; } } ) ; int i = <NUM_LIT:0> ; for ( Map < String , Object > corpus : corpora ) { if ( isCancelled ( ) ) { status . ok = true ; return status ; } if ( corpus . containsKey ( "<STR_LIT>" ) ) { final String path = ( String ) corpus . get ( "<STR_LIT>" ) ; final int finalI = i ; SwingUtilities . invokeLater ( new Runnable ( ) { @ Override public void run ( ) { lblCurrentCorpus . setText ( "<STR_LIT>" + StringUtils . abbreviateMiddle ( path , "<STR_LIT:...>" , <NUM_LIT> ) + "<STR_LIT>" + ( finalI + <NUM_LIT:1> ) + "<STR_LIT:/>" + corpora . size ( ) + "<STR_LIT:]>" ) ; pbCorpus . setValue ( finalI ) ; } } ) ; try { corpusAdministration . importCorpora ( path ) ; } catch ( Exception ex ) { log . error ( "<STR_LIT>" , ex ) ; errorMessages . append ( "<STR_LIT:[>" ) . append ( path ) . append ( "<STR_LIT>" ) ; errorMessages . append ( ex . getMessage ( ) ) . append ( path ) . append ( "<STR_LIT>" ) ; } } i ++ ; } } if ( errorMessages . length ( ) > <NUM_LIT:0> ) { status . ok = false ; return status ; } return status ; } @ Override protected void done ( ) { isImporting = false ; btOk . setEnabled ( true ) ; btSearchInputDir . setEnabled ( true ) ; txtInputDir . setEnabled ( true ) ; lblCurrentCorpus . setText ( "<STR_LIT>" ) ; pbCorpus . setValue ( pbCorpus . getMaximum ( ) ) ; pbImport . setIndeterminate ( false ) ; try { if ( ! isCancelled ( ) ) { Status status = this . get ( ) ; if ( status . ok ) { JOptionPane . showMessageDialog ( null , "<STR_LIT>" , "<STR_LIT>" , JOptionPane . INFORMATION_MESSAGE ) ; setVisible ( false ) ; } else { new ExceptionDialog ( status . ex , "<STR_LIT>" ) . setVisible ( true ) ; setVisible ( false ) ; } } } catch ( Exception ex ) { log . error ( null , ex ) ; } } } private CorpusAdministration corpusAdministration ; private SwingWorker < Status , Void > worker ; private boolean isImporting ; private List < Map < String , Object > > corpora ; public ImportDialog ( java . awt . Frame parent , boolean modal , CorpusAdministration corpusAdmin ) { this ( parent , modal , corpusAdmin , null ) ; } public ImportDialog ( java . awt . Frame parent , boolean modal , CorpusAdministration corpusAdmin , List < Map < String , Object > > corpora ) { super ( parent , modal ) ; this . corpusAdministration = corpusAdmin ; this . corpora = corpora ; confProps = new Properties ( ) ; confFile = new File ( System . getProperty ( "<STR_LIT>" ) + "<STR_LIT>" ) ; try { if ( ! confFile . exists ( ) ) { if ( ! confFile . getParentFile ( ) . mkdirs ( ) ) { log . warn ( "<STR_LIT>" + confFile . getAbsolutePath ( ) ) ; } if ( ! confFile . createNewFile ( ) ) { log . warn ( "<STR_LIT>" + confFile . getAbsolutePath ( ) ) ; } } } catch ( IOException ex ) { log . error ( null , ex ) ; } initComponents ( ) ; loadProperties ( ) ; getRootPane ( ) . setDefaultButton ( btOk ) ; isImporting = false ; worker = new ImportDialogWorker ( ) ; addAppender ( ) ; if ( this . corpora != null ) { startImport ( ) ; } } private void storeProperties ( ) { confProps . put ( "<STR_LIT>" , txtInputDir . getText ( ) ) ; FileOutputStream oStream = null ; try { oStream = new FileOutputStream ( confFile ) ; confProps . store ( oStream , "<STR_LIT>" ) ; } catch ( IOException ex ) { log . error ( null , ex ) ; } finally { if ( oStream != null ) { try { oStream . close ( ) ; } catch ( IOException ex ) { log . error ( null , ex ) ; } } } } private void loadProperties ( ) { FileInputStream iStream = null ; try { iStream = new FileInputStream ( confFile ) ; confProps . load ( iStream ) ; String lastDirectory = confProps . getProperty ( "<STR_LIT>" ) ; if ( lastDirectory != null ) { txtInputDir . setText ( lastDirectory ) ; } } catch ( IOException ex ) { log . error ( null , ex ) ; } finally { if ( iStream != null ) { try { iStream . close ( ) ; } catch ( IOException ex ) { log . error ( null , ex ) ; } } } } private void addAppender ( ) { LoggerContext lc = ( LoggerContext ) LoggerFactory . getILoggerFactory ( ) ; JoranConfigurator jc = new JoranConfigurator ( ) ; jc . setContext ( lc ) ; Appender appender = new AppenderBase < ILoggingEvent > ( ) { @ Override protected void append ( ILoggingEvent event ) { if ( event . getLevel ( ) . isGreaterOrEqual ( Level . INFO ) ) { lblStatus . setText ( event . getMessage ( ) . toString ( ) ) ; } } } ; ch . qos . logback . classic . Logger rootLogger = lc . getLogger ( Logger . ROOT_LOGGER_NAME ) ; rootLogger . addAppender ( appender ) ; appender . start ( ) ; } private void startImport ( ) { btOk . setEnabled ( false ) ; btSearchInputDir . setEnabled ( false ) ; txtInputDir . setEnabled ( false ) ; pbImport . setIndeterminate ( true ) ; isImporting = true ; worker . execute ( ) ; } @ SuppressWarnings ( "<STR_LIT:unchecked>" ) private void initComponents ( ) { fileChooser = new javax . swing . JFileChooser ( ) ; jLabel1 = new javax . swing . JLabel ( ) ; txtInputDir = new javax . swing . JTextField ( ) ; btCancel = new javax . swing . JButton ( ) ; btOk = new javax . swing . JButton ( ) ; btSearchInputDir = new javax . swing . JButton ( ) ; pbImport = new javax . swing . JProgressBar ( ) ; jLabel2 = new javax . swing . JLabel ( ) ; lblStatus = new javax . swing . JLabel ( ) ; pbCorpus = new javax . swing . JProgressBar ( ) ; lblCurrentCorpus = new javax . swing . JLabel ( ) ; fileChooser . setFileSelectionMode ( javax . swing . JFileChooser . DIRECTORIES_ONLY ) ; setDefaultCloseOperation ( javax . swing . WindowConstants . DISPOSE_ON_CLOSE ) ; setTitle ( "<STR_LIT>" ) ; setLocationByPlatform ( true ) ; jLabel1 . setText ( "<STR_LIT>" ) ; btCancel . setMnemonic ( '<CHAR_LIT:c>' ) ; btCancel . setText ( "<STR_LIT>" ) ; btCancel . addActionListener ( new java . awt . event . ActionListener ( ) { public void actionPerformed ( java . awt . event . ActionEvent evt ) { btCancelActionPerformed ( evt ) ; } } ) ; btOk . setMnemonic ( '<CHAR_LIT>' ) ; btOk . setText ( "<STR_LIT>" ) ; btOk . addActionListener ( new java . awt . event . ActionListener ( ) { public void actionPerformed ( java . awt . event . ActionEvent evt ) { btOkActionPerformed ( evt ) ; } } ) ; btSearchInputDir . setText ( "<STR_LIT:...>" ) ; btSearchInputDir . addActionListener ( new java . awt . event . ActionListener ( ) { public void actionPerformed ( java . awt . event . ActionEvent evt ) { btSearchInputDirActionPerformed ( evt ) ; } } ) ; jLabel2 . setText ( "<STR_LIT>" ) ; lblStatus . setText ( "<STR_LIT:...>" ) ; lblCurrentCorpus . setHorizontalAlignment ( javax . swing . SwingConstants . RIGHT ) ; lblCurrentCorpus . setText ( "<STR_LIT>" ) ; javax . swing . GroupLayout layout = new javax . swing . GroupLayout ( getContentPane ( ) ) ; getContentPane ( ) . setLayout ( layout ) ; layout . setHorizontalGroup ( layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . LEADING ) . addGroup ( layout . createSequentialGroup ( ) . addContainerGap ( ) . addGroup ( layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . LEADING ) . addComponent ( pbImport , javax . swing . GroupLayout . DEFAULT_SIZE , javax . swing . GroupLayout . DEFAULT_SIZE , Short . MAX_VALUE ) . addGroup ( layout . createSequentialGroup ( ) . addComponent ( jLabel1 ) . addPreferredGap ( javax . swing . LayoutStyle . ComponentPlacement . RELATED ) . addComponent ( txtInputDir , javax . swing . GroupLayout . DEFAULT_SIZE , <NUM_LIT> , Short . MAX_VALUE ) . addPreferredGap ( javax . swing . LayoutStyle . ComponentPlacement . RELATED ) . addComponent ( btSearchInputDir , javax . swing . GroupLayout . PREFERRED_SIZE , <NUM_LIT> , javax . swing . GroupLayout . PREFERRED_SIZE ) ) . addGroup ( layout . createSequentialGroup ( ) . addComponent ( jLabel2 ) . addPreferredGap ( javax . swing . LayoutStyle . ComponentPlacement . RELATED ) . addComponent ( lblStatus , javax . swing . GroupLayout . DEFAULT_SIZE , javax . swing . GroupLayout . DEFAULT_SIZE , Short . MAX_VALUE ) ) . addGroup ( javax . swing . GroupLayout . Alignment . TRAILING , layout . createSequentialGroup ( ) . addComponent ( lblCurrentCorpus , javax . swing . GroupLayout . DEFAULT_SIZE , javax . swing . GroupLayout . DEFAULT_SIZE , Short . MAX_VALUE ) . addPreferredGap ( javax . swing . LayoutStyle . ComponentPlacement . RELATED ) . addComponent ( pbCorpus , javax . swing . GroupLayout . PREFERRED_SIZE , javax . swing . GroupLayout . DEFAULT_SIZE , javax . swing . GroupLayout . PREFERRED_SIZE ) ) . addGroup ( layout . createSequentialGroup ( ) . addComponent ( btCancel , javax . swing . GroupLayout . PREFERRED_SIZE , <NUM_LIT> , javax . swing . GroupLayout . PREFERRED_SIZE ) . addPreferredGap ( javax . swing . LayoutStyle . ComponentPlacement . RELATED , javax . swing . GroupLayout . DEFAULT_SIZE , Short . MAX_VALUE ) . addComponent ( btOk , javax . swing . GroupLayout . PREFERRED_SIZE , <NUM_LIT> , javax . swing . GroupLayout . PREFERRED_SIZE ) ) ) . addContainerGap ( ) ) ) ; layout . setVerticalGroup ( layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . LEADING ) . addGroup ( layout . createSequentialGroup ( ) . addContainerGap ( ) . addGroup ( layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . BASELINE ) . addComponent ( jLabel1 ) . addComponent ( txtInputDir , javax . swing . GroupLayout . PREFERRED_SIZE , javax . swing . GroupLayout . DEFAULT_SIZE , javax . swing . GroupLayout . PREFERRED_SIZE ) . addComponent ( btSearchInputDir ) ) . addPreferredGap ( javax . swing . LayoutStyle . ComponentPlacement . RELATED ) . addGroup ( layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . LEADING , false ) . addComponent ( pbCorpus , javax . swing . GroupLayout . DEFAULT_SIZE , javax . swing . GroupLayout . DEFAULT_SIZE , Short . MAX_VALUE ) . addComponent ( lblCurrentCorpus , javax . swing . GroupLayout . DEFAULT_SIZE , javax . swing . GroupLayout . DEFAULT_SIZE , Short . MAX_VALUE ) ) . addGap ( <NUM_LIT:7> , <NUM_LIT:7> , <NUM_LIT:7> ) . addComponent ( pbImport , javax . swing . GroupLayout . PREFERRED_SIZE , javax . swing . GroupLayout . DEFAULT_SIZE , javax . swing . GroupLayout . PREFERRED_SIZE ) . addPreferredGap ( javax . swing . LayoutStyle . ComponentPlacement . UNRELATED ) . addGroup ( layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . BASELINE ) . addComponent ( jLabel2 ) . addComponent ( lblStatus , javax . swing . GroupLayout . PREFERRED_SIZE , <NUM_LIT:15> , javax . swing . GroupLayout . PREFERRED_SIZE ) ) . addPreferredGap ( javax . swing . LayoutStyle . ComponentPlacement . RELATED , javax . swing . GroupLayout . DEFAULT_SIZE , Short . MAX_VALUE ) . addGroup ( layout . createParallelGroup ( javax . swing . GroupLayout . Alignment . BASELINE ) . addComponent ( btCancel ) . addComponent ( btOk ) ) . addContainerGap ( ) ) ) ; pack ( ) ; } private void btCancelActionPerformed ( java . awt . event . ActionEvent evt ) { if ( isImporting ) { worker . cancel ( true ) ; } setVisible ( false ) ; } private void btOkActionPerformed ( java . awt . event . ActionEvent evt ) { startImport ( ) ; } private void btSearchInputDirActionPerformed ( java . awt . event . ActionEvent evt ) { if ( ! "<STR_LIT>" . equals ( txtInputDir . getText ( ) ) ) { File dir = new File ( txtInputDir . getText ( ) ) ; if ( dir . exists ( ) && dir . isDirectory ( ) ) { fileChooser . setSelectedFile ( dir ) ; } } if ( fileChooser . showDialog ( this , "<STR_LIT>" ) == JFileChooser . APPROVE_OPTION ) { File f = fileChooser . getSelectedFile ( ) ; txtInputDir . setText ( f . getAbsolutePath ( ) ) ; storeProperties ( ) ; } } private javax . swing . JButton btCancel ; private javax . swing . JButton btOk ; private javax . swing . JButton btSearchInputDir ; private javax . swing . JFileChooser fileChooser ; private javax . swing . JLabel jLabel1 ; private javax . swing . JLabel jLabel2 ; private javax . swing . JLabel lblCurrentCorpus ; private javax . swing . JLabel lblStatus ; private javax . swing . JProgressBar pbCorpus ; private javax . swing . JProgressBar pbImport ; private javax . swing . JTextField txtInputDir ; } </s>
<s> package annis . model ; import java . io . Serializable ; import java . lang . annotation . ElementType ; import java . lang . annotation . Retention ; import java . lang . annotation . RetentionPolicy ; import java . lang . annotation . Target ; import java . lang . reflect . Field ; import java . util . SortedMap ; import java . util . TreeMap ; import org . apache . commons . lang3 . builder . EqualsBuilder ; import org . apache . commons . lang3 . builder . HashCodeBuilder ; import org . slf4j . Logger ; import org . slf4j . LoggerFactory ; public class DataObject implements Serializable { @ Retention ( RetentionPolicy . RUNTIME ) @ Target ( value = ElementType . FIELD ) public static @ interface Transient { } private static final Logger log = LoggerFactory . getLogger ( DataObject . class ) ; private interface FieldCallBack { void doForField ( Field field ) throws IllegalAccessException ; } private void forEachFieldDo ( FieldCallBack fieldCallBack ) { Class < ? > clazz = this . getClass ( ) ; while ( true ) { Field [ ] fields = clazz . getDeclaredFields ( ) ; try { for ( Field field : fields ) { if ( field . getType ( ) == Logger . class ) continue ; if ( field . getAnnotation ( Transient . class ) != null ) continue ; if ( "<STR_LIT>" . equals ( field . getName ( ) ) ) continue ; field . setAccessible ( true ) ; fieldCallBack . doForField ( field ) ; } } catch ( IllegalArgumentException e ) { throw new RuntimeException ( e ) ; } catch ( IllegalAccessException e ) { throw new RuntimeException ( e ) ; } if ( clazz . getName ( ) . equals ( DataObject . class . getName ( ) ) ) break ; clazz = clazz . getSuperclass ( ) ; } } @ Override public boolean equals ( final Object obj ) { if ( obj == null ) return false ; if ( this . getClass ( ) != obj . getClass ( ) ) return false ; final EqualsBuilder equalsBuilder = new EqualsBuilder ( ) ; final Object _this = this ; forEachFieldDo ( new FieldCallBack ( ) { public void doForField ( Field field ) throws IllegalAccessException { Object thisValue = field . get ( _this ) ; Object otherValue = field . get ( obj ) ; if ( log . isDebugEnabled ( ) ) { String fieldName = field . getDeclaringClass ( ) . getSimpleName ( ) + "<STR_LIT:.>" + field . getName ( ) ; try { boolean equal = thisValue != null && thisValue . equals ( otherValue ) || thisValue == null && otherValue == null ; log . debug ( fieldName + "<STR_LIT::U+0020>" + thisValue + "<STR_LIT:U+0020>" + ( equal ? "<STR_LIT:=>" : "<STR_LIT>" ) + "<STR_LIT:U+0020>" + otherValue ) ; } catch ( RuntimeException e ) { log . error ( "<STR_LIT>" + fieldName + "<STR_LIT:(>" + thisValue + "<STR_LIT:U+002CU+0020>" + otherValue + "<STR_LIT:)>" ) ; throw e ; } } equalsBuilder . append ( thisValue , otherValue ) ; } } ) ; return equalsBuilder . isEquals ( ) ; } @ Override public int hashCode ( ) { final SortedMap < String , Object > fieldValues = new TreeMap < String , Object > ( ) ; final Object _this = this ; forEachFieldDo ( new FieldCallBack ( ) { public void doForField ( Field field ) throws IllegalAccessException { fieldValues . put ( field . getName ( ) , field . get ( _this ) ) ; } } ) ; HashCodeBuilder hashCodeBuilder = new HashCodeBuilder ( ) ; for ( Object fieldValue : fieldValues . values ( ) ) hashCodeBuilder . append ( fieldValue ) ; return hashCodeBuilder . toHashCode ( ) ; } } </s>
<s> package annis . model ; import java . io . Serializable ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . Collections ; import java . util . Comparator ; import java . util . HashMap ; import java . util . HashSet ; import java . util . List ; import java . util . Map ; import java . util . Set ; import org . apache . commons . lang3 . StringUtils ; import org . apache . commons . lang3 . builder . EqualsBuilder ; import org . apache . commons . lang3 . builder . HashCodeBuilder ; public class AnnotationGraph implements Serializable { private String documentName ; private String [ ] path ; private List < AnnisNode > nodes ; private List < Edge > edges ; private Set < Long > matchedNodeIds ; private Map < Long , AnnisNode > tokenByIndex ; public AnnotationGraph ( ) { this ( new ArrayList < AnnisNode > ( ) , new ArrayList < Edge > ( ) ) ; } public AnnotationGraph ( List < AnnisNode > nodes , List < Edge > edges ) { this . nodes = nodes ; this . edges = edges ; this . matchedNodeIds = new HashSet < Long > ( ) ; this . tokenByIndex = new HashMap < Long , AnnisNode > ( ) ; } @ Override public String toString ( ) { List < Long > ids = new ArrayList < Long > ( ) ; for ( AnnisNode node : nodes ) ids . add ( node . getId ( ) ) ; List < String > _edges = new ArrayList < String > ( ) ; for ( Edge edge : edges ) { Long src = edge . getSource ( ) != null ? edge . getSource ( ) . getId ( ) : null ; long dst = edge . getDestination ( ) . getId ( ) ; String edgeType = edge . getEdgeType ( ) != null ? edge . getEdgeType ( ) . toString ( ) : null ; String name = edge . getQualifiedName ( ) ; _edges . add ( src + "<STR_LIT>" + dst + "<STR_LIT:U+0020>" + name + "<STR_LIT:U+0020>" + edgeType ) ; } return "<STR_LIT>" + StringUtils . join ( matchedNodeIds , "<STR_LIT:->" ) + "<STR_LIT>" + ids + "<STR_LIT>" + _edges ; } public void addMatchedNodeId ( Long id ) { matchedNodeIds . add ( id ) ; } public boolean addNode ( AnnisNode node ) { node . setGraph ( this ) ; if ( node . isToken ( ) ) tokenByIndex . put ( node . getTokenIndex ( ) , node ) ; return nodes . add ( node ) ; } public boolean addEdge ( Edge edge ) { return edges . add ( edge ) ; } public AnnisNode getToken ( long tokenIndex ) { return tokenByIndex . get ( tokenIndex ) ; } public List < AnnisNode > getTokens ( ) { List < AnnisNode > tokens = new ArrayList < AnnisNode > ( ) ; for ( AnnisNode node : nodes ) { if ( node . isToken ( ) ) tokens . add ( node ) ; } Collections . sort ( tokens , new Comparator < AnnisNode > ( ) { public int compare ( AnnisNode o1 , AnnisNode o2 ) { return o1 . getTokenIndex ( ) . compareTo ( o2 . getTokenIndex ( ) ) ; } } ) ; return tokens ; } @ Override public boolean equals ( Object obj ) { if ( obj == null || ! ( obj instanceof AnnotationGraph ) ) return false ; AnnotationGraph other = ( AnnotationGraph ) obj ; return new EqualsBuilder ( ) . append ( this . nodes , other . nodes ) . append ( this . edges , other . edges ) . append ( this . matchedNodeIds , other . matchedNodeIds ) . isEquals ( ) ; } @ Override public int hashCode ( ) { return new HashCodeBuilder ( ) . append ( nodes ) . append ( edges ) . append ( matchedNodeIds ) . toHashCode ( ) ; } public List < AnnisNode > getNodes ( ) { return nodes ; } public List < Edge > getEdges ( ) { return edges ; } public Set < Long > getMatchedNodeIds ( ) { return matchedNodeIds ; } public String getDocumentName ( ) { return documentName ; } public void setDocumentName ( String documentName ) { this . documentName = documentName ; } public String [ ] getPath ( ) { return Arrays . copyOf ( path , path . length ) ; } public void setPath ( String [ ] path ) { this . path = Arrays . copyOf ( path , path . length ) ; } } </s>
<s> package annis . model ; import java . io . Serializable ; import java . util . ArrayList ; import java . util . HashSet ; import java . util . List ; import java . util . Set ; import java . util . TreeSet ; import org . apache . commons . lang3 . Validate ; import org . apache . commons . lang3 . builder . EqualsBuilder ; import org . apache . commons . lang3 . builder . HashCodeBuilder ; import annis . sqlgen . model . Join ; import annis . sqlgen . model . RankTableJoin ; @ SuppressWarnings ( "<STR_LIT:serial>" ) public class QueryNode implements Serializable { private long id ; private long corpus ; private long textId ; private long left ; private long right ; private String spannedText ; private Long tokenIndex ; private long leftToken ; private long rightToken ; private Set < QueryAnnotation > nodeAnnotations ; private String name ; private String namespace ; private boolean partOfEdge ; private boolean root ; private boolean token ; private TextMatching spanTextMatching ; private List < Join > joins ; private String variable ; private Set < QueryAnnotation > edgeAnnotations ; private Range arity ; private Range tokenArity ; private String marker ; private Long matchedNodeInQuery ; public enum TextMatching { EXACT_EQUAL ( "<STR_LIT:=>" , "<STR_LIT:\">" ) , REGEXP_EQUAL ( "<STR_LIT>" , "<STR_LIT:/>" ) , EXACT_NOT_EQUAL ( "<STR_LIT>" , "<STR_LIT:\">" ) , REGEXP_NOT_EQUAL ( "<STR_LIT>" , "<STR_LIT:/>" ) ; private String sqlOperator ; private String annisQuote ; private TextMatching ( String sqlOperator , String annisQuote ) { this . sqlOperator = sqlOperator ; this . annisQuote = annisQuote ; } public String toString ( ) { return sqlOperator ; } public String sqlOperator ( ) { return sqlOperator ; } public String quote ( ) { return annisQuote ; } } ; public static class Range implements Serializable { private int min ; private int max ; public Range ( int _min , int _max ) { min = _min ; max = _max ; } public int getMin ( ) { return min ; } public int getMax ( ) { return max ; } @ Override public int hashCode ( ) { return new HashCodeBuilder ( ) . append ( min ) . append ( max ) . toHashCode ( ) ; } @ Override public boolean equals ( Object obj ) { if ( obj instanceof Range ) { Range other = ( Range ) obj ; return new EqualsBuilder ( ) . append ( min , other . min ) . append ( max , other . max ) . isEquals ( ) ; } return false ; } } ; public QueryNode ( ) { nodeAnnotations = new TreeSet < QueryAnnotation > ( ) ; edgeAnnotations = new TreeSet < QueryAnnotation > ( ) ; joins = new ArrayList < Join > ( ) ; } public QueryNode ( long id ) { this ( ) ; this . id = id ; } public QueryNode ( long id , long corpusRef , long textRef , long left , long right , String namespace , String name , long tokenIndex , String span , long leftToken , long rightToken ) { this ( id ) ; this . corpus = corpusRef ; this . textId = textRef ; this . left = left ; this . right = right ; this . leftToken = leftToken ; this . rightToken = rightToken ; setNamespace ( namespace ) ; setName ( name ) ; setTokenIndex ( tokenIndex ) ; setSpannedText ( span , TextMatching . EXACT_EQUAL ) ; } public static String qName ( String namespace , String name ) { return name == null ? null : ( namespace == null ? name : namespace + "<STR_LIT::>" + name ) ; } public void setSpannedText ( String span ) { setSpannedText ( span , TextMatching . EXACT_EQUAL ) ; } public void setSpannedText ( String spannedText , TextMatching textMatching ) { if ( spannedText != null ) { Validate . notNull ( textMatching ) ; } this . spannedText = spannedText ; this . spanTextMatching = textMatching ; } public void clearSpannedText ( ) { this . spannedText = null ; this . spanTextMatching = null ; } @ Override public String toString ( ) { StringBuffer sb = new StringBuffer ( ) ; sb . append ( "<STR_LIT>" ) ; sb . append ( id ) ; if ( marker != null ) { sb . append ( "<STR_LIT>" ) ; sb . append ( marker ) ; sb . append ( "<STR_LIT:'>" ) ; } if ( variable != null ) { sb . append ( "<STR_LIT>" ) ; sb . append ( variable ) ; sb . append ( "<STR_LIT:'>" ) ; } if ( name != null ) { sb . append ( "<STR_LIT>" ) ; sb . append ( qName ( namespace , name ) ) ; sb . append ( "<STR_LIT:'>" ) ; } if ( token ) { sb . append ( "<STR_LIT>" ) ; } if ( spannedText != null ) { sb . append ( "<STR_LIT>" ) ; String op = spanTextMatching != null ? spanTextMatching . sqlOperator ( ) : "<STR_LIT:U+0020>" ; String quote = spanTextMatching != null ? spanTextMatching . quote ( ) : "<STR_LIT:?>" ; sb . append ( op ) ; sb . append ( quote ) ; sb . append ( spannedText ) ; sb . append ( quote ) ; } if ( isRoot ( ) ) { sb . append ( "<STR_LIT>" ) ; } if ( ! nodeAnnotations . isEmpty ( ) ) { sb . append ( "<STR_LIT>" ) ; sb . append ( nodeAnnotations ) ; } if ( ! edgeAnnotations . isEmpty ( ) ) { sb . append ( "<STR_LIT>" ) ; sb . append ( edgeAnnotations ) ; } for ( Join join : joins ) { sb . append ( "<STR_LIT:;U+0020>" ) ; sb . append ( join ) ; } return sb . toString ( ) ; } public boolean addEdgeAnnotation ( QueryAnnotation annotation ) { return edgeAnnotations . add ( annotation ) ; } public boolean addNodeAnnotation ( QueryAnnotation annotation ) { return nodeAnnotations . add ( annotation ) ; } public boolean addJoin ( Join join ) { boolean result = joins . add ( join ) ; if ( join instanceof RankTableJoin ) { this . setPartOfEdge ( true ) ; QueryNode target = join . getTarget ( ) ; target . setPartOfEdge ( true ) ; } return result ; } public String getQualifiedName ( ) { return qName ( namespace , name ) ; } @ Override public boolean equals ( Object obj ) { if ( obj == null ) { return false ; } if ( getClass ( ) != obj . getClass ( ) ) { return false ; } final QueryNode other = ( QueryNode ) obj ; if ( this . id != other . id ) { return false ; } if ( this . corpus != other . corpus ) { return false ; } if ( this . textId != other . textId ) { return false ; } if ( this . left != other . left ) { return false ; } if ( this . right != other . right ) { return false ; } if ( ( this . spannedText == null ) ? ( other . spannedText != null ) : ! this . spannedText . equals ( other . spannedText ) ) { return false ; } if ( this . leftToken != other . leftToken ) { return false ; } if ( this . nodeAnnotations != other . nodeAnnotations && ( this . nodeAnnotations == null || ! this . nodeAnnotations . equals ( other . nodeAnnotations ) ) ) { return false ; } if ( ( this . name == null ) ? ( other . name != null ) : ! this . name . equals ( other . name ) ) { return false ; } if ( ( this . namespace == null ) ? ( other . namespace != null ) : ! this . namespace . equals ( other . namespace ) ) { return false ; } if ( this . partOfEdge != other . partOfEdge ) { return false ; } if ( this . root != other . root ) { return false ; } if ( this . token != other . token ) { return false ; } if ( this . spanTextMatching != other . spanTextMatching ) { return false ; } if ( this . joins != other . joins && ( this . joins == null || ! this . joins . equals ( other . joins ) ) ) { return false ; } if ( ( this . variable == null ) ? ( other . variable != null ) : ! this . variable . equals ( other . variable ) ) { return false ; } if ( this . edgeAnnotations != other . edgeAnnotations && ( this . edgeAnnotations == null || ! this . edgeAnnotations . equals ( other . edgeAnnotations ) ) ) { return false ; } if ( ( this . marker == null ) ? ( other . marker != null ) : ! this . marker . equals ( other . marker ) ) { return false ; } if ( ( this . arity == null ) ? ( other . arity != null ) : ! this . arity . equals ( other . arity ) ) { return false ; } if ( ( this . tokenArity == null ) ? ( other . tokenArity != null ) : ! this . tokenArity . equals ( other . tokenArity ) ) { return false ; } return true ; } @ Override public int hashCode ( ) { return ( int ) id ; } public Set < QueryAnnotation > getEdgeAnnotations ( ) { return edgeAnnotations ; } public void setEdgeAnnotations ( Set < QueryAnnotation > edgeAnnotations ) { this . edgeAnnotations = edgeAnnotations ; } public boolean isRoot ( ) { return root ; } public void setRoot ( boolean root ) { this . root = root ; } public String getMarker ( ) { return marker ; } public void setMarker ( String marker ) { this . marker = marker ; } public String getName ( ) { return name ; } public void setName ( String name ) { this . name = name ; } public String getNamespace ( ) { return namespace ; } public void setNamespace ( String namespace ) { this . namespace = namespace ; } public String getSpannedText ( ) { return spannedText ; } public TextMatching getSpanTextMatching ( ) { return spanTextMatching ; } public Set < QueryAnnotation > getNodeAnnotations ( ) { return nodeAnnotations ; } public void setNodeAnnotations ( Set < QueryAnnotation > nodeAnnotations ) { this . nodeAnnotations = nodeAnnotations ; } public String getVariable ( ) { return variable ; } public void setVariable ( String variable ) { this . variable = variable ; } public long getId ( ) { return id ; } public List < Join > getJoins ( ) { return joins ; } public boolean isToken ( ) { return token ; } public void setToken ( boolean token ) { this . token = token ; } public boolean isPartOfEdge ( ) { return partOfEdge ; } public void setPartOfEdge ( boolean partOfEdge ) { this . partOfEdge = partOfEdge ; } public long getCorpus ( ) { return corpus ; } public void setCorpus ( long corpus ) { this . corpus = corpus ; } public long getTextId ( ) { return textId ; } public void setTextId ( long textIndex ) { this . textId = textIndex ; } public long getLeft ( ) { return left ; } public void setLeft ( long left ) { this . left = left ; } public long getRight ( ) { return right ; } public void setRight ( long right ) { this . right = right ; } public Long getTokenIndex ( ) { return tokenIndex ; } public void setTokenIndex ( Long tokenIndex ) { this . tokenIndex = tokenIndex ; setToken ( tokenIndex != null ) ; } public long getLeftToken ( ) { return leftToken ; } public void setLeftToken ( long leftToken ) { this . leftToken = leftToken ; } public long getRightToken ( ) { return rightToken ; } public void setRightToken ( long rightToken ) { this . rightToken = rightToken ; } public Range getArity ( ) { return arity ; } public void setArity ( Range arity ) { this . arity = arity ; } public Range getTokenArity ( ) { return tokenArity ; } public void setTokenArity ( Range tokenArity ) { this . tokenArity = tokenArity ; } public Long getMatchedNodeInQuery ( ) { return matchedNodeInQuery ; } public void setMatchedNodeInQuery ( Long matchedNodeInQuery ) { this . matchedNodeInQuery = matchedNodeInQuery ; } } </s>
<s> package annis . model ; public class AnnisConstants { public static final String ANNIS_NS = "<STR_LIT>" ; public static final String FEAT_MATCHEDIDS = "<STR_LIT>" ; public static final String FEAT_MATCHEDNODE = "<STR_LIT>" ; public static final String FEAT_INTERNALID = "<STR_LIT>" ; public static final String FEAT_CORPUSREF = "<STR_LIT>" ; public static final String FEAT_TEXTREF = "<STR_LIT>" ; public static final String FEAT_COMPONENTID = "<STR_LIT>" ; public static final String FEAT_LEFT = "<STR_LIT>" ; public static final String FEAT_LEFTTOKEN = "<STR_LIT>" ; public static final String FEAT_RIGHT = "<STR_LIT>" ; public static final String FEAT_RIGHTTOKEN = "<STR_LIT>" ; public static final String FEAT_TOKENINDEX = "<STR_LIT>" ; public static final String FEAT_SEGLEFT = "<STR_LIT>" ; public static final String FEAT_SEGRIGHT = "<STR_LIT>" ; public static final String FEAT_SEGNAME = "<STR_LIT>" ; } </s>
<s> package annis . model ; import java . io . Serializable ; import java . util . HashSet ; import java . util . Set ; import org . apache . commons . lang3 . builder . EqualsBuilder ; import org . apache . commons . lang3 . builder . HashCodeBuilder ; public class Edge implements Serializable { public enum EdgeType { COVERAGE ( "<STR_LIT:c>" , "<STR_LIT>" ) , DOMINANCE ( "<STR_LIT:d>" , "<STR_LIT>" ) , POINTING_RELATION ( "<STR_LIT:p>" , "<STR_LIT>" ) , UNKNOWN ( null , "<STR_LIT>" ) ; private String type ; private String name ; private EdgeType ( String type , String name ) { this . type = type ; this . name = name ; } @ Override public String toString ( ) { return name + ( type != null ? "<STR_LIT:(>" + type + "<STR_LIT:)>" : "<STR_LIT>" ) ; } public String getTypeChar ( ) { return type ; } public static EdgeType parseEdgeType ( String type ) { if ( "<STR_LIT:c>" . equals ( type ) ) { return COVERAGE ; } else if ( "<STR_LIT:d>" . equals ( type ) ) { return DOMINANCE ; } else if ( "<STR_LIT:p>" . equals ( type ) ) { return POINTING_RELATION ; } else { return UNKNOWN ; } } } ; private AnnisNode source ; private AnnisNode destination ; private long pre ; private long componentID ; private EdgeType edgeType ; private String namespace ; private String name ; private Set < Annotation > annotations ; public Edge ( ) { annotations = new HashSet < Annotation > ( ) ; edgeType = EdgeType . UNKNOWN ; } public boolean addAnnotation ( Annotation o ) { return annotations . add ( o ) ; } @ Override public String toString ( ) { String src = source != null ? "<STR_LIT>" + source . getId ( ) : "<STR_LIT>" ; String dst = "<STR_LIT>" + destination . getId ( ) ; String type = edgeType != null ? edgeType . toString ( ) : "<STR_LIT>" ; String qname = getQualifiedName ( ) != null ? getQualifiedName ( ) : "<STR_LIT>" ; return src + "<STR_LIT>" + dst + "<STR_LIT:U+0020>" + qname + "<STR_LIT:U+0020>" + type ; } public String getQualifiedName ( ) { return AnnisNode . qName ( namespace , name ) ; } @ Override public boolean equals ( Object obj ) { if ( obj == null ) { return false ; } if ( getClass ( ) != obj . getClass ( ) ) { return false ; } final Edge other = ( Edge ) obj ; if ( this . source != other . source && ( this . source == null || ! this . source . equals ( other . source ) ) ) { return false ; } if ( this . destination != other . destination && ( this . destination == null || ! this . destination . equals ( other . destination ) ) ) { return false ; } if ( this . pre != other . pre ) { return false ; } if ( this . componentID != other . componentID ) { return false ; } if ( this . edgeType != other . edgeType ) { return false ; } if ( ( this . namespace == null ) ? ( other . namespace != null ) : ! this . namespace . equals ( other . namespace ) ) { return false ; } if ( ( this . name == null ) ? ( other . name != null ) : ! this . name . equals ( other . name ) ) { return false ; } return true ; } @ Override public int hashCode ( ) { int hash = <NUM_LIT:5> ; hash = <NUM_LIT> * hash + ( this . source != null ? this . source . hashCode ( ) : <NUM_LIT:0> ) ; hash = <NUM_LIT> * hash + ( this . destination != null ? this . destination . hashCode ( ) : <NUM_LIT:0> ) ; hash = <NUM_LIT> * hash + ( int ) ( this . pre ^ ( this . pre > > > <NUM_LIT:32> ) ) ; hash = <NUM_LIT> * hash + ( int ) ( this . componentID ^ ( this . componentID > > > <NUM_LIT:32> ) ) ; hash = <NUM_LIT> * hash + ( this . edgeType != null ? this . edgeType . hashCode ( ) : <NUM_LIT:0> ) ; hash = <NUM_LIT> * hash + ( this . namespace != null ? this . namespace . hashCode ( ) : <NUM_LIT:0> ) ; hash = <NUM_LIT> * hash + ( this . name != null ? this . name . hashCode ( ) : <NUM_LIT:0> ) ; return hash ; } public long getPre ( ) { return pre ; } public void setPre ( long pre ) { this . pre = pre ; } public long getComponentID ( ) { return componentID ; } public void setComponentID ( long componentID ) { this . componentID = componentID ; } public EdgeType getEdgeType ( ) { return edgeType ; } public void setEdgeType ( EdgeType edgeType ) { this . edgeType = edgeType ; } public String getNamespace ( ) { return namespace ; } public void setNamespace ( String namespace ) { this . namespace = namespace ; } public String getName ( ) { return name ; } public void setName ( String name ) { this . name = name ; } public Set < Annotation > getAnnotations ( ) { return annotations ; } public AnnisNode getSource ( ) { return source ; } public void setSource ( AnnisNode source ) { this . source = source ; } public AnnisNode getDestination ( ) { return destination ; } public void setDestination ( AnnisNode destination ) { this . destination = destination ; } } </s>
<s> package annis . model ; import java . io . Serializable ; import java . util . HashSet ; import java . util . Set ; import java . util . TreeSet ; import org . apache . commons . lang3 . builder . EqualsBuilder ; import org . apache . commons . lang3 . builder . HashCodeBuilder ; @ SuppressWarnings ( "<STR_LIT:serial>" ) public class AnnisNode implements Serializable { private long id ; private long corpus ; private long textId ; private long left ; private long right ; private String spannedText ; private Long tokenIndex ; private long leftToken ; private long rightToken ; private Set < Annotation > nodeAnnotations ; private AnnotationGraph graph ; private Set < Edge > incomingEdges ; private Set < Edge > outgoingEdges ; private String name ; private String namespace ; private boolean partOfEdge ; private boolean root ; private boolean token ; private Set < Annotation > edgeAnnotations ; private Long matchedNodeInQuery ; public static class Range implements Serializable { private int min ; private int max ; public Range ( int _min , int _max ) { min = _min ; max = _max ; } public int getMin ( ) { return min ; } public int getMax ( ) { return max ; } @ Override public int hashCode ( ) { return new HashCodeBuilder ( ) . append ( min ) . append ( max ) . toHashCode ( ) ; } @ Override public boolean equals ( Object obj ) { if ( obj instanceof Range ) { Range other = ( Range ) obj ; return new EqualsBuilder ( ) . append ( min , other . min ) . append ( max , other . max ) . isEquals ( ) ; } return false ; } } ; public AnnisNode ( ) { nodeAnnotations = new TreeSet < Annotation > ( ) ; edgeAnnotations = new TreeSet < Annotation > ( ) ; incomingEdges = new HashSet < Edge > ( ) ; outgoingEdges = new HashSet < Edge > ( ) ; } public AnnisNode ( long id ) { this ( ) ; this . id = id ; } public AnnisNode ( long id , long corpusRef , long textRef , long left , long right , String namespace , String name , long tokenIndex , String span , long leftToken , long rightToken ) { this ( id ) ; this . corpus = corpusRef ; this . textId = textRef ; this . left = left ; this . right = right ; this . leftToken = leftToken ; this . rightToken = rightToken ; setNamespace ( namespace ) ; setName ( name ) ; setTokenIndex ( tokenIndex ) ; setSpannedText ( span ) ; } public static String qName ( String namespace , String name ) { return name == null ? null : ( namespace == null ? name : namespace + "<STR_LIT::>" + name ) ; } public void setSpannedText ( String spannedText ) { this . spannedText = spannedText ; } public void clearSpannedText ( ) { this . spannedText = null ; } @ Override public String toString ( ) { StringBuffer sb = new StringBuffer ( ) ; sb . append ( "<STR_LIT>" ) ; sb . append ( id ) ; if ( name != null ) { sb . append ( "<STR_LIT>" ) ; sb . append ( qName ( namespace , name ) ) ; sb . append ( "<STR_LIT:'>" ) ; } if ( token ) { sb . append ( "<STR_LIT>" ) ; } if ( spannedText != null ) { sb . append ( "<STR_LIT>" ) ; sb . append ( spannedText ) ; sb . append ( "<STR_LIT:\">" ) ; } if ( isRoot ( ) ) { sb . append ( "<STR_LIT>" ) ; } if ( ! nodeAnnotations . isEmpty ( ) ) { sb . append ( "<STR_LIT>" ) ; sb . append ( nodeAnnotations ) ; } if ( ! edgeAnnotations . isEmpty ( ) ) { sb . append ( "<STR_LIT>" ) ; sb . append ( edgeAnnotations ) ; } return sb . toString ( ) ; } public boolean addIncomingEdge ( Edge edge ) { return incomingEdges . add ( edge ) ; } public boolean addOutgoingEdge ( Edge edge ) { return outgoingEdges . add ( edge ) ; } public boolean addEdgeAnnotation ( Annotation annotation ) { return edgeAnnotations . add ( annotation ) ; } public boolean addNodeAnnotation ( Annotation annotation ) { return nodeAnnotations . add ( annotation ) ; } public String getQualifiedName ( ) { return qName ( namespace , name ) ; } @ Override public boolean equals ( Object obj ) { if ( obj == null ) { return false ; } if ( getClass ( ) != obj . getClass ( ) ) { return false ; } final AnnisNode other = ( AnnisNode ) obj ; if ( this . id != other . id ) { return false ; } if ( this . corpus != other . corpus ) { return false ; } if ( this . textId != other . textId ) { return false ; } if ( this . left != other . left ) { return false ; } if ( this . right != other . right ) { return false ; } if ( ( this . spannedText == null ) ? ( other . spannedText != null ) : ! this . spannedText . equals ( other . spannedText ) ) { return false ; } if ( this . leftToken != other . leftToken ) { return false ; } if ( this . nodeAnnotations != other . nodeAnnotations && ( this . nodeAnnotations == null || ! this . nodeAnnotations . equals ( other . nodeAnnotations ) ) ) { return false ; } if ( ( this . name == null ) ? ( other . name != null ) : ! this . name . equals ( other . name ) ) { return false ; } if ( ( this . namespace == null ) ? ( other . namespace != null ) : ! this . namespace . equals ( other . namespace ) ) { return false ; } if ( this . partOfEdge != other . partOfEdge ) { return false ; } if ( this . root != other . root ) { return false ; } if ( this . token != other . token ) { return false ; } if ( this . edgeAnnotations != other . edgeAnnotations && ( this . edgeAnnotations == null || ! this . edgeAnnotations . equals ( other . edgeAnnotations ) ) ) { return false ; } return true ; } @ Override public int hashCode ( ) { return ( int ) id ; } public Set < Annotation > getEdgeAnnotations ( ) { return edgeAnnotations ; } public void setEdgeAnnotations ( Set < Annotation > edgeAnnotations ) { this . edgeAnnotations = edgeAnnotations ; } public boolean isRoot ( ) { return root ; } public void setRoot ( boolean root ) { this . root = root ; } public String getName ( ) { return name ; } public void setName ( String name ) { this . name = name ; } public String getNamespace ( ) { return namespace ; } public void setNamespace ( String namespace ) { this . namespace = namespace ; } public String getSpannedText ( ) { return spannedText ; } public Set < Annotation > getNodeAnnotations ( ) { return nodeAnnotations ; } public void setNodeAnnotations ( Set < Annotation > nodeAnnotations ) { this . nodeAnnotations = nodeAnnotations ; } public long getId ( ) { return id ; } public boolean isToken ( ) { return token ; } public void setToken ( boolean token ) { this . token = token ; } public boolean isPartOfEdge ( ) { return partOfEdge ; } public void setPartOfEdge ( boolean partOfEdge ) { this . partOfEdge = partOfEdge ; } public long getCorpus ( ) { return corpus ; } public void setCorpus ( long corpus ) { this . corpus = corpus ; } public long getTextId ( ) { return textId ; } public void setTextId ( long textIndex ) { this . textId = textIndex ; } public long getLeft ( ) { return left ; } public void setLeft ( long left ) { this . left = left ; } public long getRight ( ) { return right ; } public void setRight ( long right ) { this . right = right ; } public Long getTokenIndex ( ) { return tokenIndex ; } public void setTokenIndex ( Long tokenIndex ) { this . tokenIndex = tokenIndex ; setToken ( tokenIndex != null ) ; } public long getLeftToken ( ) { return leftToken ; } public void setLeftToken ( long leftToken ) { this . leftToken = leftToken ; } public long getRightToken ( ) { return rightToken ; } public void setRightToken ( long rightToken ) { this . rightToken = rightToken ; } public Set < Edge > getIncomingEdges ( ) { return incomingEdges ; } public void setIncomingEdges ( Set < Edge > incomingEdges ) { this . incomingEdges = incomingEdges ; } public Set < Edge > getOutgoingEdges ( ) { return outgoingEdges ; } public void setOutgoingEdges ( Set < Edge > outgoingEdges ) { this . outgoingEdges = outgoingEdges ; } public AnnotationGraph getGraph ( ) { return graph ; } public void setGraph ( AnnotationGraph graph ) { this . graph = graph ; } public Long getMatchedNodeInQuery ( ) { return matchedNodeInQuery ; } public void setMatchedNodeInQuery ( Long matchedNodeInQuery ) { this . matchedNodeInQuery = matchedNodeInQuery ; } } </s>
<s> package annis . model ; import java . io . Serializable ; import javax . xml . bind . annotation . XmlRootElement ; import org . apache . commons . lang3 . builder . EqualsBuilder ; import org . apache . commons . lang3 . builder . HashCodeBuilder ; @ XmlRootElement public class Annotation implements Comparable < Annotation > , Serializable { private String namespace ; private String name ; private String value ; private String type ; private String corpusName ; private int pre ; public Annotation ( ) { } public Annotation ( String namespace , String name ) { this ( namespace , name , null ) ; } public Annotation ( String namespace , String name , String value ) { this . namespace = namespace ; this . name = name ; this . value = value ; } public Annotation ( String namespace , String name , String value , String type , String corpusName ) { this ( namespace , name , value ) ; this . type = type ; this . corpusName = corpusName ; } public Annotation ( String namespace , String name , String value , String type , String corpusName , int pre ) { this ( namespace , name , value , type , corpusName ) ; this . pre = pre ; } @ Override public String toString ( ) { StringBuilder sb = new StringBuilder ( ) ; sb . append ( AnnisNode . qName ( namespace , name ) ) ; if ( value != null ) { sb . append ( "<STR_LIT:=>" ) ; sb . append ( value ) ; } return sb . toString ( ) ; } @ Override public int compareTo ( Annotation o ) { String name1 = getQualifiedName ( ) ; String name2 = o . getQualifiedName ( ) ; return name1 . compareTo ( name2 ) ; } @ Override public boolean equals ( Object obj ) { if ( obj == null || ! ( obj instanceof Annotation ) ) { return false ; } Annotation other = ( Annotation ) obj ; return new EqualsBuilder ( ) . append ( this . namespace , other . namespace ) . append ( this . name , other . name ) . append ( this . value , other . value ) . isEquals ( ) ; } @ Override public int hashCode ( ) { return new HashCodeBuilder ( ) . append ( namespace ) . append ( name ) . append ( value ) . toHashCode ( ) ; } public String getValue ( ) { return value ; } public void setValue ( String value ) { this . value = value ; } public String getNamespace ( ) { return namespace ; } public void setNamespace ( String namespace ) { this . namespace = namespace ; } public String getName ( ) { return name ; } public void setName ( String name ) { this . name = name ; } public String getQualifiedName ( ) { return AnnisNode . qName ( namespace , name ) ; } public String getType ( ) { return type ; } public String getCorpusName ( ) { return corpusName ; } public void setType ( String type ) { this . type = type ; } public void setCorpusName ( String corpusName ) { this . corpusName = corpusName ; } public void setPre ( int pre ) { this . pre = pre ; } public int getPre ( ) { return pre ; } } </s>
<s> package annis . model ; import java . io . Serializable ; import org . apache . commons . lang3 . builder . EqualsBuilder ; import org . apache . commons . lang3 . builder . HashCodeBuilder ; import annis . model . QueryNode . TextMatching ; public class QueryAnnotation implements Comparable < QueryAnnotation > , Serializable { private String namespace ; private String name ; private String value ; private String type ; private String corpusName ; private TextMatching textMatching ; public QueryAnnotation ( String namespace , String name ) { this ( namespace , name , null , null ) ; } public QueryAnnotation ( String namespace , String name , String value ) { this ( namespace , name , value , TextMatching . EXACT_EQUAL ) ; } public QueryAnnotation ( String namespace , String name , String value , TextMatching textMatching ) { this . namespace = namespace ; this . name = name ; this . value = value ; this . textMatching = textMatching ; } public QueryAnnotation ( String namespace , String name , String value , String type , String corpusName ) { this ( namespace , name , value ) ; this . type = type ; this . corpusName = corpusName ; } @ Override public String toString ( ) { StringBuffer sb = new StringBuffer ( ) ; sb . append ( QueryNode . qName ( namespace , name ) ) ; if ( value != null ) { sb . append ( "<STR_LIT:U+0020>" ) ; sb . append ( textMatching ) ; sb . append ( "<STR_LIT:U+0020>" ) ; sb . append ( value ) ; } return sb . toString ( ) ; } public int compareTo ( QueryAnnotation o ) { String name1 = getQualifiedName ( ) ; String name2 = o . getQualifiedName ( ) ; return name1 . compareTo ( name2 ) ; } @ Override public boolean equals ( Object obj ) { if ( obj == null || ! ( obj instanceof QueryAnnotation ) ) return false ; QueryAnnotation other = ( QueryAnnotation ) obj ; return new EqualsBuilder ( ) . append ( this . namespace , other . namespace ) . append ( this . name , other . name ) . append ( this . value , other . value ) . append ( this . textMatching , other . textMatching ) . isEquals ( ) ; } @ Override public int hashCode ( ) { return new HashCodeBuilder ( ) . append ( namespace ) . append ( name ) . append ( value ) . append ( textMatching ) . toHashCode ( ) ; } public String getValue ( ) { return value ; } public void setValue ( String value ) { this . value = value ; } public TextMatching getTextMatching ( ) { return textMatching ; } public void setTextMatching ( TextMatching textMatching ) { this . textMatching = textMatching ; } public String getNamespace ( ) { return namespace ; } public void setNamespace ( String namespace ) { this . namespace = namespace ; } public String getName ( ) { return name ; } public void setName ( String name ) { this . name = name ; } public String getQualifiedName ( ) { return QueryNode . qName ( namespace , name ) ; } public String getType ( ) { return type ; } public String getCorpusName ( ) { return corpusName ; } } </s>
<s> package annis . gui ; import java . awt . Color ; import java . util . Locale ; import org . apache . commons . lang3 . StringUtils ; public enum MatchedNodeColors { Red ( new Color ( <NUM_LIT:255> , <NUM_LIT:0> , <NUM_LIT:0> ) ) , MediumVioletRed ( new Color ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) ) , LimeGreen ( new Color ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) ) , Peru ( new Color ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) ) , IndianRed ( new Color ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) ) , YellowGreen ( new Color ( <NUM_LIT> , <NUM_LIT:255> , <NUM_LIT> ) ) , DarkRed ( new Color ( <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:0> ) ) , OrangeRed ( new Color ( <NUM_LIT:255> , <NUM_LIT> , <NUM_LIT:0> ) ) ; private final Color color ; private MatchedNodeColors ( Color color ) { this . color = color ; } public Color getColor ( ) { return color ; } public String getHTMLColor ( ) { StringBuilder result = new StringBuilder ( "<STR_LIT:#>" ) ; result . append ( twoDigitHex ( color . getRed ( ) ) ) ; result . append ( twoDigitHex ( color . getGreen ( ) ) ) ; result . append ( twoDigitHex ( color . getBlue ( ) ) ) ; return result . toString ( ) ; } private String twoDigitHex ( int i ) { String result = Integer . toHexString ( i ) . toLowerCase ( new Locale ( "<STR_LIT:en>" ) ) ; if ( result . length ( ) > <NUM_LIT:2> ) { result = result . substring ( <NUM_LIT:0> , <NUM_LIT:2> ) ; } else if ( result . length ( ) < <NUM_LIT:2> ) { result = StringUtils . leftPad ( result , <NUM_LIT:2> , '<CHAR_LIT:0>' ) ; } return result ; } public static String colorClassByMatch ( Long match ) { if ( match == null ) { return null ; } long m = match ; m = Math . min ( m , <NUM_LIT:8> ) ; return "<STR_LIT>" + m ; } } </s>
<s> package annis . gui . media ; import net . xeoh . plugins . base . Plugin ; public interface MediaControllerFactory extends Plugin { public MediaController getOrCreate ( MediaControllerHolder holder ) ; } </s>
<s> package annis . gui . media ; public interface MimeTypeErrorListener { public void notifyCannotPlayMimeType ( String mimeType ) ; } </s>
<s> package annis . gui . media ; import annis . gui . VisualizationToggle ; import net . xeoh . plugins . base . Plugin ; public interface MediaController extends Plugin { public void play ( String resultID , double startTime ) ; public void play ( String resultID , double startTime , double endTime ) ; public void pauseAll ( ) ; public void addMediaPlayer ( MediaPlayer player , String resultID , VisualizationToggle toggle ) ; public void clearMediaPlayers ( ) ; } </s>
<s> package annis . gui . media ; public interface MediaPlayer { public void play ( double start ) ; public void play ( double start , double end ) ; public void pause ( ) ; public void stop ( ) ; } </s>