text
stringlengths 30
1.67M
|
|---|
<s> package org . nju . artemis . aejb . preprocessor ; public class Event { private int head ; private int tail ; private String event ; public Event ( int head , int tail , String event ) { super ( ) ; this . head = head ; this . tail = tail ; this . event = event ; System . out . println ( head + "<STR_LIT:->" + event + "<STR_LIT:->" + tail ) ; } public int getHead ( ) { return head ; } public void setHead ( int head ) { this . head = head ; } public int getTail ( ) { return tail ; } public void setTail ( int tail ) { this . tail = tail ; } public String getEvent ( ) { return event ; } public void setEvent ( String event ) { this . event = event ; } public String getPort ( ) { if ( event . contains ( "<STR_LIT>" ) ) { return event . split ( "<STR_LIT:\\.>" ) [ <NUM_LIT:1> ] ; } return null ; } } </s>
|
<s> package org . nju . artemis . aejb . preprocessor ; import static org . objectweb . asm . Opcodes . * ; import java . io . File ; import java . io . FileInputStream ; import java . io . FileOutputStream ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . Enumeration ; import java . util . Hashtable ; import java . util . Iterator ; import java . util . LinkedList ; import java . util . List ; import java . util . StringTokenizer ; import java . util . jar . * ; import org . objectweb . asm . ClassReader ; import org . objectweb . asm . ClassVisitor ; import org . objectweb . asm . ClassWriter ; import org . objectweb . asm . Opcodes ; import org . objectweb . asm . tree . AbstractInsnNode ; import org . objectweb . asm . tree . AnnotationNode ; import org . objectweb . asm . tree . ClassNode ; import org . objectweb . asm . tree . FieldNode ; import org . objectweb . asm . tree . FrameNode ; import org . objectweb . asm . tree . InsnList ; import org . objectweb . asm . tree . InsnNode ; import org . objectweb . asm . tree . JumpInsnNode ; import org . objectweb . asm . tree . LabelNode ; import org . objectweb . asm . tree . LdcInsnNode ; import org . objectweb . asm . tree . MethodInsnNode ; import org . objectweb . asm . tree . MethodNode ; import org . objectweb . asm . tree . TryCatchBlockNode ; import org . objectweb . asm . tree . TypeInsnNode ; import org . objectweb . asm . tree . VarInsnNode ; import org . objectweb . asm . tree . analysis . Analyzer ; import org . objectweb . asm . tree . analysis . AnalyzerException ; import org . objectweb . asm . tree . analysis . BasicInterpreter ; import org . objectweb . asm . util . TraceClassVisitor ; public class ProgramAnalyzer { private List < String > ejbs = new LinkedList ( ) ; StateMachine stateMachine = new StateMachine ( ) ; ControlFlow controlflow = new ControlFlow ( ) ; List [ ] past ; List [ ] future ; Hashtable < AbstractInsnNode , String > jumpinf = new Hashtable < AbstractInsnNode , String > ( ) ; List < String > next = new LinkedList ( ) ; List < String > stateall = new LinkedList ( ) ; public void transform ( ClassNode cn ) { if ( ( cn . access & ACC_INTERFACE ) == <NUM_LIT:0> ) { setEjbs ( cn ) ; if ( ! ejbs . isEmpty ( ) ) { System . out . println ( "<STR_LIT>" + cn . name ) ; for ( MethodNode mn : ( List < MethodNode > ) cn . methods ) { if ( isTransaction ( mn , "<STR_LIT>" ) ) { InsnList insns = mn . instructions ; stateMachine . setStart ( <NUM_LIT:0> ) ; stateMachine . setEnd ( mn . instructions . size ( ) ) ; try { ExtractControlFlow ( cn . name , mn ) ; } catch ( AnalyzerException ignored ) { } recognize_state ( <NUM_LIT:0> , <NUM_LIT:0> , mn . instructions ) ; mergeState ( ) ; ExtractMetaData ( ) ; setNext ( ) ; Iterator < AnnotationNode > iter = mn . visibleAnnotations . iterator ( ) ; while ( iter . hasNext ( ) ) { AnnotationNode an = iter . next ( ) ; if ( an . desc . equals ( "<STR_LIT>" ) ) { List < Object > valuenew = new LinkedList < Object > ( ) ; valuenew . add ( "<STR_LIT:name>" ) ; valuenew . add ( mn . name ) ; valuenew . add ( "<STR_LIT>" ) ; valuenew . add ( stateall ) ; valuenew . add ( "<STR_LIT>" ) ; valuenew . add ( next ) ; an . values = valuenew ; System . out . println ( an . values ) ; } } LabelNode lb0 = new LabelNode ( ) ; LabelNode lb1 = new LabelNode ( ) ; LabelNode lb2 = new LabelNode ( ) ; LabelNode lb3 = new LabelNode ( ) ; LabelNode lb4 = new LabelNode ( ) ; LabelNode lb5 = new LabelNode ( ) ; LabelNode lb6 = new LabelNode ( ) ; mn . tryCatchBlocks . add ( new TryCatchBlockNode ( lb0 , lb1 , lb2 , "<STR_LIT>" ) ) ; InsnList begin = new InsnList ( ) ; int localnum = mn . localVariables . size ( ) ; begin . add ( lb3 ) ; begin . add ( new InsnNode ( ACONST_NULL ) ) ; begin . add ( new VarInsnNode ( ASTORE , localnum ) ) ; begin . add ( lb0 ) ; begin . add ( new TypeInsnNode ( NEW , "<STR_LIT>" ) ) ; begin . add ( new InsnNode ( DUP ) ) ; begin . add ( new MethodInsnNode ( INVOKESPECIAL , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) ; begin . add ( new VarInsnNode ( ASTORE , localnum + <NUM_LIT:1> ) ) ; begin . add ( lb4 ) ; begin . add ( new VarInsnNode ( ALOAD , localnum + <NUM_LIT:1> ) ) ; begin . add ( new LdcInsnNode ( "<STR_LIT>" + mn . name ) ) ; begin . add ( new MethodInsnNode ( INVOKEINTERFACE , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) ; begin . add ( new TypeInsnNode ( CHECKCAST , "<STR_LIT>" ) ) ; begin . add ( new VarInsnNode ( ASTORE , localnum ) ) ; begin . add ( lb1 ) ; begin . add ( new JumpInsnNode ( GOTO , lb5 ) ) ; begin . add ( lb2 ) ; begin . add ( new FrameNode ( Opcodes . F_FULL , <NUM_LIT:2> , new Object [ ] { mn . name , "<STR_LIT>" } , <NUM_LIT:1> , new Object [ ] { "<STR_LIT>" } ) ) ; begin . add ( new VarInsnNode ( ASTORE , localnum + <NUM_LIT:1> ) ) ; begin . add ( lb6 ) ; begin . add ( new VarInsnNode ( ALOAD , localnum + <NUM_LIT:1> ) ) ; begin . add ( new MethodInsnNode ( INVOKEVIRTUAL , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) ; begin . add ( lb5 ) ; Iterator < AbstractInsnNode > i = insns . iterator ( ) ; int src = <NUM_LIT:0> ; while ( i . hasNext ( ) ) { AbstractInsnNode i1 = i . next ( ) ; if ( i1 instanceof MethodInsnNode ) { String owner = ( ( MethodInsnNode ) i1 ) . owner ; if ( ejbs . contains ( owner ) ) { String e = "<STR_LIT>" + owner + "<STR_LIT:.>" + ( ( MethodInsnNode ) i1 ) . name ; InsnList il = new InsnList ( ) ; il . add ( new TypeInsnNode ( NEW , "<STR_LIT>" ) ) ; il . add ( new InsnNode ( DUP ) ) ; il . add ( new LdcInsnNode ( mn . name + "<STR_LIT:/>" ) ) ; il . add ( new MethodInsnNode ( INVOKESPECIAL , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) ; il . add ( new VarInsnNode ( ALOAD , <NUM_LIT:0> ) ) ; il . add ( new MethodInsnNode ( INVOKEVIRTUAL , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) ; il . add ( new MethodInsnNode ( INVOKEVIRTUAL , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) ; il . add ( new MethodInsnNode ( INVOKEVIRTUAL , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) ; insns . insert ( i1 . getPrevious ( ) , il ) ; InsnList trig = new InsnList ( ) ; trig . add ( new VarInsnNode ( ALOAD , localnum ) ) ; trig . add ( new VarInsnNode ( ALOAD , <NUM_LIT:0> ) ) ; trig . add ( new MethodInsnNode ( INVOKEVIRTUAL , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) ; trig . add ( new LdcInsnNode ( e ) ) ; trig . add ( new MethodInsnNode ( INVOKEVIRTUAL , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) ; if ( i1 . getNext ( ) . getOpcode ( ) == ISTORE ) { insns . insert ( i1 . getNext ( ) , trig ) ; } else { insns . insert ( i1 , trig ) ; } insns . insert ( i1 . getPrevious ( ) , new MethodInsnNode ( INVOKEVIRTUAL , ( ( MethodInsnNode ) i1 ) . owner , ( ( MethodInsnNode ) i1 ) . name , ( ( MethodInsnNode ) i1 ) . desc . replace ( "<STR_LIT:(>" , "<STR_LIT>" ) ) ) ; insns . remove ( i1 ) ; } } else { if ( jumpinf . containsKey ( i1 ) ) { InsnList trig = new InsnList ( ) ; trig . add ( new VarInsnNode ( ALOAD , localnum ) ) ; trig . add ( new VarInsnNode ( ALOAD , <NUM_LIT:0> ) ) ; trig . add ( new MethodInsnNode ( INVOKEVIRTUAL , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) ; trig . add ( new LdcInsnNode ( jumpinf . get ( i1 ) ) ) ; trig . add ( new MethodInsnNode ( INVOKEVIRTUAL , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) ; insns . insert ( i1 . getNext ( ) , trig ) ; } else { if ( i1 . getOpcode ( ) >= IRETURN && i1 . getOpcode ( ) <= RETURN ) { InsnList trig = new InsnList ( ) ; trig . add ( new VarInsnNode ( ALOAD , localnum ) ) ; trig . add ( new VarInsnNode ( ALOAD , <NUM_LIT:0> ) ) ; trig . add ( new MethodInsnNode ( INVOKEVIRTUAL , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) ; trig . add ( new MethodInsnNode ( INVOKEVIRTUAL , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) ; insns . insert ( i1 . getPrevious ( ) , trig ) ; } } } } insns . insert ( insns . getFirst ( ) , begin ) ; } else { InsnList insns = mn . instructions ; Iterator < AbstractInsnNode > i = insns . iterator ( ) ; while ( i . hasNext ( ) ) { AbstractInsnNode i1 = i . next ( ) ; if ( i1 instanceof MethodInsnNode ) { String owner = ( ( MethodInsnNode ) i1 ) . owner ; if ( ejbs . contains ( owner ) ) { InsnList il = new InsnList ( ) ; il . add ( new TypeInsnNode ( NEW , "<STR_LIT>" ) ) ; il . add ( new InsnNode ( DUP ) ) ; il . add ( new LdcInsnNode ( "<STR_LIT:/>" ) ) ; il . add ( new MethodInsnNode ( INVOKESPECIAL , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) ; il . add ( new VarInsnNode ( ALOAD , <NUM_LIT:0> ) ) ; il . add ( new MethodInsnNode ( INVOKEVIRTUAL , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) ; il . add ( new MethodInsnNode ( INVOKEVIRTUAL , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) ; il . add ( new MethodInsnNode ( INVOKEVIRTUAL , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) ; insns . insert ( i1 . getPrevious ( ) , il ) ; insns . insert ( i1 . getPrevious ( ) , new MethodInsnNode ( INVOKEVIRTUAL , ( ( MethodInsnNode ) i1 ) . owner , ( ( MethodInsnNode ) i1 ) . name , ( ( MethodInsnNode ) i1 ) . desc . replace ( "<STR_LIT:(>" , "<STR_LIT>" ) ) ) ; insns . remove ( i1 ) ; } } } } } } } } public void setNext ( ) { List < Event > event = stateMachine . getEvents ( ) ; List state = stateMachine . getStates ( ) ; for ( int i = <NUM_LIT:0> ; i < stateMachine . getStatesCount ( ) ; i ++ ) { String nexts = "<STR_LIT>" ; int sn = ( Integer ) state . get ( i ) ; int j ; for ( j = <NUM_LIT:0> ; j < event . size ( ) ; j ++ ) { if ( sn == event . get ( j ) . getHead ( ) ) { nexts = nexts + event . get ( j ) . getEvent ( ) + "<STR_LIT:->" + state . indexOf ( event . get ( j ) . getTail ( ) ) + "<STR_LIT:U+002C>" ; } } if ( nexts . length ( ) > <NUM_LIT:1> ) { nexts . subSequence ( <NUM_LIT:0> , nexts . length ( ) - <NUM_LIT:2> ) ; } next . add ( nexts ) ; System . out . println ( i + "<STR_LIT>" + nexts ) ; } } public boolean isTransaction ( MethodNode mn , String annotationDesc ) { if ( mn . visibleAnnotations != null ) { Iterator < AnnotationNode > i = mn . visibleAnnotations . iterator ( ) ; while ( i . hasNext ( ) ) { AnnotationNode an = i . next ( ) ; if ( annotationDesc . equals ( an . desc ) ) { return true ; } } } return false ; } public void setEjbs ( ClassNode cn ) { if ( cn . visibleAnnotations != null ) { Iterator < AnnotationNode > i = cn . visibleAnnotations . iterator ( ) ; while ( i . hasNext ( ) ) { AnnotationNode an = i . next ( ) ; if ( an . desc . contains ( "<STR_LIT>" ) || an . desc . contains ( "<STR_LIT>" ) ) { String ejb = an . values . get ( <NUM_LIT:1> ) . toString ( ) . split ( "<STR_LIT:/>" ) [ <NUM_LIT:0> ] ; ejbs . add ( ejb ) ; } } } for ( FieldNode fn : ( List < FieldNode > ) cn . fields ) { if ( fn . visibleAnnotations != null ) { Iterator < AnnotationNode > fi = fn . visibleAnnotations . iterator ( ) ; while ( fi . hasNext ( ) ) { AnnotationNode fa = fi . next ( ) ; if ( fa . desc . contains ( "<STR_LIT>" ) || fa . desc . contains ( "<STR_LIT>" ) ) { String ejb = fa . values . get ( <NUM_LIT:1> ) . toString ( ) . split ( "<STR_LIT:/>" ) [ <NUM_LIT:0> ] ; ejbs . add ( ejb ) ; } } } } } public void ExtractControlFlow ( String owner , final MethodNode mn ) throws AnalyzerException { Analyzer a = new Analyzer ( new BasicInterpreter ( ) ) { @ Override protected void newControlFlowEdge ( int src , int dst ) { controlflow . addFlow ( src , dst ) ; if ( src > dst ) { controlflow . getFlow ( src ) . setIsWhile ( true ) ; } } } ; a . analyze ( owner , mn ) ; } public void recognize_state ( int src , int last_state , InsnList insns ) { if ( src < stateMachine . getEnd ( ) ) { if ( stateMachine . getStates ( ) . contains ( src ) ) { stateMachine . addEvent ( new Event ( last_state , src , "<STR_LIT>" ) ) ; } else { AbstractInsnNode an = insns . get ( src ) ; if ( an instanceof MethodInsnNode ) { String owner = ( ( MethodInsnNode ) an ) . owner ; String e = "<STR_LIT>" + owner + "<STR_LIT:.>" + ( ( MethodInsnNode ) an ) . name ; if ( ejbs . contains ( owner ) ) { stateMachine . addState ( src ) ; stateMachine . addEvent ( new Event ( last_state , src , e ) ) ; last_state = src ; recognize_state ( src + <NUM_LIT:1> , last_state , insns ) ; } } else { if ( an instanceof JumpInsnNode ) { int dst = - <NUM_LIT:1> ; if ( an . getOpcode ( ) == GOTO ) { dst = ( Integer ) controlflow . getFlow ( src ) . dst . get ( <NUM_LIT:0> ) ; recognize_state ( dst + <NUM_LIT:1> , last_state , insns ) ; } else { stateMachine . addState ( src ) ; stateMachine . addEvent ( new Event ( last_state , src , "<STR_LIT>" ) ) ; if ( controlflow . getFlow ( src ) . isWhile ) { for ( int k = <NUM_LIT:0> ; k < controlflow . getDstSize ( src ) ; k ++ ) { dst = ( Integer ) controlflow . getDst ( src ) . get ( k ) ; if ( src < dst ) { stateMachine . addState ( dst ) ; stateMachine . addEvent ( new Event ( src , dst , "<STR_LIT>" + src + "<STR_LIT>" ) ) ; jumpinf . put ( insns . get ( dst ) , "<STR_LIT>" + src + "<STR_LIT>" ) ; recognize_state ( dst + <NUM_LIT:1> , dst , insns ) ; } else { stateMachine . addState ( dst ) ; stateMachine . addEvent ( new Event ( src , dst , "<STR_LIT>" + src + "<STR_LIT>" ) ) ; jumpinf . put ( insns . get ( dst ) , "<STR_LIT>" + src + "<STR_LIT>" ) ; recognize_state ( dst + <NUM_LIT:1> , dst , insns ) ; } } } else { for ( int k = <NUM_LIT:0> ; k < controlflow . getDstSize ( src ) ; k ++ ) { dst = ( Integer ) controlflow . getDst ( src ) . get ( k ) ; stateMachine . addState ( dst ) ; stateMachine . addEvent ( new Event ( src , dst , "<STR_LIT>" + src + "<STR_LIT:)>" + k ) ) ; jumpinf . put ( insns . get ( dst ) , "<STR_LIT>" + src + "<STR_LIT:)>" + k ) ; recognize_state ( dst + <NUM_LIT:1> , dst , insns ) ; } } } } else { if ( an . getOpcode ( ) >= IRETURN && an . getOpcode ( ) <= RETURN ) { stateMachine . addState ( src ) ; stateMachine . addEvent ( new Event ( last_state , src , "<STR_LIT>" ) ) ; } else { recognize_state ( src + <NUM_LIT:1> , last_state , insns ) ; } } } } } else { stateMachine . addState ( stateMachine . getEnd ( ) ) ; stateMachine . addEvent ( new Event ( last_state , src , "<STR_LIT>" ) ) ; } } public void mergeState ( ) { stateMachine . getStates ( ) . add ( <NUM_LIT:0> , stateMachine . getStart ( ) ) ; for ( int i = <NUM_LIT:0> ; i < stateMachine . getEvents ( ) . size ( ) ; i ++ ) { Event event = stateMachine . getEvents ( ) . get ( i ) ; if ( event . getEvent ( ) . isEmpty ( ) || event . getEvent ( ) . contains ( "<STR_LIT>" ) ) { int src = event . getHead ( ) ; int dst = event . getTail ( ) ; stateMachine . mergeStates ( src , dst ) ; stateMachine . getEvents ( ) . remove ( i ) ; } } } public void showEvent ( ) { for ( int i = <NUM_LIT:0> ; i < stateMachine . getEvents ( ) . size ( ) ; i ++ ) { Event event = stateMachine . getEvents ( ) . get ( i ) ; int src = event . getHead ( ) ; int dst = event . getTail ( ) ; System . out . println ( src + "<STR_LIT:->" + event . getEvent ( ) + "<STR_LIT:->" + dst ) ; } } public void ExtractMetaData ( ) { int states_count = stateMachine . getStatesCount ( ) ; List [ ] state = new LinkedList [ states_count ] ; for ( int i = <NUM_LIT:0> ; i < states_count ; i ++ ) state [ i ] = new LinkedList ( ) ; List s = stateMachine . getStates ( ) ; for ( int i = <NUM_LIT:0> ; i < states_count ; i ++ ) { System . out . println ( i + "<STR_LIT::>" + s . get ( i ) ) ; } List < Event > e = stateMachine . getEvents ( ) ; past = new LinkedList [ states_count ] ; for ( int i = <NUM_LIT:0> ; i < states_count ; i ++ ) past [ i ] = new LinkedList ( ) ; future = new LinkedList [ states_count ] ; for ( int i = <NUM_LIT:0> ; i < states_count ; i ++ ) future [ i ] = new LinkedList ( ) ; boolean changed = true ; while ( changed ) { changed = false ; for ( int i = <NUM_LIT:0> ; i < e . size ( ) ; i ++ ) { Event event = ( Event ) e . get ( i ) ; int head = event . getHead ( ) ; int tail = event . getTail ( ) ; String port = event . getPort ( ) ; int headindex = s . indexOf ( head ) ; int tailindex = s . indexOf ( tail ) ; if ( port != null && ! past [ tailindex ] . contains ( port ) ) { past [ tailindex ] . add ( port ) ; changed = true ; } if ( head != stateMachine . getStart ( ) && headindex != - <NUM_LIT:1> ) for ( int j = <NUM_LIT:0> ; j < past [ headindex ] . size ( ) ; j ++ ) { if ( ! past [ tailindex ] . contains ( past [ headindex ] . get ( j ) ) ) { past [ tailindex ] . add ( past [ headindex ] . get ( j ) ) ; changed = true ; } } } } changed = true ; while ( changed ) { changed = false ; for ( int i = e . size ( ) - <NUM_LIT:1> ; i >= <NUM_LIT:0> ; i -- ) { Event event = ( Event ) e . get ( i ) ; int head = event . getHead ( ) ; int tail = event . getTail ( ) ; String port = event . getPort ( ) ; int headindex = s . indexOf ( head ) ; int tailindex = s . indexOf ( tail ) ; if ( port != null && ! future [ headindex ] . contains ( port ) ) { future [ headindex ] . add ( port ) ; changed = true ; } if ( tail != stateMachine . getEnd ( ) ) for ( int j = <NUM_LIT:0> ; j < future [ tailindex ] . size ( ) ; j ++ ) { if ( ! future [ headindex ] . contains ( future [ tailindex ] . get ( j ) ) ) { future [ headindex ] . add ( future [ tailindex ] . get ( j ) ) ; changed = true ; } } } } for ( int i = <NUM_LIT:0> ; i < states_count ; i ++ ) { int k = <NUM_LIT:0> , p = <NUM_LIT:0> ; String sall = "<STR_LIT>" ; if ( future [ i ] . size ( ) > <NUM_LIT:0> ) { for ( k = <NUM_LIT:0> ; k < future [ i ] . size ( ) - <NUM_LIT:1> ; k ++ ) { sall = sall + future [ i ] . get ( k ) + "<STR_LIT:U+002C>" ; } sall = sall + future [ i ] . get ( k ) ; } sall = sall + "<STR_LIT:;>" ; if ( past [ i ] . size ( ) > <NUM_LIT:0> ) { for ( p = <NUM_LIT:0> ; p < past [ i ] . size ( ) - <NUM_LIT:1> ; p ++ ) { sall = sall + past [ i ] . get ( p ) + "<STR_LIT:U+002C>" ; } sall = sall + past [ i ] . get ( p ) ; } System . out . println ( i + "<STR_LIT::>" + sall ) ; stateall . add ( sall ) ; } } public static void showClassSource ( String file ) { FileInputStream is ; ClassReader cr ; try { is = new FileInputStream ( file ) ; cr = new ClassReader ( is ) ; TraceClassVisitor trace = new TraceClassVisitor ( new PrintWriter ( System . out ) ) ; cr . accept ( trace , ClassReader . EXPAND_FRAMES ) ; is . close ( ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } } public ClassVisitor getClassAdapter ( final ClassVisitor cvr ) { return new ClassNode ( ) { @ Override public void visitEnd ( ) { transform ( this ) ; this . accept ( cvr ) ; } } ; } protected static void begin_analyze ( File tempFile ) { if ( tempFile . isDirectory ( ) ) { File file [ ] = tempFile . listFiles ( ) ; for ( int i = <NUM_LIT:0> ; i < file . length ; i ++ ) { System . out . println ( "<STR_LIT>" + file [ i ] . getName ( ) ) ; begin_analyze ( file [ i ] ) ; } } else { try { if ( tempFile . getName ( ) . endsWith ( "<STR_LIT:.class>" ) ) { System . out . println ( tempFile . getName ( ) ) ; FileInputStream input = new FileInputStream ( tempFile . getAbsolutePath ( ) ) ; ProgramAnalyzer t = new ProgramAnalyzer ( ) ; ClassReader cr = new ClassReader ( input ) ; ClassWriter cw = new ClassWriter ( ClassWriter . COMPUTE_FRAMES ) ; ClassVisitor cv = t . getClassAdapter ( cw ) ; cr . accept ( cv , <NUM_LIT:0> ) ; byte [ ] b = cw . toByteArray ( ) ; FileOutputStream fout = new FileOutputStream ( new File ( tempFile . getAbsolutePath ( ) ) ) ; fout . write ( b ) ; fout . close ( ) ; } } catch ( Exception e ) { e . printStackTrace ( ) ; } } } public static void main ( String args [ ] ) { try { JarTool jarHelper = new JarTool ( ) ; File srcJar = new File ( "<STR_LIT>" ) ; File tempFile = new File ( "<STR_LIT>" ) ; tempFile . mkdir ( ) ; File destJar = new File ( "<STR_LIT>" ) ; jarHelper . unjarDir ( srcJar , tempFile ) ; ProgramAnalyzer . begin_analyze ( tempFile ) ; jarHelper . jarDir ( tempFile , destJar ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } } } </s>
|
<s> package javax . aejb ; import static java . lang . annotation . RetentionPolicy . RUNTIME ; import java . lang . annotation . ElementType ; import java . lang . annotation . Retention ; import java . lang . annotation . Target ; @ Retention ( RUNTIME ) @ Target ( ElementType . METHOD ) public @ interface Transaction { String name ( ) default "<STR_LIT>" ; String [ ] states ( ) default { "<STR_LIT>" } ; String [ ] next ( ) default { "<STR_LIT>" } ; } </s>
|
<s> package javax . aejb ; public interface TransactionTrigger { void trigger ( String objectId , String eventName ) ; void trigger ( String objectId ) ; } </s>
|
<s> package javax . aejb ; import java . lang . annotation . ElementType ; import java . lang . annotation . Retention ; import java . lang . annotation . Target ; import java . lang . annotation . RetentionPolicy ; @ Target ( ElementType . TYPE ) @ Retention ( RetentionPolicy . RUNTIME ) public @ interface Adaptive { } </s>
|
<s> package javax . aejb ; import static java . lang . annotation . ElementType . FIELD ; import static java . lang . annotation . RetentionPolicy . RUNTIME ; import java . lang . annotation . Retention ; import java . lang . annotation . Target ; @ Retention ( RUNTIME ) @ Target ( FIELD ) public @ interface AEjb { String name ( ) default "<STR_LIT>" ; Class beanInterface ( ) default java . lang . Object . class ; String beanName ( ) default "<STR_LIT>" ; String lookup ( ) default "<STR_LIT>" ; String mappedName ( ) default "<STR_LIT>" ; String description ( ) default "<STR_LIT>" ; } </s>
|
<s> package org . nju . artemis . aejb . client ; import java . lang . reflect . InvocationTargetException ; import javax . ejb . Remote ; import javax . ejb . Stateless ; import javax . naming . InitialContext ; import javax . naming . NamingException ; @ Stateless @ Remote ( AEjbClient . class ) public class AEjbClientBean implements AEjbClient { private Object createAEjbClient ( ) { try { return new InitialContext ( ) . lookup ( "<STR_LIT>" ) ; } catch ( NamingException e ) { e . printStackTrace ( ) ; } return null ; } @ Override public Object getAEjbClient ( ) { return createAEjbClient ( ) ; } @ Override public boolean blockAEjb ( String aejbName ) { Object client = createAEjbClient ( ) ; try { return ( Boolean ) client . getClass ( ) . getDeclaredMethod ( "<STR_LIT>" , String . class ) . invoke ( client , aejbName ) ; } catch ( IllegalArgumentException e ) { e . printStackTrace ( ) ; } catch ( SecurityException e ) { e . printStackTrace ( ) ; } catch ( IllegalAccessException e ) { e . printStackTrace ( ) ; } catch ( InvocationTargetException e ) { e . printStackTrace ( ) ; } catch ( NoSuchMethodException e ) { e . printStackTrace ( ) ; } return false ; } @ Override public boolean resumeAEjb ( String aejbName ) { Object client = createAEjbClient ( ) ; try { return ( Boolean ) client . getClass ( ) . getDeclaredMethod ( "<STR_LIT>" , String . class ) . invoke ( client , aejbName ) ; } catch ( IllegalArgumentException e ) { e . printStackTrace ( ) ; } catch ( SecurityException e ) { e . printStackTrace ( ) ; } catch ( IllegalAccessException e ) { e . printStackTrace ( ) ; } catch ( InvocationTargetException e ) { e . printStackTrace ( ) ; } catch ( NoSuchMethodException e ) { e . printStackTrace ( ) ; } return false ; } @ Override public boolean switchAEjb ( String fromName , String toName , String protocol ) { Object client = createAEjbClient ( ) ; try { return ( Boolean ) client . getClass ( ) . getDeclaredMethod ( "<STR_LIT>" , String . class , String . class , String . class ) . invoke ( client , fromName , toName , protocol ) ; } catch ( IllegalArgumentException e ) { e . printStackTrace ( ) ; } catch ( SecurityException e ) { e . printStackTrace ( ) ; } catch ( IllegalAccessException e ) { e . printStackTrace ( ) ; } catch ( InvocationTargetException e ) { e . printStackTrace ( ) ; } catch ( NoSuchMethodException e ) { e . printStackTrace ( ) ; } return false ; } @ Override public boolean replaceAEjb ( String fromName , String toName , String protocol ) { return false ; } } </s>
|
<s> package org . nju . artemis . aejb . client ; public interface AEjbClient { Object getAEjbClient ( ) ; boolean blockAEjb ( String aejbName ) ; boolean resumeAEjb ( String aejbName ) ; boolean switchAEjb ( String fromName , String toName , String protocol ) ; boolean replaceAEjb ( String fromName , String toName , String protocol ) ; } </s>
|
<s> package org . eclipse . zest . tests ; import junit . framework . TestCase ; import org . eclipse . draw2d . BorderLayout ; import org . eclipse . draw2d . Ellipse ; import org . eclipse . draw2d . IFigure ; import org . eclipse . draw2d . Label ; import org . eclipse . jface . viewers . IStructuredContentProvider ; import org . eclipse . jface . viewers . LabelProvider ; import org . eclipse . jface . viewers . Viewer ; import org . eclipse . swt . SWT ; import org . eclipse . swt . widgets . Shell ; import org . eclipse . zest . core . viewers . GraphViewer ; import org . eclipse . zest . core . viewers . IFigureProvider ; import org . eclipse . zest . core . viewers . IGraphContentProvider ; import org . eclipse . zest . core . widgets . custom . CGraphNode ; import org . eclipse . zest . tests . GraphViewerTests . SampleGraphContentProvider ; import org . eclipse . zest . tests . GraphViewerTests . SampleGraphEntityContentProvider ; public class IFigureProviderTests extends TestCase { private GraphViewer viewer ; private Shell shell ; public void setUp ( ) { shell = new Shell ( ) ; viewer = new GraphViewer ( shell , SWT . NONE ) ; } public void testWithDestinationProvider ( ) { testWith ( new DestinationContentProvider ( ) ) ; } public void testWithSourceProvider ( ) { testWith ( new SourceContentProvider ( ) ) ; } public void testWithGraphProvider ( ) { testWith ( new SampleGraphEntityContentProvider ( ) ) ; } public void testWithGraphEntityProvider ( ) { testWith ( new SampleGraphContentProvider ( ) ) ; } private void testWith ( IStructuredContentProvider contentProvider ) { viewer . setContentProvider ( contentProvider ) ; viewer . setLabelProvider ( new CustomLabelProvider ( ) ) ; viewer . setInput ( new Object ( ) ) ; StringBuffer buffer = new StringBuffer ( ) ; for ( int i = <NUM_LIT:0> ; i < viewer . getGraphControl ( ) . getNodes ( ) . size ( ) ; i ++ ) { CGraphNode n = ( CGraphNode ) viewer . getGraphControl ( ) . getNodes ( ) . get ( i ) ; buffer . append ( ( ( Label ) n . getFigure ( ) . getChildren ( ) . get ( <NUM_LIT:0> ) ) . getText ( ) ) ; } String string = buffer . toString ( ) ; assertTrue ( "<STR_LIT>" , string . contains ( "<STR_LIT:1>" ) ) ; assertTrue ( "<STR_LIT>" , string . contains ( "<STR_LIT:2>" ) ) ; assertTrue ( "<STR_LIT>" , string . contains ( "<STR_LIT:3>" ) ) ; } private class DestinationContentProvider implements IGraphContentProvider { public void dispose ( ) { } public void inputChanged ( Viewer arg0 , Object arg1 , Object arg2 ) { } public Object getDestination ( Object r ) { if ( r . equals ( "<STR_LIT>" ) ) return "<STR_LIT:2>" ; if ( r . equals ( "<STR_LIT>" ) ) return "<STR_LIT:3>" ; if ( r . equals ( "<STR_LIT>" ) ) return "<STR_LIT:1>" ; return null ; } public Object [ ] getElements ( Object arg0 ) { return new String [ ] { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ; } public Object getSource ( Object r ) { return null ; } } private class SourceContentProvider implements IGraphContentProvider { public void dispose ( ) { } public void inputChanged ( Viewer arg0 , Object arg1 , Object arg2 ) { } public Object getDestination ( Object r ) { return null ; } public Object [ ] getElements ( Object arg0 ) { return new String [ ] { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ; } public Object getSource ( Object r ) { if ( r . equals ( "<STR_LIT>" ) ) return "<STR_LIT:1>" ; if ( r . equals ( "<STR_LIT>" ) ) return "<STR_LIT:2>" ; if ( r . equals ( "<STR_LIT>" ) ) return "<STR_LIT:3>" ; return null ; } } private class CustomLabelProvider extends LabelProvider implements IFigureProvider { public String getText ( Object node ) { return node . toString ( ) ; } public IFigure getFigure ( Object node ) { Ellipse e = new Ellipse ( ) ; e . setSize ( <NUM_LIT> , <NUM_LIT> ) ; e . setLayoutManager ( new BorderLayout ( ) ) ; e . add ( new Label ( node . toString ( ) ) , BorderLayout . CENTER ) ; return e ; } } } </s>
|
<s> package org . eclipse . zest . tests ; import org . eclipse . zest . tests . cloudio . TagCloudTests ; import org . eclipse . zest . tests . cloudio . TagCloudViewerTests ; import org . eclipse . zest . tests . dot . DotExportSuite ; import org . eclipse . zest . tests . dot . DotImportSuite ; import org . junit . runner . RunWith ; import org . junit . runners . Suite ; @ RunWith ( Suite . class ) @ Suite . SuiteClasses ( { GraphTests . class , GraphSelectionTests . class , GraphViewerTests . class , IFigureProviderTests . class , LayoutAlgorithmTests . class , DotExportSuite . class , DotImportSuite . class , TagCloudTests . class , TagCloudViewerTests . class } ) public final class AllHeadlessTests { } </s>
|
<s> package org . eclipse . zest . tests ; import junit . framework . Assert ; import org . eclipse . core . runtime . Platform ; import org . eclipse . zest . tests . dot . TestDotDirStore ; import org . eclipse . zest . tests . dot . TestDotExtractor ; import org . eclipse . zest . tests . dot . TestZestGraphView ; import org . junit . Before ; import org . junit . runner . RunWith ; import org . junit . runners . Suite ; @ RunWith ( Suite . class ) @ Suite . SuiteClasses ( { TestDotDirStore . class , TestDotExtractor . class , TestZestGraphView . class } ) public final class AllUiTests { @ Before public void setup ( ) { if ( ! Platform . isRunning ( ) ) { Assert . fail ( "<STR_LIT>" ) ; } } } </s>
|
<s> package org . eclipse . zest . tests ; import java . util . ArrayList ; import java . util . List ; import junit . framework . Assert ; import junit . framework . TestCase ; import org . eclipse . jface . util . DelegatingDragAdapter ; import org . eclipse . jface . viewers . IContentProvider ; import org . eclipse . jface . viewers . ISelectionChangedListener ; import org . eclipse . jface . viewers . SelectionChangedEvent ; import org . eclipse . jface . viewers . StructuredSelection ; import org . eclipse . jface . viewers . Viewer ; import org . eclipse . jface . viewers . ViewerFilter ; import org . eclipse . swt . SWT ; import org . eclipse . swt . dnd . DND ; import org . eclipse . swt . dnd . DropTarget ; import org . eclipse . swt . dnd . TextTransfer ; import org . eclipse . swt . dnd . Transfer ; import org . eclipse . swt . widgets . Event ; import org . eclipse . swt . widgets . Shell ; import org . eclipse . zest . core . viewers . GraphViewer ; import org . eclipse . zest . core . viewers . IGraphContentProvider ; import org . eclipse . zest . core . viewers . IGraphEntityContentProvider ; import org . eclipse . zest . core . widgets . Graph ; import org . eclipse . zest . core . widgets . GraphConnection ; import org . eclipse . zest . core . widgets . GraphItem ; import org . eclipse . zest . core . widgets . GraphNode ; public class GraphViewerTests extends TestCase { private GraphViewer viewer ; private Shell shell ; public void setUp ( ) { shell = new Shell ( ) ; viewer = new GraphViewer ( shell , SWT . NONE ) ; } public void testDisposalWithDropTarget ( ) { new DropTarget ( viewer . getGraphControl ( ) , DND . DROP_MOVE | DND . DROP_COPY ) ; shell . dispose ( ) ; Assert . assertTrue ( "<STR_LIT>" , viewer . getControl ( ) . isDisposed ( ) ) ; } public void testDisposalWithDragSource ( ) { viewer . addDragSupport ( DND . DROP_MOVE , new Transfer [ ] { TextTransfer . getInstance ( ) } , new DelegatingDragAdapter ( ) ) ; shell . dispose ( ) ; Assert . assertTrue ( "<STR_LIT>" , viewer . getControl ( ) . isDisposed ( ) ) ; } public void testCreateFromGraph ( ) { Graph g = new Graph ( shell , SWT . NONE ) ; new GraphConnection ( g , SWT . NONE , new GraphNode ( g , SWT . NONE ) , new GraphNode ( g , SWT . NONE ) ) ; GraphViewer v = new GraphViewer ( g ) ; Assert . assertEquals ( <NUM_LIT:2> , v . getGraphControl ( ) . getNodes ( ) . size ( ) ) ; Assert . assertEquals ( <NUM_LIT:1> , v . getGraphControl ( ) . getConnections ( ) . size ( ) ) ; } public void testFindGraphItem ( ) { Assert . assertNull ( "<STR_LIT>" , viewer . findGraphItem ( new Integer ( <NUM_LIT:5> ) ) ) ; } public void testValidSelection ( ) { Graph graph = new Graph ( shell , SWT . NONE ) ; GraphNode n1 = new GraphNode ( graph , SWT . NONE ) ; GraphNode n2 = new GraphNode ( graph , SWT . NONE ) ; GraphConnection c = new GraphConnection ( graph , SWT . NONE , n1 , n2 ) ; graph . setSelection ( new GraphItem [ ] { n1 , n2 , c } ) ; GraphViewer viewer = new GraphViewer ( graph ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:0> , ( ( StructuredSelection ) viewer . getSelection ( ) ) . size ( ) ) ; n1 . setData ( "<STR_LIT:1>" ) ; n2 . setData ( "<STR_LIT:2>" ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:2> , ( ( StructuredSelection ) viewer . getSelection ( ) ) . size ( ) ) ; } public void testPostSelectionListener ( ) { final List < SelectionChangedEvent > selected = new ArrayList < SelectionChangedEvent > ( ) ; viewer . addPostSelectionChangedListener ( new ISelectionChangedListener ( ) { public void selectionChanged ( SelectionChangedEvent event ) { selected . add ( event ) ; } } ) ; viewer . getControl ( ) . notifyListeners ( SWT . Selection , new Event ( ) ) ; assertFalse ( "<STR_LIT>" , selected . isEmpty ( ) ) ; } public void testViewerFilterWithGraphEntityContentProvider ( ) { testViewerFilter ( new SampleGraphEntityContentProvider ( ) ) ; } public void testViewerFilterWithGraphContentProvider ( ) { testViewerFilter ( new SampleGraphContentProvider ( ) ) ; } public void testViewerFilter ( IContentProvider contentProvider ) { viewer . setContentProvider ( contentProvider ) ; viewer . setInput ( new Object ( ) ) ; assertNodesAndConnections ( <NUM_LIT:3> , <NUM_LIT:3> ) ; viewer . setFilters ( new ViewerFilter [ ] { new SampleBooleanFilter ( false ) } ) ; assertNodesAndConnections ( <NUM_LIT:0> , <NUM_LIT:0> ) ; viewer . setFilters ( new ViewerFilter [ ] { new SampleBooleanFilter ( true ) } ) ; assertNodesAndConnections ( <NUM_LIT:3> , <NUM_LIT:3> ) ; } private void assertNodesAndConnections ( int nodes , int connections ) { assertEquals ( nodes , viewer . getGraphControl ( ) . getNodes ( ) . size ( ) ) ; assertEquals ( connections , viewer . getGraphControl ( ) . getConnections ( ) . size ( ) ) ; } static class SampleBooleanFilter extends ViewerFilter { private final boolean filter ; SampleBooleanFilter ( boolean filter ) { this . filter = filter ; } @ Override public boolean select ( Viewer viewer , Object parentElement , Object element ) { return filter ; } } static class SampleGraphContentProvider implements IGraphContentProvider { public void dispose ( ) { } public void inputChanged ( Viewer arg0 , Object arg1 , Object arg2 ) { } public Object getDestination ( Object r ) { if ( r . equals ( "<STR_LIT>" ) ) return "<STR_LIT:2>" ; if ( r . equals ( "<STR_LIT>" ) ) return "<STR_LIT:3>" ; if ( r . equals ( "<STR_LIT>" ) ) return "<STR_LIT:1>" ; return null ; } public Object [ ] getElements ( Object arg0 ) { return new String [ ] { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ; } public Object getSource ( Object r ) { if ( r . equals ( "<STR_LIT>" ) ) return "<STR_LIT:1>" ; if ( r . equals ( "<STR_LIT>" ) ) return "<STR_LIT:2>" ; if ( r . equals ( "<STR_LIT>" ) ) return "<STR_LIT:3>" ; return null ; } } static class SampleGraphEntityContentProvider implements IGraphEntityContentProvider { public Object [ ] getConnectedTo ( Object entity ) { if ( entity . equals ( "<STR_LIT:1>" ) ) { return new Object [ ] { "<STR_LIT:2>" } ; } if ( entity . equals ( "<STR_LIT:2>" ) ) { return new Object [ ] { "<STR_LIT:3>" } ; } if ( entity . equals ( "<STR_LIT:3>" ) ) { return new Object [ ] { "<STR_LIT:2>" } ; } return null ; } public Object [ ] getElements ( Object inputElement ) { return new String [ ] { "<STR_LIT:1>" , "<STR_LIT:2>" , "<STR_LIT:3>" } ; } public double getWeight ( Object entity1 , Object entity2 ) { return <NUM_LIT:0> ; } public void dispose ( ) { } public void inputChanged ( Viewer viewer , Object oldInput , Object newInput ) { } } } </s>
|
<s> package org . eclipse . zest . tests . dot ; import junit . framework . Assert ; import org . eclipse . swt . SWT ; import org . eclipse . swt . layout . FillLayout ; import org . eclipse . swt . widgets . Shell ; import org . eclipse . zest . core . widgets . Graph ; import org . eclipse . zest . core . widgets . GraphConnection ; import org . eclipse . zest . core . widgets . GraphNode ; import org . eclipse . zest . core . widgets . ZestStyles ; import org . eclipse . zest . internal . dot . DotImport ; import org . eclipse . zest . internal . dot . GraphCreatorInterpreter ; import org . eclipse . zest . layouts . algorithms . TreeLayoutAlgorithm ; import org . junit . Test ; public final class TestSnippetDotImport { private final GraphCreatorInterpreter interpreter = new GraphCreatorInterpreter ( ) ; @ Test public void sampleUsage ( ) { Shell shell = new Shell ( ) ; Graph graph = new Graph ( shell , SWT . NONE ) ; new DotImport ( "<STR_LIT>" ) . into ( graph ) ; assertNodesEdgesCount ( <NUM_LIT:3> , <NUM_LIT:2> , graph ) ; new DotImport ( "<STR_LIT>" ) . into ( graph ) ; assertNodesEdgesCount ( <NUM_LIT:5> , <NUM_LIT:4> , graph ) ; } @ Test public void addToEmptyGraph ( ) { Shell shell = new Shell ( ) ; Graph graph = new Graph ( shell , SWT . NONE ) ; graph . setLayoutAlgorithm ( new TreeLayoutAlgorithm ( ) , true ) ; Assert . assertEquals ( <NUM_LIT:0> , graph . getNodes ( ) . size ( ) ) ; Assert . assertEquals ( <NUM_LIT:0> , graph . getConnections ( ) . size ( ) ) ; new DotImport ( "<STR_LIT>" ) . into ( graph ) ; assertNodesEdgesCount ( <NUM_LIT:2> , <NUM_LIT:1> , graph ) ; new DotImport ( "<STR_LIT>" ) . into ( graph ) ; assertNodesEdgesCount ( <NUM_LIT:4> , <NUM_LIT:1> , graph ) ; new DotImport ( "<STR_LIT>" ) . into ( graph ) ; assertNodesEdgesCount ( <NUM_LIT:6> , <NUM_LIT:2> , graph ) ; Assert . assertEquals ( ZestStyles . CONNECTIONS_DIRECTED , graph . getConnectionStyle ( ) ) ; } @ Test public void useExistingNodes ( ) { Shell shell = new Shell ( ) ; Graph graph = new DotImport ( "<STR_LIT>" ) . newGraphInstance ( shell , SWT . NONE ) ; assertNodesEdgesCount ( <NUM_LIT:2> , <NUM_LIT:1> , graph ) ; new DotImport ( "<STR_LIT>" ) . into ( graph ) ; assertNodesEdgesCount ( <NUM_LIT:3> , <NUM_LIT:2> , graph ) ; new DotImport ( "<STR_LIT>" ) . into ( graph ) ; assertNodesEdgesCount ( <NUM_LIT:4> , <NUM_LIT:3> , graph ) ; } @ Test public void useExistingLabeledNodes ( ) { Shell shell = new Shell ( ) ; Graph graph = new DotImport ( "<STR_LIT>" ) . newGraphInstance ( shell , SWT . NONE ) ; assertNodesEdgesCount ( <NUM_LIT:2> , <NUM_LIT:0> , graph ) ; new DotImport ( "<STR_LIT>" ) . into ( graph ) ; assertNodesEdgesCount ( <NUM_LIT:2> , <NUM_LIT:1> , graph ) ; new DotImport ( "<STR_LIT>" ) . into ( graph ) ; assertNodesEdgesCount ( <NUM_LIT:3> , <NUM_LIT:2> , graph ) ; Assert . assertEquals ( ZestStyles . CONNECTIONS_DIRECTED , graph . getConnectionStyle ( ) ) ; } @ Test public void undirectedEdgeDotSyntax ( ) { Shell shell = new Shell ( ) ; Graph graph = new Graph ( shell , SWT . NONE ) ; new DotImport ( "<STR_LIT>" ) . into ( graph ) ; assertNodesEdgesCount ( <NUM_LIT:2> , <NUM_LIT:1> , graph ) ; new DotImport ( "<STR_LIT>" ) . into ( graph ) ; assertNodesEdgesCount ( <NUM_LIT:3> , <NUM_LIT:2> , graph ) ; Assert . assertEquals ( ZestStyles . CONNECTIONS_SOLID , graph . getConnectionStyle ( ) ) ; } @ Test public void addLayoutAlgorithm ( ) { Shell shell = new Shell ( ) ; Graph graph = new Graph ( shell , SWT . NONE ) ; Assert . assertEquals ( null , graph . getLayoutAlgorithm ( ) ) ; new DotImport ( "<STR_LIT>" ) . into ( graph ) ; Assert . assertEquals ( TreeLayoutAlgorithm . class , graph . getLayoutAlgorithm ( ) . getClass ( ) ) ; Assert . assertEquals ( TreeLayoutAlgorithm . LEFT_RIGHT , ( ( TreeLayoutAlgorithm ) ( graph . getLayoutAlgorithm ( ) ) ) . getDirection ( ) ) ; new DotImport ( "<STR_LIT>" ) . into ( graph ) ; Assert . assertEquals ( TreeLayoutAlgorithm . class , graph . getLayoutAlgorithm ( ) . getClass ( ) ) ; Assert . assertEquals ( TreeLayoutAlgorithm . TOP_DOWN , ( ( TreeLayoutAlgorithm ) ( graph . getLayoutAlgorithm ( ) ) ) . getDirection ( ) ) ; } @ Test public void addStyledEdge ( ) { Shell shell = new Shell ( ) ; Graph graph = new Graph ( shell , SWT . NONE ) ; Assert . assertEquals ( ZestStyles . NONE , graph . getConnectionStyle ( ) ) ; assertNodesEdgesCount ( <NUM_LIT:0> , <NUM_LIT:0> , graph ) ; new DotImport ( "<STR_LIT>" ) . into ( graph ) ; assertNodesEdgesCount ( <NUM_LIT:2> , <NUM_LIT:1> , graph ) ; GraphConnection edge = ( GraphConnection ) graph . getConnections ( ) . get ( <NUM_LIT:0> ) ; Assert . assertEquals ( SWT . LINE_DASH , edge . getLineStyle ( ) ) ; Assert . assertEquals ( "<STR_LIT>" , edge . getText ( ) ) ; new DotImport ( "<STR_LIT>" ) . into ( graph ) ; assertNodesEdgesCount ( <NUM_LIT:3> , <NUM_LIT:2> , graph ) ; edge = ( GraphConnection ) graph . getConnections ( ) . get ( <NUM_LIT:1> ) ; Assert . assertEquals ( SWT . LINE_DOT , edge . getLineStyle ( ) ) ; Assert . assertEquals ( "<STR_LIT>" , edge . getText ( ) ) ; } @ Test public void addStyledNode ( ) { Shell shell = new Shell ( ) ; Graph graph = new Graph ( shell , SWT . NONE ) ; Assert . assertEquals ( ZestStyles . NONE , graph . getConnectionStyle ( ) ) ; assertNodesEdgesCount ( <NUM_LIT:0> , <NUM_LIT:0> , graph ) ; new DotImport ( "<STR_LIT>" ) . into ( graph ) ; assertNodesEdgesCount ( <NUM_LIT:1> , <NUM_LIT:0> , graph ) ; GraphNode node = ( GraphNode ) graph . getNodes ( ) . get ( <NUM_LIT:0> ) ; Assert . assertEquals ( "<STR_LIT:one>" , node . getText ( ) ) ; new DotImport ( "<STR_LIT>" ) . into ( graph ) ; assertNodesEdgesCount ( <NUM_LIT:3> , <NUM_LIT:0> , graph ) ; Assert . assertEquals ( "<STR_LIT:two>" , ( ( GraphNode ) graph . getNodes ( ) . get ( <NUM_LIT:1> ) ) . getText ( ) ) ; Assert . assertEquals ( "<STR_LIT>" , ( ( GraphNode ) graph . getNodes ( ) . get ( <NUM_LIT:2> ) ) . getText ( ) ) ; } private void assertNodesEdgesCount ( int n , int e , Graph graph ) { Assert . assertEquals ( n , graph . getNodes ( ) . size ( ) ) ; Assert . assertEquals ( e , graph . getConnections ( ) . size ( ) ) ; } static void open ( final Shell shell ) { shell . setText ( "<STR_LIT>" ) ; shell . setLayout ( new FillLayout ( ) ) ; shell . setSize ( <NUM_LIT> , <NUM_LIT> ) ; shell . open ( ) ; while ( ! shell . isDisposed ( ) ) { while ( ! shell . getDisplay ( ) . readAndDispatch ( ) ) { shell . getDisplay ( ) . sleep ( ) ; } } } } </s>
|
<s> package org . eclipse . zest . tests . dot ; import static org . eclipse . zest . tests . dot . DotImportTestUtils . RESOURCES_TESTS ; import static org . eclipse . zest . tests . dot . DotImportTestUtils . importFrom ; import java . io . File ; import org . eclipse . swt . SWT ; import org . eclipse . swt . widgets . Shell ; import org . eclipse . zest . internal . dot . DotImport ; import org . junit . Test ; public final class TestBasicDotImport { @ Test public void sampleGraph ( ) { importFrom ( new File ( RESOURCES_TESTS + "<STR_LIT>" ) ) ; } @ Test public void basicGraph ( ) { importFrom ( new File ( RESOURCES_TESTS + "<STR_LIT>" ) ) ; } @ Test public void directedGraph ( ) { importFrom ( new File ( RESOURCES_TESTS + "<STR_LIT>" ) ) ; } @ Test public void undirectedGraph ( ) { importFrom ( new File ( RESOURCES_TESTS + "<STR_LIT>" ) ) ; } @ Test public void labeledGraph ( ) { importFrom ( new File ( RESOURCES_TESTS + "<STR_LIT>" ) ) ; } @ Test public void styledGraph ( ) { importFrom ( new File ( RESOURCES_TESTS + "<STR_LIT>" ) ) ; } @ Test public void globalNodeGraph ( ) { importFrom ( new File ( RESOURCES_TESTS + "<STR_LIT>" ) ) ; } @ Test public void globalEdgeGraph ( ) { importFrom ( new File ( RESOURCES_TESTS + "<STR_LIT>" ) ) ; } @ Test public void attributesGraph ( ) { importFrom ( new File ( RESOURCES_TESTS + "<STR_LIT>" ) ) ; } @ Test ( expected = IllegalArgumentException . class ) public void faultyGraphInstance ( ) { new DotImport ( "<STR_LIT>" ) . newGraphInstance ( new Shell ( ) , SWT . NONE ) ; } @ Test ( expected = IllegalArgumentException . class ) public void faultyGraphClass ( ) { new DotImport ( "<STR_LIT>" ) . newGraphInstance ( new Shell ( ) , SWT . NONE ) ; } } </s>
|
<s> package org . eclipse . zest . tests . dot ; import static org . junit . Assert . assertEquals ; import junit . framework . Assert ; import org . eclipse . swt . SWT ; import org . eclipse . swt . layout . FillLayout ; import org . eclipse . swt . widgets . Shell ; import org . eclipse . zest . core . widgets . Graph ; import org . eclipse . zest . dot . DotGraph ; import org . junit . Test ; public final class TestDotGraph { @ Test public void sampleUsage ( ) { Shell shell = new Shell ( ) ; DotGraph graph = new DotGraph ( "<STR_LIT>" , shell , SWT . NONE ) ; assertNodesEdgesCount ( <NUM_LIT:2> , <NUM_LIT:1> , graph ) ; graph . add ( "<STR_LIT>" ) ; assertNodesEdgesCount ( <NUM_LIT:4> , <NUM_LIT:3> , graph ) ; graph . add ( "<STR_LIT>" ) ; assertNodesEdgesCount ( <NUM_LIT:6> , <NUM_LIT:5> , graph ) ; } @ Test public void graphAttributesToDataMapping ( ) { String dotInput = "<STR_LIT>" ; DotGraph graph = new DotGraph ( dotInput , new Shell ( ) , SWT . NONE ) ; assertEquals ( "<STR_LIT>" , graph . getGraph ( ) . getData ( "<STR_LIT:key1>" ) ) ; assertEquals ( "<STR_LIT>" , graph . getGraph ( ) . getData ( "<STR_LIT>" ) ) ; } private void assertNodesEdgesCount ( int n , int e , Graph graph ) { Assert . assertEquals ( n , graph . getNodes ( ) . size ( ) ) ; Assert . assertEquals ( e , graph . getConnections ( ) . size ( ) ) ; } static void open ( final Shell shell ) { shell . setText ( "<STR_LIT>" ) ; shell . setLayout ( new FillLayout ( ) ) ; shell . setSize ( <NUM_LIT> , <NUM_LIT> ) ; shell . open ( ) ; while ( ! shell . isDisposed ( ) ) { while ( ! shell . getDisplay ( ) . readAndDispatch ( ) ) { shell . getDisplay ( ) . sleep ( ) ; } } } } </s>
|
<s> package org . eclipse . zest . tests . dot ; import org . eclipse . ui . plugin . AbstractUIPlugin ; import org . osgi . framework . BundleContext ; public class DotUiTestsActivator extends AbstractUIPlugin { public static final String PLUGIN_ID = "<STR_LIT>" ; private static DotUiTestsActivator plugin ; public DotUiTestsActivator ( ) { } public void start ( BundleContext context ) throws Exception { super . start ( context ) ; plugin = this ; } public void stop ( BundleContext context ) throws Exception { plugin = null ; super . stop ( context ) ; } public static DotUiTestsActivator getDefault ( ) { return plugin ; } } </s>
|
<s> package org . eclipse . zest . tests . dot ; import java . io . File ; import junit . framework . Assert ; public final class DotTestUtils { private DotTestUtils ( ) { } public static void wipeOutput ( final File location , final String suffix ) { String [ ] files = location . list ( ) ; int deleted = <NUM_LIT:0> ; if ( files != null && files . length > <NUM_LIT:0> ) { for ( String file : files ) { File deletionCandidate = new File ( location , file ) ; if ( ! deletionCandidate . isHidden ( ) && ! deletionCandidate . getName ( ) . startsWith ( "<STR_LIT:.>" ) ) { boolean delete = deletionCandidate . delete ( ) ; if ( delete ) { deleted ++ ; } } } int dotFiles = countFilesWithSuffix ( location , suffix ) ; Assert . assertEquals ( "<STR_LIT>" , <NUM_LIT:0> , dotFiles ) ; System . out . println ( String . format ( "<STR_LIT>" , deleted , location ) ) ; } } private static int countFilesWithSuffix ( final File folder , final String suffix ) { String [ ] list = folder . list ( ) ; int dotFiles = <NUM_LIT:0> ; for ( String name : list ) { if ( name . endsWith ( suffix ) ) { dotFiles ++ ; } } return dotFiles ; } } </s>
|
<s> package org . eclipse . zest . tests . dot . test_data ; import org . eclipse . swt . SWT ; import org . eclipse . swt . layout . FillLayout ; import org . eclipse . swt . widgets . Composite ; import org . eclipse . swt . widgets . Display ; import org . eclipse . swt . widgets . Shell ; import org . eclipse . zest . core . widgets . Graph ; import org . eclipse . zest . core . widgets . GraphConnection ; import org . eclipse . zest . core . widgets . GraphNode ; import org . eclipse . zest . core . widgets . ZestStyles ; import org . eclipse . zest . layouts . algorithms . TreeLayoutAlgorithm ; public class SimpleDigraph extends Graph { public SimpleDigraph ( final Composite parent , final int style ) { super ( parent , style ) ; setConnectionStyle ( ZestStyles . CONNECTIONS_DIRECTED ) ; setLayoutAlgorithm ( new TreeLayoutAlgorithm ( ) , true ) ; GraphNode n1 = new GraphNode ( this , SWT . NONE , "<STR_LIT:1>" ) ; GraphNode n2 = new GraphNode ( this , SWT . NONE , "<STR_LIT:2>" ) ; GraphNode n3 = new GraphNode ( this , SWT . NONE , "<STR_LIT:3>" ) ; new GraphConnection ( this , SWT . NONE , n1 , n2 ) ; new GraphConnection ( this , SWT . NONE , n2 , n3 ) ; } public static void main ( final String [ ] args ) { Display d = new Display ( ) ; Shell shell = new Shell ( d ) ; shell . setText ( SimpleDigraph . class . getSimpleName ( ) ) ; shell . setLayout ( new FillLayout ( ) ) ; shell . setSize ( <NUM_LIT> , <NUM_LIT> ) ; new SimpleDigraph ( shell , SWT . NONE ) ; shell . open ( ) ; while ( ! shell . isDisposed ( ) ) { while ( ! d . readAndDispatch ( ) ) { d . sleep ( ) ; } } } } </s>
|
<s> package org . eclipse . zest . tests . dot . test_data ; import org . eclipse . swt . SWT ; import org . eclipse . swt . layout . FillLayout ; import org . eclipse . swt . widgets . Composite ; import org . eclipse . swt . widgets . Display ; import org . eclipse . swt . widgets . Shell ; import org . eclipse . zest . core . widgets . Graph ; import org . eclipse . zest . core . widgets . GraphConnection ; import org . eclipse . zest . core . widgets . GraphNode ; import org . eclipse . zest . layouts . algorithms . TreeLayoutAlgorithm ; public class SimpleGraph extends Graph { public SimpleGraph ( final Composite parent , final int style ) { super ( parent , style ) ; setLayoutAlgorithm ( new TreeLayoutAlgorithm ( ) , true ) ; GraphNode n1 = new GraphNode ( this , SWT . NONE , "<STR_LIT:1>" ) ; GraphNode n2 = new GraphNode ( this , SWT . NONE , "<STR_LIT:2>" ) ; GraphNode n3 = new GraphNode ( this , SWT . NONE , "<STR_LIT:3>" ) ; new GraphConnection ( this , SWT . NONE , n1 , n2 ) ; new GraphConnection ( this , SWT . NONE , n1 , n3 ) ; } public static void main ( final String [ ] args ) { Display d = new Display ( ) ; Shell shell = new Shell ( d ) ; shell . setText ( SimpleGraph . class . getSimpleName ( ) ) ; shell . setLayout ( new FillLayout ( ) ) ; shell . setSize ( <NUM_LIT> , <NUM_LIT> ) ; new SimpleGraph ( shell , SWT . NONE ) ; shell . open ( ) ; while ( ! shell . isDisposed ( ) ) { while ( ! d . readAndDispatch ( ) ) { d . sleep ( ) ; } } } } </s>
|
<s> package org . eclipse . zest . tests . dot . test_data ; import org . eclipse . swt . SWT ; import org . eclipse . swt . layout . FillLayout ; import org . eclipse . swt . widgets . Composite ; import org . eclipse . swt . widgets . Display ; import org . eclipse . swt . widgets . Shell ; import org . eclipse . zest . core . widgets . Graph ; import org . eclipse . zest . core . widgets . GraphConnection ; import org . eclipse . zest . core . widgets . GraphNode ; import org . eclipse . zest . core . widgets . ZestStyles ; import org . eclipse . zest . layouts . algorithms . TreeLayoutAlgorithm ; public class SampleGraph extends Graph { public SampleGraph ( final Composite parent , final int style ) { super ( parent , style ) ; setConnectionStyle ( ZestStyles . CONNECTIONS_DIRECTED ) ; setLayoutAlgorithm ( new TreeLayoutAlgorithm ( ) , true ) ; GraphNode n1 = new GraphNode ( this , SWT . NONE , "<STR_LIT>" ) ; GraphNode n2 = new GraphNode ( this , SWT . NONE , "<STR_LIT>" ) ; GraphNode n3 = new GraphNode ( this , SWT . NONE , "<STR_LIT>" ) ; GraphNode n4 = new GraphNode ( this , SWT . NONE , "<STR_LIT>" ) ; GraphConnection n1n2 = new GraphConnection ( this , SWT . NONE , n1 , n2 ) ; n1n2 . setText ( "<STR_LIT>" ) ; n1n2 . setLineStyle ( SWT . LINE_DASH ) ; GraphConnection n2n3 = new GraphConnection ( this , SWT . NONE , n2 , n3 ) ; n2n3 . setText ( "<STR_LIT>" ) ; n2n3 . setLineStyle ( SWT . LINE_DASH ) ; GraphConnection n2n4 = new GraphConnection ( this , SWT . NONE , n2 , n4 ) ; n2n4 . setText ( "<STR_LIT>" ) ; n2n4 . setLineStyle ( SWT . LINE_DOT ) ; } public static void main ( final String [ ] args ) { Display d = new Display ( ) ; Shell shell = new Shell ( d ) ; shell . setText ( SampleGraph . class . getSimpleName ( ) ) ; shell . setLayout ( new FillLayout ( ) ) ; shell . setSize ( <NUM_LIT> , <NUM_LIT> ) ; new SampleGraph ( shell , SWT . NONE ) ; shell . open ( ) ; while ( ! shell . isDisposed ( ) ) { while ( ! d . readAndDispatch ( ) ) { d . sleep ( ) ; } } } } </s>
|
<s> package org . eclipse . zest . tests . dot . test_data ; import org . eclipse . swt . SWT ; import org . eclipse . swt . layout . FillLayout ; import org . eclipse . swt . widgets . Composite ; import org . eclipse . swt . widgets . Display ; import org . eclipse . swt . widgets . Shell ; import org . eclipse . zest . core . widgets . Graph ; import org . eclipse . zest . core . widgets . GraphConnection ; import org . eclipse . zest . core . widgets . GraphNode ; import org . eclipse . zest . core . widgets . ZestStyles ; import org . eclipse . zest . layouts . algorithms . TreeLayoutAlgorithm ; public class StyledGraph extends Graph { public StyledGraph ( final Composite parent , final int style ) { super ( parent , style ) ; setConnectionStyle ( ZestStyles . CONNECTIONS_DIRECTED ) ; setLayoutAlgorithm ( new TreeLayoutAlgorithm ( ) , true ) ; GraphNode n1 = new GraphNode ( this , SWT . NONE , "<STR_LIT:1>" ) ; GraphNode n2 = new GraphNode ( this , SWT . NONE , "<STR_LIT:2>" ) ; GraphNode n3 = new GraphNode ( this , SWT . NONE , "<STR_LIT:3>" ) ; GraphNode n4 = new GraphNode ( this , SWT . NONE , "<STR_LIT:4>" ) ; GraphNode n5 = new GraphNode ( this , SWT . NONE , "<STR_LIT:5>" ) ; GraphConnection n1n2 = new GraphConnection ( this , SWT . NONE , n1 , n2 ) ; n1n2 . setLineStyle ( SWT . LINE_DASH ) ; GraphConnection n2n3 = new GraphConnection ( this , SWT . NONE , n2 , n3 ) ; n2n3 . setLineStyle ( SWT . LINE_DOT ) ; GraphConnection n3n4 = new GraphConnection ( this , SWT . NONE , n3 , n4 ) ; n3n4 . setLineStyle ( SWT . LINE_DASHDOT ) ; GraphConnection n3n5 = new GraphConnection ( this , SWT . NONE , n3 , n5 ) ; n3n5 . setLineStyle ( SWT . LINE_SOLID ) ; } public static void main ( final String [ ] args ) { Display d = new Display ( ) ; Shell shell = new Shell ( d ) ; shell . setText ( StyledGraph . class . getSimpleName ( ) ) ; shell . setLayout ( new FillLayout ( ) ) ; shell . setSize ( <NUM_LIT> , <NUM_LIT> ) ; new StyledGraph ( shell , SWT . NONE ) ; shell . open ( ) ; while ( ! shell . isDisposed ( ) ) { while ( ! d . readAndDispatch ( ) ) { d . sleep ( ) ; } } } } </s>
|
<s> package org . eclipse . zest . tests . dot . test_data ; import org . eclipse . swt . SWT ; import org . eclipse . swt . layout . FillLayout ; import org . eclipse . swt . widgets . Composite ; import org . eclipse . swt . widgets . Display ; import org . eclipse . swt . widgets . Shell ; import org . eclipse . zest . core . widgets . Graph ; import org . eclipse . zest . core . widgets . GraphConnection ; import org . eclipse . zest . core . widgets . GraphNode ; import org . eclipse . zest . core . widgets . ZestStyles ; import org . eclipse . zest . layouts . algorithms . TreeLayoutAlgorithm ; public class LabeledGraph extends Graph { public LabeledGraph ( final Composite parent , final int style ) { super ( parent , style ) ; setConnectionStyle ( ZestStyles . CONNECTIONS_DIRECTED ) ; setLayoutAlgorithm ( new TreeLayoutAlgorithm ( ) , true ) ; GraphNode n1 = new GraphNode ( this , SWT . NONE , "<STR_LIT>" ) ; GraphNode n2 = new GraphNode ( this , SWT . NONE , "<STR_LIT>" ) ; GraphNode n3 = new GraphNode ( this , SWT . NONE , "<STR_LIT:3>" ) ; GraphNode n4 = new GraphNode ( this , SWT . NONE , "<STR_LIT:4>" ) ; GraphConnection n1n2 = new GraphConnection ( this , SWT . NONE , n1 , n2 ) ; n1n2 . setText ( "<STR_LIT>" ) ; GraphConnection n1n3 = new GraphConnection ( this , SWT . NONE , n1 , n3 ) ; n1n3 . setText ( "<STR_LIT>" ) ; new GraphConnection ( this , SWT . NONE , n3 , n4 ) ; } public static void main ( final String [ ] args ) { Display d = new Display ( ) ; Shell shell = new Shell ( d ) ; shell . setText ( LabeledGraph . class . getSimpleName ( ) ) ; shell . setLayout ( new FillLayout ( ) ) ; shell . setSize ( <NUM_LIT> , <NUM_LIT> ) ; new LabeledGraph ( shell , SWT . NONE ) ; shell . open ( ) ; while ( ! shell . isDisposed ( ) ) { while ( ! d . readAndDispatch ( ) ) { d . sleep ( ) ; } } } } </s>
|
<s> package org . eclipse . zest . tests . dot ; import java . io . File ; import junit . framework . Assert ; import org . eclipse . core . runtime . Platform ; import org . eclipse . zest . internal . dot . DotDirStore ; import org . eclipse . zest . internal . dot . DotUiActivator ; import org . junit . Before ; import org . junit . Test ; public final class TestDotDirStore { @ Before public void setup ( ) { if ( ! Platform . isRunning ( ) ) { Assert . fail ( "<STR_LIT>" ) ; } Assert . assertNotNull ( "<STR_LIT>" , TestImageExport . dotBinDir ( ) ) ; } @ Test public void askForDotDir ( ) { DotUiActivator . getDefault ( ) . getPreferenceStore ( ) . setValue ( DotDirStore . DOTPATH_KEY , TestImageExport . dotBinDir ( ) ) ; check ( DotDirStore . getDotDirPath ( ) ) ; } @ Test public void getDotDirFromPrefs ( ) { check ( DotDirStore . getDotDirPath ( ) ) ; } public void check ( final String path ) { Assert . assertNotNull ( "<STR_LIT>" , path ) ; System . out . println ( "<STR_LIT>" + path ) ; Assert . assertTrue ( "<STR_LIT>" , path . trim ( ) . length ( ) > <NUM_LIT:0> ) ; Assert . assertTrue ( "<STR_LIT>" , new File ( path ) . exists ( ) ) ; Assert . assertTrue ( "<STR_LIT>" , new File ( path ) . isDirectory ( ) ) ; } } </s>
|
<s> package org . eclipse . zest . tests . dot ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . resources . IWorkspaceRoot ; import org . eclipse . core . resources . ResourcesPlugin ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . core . runtime . IPath ; import org . eclipse . core . runtime . Path ; import org . eclipse . core . runtime . Platform ; import org . junit . Assert ; public final class ProjectHelper { static final String PROJECT_NAME = "<STR_LIT>" ; static final Path PROJECT_PATH = new Path ( Platform . getLocation ( ) . toString ( ) + "<STR_LIT:/>" + PROJECT_NAME ) ; private ProjectHelper ( ) { } static void assertProjectDoesntExist ( final IPath path ) { Assert . assertFalse ( "<STR_LIT>" + path . toFile ( ) , path . toFile ( ) . exists ( ) ) ; } static void assertProjectExists ( final IPath path ) { Assert . assertTrue ( "<STR_LIT>" + path . toFile ( ) , path . toFile ( ) . exists ( ) ) ; } static IProject createProject ( final String projectName ) { IWorkspaceRoot root = ResourcesPlugin . getWorkspace ( ) . getRoot ( ) ; IProject project = root . getProject ( projectName ) ; try { project . refreshLocal ( - <NUM_LIT:1> , null ) ; if ( project . exists ( ) ) { project . delete ( true , null ) ; assertProjectDoesntExist ( project . getLocation ( ) ) ; } project . create ( null ) ; if ( ! project . isOpen ( ) ) { project . open ( null ) ; } } catch ( CoreException e ) { e . printStackTrace ( ) ; } assertProjectExists ( project . getLocation ( ) ) ; return project ; } static void deleteProject ( final IProject project ) { try { project . refreshLocal ( - <NUM_LIT:1> , null ) ; project . delete ( true , true , null ) ; } catch ( CoreException e ) { e . printStackTrace ( ) ; } } } </s>
|
<s> package org . eclipse . zest . tests . dot ; import static org . junit . Assert . assertEquals ; import junit . framework . Assert ; import org . eclipse . swt . SWT ; import org . eclipse . swt . layout . FillLayout ; import org . eclipse . swt . widgets . Item ; import org . eclipse . swt . widgets . Shell ; import org . eclipse . zest . core . widgets . Graph ; import org . eclipse . zest . core . widgets . GraphConnection ; import org . eclipse . zest . core . widgets . GraphContainer ; import org . eclipse . zest . core . widgets . GraphNode ; import org . eclipse . zest . core . widgets . ZestStyles ; import org . eclipse . zest . dot . DotGraph ; import org . eclipse . zest . internal . dot . DotAst ; import org . eclipse . zest . internal . dot . DotImport ; import org . eclipse . zest . internal . dot . GraphCreatorInterpreter ; import org . eclipse . zest . layouts . algorithms . GridLayoutAlgorithm ; import org . eclipse . zest . layouts . algorithms . RadialLayoutAlgorithm ; import org . eclipse . zest . layouts . algorithms . SpringLayoutAlgorithm ; import org . eclipse . zest . layouts . algorithms . TreeLayoutAlgorithm ; import org . junit . Test ; public final class TestGraphInstanceDotImport { private final GraphCreatorInterpreter interpreter = new GraphCreatorInterpreter ( ) ; @ Test public void minimalUsage ( ) { Shell shell = new Shell ( ) ; DotImport dotImport = new DotImport ( "<STR_LIT>" ) ; Graph graph = dotImport . newGraphInstance ( shell , SWT . NONE ) ; System . out . println ( graph ) ; } @ Test public void dotImport ( ) { Shell shell = new Shell ( ) ; DotImport importer = new DotImport ( "<STR_LIT>" ) ; Graph graph = importer . newGraphInstance ( shell , SWT . NONE ) ; Assert . assertNotNull ( "<STR_LIT>" , graph ) ; Assert . assertEquals ( ZestStyles . CONNECTIONS_DIRECTED , graph . getConnectionStyle ( ) ) ; } @ Test public void undeclaredNodes ( ) { Graph graph = new DotImport ( "<STR_LIT>" ) . newGraphInstance ( new Shell ( ) , SWT . NONE ) ; Assert . assertEquals ( <NUM_LIT:3> , graph . getNodes ( ) . size ( ) ) ; Assert . assertEquals ( <NUM_LIT:2> , graph . getConnections ( ) . size ( ) ) ; } @ Test public void subgraphs ( ) { Shell shell = new Shell ( ) ; DotImport dotImport = new DotImport ( "<STR_LIT>" ) ; Graph graph = dotImport . newGraphInstance ( shell , SWT . NONE ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:3> , graph . getNodes ( ) . size ( ) ) ; assertEquals ( <NUM_LIT:2> , graph . getConnections ( ) . size ( ) ) ; } @ Test public void clusterSubgraphs ( ) { Shell shell = new Shell ( ) ; DotImport dotImport = new DotImport ( "<STR_LIT>" ) ; Graph graph = dotImport . newGraphInstance ( shell , SWT . NONE ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:2> , graph . getNodes ( ) . size ( ) ) ; assertEquals ( GraphContainer . class , graph . getNodes ( ) . get ( <NUM_LIT:0> ) . getClass ( ) ) ; assertEquals ( GraphContainer . class , graph . getNodes ( ) . get ( <NUM_LIT:1> ) . getClass ( ) ) ; assertEquals ( <NUM_LIT:2> , graph . getConnections ( ) . size ( ) ) ; } @ Test public void labeledClusterSubgraph ( ) { Shell shell = new Shell ( ) ; DotImport dotImport = new DotImport ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; Graph graph = dotImport . newGraphInstance ( shell , SWT . NONE ) ; assertEquals ( <NUM_LIT:4> , graph . getConnections ( ) . size ( ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:2> , graph . getNodes ( ) . size ( ) ) ; assertEquals ( "<STR_LIT>" , ( ( Item ) graph . getNodes ( ) . get ( <NUM_LIT:0> ) ) . getText ( ) ) ; assertEquals ( "<STR_LIT>" , ( ( Item ) graph . getNodes ( ) . get ( <NUM_LIT:1> ) ) . getText ( ) ) ; assertEquals ( "<STR_LIT>" , GraphContainer . class , graph . getNodes ( ) . get ( <NUM_LIT:0> ) . getClass ( ) ) ; assertEquals ( <NUM_LIT:2> , ( ( GraphContainer ) graph . getNodes ( ) . get ( <NUM_LIT:0> ) ) . getNodes ( ) . size ( ) ) ; assertEquals ( "<STR_LIT>" , GraphContainer . class , graph . getNodes ( ) . get ( <NUM_LIT:1> ) . getClass ( ) ) ; assertEquals ( <NUM_LIT:3> , ( ( GraphContainer ) graph . getNodes ( ) . get ( <NUM_LIT:1> ) ) . getNodes ( ) . size ( ) ) ; assertEquals ( RadialLayoutAlgorithm . class , ( ( GraphContainer ) graph . getNodes ( ) . get ( <NUM_LIT:0> ) ) . getLayoutAlgorithm ( ) . getClass ( ) ) ; } @ Test public void layoutClusterSubgraph ( ) { Shell shell = new Shell ( ) ; Graph graph = new DotGraph ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" , shell , SWT . NONE ) ; assertEquals ( "<STR_LIT>" , GraphContainer . class , graph . getNodes ( ) . get ( <NUM_LIT:0> ) . getClass ( ) ) ; assertEquals ( "<STR_LIT>" , GraphContainer . class , graph . getNodes ( ) . get ( <NUM_LIT:1> ) . getClass ( ) ) ; assertEquals ( RadialLayoutAlgorithm . class , ( ( GraphContainer ) graph . getNodes ( ) . get ( <NUM_LIT:0> ) ) . getLayoutAlgorithm ( ) . getClass ( ) ) ; assertEquals ( TreeLayoutAlgorithm . class , ( ( GraphContainer ) graph . getNodes ( ) . get ( <NUM_LIT:1> ) ) . getLayoutAlgorithm ( ) . getClass ( ) ) ; } @ Test public void digraphType ( ) { Shell shell = new Shell ( ) ; Graph graph = interpreter . create ( shell , SWT . NONE , parse ( "<STR_LIT>" ) ) ; Assert . assertNotNull ( "<STR_LIT>" , graph ) ; Assert . assertEquals ( ZestStyles . CONNECTIONS_DIRECTED , graph . getConnectionStyle ( ) ) ; } @ Test public void graphType ( ) { Shell shell = new Shell ( ) ; Graph graph = interpreter . create ( shell , SWT . NONE , parse ( "<STR_LIT>" ) ) ; Assert . assertNotNull ( "<STR_LIT>" , graph ) ; Assert . assertNotSame ( ZestStyles . CONNECTIONS_DIRECTED , graph . getConnectionStyle ( ) ) ; } @ Test public void nodeDefaultLabel ( ) { Graph graph = interpreter . create ( new Shell ( ) , SWT . NONE , parse ( "<STR_LIT>" ) ) ; Assert . assertNotNull ( "<STR_LIT>" , graph ) ; Assert . assertEquals ( "<STR_LIT:1>" , ( ( GraphNode ) graph . getNodes ( ) . get ( <NUM_LIT:0> ) ) . getText ( ) ) ; } @ Test public void nodeCount ( ) { Graph graph = interpreter . create ( new Shell ( ) , SWT . NONE , parse ( "<STR_LIT>" ) ) ; Assert . assertNotNull ( "<STR_LIT>" , graph ) ; Assert . assertEquals ( <NUM_LIT:2> , graph . getNodes ( ) . size ( ) ) ; } @ Test public void edgeCount ( ) { Graph graph = interpreter . create ( new Shell ( ) , SWT . NONE , parse ( "<STR_LIT>" ) ) ; Assert . assertNotNull ( "<STR_LIT>" , graph ) ; Assert . assertEquals ( <NUM_LIT:3> , graph . getConnections ( ) . size ( ) ) ; } @ Test public void nodeLabel ( ) { Graph graph = interpreter . create ( new Shell ( ) , SWT . NONE , parse ( "<STR_LIT>" ) ) ; Assert . assertNotNull ( "<STR_LIT>" , graph ) ; Assert . assertEquals ( "<STR_LIT>" , ( ( GraphNode ) graph . getNodes ( ) . get ( <NUM_LIT:0> ) ) . getText ( ) ) ; } @ Test public void edgeLabel ( ) { Graph graph = interpreter . create ( new Shell ( ) , SWT . NONE , parse ( "<STR_LIT>" ) ) ; Assert . assertNotNull ( "<STR_LIT>" , graph ) ; Assert . assertEquals ( "<STR_LIT>" , ( ( GraphConnection ) graph . getConnections ( ) . get ( <NUM_LIT:0> ) ) . getText ( ) ) ; } @ Test public void edgeStyle ( ) { Shell parent = new Shell ( ) ; Graph graph = interpreter . create ( parent , SWT . NONE , parse ( "<STR_LIT>" ) ) ; Assert . assertNotNull ( "<STR_LIT>" , graph ) ; Assert . assertEquals ( SWT . LINE_DASH , ( ( GraphConnection ) graph . getConnections ( ) . get ( <NUM_LIT:0> ) ) . getLineStyle ( ) ) ; } @ Test public void globalEdgeStyle ( ) { Shell parent = new Shell ( ) ; Graph graph = interpreter . create ( parent , SWT . NONE , parse ( "<STR_LIT>" ) ) ; Assert . assertNotNull ( "<STR_LIT>" , graph ) ; Assert . assertEquals ( SWT . LINE_DASH , ( ( GraphConnection ) graph . getConnections ( ) . get ( <NUM_LIT:0> ) ) . getLineStyle ( ) ) ; } @ Test public void globalEdgeLabel ( ) { Graph graph = interpreter . create ( new Shell ( ) , SWT . NONE , parse ( "<STR_LIT>" ) ) ; Assert . assertNotNull ( "<STR_LIT>" , graph ) ; Assert . assertEquals ( "<STR_LIT>" , ( ( GraphConnection ) graph . getConnections ( ) . get ( <NUM_LIT:0> ) ) . getText ( ) ) ; } @ Test public void globalNodeLabel ( ) { Graph graph = interpreter . create ( new Shell ( ) , SWT . NONE , parse ( "<STR_LIT>" ) ) ; Assert . assertNotNull ( "<STR_LIT>" , graph ) ; Assert . assertEquals ( "<STR_LIT>" , ( ( GraphNode ) graph . getNodes ( ) . get ( <NUM_LIT:0> ) ) . getText ( ) ) ; } @ Test public void layoutSpring ( ) { Graph graph = interpreter . create ( new Shell ( ) , SWT . NONE , parse ( "<STR_LIT>" ) ) ; Assert . assertNotNull ( "<STR_LIT>" , graph ) ; Assert . assertEquals ( SpringLayoutAlgorithm . class , graph . getLayoutAlgorithm ( ) . getClass ( ) ) ; } @ Test public void layoutGrid ( ) { Graph graph = interpreter . create ( new Shell ( ) , SWT . NONE , parse ( "<STR_LIT>" ) ) ; Assert . assertNotNull ( "<STR_LIT>" , graph ) ; Assert . assertEquals ( GridLayoutAlgorithm . class , graph . getLayoutAlgorithm ( ) . getClass ( ) ) ; } @ Test public void layoutRadial ( ) { Graph graph = interpreter . create ( new Shell ( ) , SWT . NONE , parse ( "<STR_LIT>" ) ) ; Assert . assertNotNull ( "<STR_LIT>" , graph ) ; Assert . assertEquals ( RadialLayoutAlgorithm . class , graph . getLayoutAlgorithm ( ) . getClass ( ) ) ; } @ Test public void layoutTree ( ) { Graph graph = interpreter . create ( new Shell ( ) , SWT . NONE , parse ( "<STR_LIT>" ) ) ; Assert . assertNotNull ( "<STR_LIT>" , graph ) ; Assert . assertEquals ( TreeLayoutAlgorithm . class , graph . getLayoutAlgorithm ( ) . getClass ( ) ) ; } @ Test public void layoutHorizontalTreeViaLayout ( ) { Graph graph = interpreter . create ( new Shell ( ) , SWT . NONE , parse ( "<STR_LIT>" ) ) ; Assert . assertNotNull ( "<STR_LIT>" , graph ) ; Assert . assertEquals ( TreeLayoutAlgorithm . class , graph . getLayoutAlgorithm ( ) . getClass ( ) ) ; Assert . assertEquals ( TreeLayoutAlgorithm . LEFT_RIGHT , ( ( TreeLayoutAlgorithm ) ( graph . getLayoutAlgorithm ( ) ) ) . getDirection ( ) ) ; } @ Test public void layoutHorizontalTreeViaAttribute ( ) { Graph graph = interpreter . create ( new Shell ( ) , SWT . NONE , parse ( "<STR_LIT>" ) ) ; Assert . assertNotNull ( "<STR_LIT>" , graph ) ; Assert . assertEquals ( TreeLayoutAlgorithm . class , graph . getLayoutAlgorithm ( ) . getClass ( ) ) ; Assert . assertEquals ( TreeLayoutAlgorithm . LEFT_RIGHT , ( ( TreeLayoutAlgorithm ) ( graph . getLayoutAlgorithm ( ) ) ) . getDirection ( ) ) ; } @ Test public void globalNodeAttributeAdHocNodes ( ) { Graph graph = interpreter . create ( new Shell ( ) , SWT . NONE , parse ( "<STR_LIT>" ) ) ; Assert . assertNotNull ( "<STR_LIT>" , graph ) ; Assert . assertEquals ( "<STR_LIT>" , ( ( GraphNode ) graph . getNodes ( ) . get ( <NUM_LIT:0> ) ) . getText ( ) ) ; } @ Test public void globalEdgeAttributeAdHocNodes ( ) { Graph graph = interpreter . create ( new Shell ( ) , SWT . NONE , parse ( "<STR_LIT>" ) ) ; Assert . assertNotNull ( "<STR_LIT>" , graph ) ; Assert . assertEquals ( "<STR_LIT>" , ( ( GraphConnection ) graph . getConnections ( ) . get ( <NUM_LIT:0> ) ) . getText ( ) ) ; } @ Test public void headerCommentGraph ( ) { Graph graph = interpreter . create ( new Shell ( ) , SWT . NONE , parse ( "<STR_LIT>" ) ) ; Assert . assertNotNull ( "<STR_LIT>" , graph ) ; Assert . assertEquals ( <NUM_LIT:2> , graph . getNodes ( ) . size ( ) ) ; Assert . assertEquals ( <NUM_LIT:1> , graph . getConnections ( ) . size ( ) ) ; } @ Test public void nodesBeforeEdges ( ) { Graph graph = interpreter . create ( new Shell ( ) , SWT . NONE , parse ( "<STR_LIT>" ) ) ; Assert . assertNotNull ( "<STR_LIT>" , graph ) ; Assert . assertEquals ( <NUM_LIT:4> , graph . getNodes ( ) . size ( ) ) ; Assert . assertEquals ( <NUM_LIT:3> , graph . getConnections ( ) . size ( ) ) ; } @ Test public void nodesAfterEdges ( ) { Graph graph = interpreter . create ( new Shell ( ) , SWT . NONE , parse ( "<STR_LIT>" ) ) ; Assert . assertNotNull ( "<STR_LIT>" , graph ) ; Assert . assertEquals ( <NUM_LIT:4> , graph . getNodes ( ) . size ( ) ) ; Assert . assertEquals ( <NUM_LIT:3> , graph . getConnections ( ) . size ( ) ) ; Assert . assertEquals ( "<STR_LIT>" , ( ( GraphNode ) graph . getNodes ( ) . get ( <NUM_LIT:0> ) ) . getText ( ) ) ; } @ Test public void useInterpreterTwice ( ) { String dot = "<STR_LIT>" ; Graph graph = interpreter . create ( new Shell ( ) , SWT . NONE , parse ( dot ) ) ; graph = interpreter . create ( new Shell ( ) , SWT . NONE , parse ( dot ) ) ; Assert . assertNotNull ( "<STR_LIT>" , graph ) ; Assert . assertEquals ( <NUM_LIT:4> , graph . getNodes ( ) . size ( ) ) ; Assert . assertEquals ( <NUM_LIT:3> , graph . getConnections ( ) . size ( ) ) ; } @ Test public void idsWithQuotes ( ) { String dot = "<STR_LIT>" ; Graph graph = interpreter . create ( new Shell ( ) , SWT . NONE , parse ( dot ) ) ; Assert . assertNotNull ( "<STR_LIT>" , graph ) ; Assert . assertEquals ( "<STR_LIT>" , ( ( GraphNode ) graph . getNodes ( ) . get ( <NUM_LIT:0> ) ) . getText ( ) ) ; Assert . assertEquals ( "<STR_LIT>" , ( ( GraphNode ) graph . getNodes ( ) . get ( <NUM_LIT:1> ) ) . getText ( ) ) ; } @ Test public void escapedQuotes ( ) { String dot = "<STR_LIT>" ; Graph graph = interpreter . create ( new Shell ( ) , SWT . NONE , parse ( dot ) ) ; Assert . assertNotNull ( "<STR_LIT>" , graph ) ; Assert . assertEquals ( "<STR_LIT>" , ( ( GraphNode ) graph . getNodes ( ) . get ( <NUM_LIT:0> ) ) . getText ( ) ) ; } @ Test public void fullyQuoted ( ) { String dot = "<STR_LIT>" ; Graph graph = interpreter . create ( new Shell ( ) , SWT . NONE , parse ( dot ) ) ; Assert . assertNotNull ( "<STR_LIT>" , graph ) ; Assert . assertEquals ( <NUM_LIT:2> , graph . getNodes ( ) . size ( ) ) ; Assert . assertEquals ( <NUM_LIT:1> , graph . getConnections ( ) . size ( ) ) ; Assert . assertEquals ( "<STR_LIT>" , ( ( GraphNode ) graph . getNodes ( ) . get ( <NUM_LIT:0> ) ) . getText ( ) ) ; Assert . assertEquals ( "<STR_LIT>" , ( ( GraphNode ) graph . getNodes ( ) . get ( <NUM_LIT:1> ) ) . getText ( ) ) ; } @ Test public void labelsWithQuotes ( ) { String dot = "<STR_LIT>" ; Graph graph = interpreter . create ( new Shell ( ) , SWT . NONE , parse ( dot ) ) ; Assert . assertNotNull ( "<STR_LIT>" , graph ) ; Assert . assertEquals ( "<STR_LIT>" , ( ( GraphNode ) graph . getNodes ( ) . get ( <NUM_LIT:0> ) ) . getText ( ) ) ; Assert . assertEquals ( "<STR_LIT>" , ( ( GraphNode ) graph . getNodes ( ) . get ( <NUM_LIT:1> ) ) . getText ( ) ) ; Assert . assertEquals ( "<STR_LIT>" , ( ( GraphConnection ) graph . getConnections ( ) . get ( <NUM_LIT:0> ) ) . getText ( ) ) ; } @ Test public void newLinesInLabels ( ) { String dot = "<STR_LIT>" ; Graph graph = interpreter . create ( new Shell ( ) , SWT . NONE , parse ( dot ) ) ; Assert . assertNotNull ( "<STR_LIT>" , graph ) ; Assert . assertEquals ( "<STR_LIT>" , ( ( GraphNode ) graph . getNodes ( ) . get ( <NUM_LIT:0> ) ) . getText ( ) ) ; } @ Test public void multiEdgeStatements ( ) { Graph graph = new DotGraph ( "<STR_LIT>" , new Shell ( ) , SWT . NONE ) ; assertEquals ( <NUM_LIT:4> , graph . getNodes ( ) . size ( ) ) ; assertEquals ( <NUM_LIT:3> , graph . getConnections ( ) . size ( ) ) ; assertEquals ( <NUM_LIT:1> , ( ( GraphNode ) graph . getNodes ( ) . get ( <NUM_LIT:0> ) ) . getSourceConnections ( ) . size ( ) ) ; assertEquals ( <NUM_LIT:1> , ( ( GraphNode ) graph . getNodes ( ) . get ( <NUM_LIT:1> ) ) . getSourceConnections ( ) . size ( ) ) ; assertEquals ( <NUM_LIT:1> , ( ( GraphNode ) graph . getNodes ( ) . get ( <NUM_LIT:2> ) ) . getSourceConnections ( ) . size ( ) ) ; } @ Test ( expected = IllegalArgumentException . class ) public void faultyLayout ( ) { interpreter . create ( new Shell ( ) , SWT . NONE , parse ( "<STR_LIT>" ) ) ; } @ Test ( expected = IllegalArgumentException . class ) public void faultyStyle ( ) { interpreter . create ( new Shell ( ) , SWT . NONE , parse ( "<STR_LIT>" ) ) ; } private DotAst parse ( String dot ) { return new DotImport ( dot ) . getDotAst ( ) ; } @ SuppressWarnings ( "<STR_LIT:unused>" ) private void open ( final Shell shell ) { shell . setText ( "<STR_LIT>" ) ; shell . setLayout ( new FillLayout ( ) ) ; shell . setSize ( <NUM_LIT> , <NUM_LIT> ) ; shell . open ( ) ; while ( ! shell . isDisposed ( ) ) { while ( ! shell . getDisplay ( ) . readAndDispatch ( ) ) { shell . getDisplay ( ) . sleep ( ) ; } } } } </s>
|
<s> package org . eclipse . zest . tests . dot ; import java . util . HashMap ; import java . util . Map ; import org . eclipse . zest . internal . dot . DotExtractor ; import org . junit . Assert ; import org . junit . Test ; @ SuppressWarnings ( "<STR_LIT:serial>" ) public class TestDotExtractor { Map < String , String > values = new HashMap < String , String > ( ) { { put ( "<STR_LIT>" , "<STR_LIT>" ) ; put ( "<STR_LIT>" , "<STR_LIT>" ) ; put ( "<STR_LIT>" , "<STR_LIT>" ) ; put ( "<STR_LIT>" , "<STR_LIT>" ) ; put ( "<STR_LIT>" , "<STR_LIT>" ) ; put ( "<STR_LIT>" , "<STR_LIT>" ) ; put ( "<STR_LIT>" , "<STR_LIT>" ) ; put ( "<STR_LIT>" , "<STR_LIT>" ) ; } } ; @ Test public void extractDot ( ) { for ( String input : values . keySet ( ) ) { String expected = values . get ( input ) ; String output = new DotExtractor ( input ) . getDotString ( ) ; Assert . assertEquals ( expected , output ) ; } } } </s>
|
<s> package org . eclipse . zest . tests . dot ; import org . junit . runner . RunWith ; import org . junit . runners . Suite ; @ RunWith ( Suite . class ) @ Suite . SuiteClasses ( { TestBasicDotImport . class , TestLayoutDotImport . class , TestAnimationDotImport . class , TestGraphInstanceDotImport . class , TestSnippetDotImport . class , TestDotGraph . class , TestDotAst . class , SampleUsage . class } ) public final class DotImportSuite { private DotImportSuite ( ) { } } </s>
|
<s> package org . eclipse . zest . tests . dot ; import static org . eclipse . zest . tests . dot . DotImportTestUtils . RESOURCES_TESTS ; import static org . eclipse . zest . tests . dot . DotImportTestUtils . importFrom ; import java . io . File ; import org . eclipse . zest . internal . dot . DotImport ; import org . eclipse . zest . layouts . algorithms . GridLayoutAlgorithm ; import org . eclipse . zest . layouts . algorithms . RadialLayoutAlgorithm ; import org . eclipse . zest . layouts . algorithms . SpringLayoutAlgorithm ; import org . eclipse . zest . layouts . algorithms . TreeLayoutAlgorithm ; import org . junit . Test ; public final class TestLayoutDotImport { @ Test public void treeLayout ( ) { importFrom ( new File ( RESOURCES_TESTS + "<STR_LIT>" ) ) ; } @ Test public void springLayout ( ) { importFrom ( new File ( RESOURCES_TESTS + "<STR_LIT>" ) ) ; } @ Test public void radialLayout ( ) { importFrom ( new File ( RESOURCES_TESTS + "<STR_LIT>" ) ) ; } @ Test public void gridLayout ( ) { importFrom ( new File ( RESOURCES_TESTS + "<STR_LIT>" ) ) ; } } </s>
|
<s> package org . eclipse . zest . tests . dot ; import java . io . File ; import java . io . IOException ; import java . io . InputStream ; import java . util . Properties ; import junit . framework . Assert ; import org . eclipse . zest . core . widgets . Graph ; import org . eclipse . zest . internal . dot . DotExport ; import org . junit . BeforeClass ; public class TestImageExport extends TestDotTemplate { private static String dotDir = null ; @ BeforeClass public static void setup ( ) throws IOException { dotDir = dotBinDir ( ) ; } public static String dotBinDir ( ) { if ( dotDir == null ) { Properties props = new Properties ( ) ; InputStream stream = TestImageExport . class . getResourceAsStream ( "<STR_LIT>" ) ; if ( stream == null ) { System . err . println ( "<STR_LIT>" + TestImageExport . class . getSimpleName ( ) ) ; } else try { props . load ( stream ) ; dotDir = props . getProperty ( DotExport . DOT_BIN_DIR_KEY ) ; if ( dotDir == null || dotDir . trim ( ) . length ( ) == <NUM_LIT:0> ) { System . err . println ( "<STR_LIT>" ) ; } else stream . close ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; return null ; } } return dotDir ; } @ Override protected void testDotGeneration ( final Graph graph ) { if ( dotDir != null ) { super . testDotGeneration ( graph ) ; File image = new DotExport ( graph ) . toImage ( dotDir , null ) ; Assert . assertNotNull ( "<STR_LIT>" , image ) ; System . out . println ( "<STR_LIT>" + image ) ; Assert . assertTrue ( "<STR_LIT>" , image . exists ( ) ) ; } } } </s>
|
<s> package org . eclipse . zest . tests . dot ; import java . io . File ; import org . eclipse . swt . SWT ; import org . eclipse . swt . layout . FillLayout ; import org . eclipse . swt . widgets . Display ; import org . eclipse . swt . widgets . Shell ; import org . eclipse . zest . core . widgets . Graph ; import org . eclipse . zest . core . widgets . GraphConnection ; import org . eclipse . zest . core . widgets . GraphNode ; import org . eclipse . zest . core . widgets . ZestStyles ; import org . eclipse . zest . internal . dot . DotExport ; import org . eclipse . zest . layouts . algorithms . TreeLayoutAlgorithm ; public final class DotExportSample { public static void main ( final String [ ] args ) { Display d = new Display ( ) ; Shell shell = new Shell ( d ) ; Graph graph = new Graph ( shell , SWT . NONE ) ; graph . setConnectionStyle ( ZestStyles . CONNECTIONS_DIRECTED ) ; GraphConnection edge = new GraphConnection ( graph , SWT . NONE , new GraphNode ( graph , SWT . NONE , "<STR_LIT>" ) , new GraphNode ( graph , SWT . NONE , "<STR_LIT>" ) ) ; edge . setText ( "<STR_LIT>" ) ; edge . setLineStyle ( SWT . LINE_DOT ) ; DotExport dotExport = new DotExport ( graph ) ; System . out . println ( dotExport . toDotString ( ) ) ; dotExport . toDotFile ( new File ( "<STR_LIT>" ) ) ; graph . setLayoutAlgorithm ( new TreeLayoutAlgorithm ( ) , true ) ; shell . setLayout ( new FillLayout ( ) ) ; shell . setSize ( <NUM_LIT> , <NUM_LIT> ) ; shell . open ( ) ; while ( ! shell . isDisposed ( ) ) { while ( ! d . readAndDispatch ( ) ) { d . sleep ( ) ; } } } private DotExportSample ( ) { } } </s>
|
<s> package org . eclipse . zest . tests . dot ; import java . io . File ; import org . eclipse . swt . SWT ; import org . eclipse . swt . widgets . Shell ; import org . eclipse . zest . core . widgets . Graph ; import org . eclipse . zest . internal . dot . DotImport ; import org . junit . Assert ; public final class DotImportTestUtils { private DotImportTestUtils ( ) { } static final String RESOURCES_TESTS = "<STR_LIT>" ; static void importFrom ( final File dotFile ) { Assert . assertTrue ( "<STR_LIT>" + dotFile , dotFile . exists ( ) ) ; Graph zest = new DotImport ( dotFile ) . newGraphInstance ( new Shell ( ) , SWT . NONE ) ; Assert . assertNotNull ( "<STR_LIT>" , zest ) ; System . out . println ( String . format ( "<STR_LIT>" , dotFile , zest ) ) ; } } </s>
|
<s> package org . eclipse . zest . tests . dot ; import org . eclipse . zest . tests . dot . DotTestUtils ; import org . eclipse . zest . tests . dot . TestDotExport ; import org . eclipse . zest . tests . dot . TestDotTemplate ; import org . eclipse . zest . tests . dot . TestImageExport ; import org . junit . BeforeClass ; import org . junit . runner . RunWith ; import org . junit . runners . Suite ; @ RunWith ( Suite . class ) @ Suite . SuiteClasses ( { TestDotTemplate . class , TestDotExport . class , TestImageExport . class } ) public final class DotExportSuite { private DotExportSuite ( ) { } @ BeforeClass public static void wipe ( ) { DotTestUtils . wipeOutput ( TestDotExport . OUTPUT , "<STR_LIT>" ) ; } } </s>
|
<s> package org . eclipse . zest . tests . dot ; import static org . junit . Assert . assertTrue ; import java . io . File ; import java . io . FileNotFoundException ; import java . util . Scanner ; import junit . framework . Assert ; import org . eclipse . swt . SWT ; import org . eclipse . swt . widgets . Shell ; import org . eclipse . zest . core . widgets . Graph ; import org . eclipse . zest . core . widgets . GraphContainer ; import org . eclipse . zest . core . widgets . GraphNode ; import org . eclipse . zest . dot . DotGraph ; import org . eclipse . zest . internal . dot . DotExport ; import org . eclipse . zest . layouts . algorithms . GridLayoutAlgorithm ; import org . eclipse . zest . layouts . algorithms . RadialLayoutAlgorithm ; import org . eclipse . zest . layouts . algorithms . SpringLayoutAlgorithm ; import org . eclipse . zest . layouts . algorithms . TreeLayoutAlgorithm ; import org . junit . Test ; public class TestDotExport extends TestDotTemplate { public static final File OUTPUT = new File ( "<STR_LIT>" ) ; @ Override protected void testDotGeneration ( final Graph graph ) { super . testDotGeneration ( graph ) ; DotExport dotExport = new DotExport ( graph ) ; String dot = dotExport . toDotString ( ) ; assertNoBlankLines ( dot ) ; System . out . println ( dot ) ; File file = new File ( OUTPUT , new DotExport ( graph ) . toString ( ) + "<STR_LIT>" ) ; dotExport . toDotFile ( file ) ; Assert . assertTrue ( "<STR_LIT>" , file . exists ( ) ) ; String dotRead = read ( file ) ; Assert . assertTrue ( "<STR_LIT>" , dotRead . contains ( graph . getClass ( ) . getSimpleName ( ) ) ) ; Assert . assertEquals ( "<STR_LIT>" , dot , dotRead ) ; } @ Test public void graphContainerExport ( ) { Graph graph = new Graph ( new Shell ( ) , SWT . NONE ) ; GraphContainer container = new GraphContainer ( graph , SWT . NONE ) ; GraphNode node = new GraphNode ( container , SWT . NONE ) ; String nodeLabel = "<STR_LIT>" ; String containerLabel = "<STR_LIT>" ; node . setText ( nodeLabel ) ; container . setText ( containerLabel ) ; String dot = new DotExport ( graph ) . toDotString ( ) ; Assert . assertTrue ( "<STR_LIT>" , ! dot . contains ( containerLabel ) ) ; Assert . assertTrue ( "<STR_LIT>" , dot . contains ( nodeLabel ) ) ; } @ Test public void zestToGraphvizLayoutMapping ( ) { DotGraph graph = new DotGraph ( new Shell ( ) , SWT . NONE ) ; graph . setLayoutAlgorithm ( new TreeLayoutAlgorithm ( ) , false ) ; assertTrue ( "<STR_LIT>" , graph . toDot ( ) . contains ( "<STR_LIT>" ) ) ; graph . setLayoutAlgorithm ( new RadialLayoutAlgorithm ( ) , false ) ; assertTrue ( "<STR_LIT>" , graph . toDot ( ) . contains ( "<STR_LIT>" ) ) ; graph . setLayoutAlgorithm ( new GridLayoutAlgorithm ( ) , false ) ; assertTrue ( "<STR_LIT>" , graph . toDot ( ) . contains ( "<STR_LIT>" ) ) ; graph . setLayoutAlgorithm ( new SpringLayoutAlgorithm ( ) , false ) ; assertTrue ( "<STR_LIT>" , graph . toDot ( ) . contains ( "<STR_LIT>" ) ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:100> ; i ++ ) { new GraphNode ( graph , SWT . NONE ) ; } assertTrue ( "<STR_LIT>" , graph . toDot ( ) . contains ( "<STR_LIT>" ) ) ; } private void assertNoBlankLines ( final String dot ) { Scanner scanner = new Scanner ( dot ) ; while ( scanner . hasNextLine ( ) ) { if ( scanner . nextLine ( ) . trim ( ) . equals ( "<STR_LIT>" ) ) { Assert . fail ( "<STR_LIT>" ) ; } } } private String read ( final File file ) { try { Scanner scanner = new Scanner ( file ) ; StringBuilder builder = new StringBuilder ( ) ; while ( scanner . hasNextLine ( ) ) { builder . append ( scanner . nextLine ( ) + "<STR_LIT:n>" ) ; } return builder . toString ( ) ; } catch ( FileNotFoundException e ) { e . printStackTrace ( ) ; } return null ; } } </s>
|
<s> package org . eclipse . zest . tests . dot ; import java . io . File ; import java . io . IOException ; import junit . framework . Assert ; import org . eclipse . core . runtime . Platform ; import org . eclipse . ui . IWorkbenchPage ; import org . eclipse . ui . PartInitException ; import org . eclipse . ui . PlatformUI ; import org . eclipse . zest . core . widgets . Graph ; import org . eclipse . zest . internal . dot . DotExport ; import org . eclipse . zest . internal . dot . ZestGraphView ; import org . junit . BeforeClass ; import org . junit . Test ; public final class TestZestGraphView { private static final String DOT = "<STR_LIT>" ; @ BeforeClass public static void setup ( ) { if ( ! Platform . isRunning ( ) ) { Assert . fail ( "<STR_LIT>" ) ; } } @ Test public void loadGraphFromDot ( ) throws PartInitException , InterruptedException , IOException { Graph g = loadGraphInView ( DOT ) ; Assert . assertEquals ( <NUM_LIT:2> , g . getNodes ( ) . size ( ) ) ; Assert . assertEquals ( <NUM_LIT:1> , g . getConnections ( ) . size ( ) ) ; } @ Test public void experimentalSwtImageExport ( ) throws PartInitException , InterruptedException , IOException { Graph g = loadGraphInView ( DOT ) ; DotExport export = new DotExport ( g ) ; File image = export . toImage ( File . createTempFile ( "<STR_LIT>" , "<STR_LIT>" ) . getAbsolutePath ( ) ) ; Assert . assertTrue ( image . exists ( ) ) ; } private Graph loadGraphInView ( String dot ) throws PartInitException { IWorkbenchPage page = PlatformUI . getWorkbench ( ) . getActiveWorkbenchWindow ( ) . getActivePage ( ) ; ZestGraphView graphView = ( ZestGraphView ) page . showView ( ZestGraphView . ID ) ; graphView . setGraph ( dot , false ) ; Graph g = graphView . getGraph ( ) ; return g ; } } </s>
|
<s> package org . eclipse . zest . tests . dot ; import java . io . File ; import junit . framework . Assert ; import org . eclipse . zest . internal . dot . DotAst ; import org . eclipse . zest . internal . dot . DotFileUtils ; import org . junit . Test ; public class TestDotAst { private static final DotAst DOT_AST = new DotAst ( DotFileUtils . read ( new File ( DotImportTestUtils . RESOURCES_TESTS + "<STR_LIT>" ) ) ) ; @ Test public void parseName ( ) { Assert . assertEquals ( "<STR_LIT>" , DOT_AST . graphName ( ) ) ; } @ Test public void parseErrors ( ) { Assert . assertEquals ( <NUM_LIT:0> , DOT_AST . errors ( ) . size ( ) ) ; } } </s>
|
<s> package org . eclipse . zest . tests . dot ; import static org . eclipse . zest . tests . dot . DotImportTestUtils . RESOURCES_TESTS ; import static org . eclipse . zest . tests . dot . DotImportTestUtils . importFrom ; import java . io . File ; import org . eclipse . zest . internal . dot . DotImport ; import org . junit . Test ; public final class TestAnimationDotImport { @ Test public void simple ( ) { importFrom ( new File ( RESOURCES_TESTS + "<STR_LIT>" ) ) ; } @ Test public void binTree ( ) { importFrom ( new File ( RESOURCES_TESTS + "<STR_LIT>" ) ) ; } @ Test public void layout ( ) { importFrom ( new File ( RESOURCES_TESTS + "<STR_LIT>" ) ) ; } @ Test public void full ( ) { importFrom ( new File ( RESOURCES_TESTS + "<STR_LIT>" ) ) ; } } </s>
|
<s> package org . eclipse . zest . tests . dot ; import junit . framework . Assert ; import org . eclipse . swt . SWT ; import org . eclipse . swt . widgets . Shell ; import org . eclipse . zest . core . widgets . Graph ; import org . eclipse . zest . core . widgets . GraphConnection ; import org . eclipse . zest . core . widgets . GraphNode ; import org . eclipse . zest . core . widgets . ZestStyles ; import org . eclipse . zest . internal . dot . DotTemplate ; import org . eclipse . zest . layouts . algorithms . TreeLayoutAlgorithm ; import org . eclipse . zest . tests . dot . test_data . LabeledGraph ; import org . eclipse . zest . tests . dot . test_data . SampleGraph ; import org . eclipse . zest . tests . dot . test_data . SimpleDigraph ; import org . eclipse . zest . tests . dot . test_data . SimpleGraph ; import org . eclipse . zest . tests . dot . test_data . StyledGraph ; import org . junit . Test ; public class TestDotTemplate { private static Shell shell = new Shell ( ) ; @ Test public void zestGraph ( ) { Graph graph = new Graph ( shell , SWT . NONE ) ; graph . setLayoutAlgorithm ( new TreeLayoutAlgorithm ( TreeLayoutAlgorithm . LEFT_RIGHT ) , true ) ; graph . setConnectionStyle ( ZestStyles . CONNECTIONS_DIRECTED ) ; GraphConnection edge = new GraphConnection ( graph , SWT . NONE , new GraphNode ( graph , SWT . NONE , "<STR_LIT>" ) , new GraphNode ( graph , SWT . NONE , "<STR_LIT>" ) ) ; edge . setText ( "<STR_LIT>" ) ; edge . setLineStyle ( SWT . LINE_DOT ) ; String dot = new DotTemplate ( ) . generate ( graph ) ; Assert . assertTrue ( "<STR_LIT>" , dot . contains ( "<STR_LIT>" ) ) ; testDotGeneration ( graph ) ; } @ Test public void sampleGraph ( ) { testDotGeneration ( new SampleGraph ( shell , SWT . NONE ) ) ; } @ Test public void simpleGraph ( ) { testDotGeneration ( new SimpleGraph ( shell , SWT . NONE ) ) ; } @ Test public void directedGraph ( ) { testDotGeneration ( new SimpleDigraph ( shell , SWT . NONE ) ) ; } @ Test public void labeledGraph ( ) { testDotGeneration ( new LabeledGraph ( shell , SWT . NONE ) ) ; } @ Test public void styledGraph ( ) { testDotGeneration ( new StyledGraph ( shell , SWT . NONE ) ) ; } protected void testDotGeneration ( final Graph graph ) { String dot = new DotTemplate ( ) . generate ( graph ) ; Assert . assertFalse ( "<STR_LIT>" , dot . contains ( "<STR_LIT>" ) ) ; Assert . assertTrue ( "<STR_LIT>" , dot . contains ( graph . getClass ( ) . getSimpleName ( ) ) ) ; Assert . assertTrue ( graph . getConnectionStyle ( ) == ZestStyles . CONNECTIONS_DIRECTED ? dot . contains ( "<STR_LIT>" ) : ! dot . contains ( "<STR_LIT>" ) ) ; System . out . println ( dot ) ; } } </s>
|
<s> package org . eclipse . zest . tests . dot ; import java . lang . reflect . Constructor ; import java . lang . reflect . InvocationTargetException ; import java . net . URL ; import java . net . URLClassLoader ; import java . util . ArrayList ; import java . util . List ; import org . eclipse . swt . widgets . Composite ; import org . eclipse . zest . core . widgets . Graph ; final class ExperimentalDotImport { private ExperimentalDotImport ( ) { } static Graph loadGraph ( final String graphName , final URL outputDirUrl , final Composite parent , final int style ) { try { URLClassLoader ucl = getUrlClassLoader ( outputDirUrl ) ; Class < ? > clazz = Class . forName ( "<STR_LIT>" + graphName , true , ucl ) ; for ( Constructor < ? > c : clazz . getConstructors ( ) ) { if ( c . getParameterTypes ( ) . length == <NUM_LIT:2> ) { Object object = c . newInstance ( parent , ( Integer ) style ) ; return ( Graph ) object ; } } } catch ( ClassNotFoundException e ) { e . printStackTrace ( ) ; } catch ( IllegalArgumentException e ) { e . printStackTrace ( ) ; } catch ( InstantiationException e ) { e . printStackTrace ( ) ; } catch ( IllegalAccessException e ) { e . printStackTrace ( ) ; } catch ( InvocationTargetException e ) { e . printStackTrace ( ) ; } return null ; } private static URLClassLoader getUrlClassLoader ( final URL outputDirUrl ) { URL [ ] urls ; List < URL > urlList = new ArrayList < URL > ( ) ; if ( outputDirUrl != null ) { urlList . add ( outputDirUrl ) ; } urls = urlList . toArray ( new URL [ ] { } ) ; ClassLoader loader = Thread . currentThread ( ) . getContextClassLoader ( ) ; URLClassLoader ucl = new URLClassLoader ( urls , loader ) ; return ucl ; } } </s>
|
<s> package org . eclipse . zest . tests . dot ; import org . eclipse . swt . SWT ; import org . eclipse . swt . layout . FillLayout ; import org . eclipse . swt . widgets . Display ; import org . eclipse . swt . widgets . Shell ; import org . eclipse . zest . dot . DotGraph ; import org . junit . Test ; public class SampleUsage { @ Test public void sampleUsage ( ) { Shell shell = new Shell ( ) ; DotGraph graph = new DotGraph ( "<STR_LIT>" , shell , SWT . NONE ) ; graph . add ( "<STR_LIT>" ) . add ( "<STR_LIT>" ) ; graph . add ( "<STR_LIT>" ) ; String dot = graph . toDot ( ) ; System . out . println ( graph ) ; System . out . println ( dot ) ; } @ SuppressWarnings ( "<STR_LIT:unused>" ) private void open ( final Shell shell ) { shell . setText ( DotGraph . class . getSimpleName ( ) ) ; shell . setLayout ( new FillLayout ( ) ) ; shell . setSize ( <NUM_LIT> , <NUM_LIT> ) ; shell . open ( ) ; Display display = shell . getDisplay ( ) ; while ( ! shell . isDisposed ( ) ) if ( ! display . readAndDispatch ( ) ) display . sleep ( ) ; display . dispose ( ) ; } } </s>
|
<s> package org . eclipse . zest . tests ; import junit . framework . TestCase ; import org . eclipse . draw2d . Figure ; import org . eclipse . swt . SWT ; import org . eclipse . swt . widgets . Shell ; import org . eclipse . zest . core . widgets . Graph ; import org . eclipse . zest . core . widgets . GraphConnection ; import org . eclipse . zest . core . widgets . GraphItem ; import org . eclipse . zest . core . widgets . GraphNode ; import org . eclipse . zest . core . widgets . internal . ZestRootLayer ; public class GraphTests extends TestCase { private static final int STYLE = SWT . NONE ; private GraphNode [ ] nodes ; private Graph graph ; private GraphConnection connection ; Shell shell ; protected void setUp ( ) throws Exception { shell = new Shell ( ) ; graph = new Graph ( shell , STYLE ) ; nodes = new GraphNode [ ] { new GraphNode ( graph , STYLE ) , new GraphNode ( graph , STYLE ) } ; connection = new GraphConnection ( graph , STYLE , nodes [ <NUM_LIT:0> ] , nodes [ <NUM_LIT:1> ] ) ; } public void testGraphData ( ) { graph . setData ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , graph . getData ( ) ) ; } public void testNodeItemData ( ) { GraphItem item = ( GraphNode ) graph . getNodes ( ) . get ( <NUM_LIT:0> ) ; item . setData ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , item . getData ( ) ) ; } public void testConnectionItemData ( ) { GraphItem item = ( GraphConnection ) graph . getConnections ( ) . get ( <NUM_LIT:0> ) ; item . setData ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , item . getData ( ) ) ; } public void testDisposeGraphWithDisposedNode ( ) { nodes [ <NUM_LIT:0> ] . dispose ( ) ; graph . getNodes ( ) . add ( nodes [ <NUM_LIT:0> ] ) ; assertTrue ( "<STR_LIT>" , nodes [ <NUM_LIT:0> ] . isDisposed ( ) ) ; graph . dispose ( ) ; assertTrue ( "<STR_LIT>" , graph . isDisposed ( ) ) ; } public void testDisposeGraphWithDisposedConnection ( ) { connection . dispose ( ) ; graph . getConnections ( ) . add ( connection ) ; assertTrue ( "<STR_LIT>" , connection . isDisposed ( ) ) ; graph . dispose ( ) ; assertTrue ( "<STR_LIT>" , graph . isDisposed ( ) ) ; } public void testUnHighlightNode ( ) { new ZestRootLayer ( ) . unHighlightNode ( new Figure ( ) ) ; } public void testUnHighlightConnection ( ) { new ZestRootLayer ( ) . unHighlightConnection ( new Figure ( ) ) ; } public void testDisposal ( ) { GraphNode n = ( GraphNode ) graph . getNodes ( ) . get ( <NUM_LIT:0> ) ; GraphConnection c = ( GraphConnection ) graph . getConnections ( ) . get ( <NUM_LIT:0> ) ; shell . dispose ( ) ; assertTrue ( "<STR_LIT>" , n . isDisposed ( ) ) ; assertTrue ( "<STR_LIT>" , c . isDisposed ( ) ) ; } } </s>
|
<s> package org . eclipse . zest . tests ; import junit . framework . Assert ; import junit . framework . TestCase ; import org . eclipse . swt . SWT ; import org . eclipse . swt . widgets . Item ; import org . eclipse . swt . widgets . Shell ; import org . eclipse . zest . core . widgets . DAGExpandCollapseManager ; import org . eclipse . zest . core . widgets . DefaultSubgraph ; import org . eclipse . zest . core . widgets . Graph ; import org . eclipse . zest . core . widgets . GraphConnection ; import org . eclipse . zest . core . widgets . GraphItem ; import org . eclipse . zest . core . widgets . GraphNode ; import org . eclipse . zest . core . widgets . LayoutFilter ; import org . eclipse . zest . layouts . LayoutAlgorithm ; import org . eclipse . zest . layouts . algorithms . GridLayoutAlgorithm ; import org . eclipse . zest . layouts . interfaces . LayoutContext ; public class LayoutAlgorithmTests extends TestCase { public void testCustomLayoutSimpleItemAccess ( ) { Graph graph = new Graph ( new Shell ( ) , SWT . NONE ) ; new GraphNode ( graph , SWT . NONE ) ; graph . setLayoutAlgorithm ( new LayoutAlgorithm ( ) { public void setLayoutContext ( LayoutContext context ) { Item [ ] all = context . getEntities ( ) [ <NUM_LIT:0> ] . getItems ( ) ; Item [ ] nodes = context . getNodes ( ) [ <NUM_LIT:0> ] . getItems ( ) ; Assert . assertEquals ( <NUM_LIT:1> , all . length ) ; Assert . assertEquals ( <NUM_LIT:1> , nodes . length ) ; Assert . assertTrue ( "<STR_LIT>" , all instanceof GraphNode [ ] ) ; Assert . assertTrue ( "<STR_LIT>" , nodes instanceof GraphNode [ ] ) ; Assert . assertTrue ( "<STR_LIT>" , all [ <NUM_LIT:0> ] instanceof GraphNode ) ; Assert . assertTrue ( "<STR_LIT>" , nodes [ <NUM_LIT:0> ] instanceof GraphNode ) ; } public void applyLayout ( boolean clean ) { } } , true ) ; } public void testCustomLayoutSubgraphItemAccess ( ) { Graph graph = new Graph ( new Shell ( ) , SWT . NONE ) ; graph . setSubgraphFactory ( new DefaultSubgraph . PrunedSuccessorsSubgraphFactory ( ) ) ; graph . setExpandCollapseManager ( new DAGExpandCollapseManager ( ) ) ; GraphNode n1 = new GraphNode ( graph , SWT . NONE ) ; GraphNode n2 = new GraphNode ( graph , SWT . NONE ) ; GraphNode n3 = new GraphNode ( graph , SWT . NONE ) ; new GraphConnection ( graph , SWT . NONE , n1 , n2 ) ; new GraphConnection ( graph , SWT . NONE , n1 , n3 ) ; graph . setLayoutAlgorithm ( new LayoutAlgorithm ( ) { public void setLayoutContext ( LayoutContext context ) { Assert . assertEquals ( <NUM_LIT:1> , context . getSubgraphs ( ) . length ) ; Item [ ] sub = context . getSubgraphs ( ) [ <NUM_LIT:0> ] . getItems ( ) ; Assert . assertEquals ( <NUM_LIT:3> , sub . length ) ; Assert . assertTrue ( "<STR_LIT>" , sub instanceof GraphNode [ ] ) ; Assert . assertTrue ( "<STR_LIT>" , sub [ <NUM_LIT:0> ] instanceof GraphNode ) ; } public void applyLayout ( boolean clean ) { } } , true ) ; } public void testCustomLayoutSubgraphFilteredAccess ( ) { Graph graph = new Graph ( new Shell ( ) , SWT . NONE ) ; graph . setSubgraphFactory ( new DefaultSubgraph . PrunedSuccessorsSubgraphFactory ( ) ) ; graph . setExpandCollapseManager ( new DAGExpandCollapseManager ( ) ) ; GraphNode n1 = new GraphNode ( graph , SWT . NONE ) ; GraphNode n2 = new GraphNode ( graph , SWT . NONE , "<STR_LIT>" ) ; GraphNode n3 = new GraphNode ( graph , SWT . NONE ) ; new GraphConnection ( graph , SWT . NONE , n1 , n2 ) ; new GraphConnection ( graph , SWT . NONE , n1 , n3 ) ; graph . addLayoutFilter ( new LayoutFilter ( ) { public boolean isObjectFiltered ( GraphItem item ) { if ( item instanceof GraphNode ) { GraphNode node = ( GraphNode ) item ; if ( node . getText ( ) . equals ( "<STR_LIT>" ) ) { return true ; } } return false ; } } ) ; graph . setLayoutAlgorithm ( new LayoutAlgorithm ( ) { public void setLayoutContext ( LayoutContext context ) { Assert . assertEquals ( <NUM_LIT:1> , context . getSubgraphs ( ) . length ) ; Item [ ] sub = context . getSubgraphs ( ) [ <NUM_LIT:0> ] . getItems ( ) ; Assert . assertEquals ( <NUM_LIT:2> , sub . length ) ; } public void applyLayout ( boolean clean ) { } } , true ) ; } public void testGridLayoutAlgorithmEmptyGraph ( ) { Graph graph = new Graph ( new Shell ( ) , SWT . NONE ) ; graph . setLayoutAlgorithm ( new GridLayoutAlgorithm ( ) , true ) ; Assert . assertEquals ( GridLayoutAlgorithm . class , graph . getLayoutAlgorithm ( ) . getClass ( ) ) ; } } </s>
|
<s> package org . eclipse . zest . tests . cloudio ; import org . eclipse . jface . viewers . BaseLabelProvider ; import org . eclipse . swt . graphics . Color ; import org . eclipse . swt . graphics . FontData ; import org . eclipse . swt . graphics . RGB ; import org . eclipse . swt . widgets . Display ; import org . eclipse . zest . cloudio . ICloudLabelProvider ; public class TestLabelProvider extends BaseLabelProvider implements ICloudLabelProvider { public static final double WEIGHT = <NUM_LIT> ; public static final float ANGLE = <NUM_LIT> ; public static Color COLOR = new Color ( Display . getDefault ( ) , new RGB ( <NUM_LIT:100> , <NUM_LIT:100> , <NUM_LIT:100> ) ) ; public static FontData [ ] FONT_DATA = Display . getDefault ( ) . getShells ( ) [ <NUM_LIT:0> ] . getFont ( ) . getFontData ( ) ; public String getLabel ( Object element ) { return element . toString ( ) ; } public double getWeight ( Object element ) { return WEIGHT ; } public Color getColor ( Object element ) { return COLOR ; } public FontData [ ] getFontData ( Object element ) { return FONT_DATA . clone ( ) ; } public float getAngle ( Object element ) { return ANGLE ; } public String getToolTip ( Object element ) { return getLabel ( element ) ; } } </s>
|
<s> package org . eclipse . zest . tests . cloudio ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . HashSet ; import java . util . List ; import java . util . Set ; import junit . framework . Assert ; import org . eclipse . swt . SWT ; import org . eclipse . swt . events . MouseEvent ; import org . eclipse . swt . events . MouseListener ; import org . eclipse . swt . events . MouseMoveListener ; import org . eclipse . swt . events . MouseTrackListener ; import org . eclipse . swt . events . MouseWheelListener ; import org . eclipse . swt . events . SelectionEvent ; import org . eclipse . swt . events . SelectionListener ; import org . eclipse . swt . graphics . Color ; import org . eclipse . swt . graphics . Rectangle ; import org . eclipse . swt . layout . FillLayout ; import org . eclipse . swt . widgets . Composite ; import org . eclipse . swt . widgets . Display ; import org . eclipse . swt . widgets . Event ; import org . eclipse . swt . widgets . Shell ; import org . eclipse . zest . cloudio . TagCloud ; import org . eclipse . zest . cloudio . Word ; import org . junit . After ; import org . junit . Before ; import org . junit . Test ; public class TagCloudTests { private Display display ; private boolean createdDisplay = false ; private Composite composite ; @ Before public void setUp ( ) throws Exception { display = Display . getCurrent ( ) ; if ( display == null ) { display = new Display ( ) ; createdDisplay = true ; } composite = new Shell ( display ) ; composite . setLayout ( new FillLayout ( ) ) ; } @ After public void tearDown ( ) throws Exception { composite . dispose ( ) ; if ( createdDisplay ) { display . dispose ( ) ; } } @ Test ( expected = IllegalArgumentException . class ) public void testConstructor_NullParent ( ) { new TagCloud ( null , SWT . NONE ) ; } @ Test public void testConstructor_ValidParent ( ) { TagCloud cloud = new TagCloud ( composite , SWT . NONE ) ; Assert . assertNotNull ( cloud ) ; } @ Test public void testDispose ( ) { TagCloud cloud = new TagCloud ( composite , SWT . NONE ) ; cloud . dispose ( ) ; Assert . assertTrue ( cloud . isDisposed ( ) ) ; } @ Test ( expected = IllegalArgumentException . class ) public void testSetInvalidBackgroundColor ( ) { TagCloud cloud = new TagCloud ( composite , SWT . NONE ) ; cloud . setBackground ( null ) ; } @ Test public void testSetValidBackgroundColor ( ) { TagCloud cloud = new TagCloud ( composite , SWT . NONE ) ; Color color = Display . getCurrent ( ) . getSystemColor ( SWT . COLOR_RED ) ; cloud . setBackground ( color ) ; Assert . assertEquals ( color , cloud . getBackground ( ) ) ; } @ Test public void testDefaultBackgroundColor ( ) { TagCloud cloud = new TagCloud ( composite , SWT . NONE ) ; Assert . assertNotNull ( cloud . getBackground ( ) ) ; } @ Test ( expected = IllegalArgumentException . class ) public void testSetInvalidSelectionColor ( ) { TagCloud cloud = new TagCloud ( composite , SWT . NONE ) ; cloud . setSelectionColor ( null ) ; } @ Test public void testSetValidSelectionColor ( ) { TagCloud cloud = new TagCloud ( composite , SWT . NONE ) ; Color color = Display . getCurrent ( ) . getSystemColor ( SWT . COLOR_RED ) ; cloud . setSelectionColor ( color ) ; Assert . assertEquals ( color , cloud . getSelectionColor ( ) ) ; } @ Test public void testDefaultSelectionColor ( ) { TagCloud cloud = new TagCloud ( composite , SWT . NONE ) ; Assert . assertNotNull ( cloud . getSelectionColor ( ) ) ; } @ Test ( expected = IllegalArgumentException . class ) public void testSetInvalidMaxFontSize ( ) { TagCloud cloud = new TagCloud ( composite , SWT . NONE ) ; cloud . setMaxFontSize ( <NUM_LIT:0> ) ; } @ Test ( expected = IllegalArgumentException . class ) public void testSetInvalidMinFontSize ( ) { TagCloud cloud = new TagCloud ( composite , SWT . NONE ) ; cloud . setMinFontSize ( <NUM_LIT:0> ) ; } @ Test public void testSetValidMaxFontSize ( ) { TagCloud cloud = new TagCloud ( composite , SWT . NONE ) ; int size = cloud . getMaxFontSize ( ) + <NUM_LIT:1> ; cloud . setMaxFontSize ( size * <NUM_LIT:2> ) ; Assert . assertEquals ( size * <NUM_LIT:2> , cloud . getMaxFontSize ( ) ) ; } @ Test public void testSetValidMinFontSize ( ) { TagCloud cloud = new TagCloud ( composite , SWT . NONE ) ; int size = cloud . getMinFontSize ( ) + <NUM_LIT:1> ; cloud . setMinFontSize ( size * <NUM_LIT:2> ) ; Assert . assertEquals ( size * <NUM_LIT:2> , cloud . getMinFontSize ( ) ) ; } @ Test ( expected = IllegalArgumentException . class ) public void testSetIllegalWords1 ( ) { TagCloud cloud = new TagCloud ( composite , SWT . NONE ) ; cloud . setWords ( null , null ) ; } @ Test ( expected = IllegalArgumentException . class ) public void testSetIllegalWords2 ( ) { TagCloud cloud = new TagCloud ( composite , SWT . NONE ) ; List < Word > words = new ArrayList < Word > ( ) ; words . add ( null ) ; cloud . setWords ( words , null ) ; } @ Test ( expected = IllegalArgumentException . class ) public void testSetIllegalWords3 ( ) { TagCloud cloud = new TagCloud ( composite , SWT . NONE ) ; List < Word > words = new ArrayList < Word > ( ) ; Word w = new Word ( "<STR_LIT>" ) ; w . setFontData ( composite . getFont ( ) . getFontData ( ) ) ; w . weight = Math . random ( ) ; words . add ( w ) ; cloud . setWords ( words , null ) ; } @ Test ( expected = IllegalArgumentException . class ) public void testSetIllegalWords4 ( ) { TagCloud cloud = new TagCloud ( composite , SWT . NONE ) ; List < Word > words = new ArrayList < Word > ( ) ; Word w = new Word ( "<STR_LIT>" ) ; w . setColor ( Display . getDefault ( ) . getSystemColor ( SWT . COLOR_RED ) ) ; w . weight = Math . random ( ) ; words . add ( w ) ; cloud . setWords ( words , null ) ; } @ Test ( expected = IllegalArgumentException . class ) public void testSetIllegalWords5 ( ) { TagCloud cloud = new TagCloud ( composite , SWT . NONE ) ; List < Word > words = new ArrayList < Word > ( ) ; Word word = getWord ( ) ; word . angle = - <NUM_LIT> ; words . add ( word ) ; cloud . setWords ( words , null ) ; } @ Test ( expected = IllegalArgumentException . class ) public void testSetIllegalWords6 ( ) { TagCloud cloud = new TagCloud ( composite , SWT . NONE ) ; List < Word > words = new ArrayList < Word > ( ) ; Word word = getWord ( ) ; word . angle = <NUM_LIT> ; words . add ( word ) ; cloud . setWords ( words , null ) ; } @ Test ( expected = IllegalArgumentException . class ) public void testSetIllegalWords7 ( ) { TagCloud cloud = new TagCloud ( composite , SWT . NONE ) ; List < Word > words = new ArrayList < Word > ( ) ; Word word = getWord ( ) ; word . weight = - <NUM_LIT:1> ; words . add ( word ) ; cloud . setWords ( words , null ) ; } @ Test ( expected = IllegalArgumentException . class ) public void testSetIllegalWords8 ( ) { TagCloud cloud = new TagCloud ( composite , SWT . NONE ) ; List < Word > words = new ArrayList < Word > ( ) ; Word word = getWord ( ) ; word . weight = <NUM_LIT:2> ; words . add ( word ) ; cloud . setWords ( words , null ) ; } @ Test ( expected = IllegalArgumentException . class ) public void testSetIllegalWords9 ( ) { TagCloud cloud = new TagCloud ( composite , SWT . NONE ) ; List < Word > words = new ArrayList < Word > ( ) ; Word word = new Word ( null ) ; words . add ( word ) ; cloud . setWords ( words , null ) ; } private Word getWord ( ) { Word w = new Word ( "<STR_LIT>" ) ; w . setColor ( Display . getDefault ( ) . getSystemColor ( SWT . COLOR_GRAY ) ) ; w . setFontData ( composite . getFont ( ) . getFontData ( ) ) ; w . weight = <NUM_LIT:1> ; return w ; } @ Test public void testSetEmptyWordList ( ) { TagCloud cloud = new TagCloud ( composite , SWT . NONE ) ; List < Word > words = new ArrayList < Word > ( ) ; int placed = cloud . setWords ( words , null ) ; Assert . assertEquals ( <NUM_LIT:0> , placed ) ; } @ Test public void testSetWordList ( ) { TagCloud cloud = new TagCloud ( composite , SWT . NONE ) ; List < Word > words = new ArrayList < Word > ( ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:10> ; i ++ ) { words . add ( getWord ( ) ) ; } int placed = cloud . setWords ( words , null ) ; Assert . assertEquals ( <NUM_LIT:10> , placed ) ; } @ Test ( expected = IllegalArgumentException . class ) public void testSetInvalidOpacity1 ( ) { TagCloud cloud = new TagCloud ( composite , SWT . NONE ) ; cloud . setOpacity ( - <NUM_LIT:1> ) ; } @ Test ( expected = IllegalArgumentException . class ) public void testSetInvalidOpacity2 ( ) { TagCloud cloud = new TagCloud ( composite , SWT . NONE ) ; cloud . setOpacity ( <NUM_LIT> ) ; } @ Test ( expected = IllegalArgumentException . class ) public void testSetInvalidLayouter ( ) { TagCloud cloud = new TagCloud ( composite , SWT . NONE ) ; cloud . setLayouter ( null ) ; } @ Test public void testZoomIn ( ) { TagCloud cloud = new TagCloud ( composite , SWT . NONE ) ; cloud . setWords ( Arrays . asList ( getWord ( ) ) , null ) ; double zoom = cloud . getZoom ( ) ; cloud . zoomIn ( ) ; Assert . assertTrue ( cloud . getZoom ( ) > zoom ) ; } @ Test public void testZoomReset ( ) { TagCloud cloud = new TagCloud ( composite , SWT . NONE ) ; cloud . setWords ( Arrays . asList ( getWord ( ) ) , null ) ; double zoom = cloud . getZoom ( ) ; cloud . zoomReset ( ) ; Assert . assertTrue ( cloud . getZoom ( ) > zoom ) ; Assert . assertEquals ( cloud . getZoom ( ) , <NUM_LIT:1.0> ) ; } @ Test public void testZoomOut ( ) { TagCloud cloud = new TagCloud ( composite , SWT . NONE ) ; cloud . setWords ( Arrays . asList ( getWord ( ) ) , null ) ; cloud . zoomReset ( ) ; double zoom = cloud . getZoom ( ) ; cloud . zoomOut ( ) ; Assert . assertTrue ( cloud . getZoom ( ) < zoom ) ; } @ Test public void testZoomFit ( ) { TagCloud cloud = new TagCloud ( composite , SWT . V_SCROLL | SWT . H_SCROLL ) ; cloud . setWords ( Arrays . asList ( getWord ( ) ) , null ) ; cloud . zoomReset ( ) ; double zoom = cloud . getZoom ( ) ; cloud . zoomFit ( ) ; Assert . assertTrue ( cloud . getZoom ( ) < zoom ) ; } @ Test public void testGetImageData ( ) { TagCloud cloud = new TagCloud ( composite , SWT . NONE ) ; Assert . assertNotNull ( cloud . getImageData ( ) ) ; } @ Test public void testInitialSelection ( ) { TagCloud cloud = new TagCloud ( composite , SWT . NONE ) ; Set < Word > selection = cloud . getSelection ( ) ; Assert . assertNotNull ( selection ) ; Assert . assertTrue ( selection . isEmpty ( ) ) ; } @ Test public void testSetSelection ( ) { TagCloud cloud = new TagCloud ( composite , SWT . NONE ) ; List < Word > words = new ArrayList < Word > ( ) ; words . add ( getWord ( ) ) ; words . add ( getWord ( ) ) ; cloud . setWords ( words , null ) ; Set < Word > sel = new HashSet < Word > ( ) ; sel . add ( words . get ( <NUM_LIT:0> ) ) ; cloud . setSelection ( sel ) ; Set < Word > selection = cloud . getSelection ( ) ; Assert . assertEquals ( sel , selection ) ; cloud . setSelection ( new HashSet < Word > ( ) ) ; selection = cloud . getSelection ( ) ; Assert . assertTrue ( selection . isEmpty ( ) ) ; } @ Test public void testSetNotExistingSelection1 ( ) { TagCloud cloud = new TagCloud ( composite , SWT . NONE ) ; List < Word > words = new ArrayList < Word > ( ) ; words . add ( getWord ( ) ) ; words . add ( getWord ( ) ) ; cloud . setWords ( words , null ) ; Set < Word > sel = new HashSet < Word > ( ) ; sel . add ( getWord ( ) ) ; cloud . setSelection ( sel ) ; Set < Word > selection = cloud . getSelection ( ) ; Assert . assertTrue ( selection . isEmpty ( ) ) ; } @ Test public void testSetNotExistingSelection2 ( ) { TagCloud cloud = new TagCloud ( composite , SWT . NONE ) ; Set < Word > sel = new HashSet < Word > ( ) ; sel . add ( getWord ( ) ) ; cloud . setSelection ( sel ) ; Set < Word > selection = cloud . getSelection ( ) ; Assert . assertTrue ( selection . isEmpty ( ) ) ; } @ Test ( expected = IllegalArgumentException . class ) public void testSetInvalidBoost ( ) { TagCloud cloud = new TagCloud ( composite , SWT . NONE ) ; cloud . setBoost ( - <NUM_LIT:1> ) ; } @ Test public void testSetValidBoost ( ) { TagCloud cloud = new TagCloud ( composite , SWT . NONE ) ; Assert . assertEquals ( <NUM_LIT:0> , cloud . getBoost ( ) ) ; cloud . setBoost ( <NUM_LIT:3> ) ; Assert . assertEquals ( <NUM_LIT:3> , cloud . getBoost ( ) ) ; } @ Test ( expected = IllegalArgumentException . class ) public void testSetInvalidBoostFactor ( ) { TagCloud cloud = new TagCloud ( composite , SWT . NONE ) ; cloud . setBoostFactor ( <NUM_LIT:0> ) ; } @ Test public void testSetValidBoostFactor ( ) { TagCloud cloud = new TagCloud ( composite , SWT . NONE ) ; cloud . setBoostFactor ( <NUM_LIT> ) ; Assert . assertEquals ( <NUM_LIT> , cloud . getBoostFactor ( ) ) ; cloud . setBoostFactor ( - <NUM_LIT> ) ; Assert . assertEquals ( - <NUM_LIT> , cloud . getBoostFactor ( ) ) ; } @ Test public void testLayout ( ) { TagCloud cloud = new TagCloud ( composite , SWT . NONE ) ; List < Word > words = new ArrayList < Word > ( ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:10> ; i ++ ) { words . add ( getWord ( ) ) ; } for ( Word word : words ) { Assert . assertTrue ( word . x == <NUM_LIT:0> ) ; Assert . assertTrue ( word . y == <NUM_LIT:0> ) ; } cloud . setWords ( words , null ) ; List < Rectangle > rects = new ArrayList < Rectangle > ( ) ; for ( Word word : words ) { Assert . assertTrue ( word . x != <NUM_LIT:0> ) ; Assert . assertTrue ( word . y != <NUM_LIT:0> ) ; word . angle = <NUM_LIT> ; rects . add ( new Rectangle ( word . x , word . y , word . width , word . height ) ) ; } cloud . layoutCloud ( null , false ) ; boolean posChanged = false ; boolean rectChanged = false ; for ( int i = <NUM_LIT:0> ; i < words . size ( ) ; i ++ ) { Word w = words . get ( i ) ; Rectangle r = rects . get ( i ) ; if ( w . x != r . x || w . y != r . y ) { posChanged = true ; } if ( w . width != r . width || w . height != r . height ) { rectChanged = true ; } } Assert . assertTrue ( posChanged ) ; Assert . assertFalse ( rectChanged ) ; cloud . layoutCloud ( null , true ) ; posChanged = false ; rectChanged = false ; for ( int i = <NUM_LIT:0> ; i < words . size ( ) ; i ++ ) { Word w = words . get ( i ) ; Rectangle r = rects . get ( i ) ; if ( w . x != r . x || w . y != r . y ) { posChanged = true ; } if ( w . width != r . width || w . height != r . height ) { rectChanged = true ; } } Assert . assertTrue ( posChanged ) ; Assert . assertTrue ( rectChanged ) ; } class UniversalListener implements MouseListener , MouseTrackListener , MouseWheelListener , MouseMoveListener , SelectionListener { private int mouseUp ; private int mouseDown ; private int mouseDC ; private int mouseMove ; private int mouseScrolled ; private int mouseExit ; private int mouseEnter ; private int mouseHover ; private Set < Word > selection ; public void mouseUp ( MouseEvent e ) { mouseUp ++ ; } public void mouseDown ( MouseEvent e ) { mouseDown ++ ; } public void mouseDoubleClick ( MouseEvent e ) { mouseDC ++ ; } public void mouseMove ( MouseEvent e ) { mouseMove ++ ; System . out . println ( "<STR_LIT>" ) ; } public void mouseScrolled ( MouseEvent e ) { mouseScrolled ++ ; } public void mouseEnter ( MouseEvent e ) { mouseEnter ++ ; } public void mouseExit ( MouseEvent e ) { mouseExit ++ ; } public void mouseHover ( MouseEvent e ) { mouseHover ++ ; } @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void widgetSelected ( SelectionEvent e ) { this . selection = ( Set < Word > ) e . data ; } public void widgetDefaultSelected ( SelectionEvent e ) { } } @ Test public void testMouseListener ( ) { TagCloud cloud = new TagCloud ( composite , SWT . NONE ) ; UniversalListener ml = new UniversalListener ( ) ; List < Word > words = new ArrayList < Word > ( ) ; Word word = getWord ( ) ; words . add ( word ) ; cloud . setWords ( words , null ) ; Event e = new Event ( ) ; cloud . addMouseListener ( ml ) ; cloud . notifyListeners ( SWT . MouseUp , e ) ; cloud . notifyListeners ( SWT . MouseDoubleClick , e ) ; cloud . notifyListeners ( SWT . MouseDown , e ) ; Assert . assertEquals ( <NUM_LIT:1> , ml . mouseUp ) ; Assert . assertEquals ( <NUM_LIT:1> , ml . mouseDC ) ; Assert . assertEquals ( <NUM_LIT:1> , ml . mouseDown ) ; cloud . removeMouseListener ( ml ) ; cloud . notifyListeners ( SWT . MouseUp , e ) ; cloud . notifyListeners ( SWT . MouseDoubleClick , e ) ; cloud . notifyListeners ( SWT . MouseDown , e ) ; Assert . assertEquals ( <NUM_LIT:1> , ml . mouseUp ) ; Assert . assertEquals ( <NUM_LIT:1> , ml . mouseDC ) ; Assert . assertEquals ( <NUM_LIT:1> , ml . mouseDown ) ; } @ Test public void testMouseMoveListener ( ) { TagCloud cloud = new TagCloud ( composite , SWT . NONE ) ; List < Word > words = new ArrayList < Word > ( ) ; Word word = getWord ( ) ; words . add ( word ) ; cloud . setWords ( words , null ) ; Event e = new Event ( ) ; e . x = word . x ; e . y = word . y ; UniversalListener ml = new UniversalListener ( ) ; cloud . addMouseMoveListener ( ml ) ; cloud . notifyListeners ( SWT . MouseMove , e ) ; Assert . assertEquals ( <NUM_LIT:1> , ml . mouseMove ) ; cloud . removeMouseMoveListener ( ml ) ; cloud . notifyListeners ( SWT . MouseMove , e ) ; Assert . assertEquals ( <NUM_LIT:1> , ml . mouseMove ) ; } @ Test public void testMouseWheelListener ( ) { TagCloud cloud = new TagCloud ( composite , SWT . NONE ) ; UniversalListener ml = new UniversalListener ( ) ; cloud . addMouseWheelListener ( ml ) ; cloud . notifyListeners ( SWT . MouseWheel , new Event ( ) ) ; Assert . assertEquals ( <NUM_LIT:1> , ml . mouseScrolled ) ; cloud . removeMouseWheelListener ( ml ) ; cloud . notifyListeners ( SWT . MouseWheel , new Event ( ) ) ; Assert . assertEquals ( <NUM_LIT:1> , ml . mouseScrolled ) ; } @ Test public void testSelectionListener ( ) { TagCloud cloud = new TagCloud ( composite , SWT . NONE ) ; List < Word > words = new ArrayList < Word > ( ) ; Word word = getWord ( ) ; words . add ( word ) ; cloud . setWords ( words , null ) ; UniversalListener sl = new UniversalListener ( ) ; cloud . addSelectionListener ( sl ) ; cloud . setSelection ( new HashSet < Word > ( words ) ) ; Assert . assertEquals ( <NUM_LIT:1> , sl . selection . size ( ) ) ; cloud . setSelection ( new HashSet < Word > ( ) ) ; Assert . assertEquals ( <NUM_LIT:0> , sl . selection . size ( ) ) ; cloud . removeSelectionListener ( sl ) ; cloud . setSelection ( new HashSet < Word > ( words ) ) ; Assert . assertEquals ( <NUM_LIT:0> , sl . selection . size ( ) ) ; } } </s>
|
<s> package org . eclipse . zest . tests . cloudio ; import java . util . ArrayList ; import java . util . List ; import junit . framework . Assert ; import org . eclipse . jface . viewers . BaseLabelProvider ; import org . eclipse . jface . viewers . IContentProvider ; import org . eclipse . jface . viewers . ITreeContentProvider ; import org . eclipse . jface . viewers . Viewer ; import org . eclipse . swt . SWT ; import org . eclipse . swt . layout . FillLayout ; import org . eclipse . swt . widgets . Composite ; import org . eclipse . swt . widgets . Display ; import org . eclipse . swt . widgets . Shell ; import org . eclipse . zest . cloudio . TagCloud ; import org . eclipse . zest . cloudio . TagCloudViewer ; import org . eclipse . zest . cloudio . Word ; import org . eclipse . zest . cloudio . layout . DefaultLayouter ; import org . junit . After ; import org . junit . Before ; import org . junit . Test ; public class TagCloudViewerTests { private Display display ; private boolean createdDisplay = false ; private Composite composite ; private TagCloud cloud ; @ Before public void setUp ( ) throws Exception { display = Display . getCurrent ( ) ; if ( display == null ) { display = new Display ( ) ; createdDisplay = true ; } composite = new Shell ( display ) ; composite . setLayout ( new FillLayout ( ) ) ; cloud = new TagCloud ( composite , SWT . NONE ) ; } @ After public void tearDown ( ) throws Exception { composite . dispose ( ) ; if ( createdDisplay ) { display . dispose ( ) ; } } @ Test ( expected = IllegalArgumentException . class ) public void testConstructor_NullCloud ( ) { new TagCloudViewer ( null ) ; } @ Test ( expected = IllegalArgumentException . class ) public void testConstructor_DisposedCloud ( ) { cloud . dispose ( ) ; new TagCloudViewer ( cloud ) ; } @ Test public void testConstructor_ValidCloud ( ) { TagCloudViewer viewer = new TagCloudViewer ( cloud ) ; TagCloud cloud = viewer . getCloud ( ) ; Assert . assertNotNull ( cloud ) ; Assert . assertEquals ( this . cloud , cloud ) ; Assert . assertTrue ( viewer . getSelection ( ) != null ) ; Assert . assertTrue ( viewer . getSelection ( ) . isEmpty ( ) ) ; } @ Test ( expected = IllegalArgumentException . class ) public void testInvalidLabelProvider ( ) { TagCloudViewer viewer = new TagCloudViewer ( cloud ) ; viewer . setLabelProvider ( null ) ; } @ Test ( expected = IllegalArgumentException . class ) public void testInvalidLabelProvider2 ( ) { TagCloudViewer viewer = new TagCloudViewer ( cloud ) ; viewer . setLabelProvider ( new BaseLabelProvider ( ) ) ; } @ Test public void testValidLabelProvider ( ) { TagCloudViewer viewer = new TagCloudViewer ( cloud ) ; TestLabelProvider labelProvider = new TestLabelProvider ( ) ; viewer . setLabelProvider ( labelProvider ) ; Assert . assertEquals ( labelProvider , viewer . getLabelProvider ( ) ) ; } @ Test ( expected = IllegalArgumentException . class ) public void testInvalidContentProvider ( ) { TagCloudViewer viewer = new TagCloudViewer ( cloud ) ; viewer . setContentProvider ( null ) ; } @ Test ( expected = IllegalArgumentException . class ) public void testInvalidContentProvider2 ( ) { TagCloudViewer viewer = new TagCloudViewer ( cloud ) ; viewer . setContentProvider ( new IContentProvider ( ) { public void inputChanged ( Viewer viewer , Object oldInput , Object newInput ) { } public void dispose ( ) { } } ) ; } private static class ListContentProvider implements ITreeContentProvider { public void dispose ( ) { } public void inputChanged ( Viewer viewer , Object oldInput , Object newInput ) { } public Object [ ] getElements ( Object inputElement ) { return ( ( List < ? > ) inputElement ) . toArray ( ) ; } public Object [ ] getChildren ( Object parentElement ) { return null ; } public Object getParent ( Object element ) { return null ; } public boolean hasChildren ( Object element ) { return false ; } } @ Test public void testValidContentProvider ( ) { TagCloudViewer viewer = new TagCloudViewer ( cloud ) ; ListContentProvider provider = new ListContentProvider ( ) ; viewer . setContentProvider ( provider ) ; Assert . assertEquals ( provider , viewer . getContentProvider ( ) ) ; } @ Test public void testValidLabelAsignment ( ) { TagCloudViewer viewer = new TagCloudViewer ( cloud ) ; ListContentProvider provider = new ListContentProvider ( ) ; viewer . setContentProvider ( provider ) ; TestLabelProvider labelProvider = new TestLabelProvider ( ) ; viewer . setLabelProvider ( labelProvider ) ; List < String > data = new ArrayList < String > ( ) ; data . add ( "<STR_LIT:Hello>" ) ; data . add ( "<STR_LIT>" ) ; viewer . setInput ( data ) ; List < Word > words = viewer . getCloud ( ) . getWords ( ) ; for ( Word word : words ) { Assert . assertEquals ( TestLabelProvider . COLOR , word . getColor ( ) ) ; for ( int i = <NUM_LIT:0> ; i < TestLabelProvider . FONT_DATA . length ; i ++ ) { Assert . assertEquals ( TestLabelProvider . FONT_DATA [ i ] , word . getFontData ( ) [ i ] ) ; } Assert . assertEquals ( TestLabelProvider . ANGLE , word . angle ) ; Assert . assertEquals ( TestLabelProvider . WEIGHT , word . weight ) ; Assert . assertTrue ( word . x != <NUM_LIT:0> ) ; Assert . assertTrue ( word . y != <NUM_LIT:0> ) ; Assert . assertTrue ( word . width != <NUM_LIT:0> ) ; Assert . assertTrue ( word . height != <NUM_LIT:0> ) ; } } @ Test ( expected = IllegalArgumentException . class ) public void testInvalidLayouter ( ) { TagCloudViewer viewer = new TagCloudViewer ( cloud ) ; viewer . setLayouter ( null ) ; } @ Test public void testValidLayouter ( ) { TagCloudViewer viewer = new TagCloudViewer ( cloud ) ; DefaultLayouter layouter = new DefaultLayouter ( <NUM_LIT:5> , <NUM_LIT:5> ) ; viewer . setLayouter ( layouter ) ; Assert . assertEquals ( layouter , viewer . getLayouter ( ) ) ; } } </s>
|
<s> package org . eclipse . zest . tests ; import java . util . ArrayList ; import java . util . Iterator ; import java . util . List ; import junit . framework . TestCase ; import org . eclipse . swt . SWT ; import org . eclipse . swt . events . SelectionEvent ; import org . eclipse . swt . events . SelectionListener ; import org . eclipse . swt . widgets . Event ; import org . eclipse . swt . widgets . Shell ; import org . eclipse . zest . core . widgets . Graph ; import org . eclipse . zest . core . widgets . GraphConnection ; import org . eclipse . zest . core . widgets . GraphNode ; public class GraphSelectionTests extends TestCase { private static final int STYLE = SWT . NONE ; private GraphNode [ ] nodes ; private Graph graph ; protected void setUp ( ) throws Exception { graph = new Graph ( new Shell ( ) , STYLE ) ; nodes = new GraphNode [ ] { new GraphNode ( graph , STYLE ) , new GraphNode ( graph , STYLE ) } ; new GraphConnection ( graph , STYLE , nodes [ <NUM_LIT:0> ] , nodes [ <NUM_LIT:1> ] ) ; } public void testSetSelectionGetSelection ( ) { graph . setSelection ( new GraphNode [ ] { } ) ; assertEquals ( <NUM_LIT:0> , graph . getSelection ( ) . size ( ) ) ; graph . setSelection ( nodes ) ; assertEquals ( <NUM_LIT:2> , graph . getSelection ( ) . size ( ) ) ; } public void testSelectAllGetSelection ( ) { graph . selectAll ( ) ; assertEquals ( <NUM_LIT:2> , graph . getSelection ( ) . size ( ) ) ; } public void testAddSelectionListenerEventIdentity ( ) { final List selectionEvents = new ArrayList ( ) ; graph . addSelectionListener ( setupListener ( selectionEvents ) ) ; graph . addSelectionListener ( setupListener ( selectionEvents ) ) ; Event event = new Event ( ) ; event . widget = nodes [ <NUM_LIT:0> ] ; graph . notifyListeners ( SWT . Selection , event ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:2> , selectionEvents . size ( ) ) ; assertEquals ( "<STR_LIT>" , selectionEvents . get ( <NUM_LIT:0> ) , selectionEvents . get ( <NUM_LIT:1> ) ) ; } public void testSelectedNodeDisposal ( ) { graph . setSelection ( nodes ) ; nodes [ <NUM_LIT:0> ] . dispose ( ) ; graph . layout ( ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , graph . getSelection ( ) . size ( ) ) ; } public void testAddSelectionListenerSetSelection ( ) { final List selectionEvents = new ArrayList ( ) ; graph . addSelectionListener ( setupListener ( selectionEvents ) ) ; graph . setSelection ( nodes ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:0> , selectionEvents . size ( ) ) ; for ( int i = <NUM_LIT:0> ; i < nodes . length ; i ++ ) { GraphNode node = nodes [ i ] ; assertTrue ( "<STR_LIT>" , node . isSelected ( ) ) ; } graph . setSelection ( new GraphNode [ ] { nodes [ <NUM_LIT:0> ] } ) ; for ( int i = <NUM_LIT:1> ; i < nodes . length ; i ++ ) { GraphNode node = nodes [ i ] ; assertFalse ( "<STR_LIT>" , node . isSelected ( ) ) ; } } public void testAddSelectionListenerSelectAll ( ) { final List selectionEvents = new ArrayList ( ) ; graph . addSelectionListener ( setupListener ( selectionEvents ) ) ; graph . selectAll ( ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:0> , selectionEvents . size ( ) ) ; for ( Iterator iterator = graph . getNodes ( ) . iterator ( ) ; iterator . hasNext ( ) ; ) { GraphNode node = ( GraphNode ) iterator . next ( ) ; assertTrue ( "<STR_LIT>" , node . isSelected ( ) ) ; } } public void testAddSelectionListenerNotifyListeners ( ) { final List selectionEvents = new ArrayList ( ) ; graph . addSelectionListener ( setupListener ( selectionEvents ) ) ; graph . setSelection ( nodes ) ; Event event = new Event ( ) ; event . widget = graph ; graph . notifyListeners ( SWT . Dispose , event ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:0> , selectionEvents . size ( ) ) ; graph . notifyListeners ( SWT . Selection , event ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , selectionEvents . size ( ) ) ; } public void testClearGraphCheckSelection ( ) throws Exception { graph . setSelection ( nodes ) ; assertEquals ( <NUM_LIT:2> , graph . getSelection ( ) . size ( ) ) ; graph . clear ( ) ; assertEquals ( <NUM_LIT:0> , graph . getNodes ( ) . size ( ) ) ; assertEquals ( <NUM_LIT:0> , graph . getConnections ( ) . size ( ) ) ; assertEquals ( <NUM_LIT:0> , graph . getSelection ( ) . size ( ) ) ; setUp ( ) ; assertEquals ( <NUM_LIT:2> , graph . getNodes ( ) . size ( ) ) ; assertEquals ( <NUM_LIT:1> , graph . getConnections ( ) . size ( ) ) ; } private SelectionListener setupListener ( final List events ) { return new SelectionListener ( ) { public void widgetSelected ( SelectionEvent e ) { events . add ( e ) ; } public void widgetDefaultSelected ( SelectionEvent e ) { } } ; } } </s>
|
<s> package org . eclipse . zest . tests ; import junit . framework . Assert ; import org . eclipse . core . runtime . Platform ; import org . junit . Before ; import org . junit . runner . RunWith ; import org . junit . runners . Suite ; @ RunWith ( Suite . class ) @ Suite . SuiteClasses ( { AllHeadlessTests . class , AllUiTests . class } ) public final class AllTests { @ Before public void setup ( ) { if ( ! Platform . isRunning ( ) ) { Assert . fail ( "<STR_LIT>" ) ; } } } </s>
|
<s> package org . eclipse . zest . core . viewers . internal ; import java . util . Iterator ; import java . util . List ; import org . eclipse . zest . core . viewers . AbstractStructuredGraphViewer ; import org . eclipse . zest . core . viewers . IFigureProvider ; import org . eclipse . zest . core . viewers . IGraphContentProvider ; import org . eclipse . zest . core . widgets . Graph ; import org . eclipse . zest . core . widgets . GraphConnection ; import org . eclipse . zest . core . widgets . GraphNode ; public class GraphModelFactory extends AbstractStylingModelFactory { AbstractStructuredGraphViewer viewer = null ; public GraphModelFactory ( AbstractStructuredGraphViewer viewer ) { super ( viewer ) ; this . viewer = viewer ; } public Graph createGraphModel ( Graph model ) { doBuildGraph ( model ) ; return model ; } protected void doBuildGraph ( Graph model ) { super . doBuildGraph ( model ) ; Object rels [ ] = getContentProvider ( ) . getElements ( getViewer ( ) . getInput ( ) ) ; if ( rels != null ) { IFigureProvider figureProvider = null ; if ( getLabelProvider ( ) instanceof IFigureProvider ) { figureProvider = ( IFigureProvider ) getLabelProvider ( ) ; } for ( int i = <NUM_LIT:0> ; i < rels . length ; i ++ ) { Object source = getCastedContent ( ) . getSource ( rels [ i ] ) ; source = filterElement ( getViewer ( ) . getInput ( ) , source ) ? null : source ; Object dest = getCastedContent ( ) . getDestination ( rels [ i ] ) ; dest = filterElement ( getViewer ( ) . getInput ( ) , dest ) ? null : dest ; if ( source == null ) { if ( dest != null ) { if ( figureProvider != null ) { createNode ( model , dest , figureProvider . getFigure ( dest ) ) ; } else { createNode ( model , dest ) ; } } continue ; } else if ( dest == null ) { if ( source != null ) { if ( figureProvider != null ) { createNode ( model , source , figureProvider . getFigure ( source ) ) ; } else { createNode ( model , source ) ; } } continue ; } if ( source != null && dest != null && ! filterElement ( getViewer ( ) . getInput ( ) , rels [ i ] ) ) { createConnection ( model , rels [ i ] , getCastedContent ( ) . getSource ( rels [ i ] ) , getCastedContent ( ) . getDestination ( rels [ i ] ) ) ; } } } } private IGraphContentProvider getCastedContent ( ) { return ( IGraphContentProvider ) getContentProvider ( ) ; } public void refresh ( Graph graph , Object element ) { refresh ( graph , element , false ) ; } public void refresh ( Graph graph , Object element , boolean updateLabels ) { GraphConnection conn = viewer . getGraphModelConnection ( element ) ; if ( conn == null ) { GraphNode node = viewer . getGraphModelNode ( element ) ; if ( node != null ) { List connections = node . getSourceConnections ( ) ; for ( Iterator it = connections . iterator ( ) ; it . hasNext ( ) ; ) { GraphConnection c = ( GraphConnection ) it . next ( ) ; refresh ( graph , c . getExternalConnection ( ) , updateLabels ) ; } connections = node . getTargetConnections ( ) ; for ( Iterator it = connections . iterator ( ) ; it . hasNext ( ) ; ) { GraphConnection c = ( GraphConnection ) it . next ( ) ; refresh ( graph , c . getExternalConnection ( ) , updateLabels ) ; } } return ; } Object oldSource = conn . getSource ( ) . getData ( ) ; Object oldDest = conn . getDestination ( ) . getData ( ) ; Object newSource = getCastedContent ( ) . getSource ( element ) ; Object newDest = getCastedContent ( ) . getDestination ( element ) ; if ( ! ( oldSource . equals ( newSource ) && oldDest . equals ( newDest ) ) ) { GraphNode internalSource = viewer . getGraphModelNode ( newSource ) ; GraphNode internalDest = viewer . getGraphModelNode ( newDest ) ; if ( internalSource == null ) { internalSource = createNode ( graph , newSource ) ; } else if ( updateLabels ) { styleItem ( internalSource ) ; } if ( internalDest == null ) { internalDest = createNode ( graph , newDest ) ; } else if ( updateLabels ) { styleItem ( internalDest ) ; } if ( updateLabels ) { styleItem ( conn ) ; } } } } </s>
|
<s> package org . eclipse . zest . core . viewers . internal ; import org . eclipse . draw2d . ConnectionRouter ; import org . eclipse . draw2d . IFigure ; import org . eclipse . jface . viewers . IBaseLabelProvider ; import org . eclipse . jface . viewers . IColorProvider ; import org . eclipse . jface . viewers . IFontProvider ; import org . eclipse . jface . viewers . ILabelProvider ; import org . eclipse . swt . SWT ; import org . eclipse . swt . SWTError ; import org . eclipse . swt . graphics . Color ; import org . eclipse . zest . core . viewers . IConnectionStyleProvider ; import org . eclipse . zest . core . viewers . IEntityConnectionStyleProvider ; import org . eclipse . zest . core . viewers . IEntityStyleProvider ; import org . eclipse . zest . core . viewers . ISelfStyleProvider ; import org . eclipse . zest . core . widgets . GraphConnection ; import org . eclipse . zest . core . widgets . GraphItem ; import org . eclipse . zest . core . widgets . GraphNode ; import org . eclipse . zest . core . widgets . ZestStyles ; public class GraphItemStyler { public static void styleItem ( GraphItem item , final IBaseLabelProvider labelProvider ) { if ( item instanceof GraphNode ) { GraphNode node = ( GraphNode ) item ; if ( node . getGraphModel ( ) . getNodeStyle ( ) != ZestStyles . NONE ) { node . setNodeStyle ( node . getGraphModel ( ) . getNodeStyle ( ) ) ; } else { node . setNodeStyle ( SWT . NONE ) ; } Object entity = node . getData ( ) ; if ( labelProvider instanceof IEntityStyleProvider ) { styleNode ( node , ( IEntityStyleProvider ) labelProvider ) ; } if ( labelProvider instanceof IColorProvider ) { IColorProvider colorProvider = ( IColorProvider ) labelProvider ; node . setForegroundColor ( colorProvider . getForeground ( entity ) ) ; node . setBackgroundColor ( colorProvider . getBackground ( entity ) ) ; } if ( labelProvider instanceof IFontProvider ) { IFontProvider fontProvider = ( IFontProvider ) labelProvider ; node . setFont ( fontProvider . getFont ( entity ) ) ; } if ( labelProvider instanceof ILabelProvider ) { String text = ( ( ILabelProvider ) labelProvider ) . getText ( node . getData ( ) ) ; node . setText ( ( text != null ) ? text : "<STR_LIT>" ) ; node . setImage ( ( ( ILabelProvider ) labelProvider ) . getImage ( node . getData ( ) ) ) ; } if ( labelProvider instanceof ISelfStyleProvider ) { ( ( ISelfStyleProvider ) labelProvider ) . selfStyleNode ( entity , node ) ; } } else if ( item instanceof GraphConnection ) { GraphConnection conn = ( GraphConnection ) item ; if ( conn . getGraphModel ( ) . getConnectionStyle ( ) != ZestStyles . NONE ) { int s = conn . getGraphModel ( ) . getConnectionStyle ( ) ; conn . setConnectionStyle ( s ) ; } else { conn . setConnectionStyle ( SWT . NONE ) ; } if ( labelProvider instanceof ILabelProvider ) { String text = ( ( ILabelProvider ) labelProvider ) . getText ( conn . getExternalConnection ( ) ) ; conn . setText ( ( text != null ) ? text : "<STR_LIT>" ) ; conn . setImage ( ( ( ILabelProvider ) labelProvider ) . getImage ( conn . getExternalConnection ( ) ) ) ; } if ( labelProvider instanceof IEntityConnectionStyleProvider ) { styleEntityConnection ( conn , ( IEntityConnectionStyleProvider ) labelProvider ) ; } else if ( labelProvider instanceof IConnectionStyleProvider ) { styleConnection ( conn , ( IConnectionStyleProvider ) labelProvider ) ; } int swt = getLineStyleForZestStyle ( conn . getConnectionStyle ( ) ) ; conn . setLineStyle ( swt ) ; if ( labelProvider instanceof ISelfStyleProvider ) { ( ( ISelfStyleProvider ) labelProvider ) . selfStyleConnection ( conn . getData ( ) , conn ) ; } } } private static void styleConnection ( GraphConnection conn , IConnectionStyleProvider provider ) { Object rel = conn . getExternalConnection ( ) ; Color c ; int style = provider . getConnectionStyle ( rel ) ; if ( ! ZestStyles . validateConnectionStyle ( style ) ) { throw new SWTError ( SWT . ERROR_INVALID_ARGUMENT ) ; } if ( style != ZestStyles . NONE ) { conn . setConnectionStyle ( style ) ; } if ( ( c = provider . getHighlightColor ( rel ) ) != null ) { conn . setHighlightColor ( c ) ; } if ( ( c = provider . getColor ( rel ) ) != null ) { conn . setLineColor ( c ) ; } IFigure tooltip ; if ( ( tooltip = provider . getTooltip ( rel ) ) != null ) { conn . setTooltip ( tooltip ) ; } int w = - <NUM_LIT:1> ; if ( ( w = provider . getLineWidth ( rel ) ) >= <NUM_LIT:0> ) { conn . setLineWidth ( w ) ; } ConnectionRouter cr ; if ( ( cr = provider . getRouter ( rel ) ) != null ) { conn . setRouter ( cr ) ; } } private static void styleEntityConnection ( GraphConnection conn , IEntityConnectionStyleProvider provider ) { Object src = conn . getSource ( ) . getData ( ) ; Object dest = conn . getDestination ( ) . getData ( ) ; Color c ; int style = provider . getConnectionStyle ( src , dest ) ; if ( ! ZestStyles . validateConnectionStyle ( style ) ) { throw new SWTError ( SWT . ERROR_INVALID_ARGUMENT ) ; } if ( style != ZestStyles . NONE ) { conn . setConnectionStyle ( style ) ; } if ( ( c = provider . getColor ( src , dest ) ) != null ) { conn . setLineColor ( c ) ; } if ( ( c = provider . getHighlightColor ( src , dest ) ) != null ) { conn . setHighlightColor ( c ) ; } int w = - <NUM_LIT:1> ; if ( ( w = provider . getLineWidth ( src , dest ) ) >= <NUM_LIT:0> ) { conn . setLineWidth ( w ) ; } ConnectionRouter cr ; if ( ( cr = provider . getRouter ( src , dest ) ) != null ) { conn . setRouter ( cr ) ; } } private static void styleNode ( GraphNode node , IEntityStyleProvider provider ) { Object entity = node . getData ( ) ; Color c ; IFigure figure ; int width = - <NUM_LIT:1> ; if ( provider . fisheyeNode ( entity ) == true ) { node . setNodeStyle ( node . getNodeStyle ( ) | ZestStyles . NODES_FISHEYE ) ; } if ( ( c = provider . getBorderColor ( entity ) ) != null ) { node . setBorderColor ( c ) ; } if ( ( c = provider . getBorderHighlightColor ( entity ) ) != null ) { node . setBorderHighlightColor ( c ) ; } if ( ( c = provider . getNodeHighlightColor ( entity ) ) != null ) { node . setHighlightColor ( c ) ; } if ( ( c = provider . getBackgroundColour ( entity ) ) != null ) { node . setBackgroundColor ( c ) ; } if ( ( c = provider . getForegroundColour ( entity ) ) != null ) { node . setForegroundColor ( c ) ; } if ( ( width = provider . getBorderWidth ( entity ) ) >= <NUM_LIT:0> ) { node . setBorderWidth ( width ) ; } if ( ( figure = provider . getTooltip ( entity ) ) != null ) { node . setTooltip ( figure ) ; } } public static int getLineStyleForZestStyle ( int style ) { int lineStyles = ZestStyles . CONNECTIONS_DASH_DOT | ZestStyles . CONNECTIONS_DASH | ZestStyles . CONNECTIONS_DOT | ZestStyles . CONNECTIONS_SOLID ; style = style & lineStyles ; if ( style == <NUM_LIT:0> ) { style = ZestStyles . CONNECTIONS_SOLID ; } switch ( style ) { case ZestStyles . CONNECTIONS_DASH_DOT : return SWT . LINE_DASHDOT ; case ZestStyles . CONNECTIONS_DASH : return SWT . LINE_DASH ; case ZestStyles . CONNECTIONS_DOT : return SWT . LINE_DOT ; } return SWT . LINE_SOLID ; } } </s>
|
<s> package org . eclipse . zest . core . viewers . internal ; import org . eclipse . jface . viewers . ITreeContentProvider ; import org . eclipse . zest . core . viewers . AbstractStructuredGraphViewer ; import org . eclipse . zest . core . viewers . EntityConnectionData ; import org . eclipse . zest . core . widgets . Graph ; import org . eclipse . zest . core . widgets . GraphConnection ; import org . eclipse . zest . core . widgets . GraphNode ; public class TreeModelEntityFactory extends AbstractStylingModelFactory { AbstractStructuredGraphViewer viewer = null ; public TreeModelEntityFactory ( AbstractStructuredGraphViewer viewer ) { super ( viewer ) ; this . viewer = viewer ; } @ Override public Graph createGraphModel ( Graph model ) { doBuildGraph ( model ) ; return model ; } @ Override protected void doBuildGraph ( Graph model ) { super . doBuildGraph ( model ) ; Object inputElement = getViewer ( ) . getInput ( ) ; ITreeContentProvider provider = ( ITreeContentProvider ) getContentProvider ( ) ; Object [ ] entities = provider . getElements ( inputElement ) ; if ( entities == null ) return ; for ( Object data : entities ) { createGraphNodes ( model , data , provider ) ; } } private GraphNode createGraphNodes ( Graph model , Object data , ITreeContentProvider provider ) { GraphNode node = createNode ( model , data ) ; if ( provider . hasChildren ( data ) ) { for ( Object child : provider . getChildren ( data ) ) { GraphNode childNode = createGraphNodes ( model , child , provider ) ; EntityConnectionData connectionData = new EntityConnectionData ( node , childNode ) ; createConnection ( model , connectionData , data , child ) ; } } return node ; } @ Override public void refresh ( Graph graph , Object element , boolean updateLabels ) { if ( element == null ) { return ; } GraphNode node = viewer . getGraphModelNode ( element ) ; if ( node == null ) { GraphConnection conn = viewer . getGraphModelConnection ( element ) ; if ( conn != null ) { refresh ( graph , conn . getSource ( ) . getData ( ) , updateLabels ) ; refresh ( graph , conn . getDestination ( ) . getData ( ) , updateLabels ) ; return ; } } if ( node == null ) return ; reconnect ( graph , element , updateLabels ) ; if ( updateLabels ) update ( node ) ; } private void reconnect ( Graph graph , Object element , boolean updateLabels ) { GraphNode sourceNode = viewer . getGraphModelNode ( element ) ; Object [ ] children = ( ( ITreeContentProvider ) getContentProvider ( ) ) . getChildren ( element ) ; EntityConnectionData data = null ; GraphConnection oldConnection = null ; GraphConnection newConnection = null ; for ( Object child : children ) { GraphNode destNode = viewer . getGraphModelNode ( child ) ; data = new EntityConnectionData ( sourceNode , destNode ) ; oldConnection = viewer . getGraphModelConnection ( data ) ; if ( oldConnection != null ) { viewer . removeGraphModelConnection ( oldConnection ) ; newConnection = createConnection ( graph , data , sourceNode . getData ( ) , destNode . getData ( ) ) ; if ( updateLabels ) { styleItem ( newConnection ) ; } } refresh ( graph , child , updateLabels ) ; } } } </s>
|
<s> package org . eclipse . zest . core . viewers . internal ; import java . util . HashSet ; import java . util . Iterator ; import java . util . LinkedList ; import java . util . List ; import java . util . Set ; import org . eclipse . zest . core . viewers . AbstractStructuredGraphViewer ; import org . eclipse . zest . core . viewers . EntityConnectionData ; import org . eclipse . zest . core . viewers . IGraphEntityContentProvider ; import org . eclipse . zest . core . widgets . Graph ; import org . eclipse . zest . core . widgets . GraphConnection ; import org . eclipse . zest . core . widgets . GraphItem ; import org . eclipse . zest . core . widgets . GraphNode ; public class GraphModelEntityFactory extends AbstractStylingModelFactory { AbstractStructuredGraphViewer viewer = null ; public GraphModelEntityFactory ( AbstractStructuredGraphViewer viewer ) { super ( viewer ) ; this . viewer = viewer ; } public Graph createGraphModel ( Graph model ) { doBuildGraph ( model ) ; return model ; } protected void doBuildGraph ( Graph model ) { super . doBuildGraph ( model ) ; Object inputElement = getViewer ( ) . getInput ( ) ; Object entities [ ] = getContentProvider ( ) . getElements ( inputElement ) ; if ( entities == null ) { return ; } for ( int i = <NUM_LIT:0> ; i < entities . length ; i ++ ) { Object data = entities [ i ] ; if ( ! filterElement ( inputElement , data ) ) { createNode ( model , data ) ; } } Set keySet = ( ( AbstractStructuredGraphViewer ) getViewer ( ) ) . getNodesMap ( ) . keySet ( ) ; entities = keySet . toArray ( ) ; for ( int i = <NUM_LIT:0> ; i < entities . length ; i ++ ) { Object data = entities [ i ] ; if ( filterElement ( inputElement , data ) ) { continue ; } Object [ ] related = ( ( IGraphEntityContentProvider ) getContentProvider ( ) ) . getConnectedTo ( data ) ; if ( related != null ) { for ( int j = <NUM_LIT:0> ; j < related . length ; j ++ ) { if ( filterElement ( inputElement , related [ j ] ) ) { continue ; } EntityConnectionData connectionData = new EntityConnectionData ( data , related [ j ] ) ; if ( filterElement ( inputElement , connectionData ) ) { continue ; } createConnection ( model , connectionData , data , related [ j ] ) ; } } } } public void refresh ( Graph graph , Object element , boolean refreshLabels ) { if ( element == null ) { return ; } GraphNode node = viewer . getGraphModelNode ( element ) ; if ( node == null ) { GraphConnection conn = viewer . getGraphModelConnection ( element ) ; if ( conn != null ) { refresh ( graph , conn . getSource ( ) . getData ( ) , refreshLabels ) ; refresh ( graph , conn . getDestination ( ) . getData ( ) , refreshLabels ) ; return ; } } if ( node == null ) { return ; } reconnect ( graph , element , refreshLabels ) ; if ( refreshLabels ) { update ( node ) ; for ( Iterator it = node . getSourceConnections ( ) . iterator ( ) ; it . hasNext ( ) ; ) { update ( ( GraphItem ) it . next ( ) ) ; } for ( Iterator it = node . getTargetConnections ( ) . iterator ( ) ; it . hasNext ( ) ; ) { update ( ( GraphItem ) it . next ( ) ) ; } } } private void reconnect ( Graph graph , Object element , boolean refreshLabels ) { GraphNode node = viewer . getGraphModelNode ( element ) ; Object [ ] related = ( ( IGraphEntityContentProvider ) getContentProvider ( ) ) . getConnectedTo ( element ) ; List connections = node . getSourceConnections ( ) ; LinkedList toAdd = new LinkedList ( ) ; LinkedList toDelete = new LinkedList ( ) ; LinkedList toKeep = new LinkedList ( ) ; HashSet oldExternalConnections = new HashSet ( ) ; HashSet newExternalConnections = new HashSet ( ) ; for ( Iterator it = connections . iterator ( ) ; it . hasNext ( ) ; ) { oldExternalConnections . add ( ( ( GraphConnection ) it . next ( ) ) . getExternalConnection ( ) ) ; } for ( int i = <NUM_LIT:0> ; i < related . length ; i ++ ) { newExternalConnections . add ( new EntityConnectionData ( element , related [ i ] ) ) ; } for ( Iterator it = oldExternalConnections . iterator ( ) ; it . hasNext ( ) ; ) { Object next = it . next ( ) ; if ( ! newExternalConnections . contains ( next ) ) { toDelete . add ( next ) ; } else { toKeep . add ( next ) ; } } for ( Iterator it = newExternalConnections . iterator ( ) ; it . hasNext ( ) ; ) { Object next = it . next ( ) ; if ( ! oldExternalConnections . contains ( next ) ) { toAdd . add ( next ) ; } } for ( Iterator it = toDelete . iterator ( ) ; it . hasNext ( ) ; ) { viewer . removeGraphModelConnection ( it . next ( ) ) ; } toDelete . clear ( ) ; LinkedList newNodeList = new LinkedList ( ) ; for ( Iterator it = toAdd . iterator ( ) ; it . hasNext ( ) ; ) { EntityConnectionData data = ( EntityConnectionData ) it . next ( ) ; GraphNode dest = viewer . getGraphModelNode ( data . dest ) ; if ( dest == null ) { newNodeList . add ( data . dest ) ; } createConnection ( graph , data , data . source , data . dest ) ; } toAdd . clear ( ) ; if ( refreshLabels ) { for ( Iterator i = toKeep . iterator ( ) ; i . hasNext ( ) ; ) { styleItem ( viewer . getGraphModelConnection ( i . next ( ) ) ) ; } } for ( Iterator it = newNodeList . iterator ( ) ; it . hasNext ( ) ; ) { refresh ( graph , it . next ( ) ) ; } } public void refresh ( Graph graph , Object element ) { refresh ( graph , element , false ) ; } } </s>
|
<s> package org . eclipse . zest . core . viewers . internal ; import org . eclipse . jface . viewers . IBaseLabelProvider ; import org . eclipse . jface . viewers . IStructuredContentProvider ; import org . eclipse . jface . viewers . StructuredViewer ; import org . eclipse . zest . core . widgets . Graph ; import org . eclipse . zest . core . widgets . GraphConnection ; import org . eclipse . zest . core . widgets . GraphItem ; import org . eclipse . zest . core . widgets . GraphNode ; public interface IStylingGraphModelFactory { public IBaseLabelProvider getLabelProvider ( ) ; public IStructuredContentProvider getContentProvider ( ) ; public Graph createGraphModel ( Graph model ) ; public GraphNode createNode ( Graph graph , Object element ) ; public GraphConnection createConnection ( Graph graph , Object element , Object source , Object dest ) ; public void update ( GraphItem [ ] items ) ; public void update ( GraphItem item ) ; public void refresh ( Graph graph , Object element ) ; public void refresh ( Graph graph , Object element , boolean updateLabels ) ; public void refreshGraph ( Graph graph ) ; public StructuredViewer getViewer ( ) ; public void setConnectionStyle ( int style ) ; public int getConnectionStyle ( ) ; public void setNodeStyle ( int style ) ; public int getNodeStyle ( ) ; } </s>
|
<s> package org . eclipse . zest . core . viewers . internal ; import java . util . ArrayList ; import java . util . List ; import org . eclipse . zest . core . viewers . AbstractStructuredGraphViewer ; import org . eclipse . zest . core . viewers . IGraphEntityRelationshipContentProvider ; import org . eclipse . zest . core . widgets . Graph ; import org . eclipse . zest . core . widgets . GraphContainer ; import org . eclipse . zest . core . widgets . GraphNode ; public class GraphModelEntityRelationshipFactory extends AbstractStylingModelFactory { public GraphModelEntityRelationshipFactory ( AbstractStructuredGraphViewer viewer ) { super ( viewer ) ; if ( ! ( viewer . getContentProvider ( ) instanceof IGraphEntityRelationshipContentProvider ) ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } } public Graph createGraphModel ( Graph model ) { doBuildGraph ( model ) ; return model ; } protected void doBuildGraph ( Graph model ) { super . doBuildGraph ( model ) ; Object [ ] nodes = getContentProvider ( ) . getElements ( getViewer ( ) . getInput ( ) ) ; nodes = filter ( getViewer ( ) . getInput ( ) , nodes ) ; createModelNodes ( model , nodes ) ; createModelRelationships ( model ) ; } private void createModelRelationships ( Graph model ) { GraphNode [ ] modelNodes = getNodesArray ( model ) ; List listOfNodes = new ArrayList ( ) ; for ( int i = <NUM_LIT:0> ; i < modelNodes . length ; i ++ ) { listOfNodes . add ( modelNodes [ i ] ) ; } for ( int i = <NUM_LIT:0> ; i < listOfNodes . size ( ) ; i ++ ) { GraphNode node = ( GraphNode ) listOfNodes . get ( i ) ; if ( node instanceof GraphContainer ) { List childNodes = ( ( GraphContainer ) node ) . getNodes ( ) ; listOfNodes . addAll ( childNodes ) ; } } modelNodes = ( GraphNode [ ] ) listOfNodes . toArray ( new GraphNode [ listOfNodes . size ( ) ] ) ; IGraphEntityRelationshipContentProvider content = getCastedContent ( ) ; for ( int i = <NUM_LIT:0> ; i < modelNodes . length ; i ++ ) { for ( int j = <NUM_LIT:0> ; j < modelNodes . length ; j ++ ) { Object [ ] rels = content . getRelationships ( modelNodes [ i ] . getData ( ) , modelNodes [ j ] . getData ( ) ) ; if ( rels != null ) { rels = filter ( getViewer ( ) . getInput ( ) , rels ) ; for ( int r = <NUM_LIT:0> ; r < rels . length ; r ++ ) { createConnection ( model , rels [ r ] , modelNodes [ i ] . getData ( ) , modelNodes [ j ] . getData ( ) ) ; } } } } } private void createModelNodes ( Graph model , Object [ ] nodes ) { for ( int i = <NUM_LIT:0> ; i < nodes . length ; i ++ ) { createNode ( model , nodes [ i ] ) ; } } public void refresh ( Graph graph , Object element ) { refresh ( graph , element , false ) ; } public void refresh ( Graph graph , Object element , boolean updateLabels ) { refreshGraph ( graph ) ; } private IGraphEntityRelationshipContentProvider getCastedContent ( ) { return ( IGraphEntityRelationshipContentProvider ) getContentProvider ( ) ; } } </s>
|
<s> package org . eclipse . zest . core . viewers . internal ; import java . util . HashMap ; import java . util . Iterator ; import java . util . LinkedList ; import java . util . List ; import java . util . Map ; import org . eclipse . draw2d . IFigure ; import org . eclipse . jface . viewers . IBaseLabelProvider ; import org . eclipse . jface . viewers . IStructuredContentProvider ; import org . eclipse . jface . viewers . StructuredViewer ; import org . eclipse . jface . viewers . ViewerFilter ; import org . eclipse . swt . SWT ; import org . eclipse . zest . core . viewers . AbstractStructuredGraphViewer ; import org . eclipse . zest . core . viewers . IFigureProvider ; import org . eclipse . zest . core . viewers . INestedContentProvider ; import org . eclipse . zest . core . widgets . Graph ; import org . eclipse . zest . core . widgets . GraphConnection ; import org . eclipse . zest . core . widgets . GraphContainer ; import org . eclipse . zest . core . widgets . GraphItem ; import org . eclipse . zest . core . widgets . GraphNode ; public abstract class AbstractStylingModelFactory implements IStylingGraphModelFactory { private AbstractStructuredGraphViewer viewer ; private int connectionStyle ; private int nodeStyle ; public AbstractStylingModelFactory ( AbstractStructuredGraphViewer viewer ) { this . viewer = viewer ; this . connectionStyle = SWT . NONE ; this . nodeStyle = SWT . NONE ; } public void styleConnection ( GraphConnection conn ) { GraphNode source = conn . getSource ( ) ; GraphNode dest = conn . getDestination ( ) ; LinkedList rightList = getConnectionList ( source , dest ) ; LinkedList leftList = null ; if ( dest != source ) { leftList = getConnectionList ( dest , source ) ; } int size = ( leftList != null ) ? leftList . size ( ) + rightList . size ( ) : rightList . size ( ) ; adjustCurves ( rightList , size ) ; if ( leftList != null ) { adjustCurves ( leftList , size ) ; } } protected void adjustCurves ( List connections , int size ) { for ( int i = <NUM_LIT:0> ; i < connections . size ( ) ; i ++ ) { GraphConnection conn = ( GraphConnection ) connections . get ( i ) ; int radius = <NUM_LIT:20> ; if ( conn . getSource ( ) == conn . getDestination ( ) ) { radius = <NUM_LIT> ; } else if ( size < <NUM_LIT:2> ) { radius = <NUM_LIT:0> ; } conn . setCurveDepth ( ( i + <NUM_LIT:1> ) * radius ) ; } } private LinkedList getConnectionList ( GraphNode source , GraphNode dest ) { LinkedList list = new LinkedList ( ) ; Iterator i = source . getSourceConnections ( ) . iterator ( ) ; while ( i . hasNext ( ) ) { GraphConnection c = ( GraphConnection ) i . next ( ) ; if ( c . getDestination ( ) == dest ) { list . add ( c ) ; } } return list ; } public void styleItem ( GraphItem item ) { GraphItemStyler . styleItem ( item , getLabelProvider ( ) ) ; if ( item instanceof GraphConnection ) { styleConnection ( ( GraphConnection ) item ) ; } } public StructuredViewer getViewer ( ) { return viewer ; } public IBaseLabelProvider getLabelProvider ( ) { return viewer . getLabelProvider ( ) ; } public IStructuredContentProvider getContentProvider ( ) { return ( IStructuredContentProvider ) viewer . getContentProvider ( ) ; } public GraphConnection createConnection ( Graph graph , Object element , Object source , Object dest ) { if ( source == null || dest == null ) { return null ; } GraphConnection oldConnection = viewer . getGraphModelConnection ( element ) ; GraphNode sn = viewer . getGraphModelNode ( source ) ; GraphNode dn = viewer . getGraphModelNode ( dest ) ; if ( oldConnection != null ) { if ( sn != oldConnection . getSource ( ) || dn != oldConnection . getDestination ( ) ) { viewer . removeGraphModelConnection ( oldConnection ) ; } else { styleItem ( oldConnection ) ; return oldConnection ; } } if ( sn == null ) { sn = createNode ( graph , source ) ; } if ( dn == null ) { dn = createNode ( graph , dest ) ; } GraphConnection c = viewer . addGraphModelConnection ( element , sn , dn ) ; styleItem ( c ) ; return c ; } public GraphNode createNode ( Graph graph , Object element , IFigure figure ) { GraphNode node = null ; if ( getContentProvider ( ) instanceof INestedContentProvider ) { boolean isContainer = ( ( INestedContentProvider ) getContentProvider ( ) ) . hasChildren ( element ) ; if ( isContainer ) { node = viewer . addGraphModelContainer ( element ) ; styleItem ( node ) ; Object [ ] childNodes = ( ( INestedContentProvider ) getContentProvider ( ) ) . getChildren ( element ) ; childNodes = filter ( getViewer ( ) . getInput ( ) , childNodes ) ; if ( childNodes == null ) { return node ; } for ( int i = <NUM_LIT:0> ; i < childNodes . length ; i ++ ) { GraphNode childNode = viewer . addGraphModelNode ( ( GraphContainer ) node , childNodes [ i ] ) ; styleItem ( childNode ) ; } ( ( GraphContainer ) node ) . applyLayout ( ) ; return node ; } } node = viewer . addGraphModelNode ( element , figure ) ; styleItem ( node ) ; return node ; } public GraphNode createNode ( Graph graph , Object element ) { IFigure nodeFigure = null ; if ( getLabelProvider ( ) instanceof IFigureProvider ) { nodeFigure = ( ( IFigureProvider ) getLabelProvider ( ) ) . getFigure ( element ) ; } return this . createNode ( graph , element , nodeFigure ) ; } public void setConnectionStyle ( int style ) { this . connectionStyle = style ; } public int getConnectionStyle ( ) { return connectionStyle ; } public void setNodeStyle ( int style ) { this . nodeStyle = style ; } public int getNodeStyle ( ) { return nodeStyle ; } public void update ( GraphItem item ) { styleItem ( item ) ; } public void update ( GraphItem [ ] items ) { for ( int i = <NUM_LIT:0> ; i < items . length ; i ++ ) { styleItem ( items [ i ] ) ; } } public void refreshGraph ( Graph graph ) { Map oldMap = viewer . getNodesMap ( ) ; HashMap nodesMap = new HashMap ( ) ; for ( Iterator keys = oldMap . keySet ( ) . iterator ( ) ; keys . hasNext ( ) ; ) { Object key = keys . next ( ) ; nodesMap . put ( key , oldMap . get ( key ) ) ; } clearGraph ( graph ) ; doBuildGraph ( graph ) ; GraphNode [ ] nodes = getNodesArray ( graph ) ; if ( nodes . length < nodesMap . keySet ( ) . size ( ) ) { for ( int i = <NUM_LIT:0> ; i < nodes . length ; i ++ ) { GraphNode oldNode = ( GraphNode ) nodesMap . get ( nodes [ i ] . getData ( ) ) ; if ( oldNode != null ) { nodes [ i ] . setLocation ( oldNode . getLocation ( ) . x , oldNode . getLocation ( ) . y ) ; if ( oldNode . isSizeFixed ( ) ) { nodes [ i ] . setSize ( oldNode . getSize ( ) . width , oldNode . getSize ( ) . height ) ; } } } } else { for ( Iterator i = nodesMap . keySet ( ) . iterator ( ) ; i . hasNext ( ) ; ) { Object key = i . next ( ) ; GraphNode node = viewer . getGraphModelNode ( key ) ; if ( node != null ) { GraphNode oldNode = ( GraphNode ) nodesMap . get ( key ) ; node . setLocation ( oldNode . getLocation ( ) . x , oldNode . getLocation ( ) . y ) ; if ( oldNode . isSizeFixed ( ) ) { node . setSize ( oldNode . getSize ( ) . width , oldNode . getSize ( ) . height ) ; } } } } } public void clearGraph ( Graph graph ) { graph . setSelection ( null ) ; Object [ ] nodeElements = viewer . getNodeElements ( ) ; for ( int i = <NUM_LIT:0> ; i < nodeElements . length ; i ++ ) { viewer . removeGraphModelNode ( nodeElements [ i ] ) ; } Object [ ] connectionElements = viewer . getConnectionElements ( ) ; for ( int i = <NUM_LIT:0> ; i < connectionElements . length ; i ++ ) { viewer . removeGraphModelConnection ( connectionElements [ i ] ) ; } } protected void doBuildGraph ( Graph model ) { clearGraph ( model ) ; model . setConnectionStyle ( getConnectionStyle ( ) ) ; model . setNodeStyle ( getNodeStyle ( ) ) ; } protected boolean filterElement ( Object parent , Object element ) { ViewerFilter [ ] filters = getViewer ( ) . getFilters ( ) ; for ( int i = <NUM_LIT:0> ; i < filters . length ; i ++ ) { boolean selected = filters [ i ] . select ( viewer , parent , element ) ; if ( ! selected ) { return true ; } } return false ; } protected Object [ ] filter ( Object parent , Object [ ] elements ) { Object [ ] result = elements ; ViewerFilter [ ] filters = getViewer ( ) . getFilters ( ) ; for ( int i = <NUM_LIT:0> ; i < filters . length ; i ++ ) { result = filters [ i ] . filter ( viewer , parent , result ) ; } return result ; } public void refresh ( Graph graph , Object element ) { refresh ( graph , element , false ) ; } protected GraphNode [ ] getNodesArray ( Graph graph ) { GraphNode [ ] nodesArray = new GraphNode [ graph . getNodes ( ) . size ( ) ] ; nodesArray = ( GraphNode [ ] ) graph . getNodes ( ) . toArray ( nodesArray ) ; return nodesArray ; } protected GraphConnection [ ] getConnectionArray ( Graph graph ) { GraphConnection [ ] connectionArray = new GraphConnection [ graph . getConnections ( ) . size ( ) ] ; connectionArray = ( GraphConnection [ ] ) graph . getConnections ( ) . toArray ( connectionArray ) ; return connectionArray ; } } </s>
|
<s> package org . eclipse . zest . core . viewers ; import org . eclipse . jface . viewers . IStructuredContentProvider ; public interface IGraphEntityContentProvider extends IStructuredContentProvider { public Object [ ] getElements ( Object inputElement ) ; public Object [ ] getConnectedTo ( Object entity ) ; } </s>
|
<s> package org . eclipse . zest . core . viewers ; import org . eclipse . zest . core . widgets . GraphConnection ; import org . eclipse . zest . core . widgets . GraphNode ; public interface ISelfStyleProvider { public void selfStyleConnection ( Object element , GraphConnection connection ) ; public void selfStyleNode ( Object element , GraphNode node ) ; } </s>
|
<s> package org . eclipse . zest . core . viewers ; import org . eclipse . jface . viewers . IStructuredContentProvider ; public interface IGraphContentProvider extends IStructuredContentProvider { public Object getSource ( Object rel ) ; public Object getDestination ( Object rel ) ; public Object [ ] getElements ( Object input ) ; } </s>
|
<s> package org . eclipse . zest . core . viewers ; import org . eclipse . jface . action . ContributionItem ; import org . eclipse . swt . SWT ; import org . eclipse . swt . events . MenuAdapter ; import org . eclipse . swt . events . MenuEvent ; import org . eclipse . swt . events . SelectionAdapter ; import org . eclipse . swt . events . SelectionEvent ; import org . eclipse . swt . widgets . Combo ; import org . eclipse . swt . widgets . Composite ; import org . eclipse . swt . widgets . CoolBar ; import org . eclipse . swt . widgets . CoolItem ; import org . eclipse . swt . widgets . Menu ; import org . eclipse . swt . widgets . MenuItem ; import org . eclipse . swt . widgets . ToolBar ; import org . eclipse . swt . widgets . ToolItem ; import org . eclipse . zest . core . widgets . zooming . ZoomListener ; import org . eclipse . zest . core . widgets . zooming . ZoomManager ; public class ZoomContributionViewItem extends ContributionItem implements ZoomListener { public static final String FIT_WIDTH = ZoomManager . FIT_WIDTH ; public static final String FIT_HEIGHT = ZoomManager . FIT_HEIGHT ; public static final String FIT_ALL = ZoomManager . FIT_ALL ; private String [ ] zoomLevels ; private ZoomManager zoomManager ; private Combo combo ; private Menu fMenu ; private MenuAdapter menuAdapter = new MenuAdapter ( ) { public void menuShown ( MenuEvent e ) { refresh ( true ) ; } } ; public ZoomContributionViewItem ( IZoomableWorkbenchPart part ) { zoomManager = part . getZoomableViewer ( ) . getZoomManager ( ) ; zoomManager . addZoomListener ( this ) ; } public void fill ( Menu menu , int index ) { if ( this . fMenu == null || this . fMenu != menu ) { if ( this . fMenu != null ) { this . fMenu . removeMenuListener ( menuAdapter ) ; this . fMenu = null ; } this . fMenu = menu ; menu . addMenuListener ( menuAdapter ) ; } } public void fill ( CoolBar parent , int index ) { CoolItem item = new CoolItem ( parent , SWT . DROP_DOWN ) ; Combo combo = createCombo ( parent ) ; item . setControl ( combo ) ; } public void fill ( ToolBar parent , int index ) { ToolItem item = new ToolItem ( parent , SWT . SEPARATOR ) ; Combo combo = createCombo ( parent ) ; item . setControl ( combo ) ; item . setWidth ( combo . computeSize ( SWT . DEFAULT , SWT . DEFAULT , true ) . x ) ; refreshCombo ( false ) ; } private Combo createCombo ( Composite parent ) { this . combo = new Combo ( parent , SWT . NONE ) ; zoomLevels = zoomManager . getZoomLevelsAsText ( ) ; this . combo . setItems ( zoomLevels ) ; this . combo . addSelectionListener ( new SelectionAdapter ( ) { public void widgetSelected ( SelectionEvent e ) { int selection = combo . getSelectionIndex ( ) ; if ( selection > <NUM_LIT:0> ) { doZoom ( combo . getItem ( selection ) ) ; } else { doZoom ( combo . getItem ( <NUM_LIT:0> ) ) ; } } } ) ; return this . combo ; } private void doZoom ( String zoom ) { if ( zoomManager != null ) { zoomManager . setZoomAsText ( zoom ) ; } } private void refresh ( boolean rebuild ) { if ( combo != null && ! combo . isDisposed ( ) ) { refreshCombo ( rebuild ) ; } if ( fMenu != null && ! fMenu . isDisposed ( ) ) { refreshMenu ( rebuild ) ; } } private void refreshMenu ( boolean rebuild ) { fMenu . setEnabled ( false ) ; if ( zoomManager == null ) { return ; } if ( rebuild ) { zoomLevels = zoomManager . getZoomLevelsAsText ( ) ; MenuItem [ ] oldItems = fMenu . getItems ( ) ; for ( int i = <NUM_LIT:0> ; i < oldItems . length ; i ++ ) { if ( oldItems [ i ] . getData ( ) == this ) { oldItems [ i ] . dispose ( ) ; } } for ( int i = <NUM_LIT:0> ; i < zoomLevels . length ; i ++ ) { MenuItem item = new MenuItem ( fMenu , SWT . RADIO ) ; item . setText ( zoomLevels [ i ] ) ; item . setData ( this ) ; item . addSelectionListener ( new SelectionAdapter ( ) { public void widgetSelected ( SelectionEvent e ) { MenuItem source = ( MenuItem ) e . getSource ( ) ; doZoom ( source . getText ( ) ) ; } } ) ; } } String zoom = zoomManager . getZoomAsText ( ) ; MenuItem [ ] items = fMenu . getItems ( ) ; for ( int i = <NUM_LIT:0> ; i < items . length ; i ++ ) { MenuItem item = items [ i ] ; if ( item . getData ( ) == this ) { item . setSelection ( false ) ; if ( zoom . equalsIgnoreCase ( item . getText ( ) ) ) { item . setSelection ( true ) ; } } } fMenu . setEnabled ( true ) ; } private void refreshCombo ( boolean rebuild ) { combo . setEnabled ( false ) ; if ( zoomManager == null ) { return ; } if ( rebuild ) { combo . setItems ( zoomManager . getZoomLevelsAsText ( ) ) ; } String zoom = zoomManager . getZoomAsText ( ) ; int index = combo . indexOf ( zoom ) ; if ( index > <NUM_LIT:0> ) { combo . select ( index ) ; } else { int no = zoomLevels . length ; if ( combo . getItemCount ( ) > no ) { combo . remove ( no ) ; } combo . add ( zoom , no ) ; combo . select ( no ) ; } combo . setEnabled ( true ) ; } public void zoomChanged ( double z ) { refresh ( false ) ; } public void dispose ( ) { if ( combo != null ) { combo = null ; } if ( fMenu != null ) { fMenu = null ; } if ( zoomManager != null ) { zoomManager . removeZoomListener ( this ) ; } super . dispose ( ) ; } } </s>
|
<s> package org . eclipse . zest . core . viewers ; public interface IZoomableWorkbenchPart { AbstractZoomableViewer getZoomableViewer ( ) ; } </s>
|
<s> package org . eclipse . zest . core . viewers ; import org . eclipse . draw2d . IFigure ; import org . eclipse . swt . graphics . Color ; import org . eclipse . ui . services . IDisposable ; public interface IEntityStyleProvider extends IDisposable { public Color getNodeHighlightColor ( Object entity ) ; public Color getBorderColor ( Object entity ) ; public Color getBorderHighlightColor ( Object entity ) ; public int getBorderWidth ( Object entity ) ; public Color getBackgroundColour ( Object entity ) ; public Color getForegroundColour ( Object entity ) ; public IFigure getTooltip ( Object entity ) ; public boolean fisheyeNode ( Object entity ) ; } </s>
|
<s> package org . eclipse . zest . core . viewers ; import org . eclipse . draw2d . ConnectionRouter ; import org . eclipse . draw2d . IFigure ; import org . eclipse . swt . graphics . Color ; import org . eclipse . ui . services . IDisposable ; public interface IEntityConnectionStyleProvider extends IDisposable { public int getConnectionStyle ( Object src , Object dest ) ; public Color getColor ( Object src , Object dest ) ; public Color getHighlightColor ( Object src , Object dest ) ; public int getLineWidth ( Object src , Object dest ) ; public IFigure getTooltip ( Object src , Object dest ) ; public ConnectionRouter getRouter ( Object src , Object dest ) ; } </s>
|
<s> package org . eclipse . zest . core . viewers ; import org . eclipse . draw2d . geometry . Rectangle ; import org . eclipse . jface . viewers . StructuredViewer ; import org . eclipse . zest . core . widgets . zooming . ZoomManager ; public abstract class AbstractZoomableViewer extends StructuredViewer { protected abstract ZoomManager getZoomManager ( ) ; public void zoomTo ( int x , int y , int width , int height ) { Rectangle r = new Rectangle ( x , y , width , height ) ; if ( r . isEmpty ( ) ) { getZoomManager ( ) . setZoomAsText ( "<STR_LIT>" ) ; } else { getZoomManager ( ) . zoomTo ( r ) ; } } } </s>
|
<s> package org . eclipse . zest . core . viewers ; import org . eclipse . draw2d . ConnectionRouter ; import org . eclipse . draw2d . IFigure ; import org . eclipse . swt . graphics . Color ; import org . eclipse . ui . services . IDisposable ; public interface IConnectionStyleProvider extends IDisposable { public int getConnectionStyle ( Object rel ) ; public Color getColor ( Object rel ) ; public Color getHighlightColor ( Object rel ) ; public int getLineWidth ( Object rel ) ; public IFigure getTooltip ( Object rel ) ; public ConnectionRouter getRouter ( Object rel ) ; } </s>
|
<s> package org . eclipse . zest . core . viewers ; import org . eclipse . draw2d . IFigure ; public interface IFigureProvider { public IFigure getFigure ( Object element ) ; } </s>
|
<s> package org . eclipse . zest . core . viewers ; import java . util . ArrayList ; import java . util . Iterator ; import java . util . List ; import org . eclipse . jface . viewers . DoubleClickEvent ; import org . eclipse . jface . viewers . IContentProvider ; import org . eclipse . jface . viewers . ISelection ; import org . eclipse . jface . viewers . ISelectionChangedListener ; import org . eclipse . jface . viewers . ISelectionProvider ; import org . eclipse . jface . viewers . ITreeContentProvider ; import org . eclipse . jface . viewers . SelectionChangedEvent ; import org . eclipse . swt . SWT ; import org . eclipse . swt . events . MouseEvent ; import org . eclipse . swt . events . MouseListener ; import org . eclipse . swt . events . SelectionAdapter ; import org . eclipse . swt . events . SelectionEvent ; import org . eclipse . swt . widgets . Composite ; import org . eclipse . swt . widgets . Control ; import org . eclipse . swt . widgets . Widget ; import org . eclipse . zest . core . viewers . internal . GraphModelEntityFactory ; import org . eclipse . zest . core . viewers . internal . GraphModelEntityRelationshipFactory ; import org . eclipse . zest . core . viewers . internal . GraphModelFactory ; import org . eclipse . zest . core . viewers . internal . IStylingGraphModelFactory ; import org . eclipse . zest . core . viewers . internal . TreeModelEntityFactory ; import org . eclipse . zest . core . widgets . Graph ; import org . eclipse . zest . core . widgets . GraphItem ; import org . eclipse . zest . core . widgets . ZestStyles ; import org . eclipse . zest . core . widgets . zooming . ZoomManager ; import org . eclipse . zest . layouts . LayoutAlgorithm ; public class GraphViewer extends AbstractStructuredGraphViewer implements ISelectionProvider { protected Graph graph = null ; private IStylingGraphModelFactory modelFactory = null ; private List selectionChangedListeners = null ; public GraphViewer ( Composite composite , int style ) { super ( style ) ; this . graph = new Graph ( composite , style ) ; hookControl ( this . graph ) ; } public GraphViewer ( Graph graph ) { super ( graph . getStyle ( ) ) ; this . graph = graph ; hookControl ( this . graph ) ; } protected void hookControl ( Control control ) { super . hookControl ( control ) ; selectionChangedListeners = new ArrayList ( ) ; getGraphControl ( ) . addSelectionListener ( new SelectionAdapter ( ) { public void widgetSelected ( SelectionEvent e ) { Iterator iterator = selectionChangedListeners . iterator ( ) ; ISelection structuredSelection = getSelection ( ) ; SelectionChangedEvent event = new SelectionChangedEvent ( GraphViewer . this , structuredSelection ) ; while ( iterator . hasNext ( ) ) { ISelectionChangedListener listener = ( ISelectionChangedListener ) iterator . next ( ) ; listener . selectionChanged ( event ) ; } firePostSelectionChanged ( event ) ; } } ) ; control . addMouseListener ( new MouseListener ( ) { public void mouseDoubleClick ( MouseEvent e ) { DoubleClickEvent doubleClickEvent = new DoubleClickEvent ( GraphViewer . this , getSelection ( ) ) ; fireDoubleClick ( doubleClickEvent ) ; } public void mouseDown ( MouseEvent e ) { } public void mouseUp ( MouseEvent e ) { } } ) ; } protected void inputChanged ( Object input , Object oldInput ) { graph . setDynamicLayout ( false ) ; super . inputChanged ( input , oldInput ) ; graph . setDynamicLayout ( true ) ; graph . applyLayout ( ) ; } public int getStyle ( ) { return this . graph . getStyle ( ) ; } public Graph getGraphControl ( ) { return super . getGraphControl ( ) ; } ; public void setLayoutAlgorithm ( LayoutAlgorithm algorithm , boolean runLayout ) { graph . setLayoutAlgorithm ( algorithm , runLayout ) ; } public void setLayoutAlgorithm ( LayoutAlgorithm algorithm ) { super . setLayoutAlgorithm ( algorithm ) ; } public void setNodeStyle ( int nodeStyle ) { super . setNodeStyle ( nodeStyle ) ; this . graph . setNodeStyle ( nodeStyle ) ; } public void setContentProvider ( IContentProvider contentProvider ) { if ( contentProvider instanceof IGraphContentProvider ) { super . setContentProvider ( contentProvider ) ; } else if ( contentProvider instanceof IGraphEntityContentProvider ) { super . setContentProvider ( contentProvider ) ; } else if ( contentProvider instanceof IGraphEntityRelationshipContentProvider ) { super . setContentProvider ( contentProvider ) ; } else if ( contentProvider instanceof ITreeContentProvider ) { super . setContentProvider ( contentProvider ) ; } else { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } } public GraphItem findGraphItem ( Object element ) { Widget [ ] result = findItems ( element ) ; return ( result . length == <NUM_LIT:0> || ! ( result [ <NUM_LIT:0> ] instanceof GraphItem ) ) ? null : ( GraphItem ) result [ <NUM_LIT:0> ] ; } public void applyLayout ( ) { graph . applyLayout ( ) ; } protected void setSelectionToWidget ( List l , boolean reveal ) { GraphItem [ ] listOfItems = findItems ( l ) ; graph . setSelection ( listOfItems ) ; } public Control getControl ( ) { return graph ; } public Object [ ] getNodeElements ( ) { return super . getNodeElements ( ) ; } public Object [ ] getConnectionElements ( ) { return super . getConnectionElements ( ) ; } public void reveal ( Object element ) { super . reveal ( element ) ; } public void setConnectionStyle ( int connectionStyle ) { super . setConnectionStyle ( connectionStyle ) ; } public void unReveal ( Object element ) { super . unReveal ( element ) ; } public void addSelectionChangedListener ( ISelectionChangedListener listener ) { if ( ! selectionChangedListeners . contains ( listener ) ) { selectionChangedListeners . add ( listener ) ; } } public void removeSelectionChangedListener ( ISelectionChangedListener listener ) { if ( selectionChangedListeners . contains ( listener ) ) { selectionChangedListeners . remove ( listener ) ; } } public void refresh ( Object element ) { boolean dynamicLayoutEnabled = graph . isDynamicLayoutEnabled ( ) ; graph . setDynamicLayout ( false ) ; super . refresh ( element ) ; graph . setDynamicLayout ( dynamicLayoutEnabled ) ; } public void refresh ( Object element , boolean updateLabels ) { boolean dynamicLayoutEnabled = graph . isDynamicLayoutEnabled ( ) ; graph . setDynamicLayout ( false ) ; super . refresh ( element , updateLabels ) ; graph . setDynamicLayout ( dynamicLayoutEnabled ) ; } public void update ( Object element , String [ ] properties ) { boolean dynamicLayoutEnabled = graph . isDynamicLayoutEnabled ( ) ; graph . setDynamicLayout ( false ) ; super . update ( element , properties ) ; graph . setDynamicLayout ( dynamicLayoutEnabled ) ; } public void update ( Object [ ] elements , String [ ] properties ) { boolean dynamicLayoutEnabled = graph . isDynamicLayoutEnabled ( ) ; graph . setDynamicLayout ( false ) ; super . update ( elements , properties ) ; graph . setDynamicLayout ( dynamicLayoutEnabled ) ; } protected ZoomManager getZoomManager ( ) { return getGraphControl ( ) . getZoomManager ( ) ; } protected IStylingGraphModelFactory getFactory ( ) { if ( modelFactory == null ) { if ( getContentProvider ( ) instanceof IGraphContentProvider ) { modelFactory = new GraphModelFactory ( this ) ; } else if ( getContentProvider ( ) instanceof IGraphEntityContentProvider ) { modelFactory = new GraphModelEntityFactory ( this ) ; } else if ( getContentProvider ( ) instanceof IGraphEntityRelationshipContentProvider ) { modelFactory = new GraphModelEntityRelationshipFactory ( this ) ; } else if ( getContentProvider ( ) instanceof ITreeContentProvider ) { modelFactory = new TreeModelEntityFactory ( this ) ; } } return modelFactory ; } protected LayoutAlgorithm getLayoutAlgorithm ( ) { return graph . getLayoutAlgorithm ( ) ; } } </s>
|
<s> package org . eclipse . zest . core . viewers ; import org . eclipse . jface . viewers . IStructuredContentProvider ; public interface IGraphEntityRelationshipContentProvider extends IStructuredContentProvider { public Object [ ] getRelationships ( Object source , Object dest ) ; } </s>
|
<s> package org . eclipse . zest . core . viewers ; import java . util . ArrayList ; import java . util . Comparator ; import java . util . HashMap ; import java . util . Iterator ; import java . util . LinkedList ; import java . util . List ; import java . util . Map ; import java . util . TreeSet ; import org . eclipse . draw2d . IFigure ; import org . eclipse . draw2d . geometry . Point ; import org . eclipse . swt . SWT ; import org . eclipse . swt . SWTError ; import org . eclipse . swt . widgets . Widget ; import org . eclipse . zest . core . viewers . internal . IStylingGraphModelFactory ; import org . eclipse . zest . core . widgets . Graph ; import org . eclipse . zest . core . widgets . GraphConnection ; import org . eclipse . zest . core . widgets . GraphContainer ; import org . eclipse . zest . core . widgets . GraphItem ; import org . eclipse . zest . core . widgets . GraphNode ; import org . eclipse . zest . core . widgets . ZestStyles ; import org . eclipse . zest . core . widgets . custom . CGraphNode ; import org . eclipse . zest . layouts . LayoutAlgorithm ; public abstract class AbstractStructuredGraphViewer extends AbstractZoomableViewer { private int graphStyle ; private int nodeStyle ; private int connectionStyle ; private HashMap nodesMap = new HashMap ( ) ; private HashMap connectionsMap = new HashMap ( ) ; private class SimpleGraphComparator implements Comparator { TreeSet storedStrings ; public SimpleGraphComparator ( ) { this . storedStrings = new TreeSet ( ) ; } public int compare ( Object arg0 , Object arg1 ) { if ( arg0 instanceof GraphNode && arg1 instanceof GraphConnection ) { return <NUM_LIT:1> ; } else if ( arg0 instanceof GraphConnection && arg1 instanceof GraphNode ) { return - <NUM_LIT:1> ; } if ( arg0 . equals ( arg1 ) ) { return <NUM_LIT:0> ; } return getObjectString ( arg0 ) . compareTo ( getObjectString ( arg1 ) ) ; } private String getObjectString ( Object o ) { String s = o . getClass ( ) . getName ( ) + "<STR_LIT:@>" + Integer . toHexString ( o . hashCode ( ) ) ; while ( storedStrings . contains ( s ) ) { s = s + '<CHAR_LIT>' ; } return s ; } } protected AbstractStructuredGraphViewer ( int graphStyle ) { this . graphStyle = graphStyle ; this . connectionStyle = SWT . NONE ; this . nodeStyle = SWT . NONE ; } public void setNodeStyle ( int nodeStyle ) { if ( getInput ( ) != null ) { throw new SWTError ( SWT . ERROR_UNSPECIFIED ) ; } this . nodeStyle = nodeStyle ; } public void setConnectionStyle ( int connectionStyle ) { if ( getInput ( ) != null ) { throw new SWTError ( SWT . ERROR_UNSPECIFIED ) ; } if ( ! ZestStyles . validateConnectionStyle ( connectionStyle ) ) { throw new SWTError ( SWT . ERROR_INVALID_ARGUMENT ) ; } this . connectionStyle = connectionStyle ; } public int getGraphStyle ( ) { return graphStyle ; } public int getNodeStyle ( ) { return nodeStyle ; } public Graph getGraphControl ( ) { return ( Graph ) getControl ( ) ; } public int getConnectionStyle ( ) { return connectionStyle ; } public abstract void setLayoutAlgorithm ( LayoutAlgorithm algorithm , boolean run ) ; protected abstract LayoutAlgorithm getLayoutAlgorithm ( ) ; public void setLayoutAlgorithm ( LayoutAlgorithm algorithm ) { setLayoutAlgorithm ( algorithm , false ) ; } public Object [ ] getNodeElements ( ) { return this . nodesMap . keySet ( ) . toArray ( ) ; } public Object [ ] getConnectionElements ( ) { return this . connectionsMap . keySet ( ) . toArray ( ) ; } public HashMap getNodesMap ( ) { return this . nodesMap ; } public GraphNode addGraphModelContainer ( Object element ) { GraphNode node = this . getGraphModelNode ( element ) ; if ( node == null ) { node = new GraphContainer ( ( Graph ) getControl ( ) , SWT . NONE ) ; this . nodesMap . put ( element , node ) ; node . setData ( element ) ; } return node ; } public GraphNode addGraphModelNode ( GraphContainer container , Object element ) { GraphNode node = this . getGraphModelNode ( element ) ; if ( node == null ) { node = new GraphNode ( container , SWT . NONE ) ; this . nodesMap . put ( element , node ) ; node . setData ( element ) ; } return node ; } public GraphNode addGraphModelNode ( Object element , IFigure figure ) { GraphNode node = this . getGraphModelNode ( element ) ; if ( node == null ) { if ( figure != null ) { node = new CGraphNode ( ( Graph ) getControl ( ) , SWT . NONE , figure ) ; this . nodesMap . put ( element , node ) ; node . setData ( element ) ; } else { node = new GraphNode ( ( Graph ) getControl ( ) , SWT . NONE ) ; this . nodesMap . put ( element , node ) ; node . setData ( element ) ; } } return node ; } public GraphConnection addGraphModelConnection ( Object element , GraphNode source , GraphNode target ) { GraphConnection connection = this . getGraphModelConnection ( element ) ; if ( connection == null ) { connection = new GraphConnection ( ( Graph ) getControl ( ) , SWT . NONE , source , target ) ; this . connectionsMap . put ( element , connection ) ; connection . setData ( element ) ; } return connection ; } public GraphConnection getGraphModelConnection ( Object obj ) { return ( GraphConnection ) this . connectionsMap . get ( obj ) ; } public GraphNode getGraphModelNode ( Object obj ) { return ( GraphNode ) this . nodesMap . get ( obj ) ; } public void removeGraphModelConnection ( Object obj ) { GraphConnection connection = ( GraphConnection ) connectionsMap . get ( obj ) ; if ( connection != null ) { connectionsMap . remove ( obj ) ; if ( ! connection . isDisposed ( ) ) { connection . dispose ( ) ; } } } public void removeGraphModelNode ( Object obj ) { GraphNode node = ( GraphNode ) nodesMap . get ( obj ) ; if ( node != null ) { nodesMap . remove ( obj ) ; if ( ! node . isDisposed ( ) ) { node . dispose ( ) ; } } } protected void internalRefresh ( Object element ) { if ( getInput ( ) == null ) { return ; } if ( element == getInput ( ) ) { getFactory ( ) . refreshGraph ( getGraphControl ( ) ) ; } else { getFactory ( ) . refresh ( getGraphControl ( ) , element ) ; } getGraphControl ( ) . getLightweightSystem ( ) . getUpdateManager ( ) . performUpdate ( ) ; } protected void doUpdateItem ( Widget item , Object element , boolean fullMap ) { if ( item == getGraphControl ( ) ) { getFactory ( ) . update ( getNodesArray ( getGraphControl ( ) ) ) ; getFactory ( ) . update ( getConnectionsArray ( getGraphControl ( ) ) ) ; } else if ( item instanceof GraphItem ) { getFactory ( ) . update ( ( GraphItem ) item ) ; } } protected Widget doFindInputItem ( Object element ) { if ( element == getInput ( ) && element instanceof Widget ) { return ( Widget ) element ; } return null ; } protected Widget doFindItem ( Object element ) { Widget node = ( Widget ) nodesMap . get ( element ) ; Widget connection = ( Widget ) connectionsMap . get ( element ) ; return ( node != null ) ? node : connection ; } protected List getSelectionFromWidget ( ) { List internalSelection = getWidgetSelection ( ) ; LinkedList externalSelection = new LinkedList ( ) ; for ( Iterator i = internalSelection . iterator ( ) ; i . hasNext ( ) ; ) { Object data = ( ( GraphItem ) i . next ( ) ) . getData ( ) ; if ( data != null ) { externalSelection . add ( data ) ; } } return externalSelection ; } protected GraphItem [ ] findItems ( List l ) { if ( l == null ) { return new GraphItem [ <NUM_LIT:0> ] ; } ArrayList list = new ArrayList ( ) ; Iterator iterator = l . iterator ( ) ; while ( iterator . hasNext ( ) ) { GraphItem w = ( GraphItem ) findItem ( iterator . next ( ) ) ; list . add ( w ) ; } return ( GraphItem [ ] ) list . toArray ( new GraphItem [ list . size ( ) ] ) ; } protected void setSelectionToWidget ( List l , boolean reveal ) { Graph control = ( Graph ) getControl ( ) ; List selection = new LinkedList ( ) ; for ( Iterator i = l . iterator ( ) ; i . hasNext ( ) ; ) { Object obj = i . next ( ) ; GraphNode node = ( GraphNode ) nodesMap . get ( obj ) ; GraphConnection conn = ( GraphConnection ) connectionsMap . get ( obj ) ; if ( node != null ) { selection . add ( node ) ; } if ( conn != null ) { selection . add ( conn ) ; } } control . setSelection ( ( GraphNode [ ] ) selection . toArray ( new GraphNode [ selection . size ( ) ] ) ) ; } protected List getWidgetSelection ( ) { Graph control = ( Graph ) getControl ( ) ; return control . getSelection ( ) ; } protected void inputChanged ( Object input , Object oldInput ) { IStylingGraphModelFactory factory = getFactory ( ) ; factory . setConnectionStyle ( getConnectionStyle ( ) ) ; factory . setNodeStyle ( getNodeStyle ( ) ) ; Map oldNodesMap = nodesMap ; Graph graph = ( Graph ) getControl ( ) ; graph . setSelection ( new GraphNode [ <NUM_LIT:0> ] ) ; Iterator iterator = nodesMap . values ( ) . iterator ( ) ; while ( iterator . hasNext ( ) ) { GraphNode node = ( GraphNode ) iterator . next ( ) ; if ( ! node . isDisposed ( ) ) { node . dispose ( ) ; } } iterator = connectionsMap . values ( ) . iterator ( ) ; while ( iterator . hasNext ( ) ) { GraphConnection connection = ( GraphConnection ) iterator . next ( ) ; if ( ! connection . isDisposed ( ) ) { connection . dispose ( ) ; } } nodesMap = new HashMap ( ) ; connectionsMap = new HashMap ( ) ; graph = factory . createGraphModel ( graph ) ; ( ( Graph ) getControl ( ) ) . setNodeStyle ( getNodeStyle ( ) ) ; ( ( Graph ) getControl ( ) ) . setConnectionStyle ( getConnectionStyle ( ) ) ; for ( Iterator iter = oldNodesMap . keySet ( ) . iterator ( ) ; iter . hasNext ( ) ; ) { Object data = iter . next ( ) ; GraphNode newNode = ( GraphNode ) nodesMap . get ( data ) ; if ( newNode != null ) { GraphNode oldNode = ( GraphNode ) oldNodesMap . get ( data ) ; newNode . setLocation ( oldNode . getLocation ( ) . x , oldNode . getLocation ( ) . y ) ; if ( oldNode . isSizeFixed ( ) ) { newNode . setSize ( oldNode . getSize ( ) . width , oldNode . getSize ( ) . height ) ; } } } } protected abstract IStylingGraphModelFactory getFactory ( ) ; protected void filterVisuals ( ) { if ( getGraphControl ( ) == null ) { return ; } Object [ ] filtered = getFilteredChildren ( getInput ( ) ) ; SimpleGraphComparator comparator = new SimpleGraphComparator ( ) ; TreeSet filteredElements = new TreeSet ( comparator ) ; TreeSet unfilteredElements = new TreeSet ( comparator ) ; List connections = getGraphControl ( ) . getConnections ( ) ; List nodes = getGraphControl ( ) . getNodes ( ) ; if ( filtered . length == <NUM_LIT:0> ) { for ( Iterator i = connections . iterator ( ) ; i . hasNext ( ) ; ) { GraphConnection c = ( GraphConnection ) i . next ( ) ; c . setVisible ( false ) ; } for ( Iterator i = nodes . iterator ( ) ; i . hasNext ( ) ; ) { GraphNode n = ( GraphNode ) i . next ( ) ; n . setVisible ( false ) ; } return ; } for ( Iterator i = connections . iterator ( ) ; i . hasNext ( ) ; ) { GraphConnection c = ( GraphConnection ) i . next ( ) ; if ( c . getExternalConnection ( ) != null ) { unfilteredElements . add ( c ) ; } } for ( Iterator i = nodes . iterator ( ) ; i . hasNext ( ) ; ) { GraphNode n = ( GraphNode ) i . next ( ) ; if ( n . getData ( ) != null ) { unfilteredElements . add ( n ) ; } } for ( int i = <NUM_LIT:0> ; i < filtered . length ; i ++ ) { Object modelElement = connectionsMap . get ( filtered [ i ] ) ; if ( modelElement == null ) { modelElement = nodesMap . get ( filtered [ i ] ) ; } if ( modelElement != null ) { filteredElements . add ( modelElement ) ; } } unfilteredElements . removeAll ( filteredElements ) ; while ( unfilteredElements . size ( ) > <NUM_LIT:0> ) { GraphItem i = ( GraphItem ) unfilteredElements . first ( ) ; i . setVisible ( false ) ; unfilteredElements . remove ( i ) ; } while ( filteredElements . size ( ) > <NUM_LIT:0> ) { GraphItem i = ( GraphItem ) filteredElements . first ( ) ; i . setVisible ( true ) ; filteredElements . remove ( i ) ; } } protected Object [ ] getRawChildren ( Object parent ) { if ( parent == getInput ( ) ) { LinkedList children = new LinkedList ( ) ; if ( getGraphControl ( ) != null ) { List connections = getGraphControl ( ) . getConnections ( ) ; List nodes = getGraphControl ( ) . getNodes ( ) ; for ( Iterator i = connections . iterator ( ) ; i . hasNext ( ) ; ) { GraphConnection c = ( GraphConnection ) i . next ( ) ; if ( c . getExternalConnection ( ) != null ) { children . add ( c . getExternalConnection ( ) ) ; } } for ( Iterator i = nodes . iterator ( ) ; i . hasNext ( ) ; ) { GraphNode n = ( GraphNode ) i . next ( ) ; if ( n . getData ( ) != null ) { children . add ( n . getData ( ) ) ; } } return children . toArray ( ) ; } } return super . getRawChildren ( parent ) ; } public void reveal ( Object element ) { Widget [ ] items = this . findItems ( element ) ; Point location = null ; for ( int i = <NUM_LIT:0> ; i < items . length ; i ++ ) { Widget item = items [ i ] ; if ( item instanceof GraphNode ) { GraphNode graphModelNode = ( GraphNode ) item ; graphModelNode . highlight ( ) ; location = getTopLeftBoundary ( graphModelNode . getLocation ( ) , location ) ; } else if ( item instanceof GraphConnection ) { GraphConnection graphModelConnection = ( GraphConnection ) item ; graphModelConnection . highlight ( ) ; location = getTopLeftBoundary ( graphModelConnection . getSource ( ) . getLocation ( ) , location ) ; location = getTopLeftBoundary ( graphModelConnection . getDestination ( ) . getLocation ( ) , location ) ; } } if ( location != null ) { getGraphControl ( ) . scrollSmoothTo ( location . x , location . y ) ; } } private Point getTopLeftBoundary ( Point point1 , Point point2 ) { if ( point2 != null ) { return new Point ( Math . min ( point1 . x , point2 . x ) , Math . min ( point1 . y , point2 . y ) ) ; } else { return point1 ; } } public void unReveal ( Object element ) { Widget [ ] items = this . findItems ( element ) ; for ( int i = <NUM_LIT:0> ; i < items . length ; i ++ ) { Widget item = items [ i ] ; if ( item instanceof GraphNode ) { GraphNode graphModelNode = ( GraphNode ) item ; graphModelNode . unhighlight ( ) ; } else if ( item instanceof GraphConnection ) { GraphConnection graphModelConnection = ( GraphConnection ) item ; graphModelConnection . unhighlight ( ) ; } } } public abstract void applyLayout ( ) ; public void removeRelationship ( Object connection ) { GraphConnection relationship = ( GraphConnection ) connectionsMap . get ( connection ) ; if ( relationship != null ) { relationship . dispose ( ) ; } } public void addNode ( Object element ) { if ( nodesMap . get ( element ) == null ) { getFactory ( ) . createNode ( getGraphControl ( ) , element ) ; } } public void removeNode ( Object element ) { GraphNode node = ( GraphNode ) nodesMap . get ( element ) ; if ( node != null ) { node . dispose ( ) ; } } public void addRelationship ( Object connection , Object srcNode , Object destNode ) { IStylingGraphModelFactory modelFactory = getFactory ( ) ; modelFactory . createConnection ( getGraphControl ( ) , connection , srcNode , destNode ) ; } public void addRelationship ( Object connection ) { IStylingGraphModelFactory modelFactory = getFactory ( ) ; if ( connectionsMap . get ( connection ) == null ) { if ( modelFactory . getContentProvider ( ) instanceof IGraphContentProvider ) { IGraphContentProvider content = ( ( IGraphContentProvider ) modelFactory . getContentProvider ( ) ) ; Object source = content . getSource ( connection ) ; Object dest = content . getDestination ( connection ) ; modelFactory . createConnection ( getGraphControl ( ) , connection , source , dest ) ; } else { throw new UnsupportedOperationException ( ) ; } } } protected GraphConnection [ ] getConnectionsArray ( Graph graph ) { GraphConnection [ ] connsArray = new GraphConnection [ graph . getConnections ( ) . size ( ) ] ; connsArray = ( GraphConnection [ ] ) graph . getConnections ( ) . toArray ( connsArray ) ; return connsArray ; } protected GraphNode [ ] getNodesArray ( Graph graph ) { GraphNode [ ] nodesArray = new GraphNode [ graph . getNodes ( ) . size ( ) ] ; nodesArray = ( GraphNode [ ] ) graph . getNodes ( ) . toArray ( nodesArray ) ; return nodesArray ; } } </s>
|
<s> package org . eclipse . zest . core . viewers ; public interface INestedContentProvider { public boolean hasChildren ( Object element ) ; public Object [ ] getChildren ( Object element ) ; } </s>
|
<s> package org . eclipse . zest . core . viewers ; public final class EntityConnectionData { public final Object source ; public final Object dest ; public EntityConnectionData ( Object source , Object dest ) { this . source = source ; this . dest = dest ; } public boolean equals ( Object obj ) { if ( ! ( obj instanceof EntityConnectionData ) ) { return false ; } EntityConnectionData that = ( EntityConnectionData ) obj ; return ( this . source . equals ( that . source ) && this . dest . equals ( that . dest ) ) ; } public int hashCode ( ) { return this . source . hashCode ( ) + this . dest . hashCode ( ) ; } } </s>
|
<s> class Node { Node parent ; Node left ; Node right ; } </s>
|
<s> package org . eclipse . zest . internal . dot ; import java . io . File ; import java . net . MalformedURLException ; import java . util . regex . Matcher ; import java . util . regex . Pattern ; import org . eclipse . core . resources . IFile ; import org . eclipse . zest . DotUiMessages ; public final class DotExtractor { public static final String NO_DOT = "<STR_LIT>" + DotUiMessages . DotExtractor_0 + "<STR_LIT>" ; private String input = NO_DOT ; public DotExtractor ( final String input ) { this . input = input ; } public DotExtractor ( final IFile file ) throws MalformedURLException { this ( DotFileUtils . read ( DotFileUtils . resolve ( file . getLocationURI ( ) . toURL ( ) ) ) ) ; } public DotExtractor ( final File file ) { this ( DotFileUtils . read ( file ) ) ; } public String getDotString ( ) { return trimNonDotSuffix ( trimNonDotPrefix ( ) ) ; } private String trimNonDotPrefix ( ) { Matcher m = Pattern . compile ( "<STR_LIT>" , Pattern . DOTALL ) . matcher ( input ) ; String dotSubstring = m . find ( ) ? m . group ( <NUM_LIT:1> ) : NO_DOT ; return dotSubstring ; } private String trimNonDotSuffix ( String dot ) { int first = dot . indexOf ( '<CHAR_LIT>' ) + <NUM_LIT:1> ; StringBuilder builder = new StringBuilder ( dot . substring ( <NUM_LIT:0> , first ) ) ; int count = <NUM_LIT:1> ; int index = first ; while ( count > <NUM_LIT:0> && index < dot . length ( ) ) { char c = dot . charAt ( index ) ; builder . append ( c ) ; count = ( c == '<CHAR_LIT>' ) ? count + <NUM_LIT:1> : ( c == '<CHAR_LIT:}>' ) ? count - <NUM_LIT:1> : count ; index ++ ; } return builder . toString ( ) . trim ( ) ; } } </s>
|
<s> package org . eclipse . zest . internal . dot . parser . ui . labeling ; import org . eclipse . emf . edit . ui . provider . AdapterFactoryLabelProvider ; import org . eclipse . xtext . ui . label . DefaultEObjectLabelProvider ; import com . google . inject . Inject ; public class DotLabelProvider extends DefaultEObjectLabelProvider { @ Inject public DotLabelProvider ( AdapterFactoryLabelProvider delegate ) { super ( delegate ) ; } } </s>
|
<s> package org . eclipse . zest . internal . dot . parser . ui . labeling ; import org . eclipse . xtext . ui . label . DefaultDescriptionLabelProvider ; public class DotDescriptionLabelProvider extends DefaultDescriptionLabelProvider { } </s>
|
<s> package org . eclipse . zest . internal . dot . parser . ui ; import org . eclipse . ui . plugin . AbstractUIPlugin ; public class DotUiModule extends org . eclipse . zest . internal . dot . parser . ui . AbstractDotUiModule { public DotUiModule ( AbstractUIPlugin plugin ) { super ( plugin ) ; } } </s>
|
<s> package org . eclipse . zest . internal . dot . parser . ui . outline ; import org . eclipse . xtext . ui . editor . outline . impl . DefaultOutlineTreeProvider ; public class DotOutlineTreeProvider extends DefaultOutlineTreeProvider { } </s>
|
<s> package org . eclipse . zest . internal . dot . parser . ui . contentassist ; public class DotProposalProvider extends AbstractDotProposalProvider { } </s>
|
<s> package org . eclipse . zest . internal . dot . parser . ui . quickfix ; import org . eclipse . xtext . ui . editor . quickfix . DefaultQuickfixProvider ; public class DotQuickfixProvider extends DefaultQuickfixProvider { } </s>
|
<s> package org . eclipse . zest . internal . dot ; import java . io . File ; import org . eclipse . jface . dialogs . MessageDialog ; import org . eclipse . swt . widgets . DirectoryDialog ; import org . eclipse . ui . IWorkbenchWindow ; import org . eclipse . ui . PlatformUI ; import org . eclipse . zest . DotUiMessages ; public final class DotDirStore { private DotDirStore ( ) { } public static final String DOTPATH_KEY = DotUiActivator . PLUGIN_ID + "<STR_LIT>" ; private enum Caption { DOT_SELECT_SHORT ( DotUiMessages . DotDirStore_0 ) , DOT_SELECT_LONG ( DotUiMessages . DotDirStore_1 ) , NOT_FOUND_LONG ( DotUiMessages . DotDirStore_2 ) , NOT_FOUND_SHORT ( DotUiMessages . DotDirStore_3 ) ; private String s ; Caption ( final String s ) { this . s = s ; } } public static String getDotDirPath ( ) { if ( dotPathFromPreferences ( ) . length ( ) == <NUM_LIT:0> ) { setDotDirPath ( ) ; } return dotPathFromPreferences ( ) ; } public static void setDotDirPath ( ) { IWorkbenchWindow parent = PlatformUI . getWorkbench ( ) . getActiveWorkbenchWindow ( ) ; DirectoryDialog dialog = new DirectoryDialog ( parent . getShell ( ) ) ; dialog . setMessage ( Caption . DOT_SELECT_LONG . s ) ; dialog . setText ( Caption . DOT_SELECT_SHORT . s ) ; processUserInput ( parent , dialog ) ; } private static void processUserInput ( final IWorkbenchWindow parent , final DirectoryDialog dialog ) { String selectedPath = dialog . open ( ) ; if ( selectedPath != null ) { if ( ! containsDot ( new File ( selectedPath ) ) ) { MessageDialog . openError ( parent . getShell ( ) , Caption . NOT_FOUND_SHORT . s , Caption . NOT_FOUND_LONG . s ) ; } else { DotUiActivator . getDefault ( ) . getPreferenceStore ( ) . setValue ( DOTPATH_KEY , selectedPath + File . separator ) ; } } } private static boolean containsDot ( final File folder ) { String [ ] files = folder . list ( ) ; for ( int i = <NUM_LIT:0> ; i < files . length ; i ++ ) { if ( files [ i ] . equals ( "<STR_LIT>" ) || files [ i ] . equals ( "<STR_LIT>" ) ) { return true ; } } return false ; } private static String dotPathFromPreferences ( ) { return DotUiActivator . getDefault ( ) . getPreferenceStore ( ) . getString ( DOTPATH_KEY ) ; } } </s>
|
<s> package org . eclipse . zest . internal . dot ; import java . io . File ; import java . net . MalformedURLException ; import java . net . URL ; import org . eclipse . core . filesystem . EFS ; import org . eclipse . core . filesystem . IFileStore ; import org . eclipse . core . resources . IFile ; import org . eclipse . core . resources . IResource ; import org . eclipse . core . resources . IResourceChangeEvent ; import org . eclipse . core . resources . IResourceChangeListener ; import org . eclipse . core . resources . IResourceDelta ; import org . eclipse . core . resources . IResourceDeltaVisitor ; import org . eclipse . core . resources . IWorkspace ; import org . eclipse . core . resources . IWorkspaceRoot ; import org . eclipse . core . resources . IWorkspaceRunnable ; import org . eclipse . core . resources . ResourcesPlugin ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . core . runtime . IPath ; import org . eclipse . core . runtime . IProgressMonitor ; import org . eclipse . core . runtime . Path ; import org . eclipse . core . runtime . Status ; import org . eclipse . jface . action . Action ; import org . eclipse . jface . action . ActionContributionItem ; import org . eclipse . jface . action . IContributionItem ; import org . eclipse . jface . action . IToolBarManager ; import org . eclipse . jface . action . Separator ; import org . eclipse . jface . dialogs . MessageDialog ; import org . eclipse . jface . resource . JFaceResources ; import org . eclipse . swt . SWT ; import org . eclipse . swt . graphics . Color ; import org . eclipse . swt . graphics . RGB ; import org . eclipse . swt . layout . GridData ; import org . eclipse . swt . layout . GridLayout ; import org . eclipse . swt . widgets . Composite ; import org . eclipse . swt . widgets . Display ; import org . eclipse . swt . widgets . Shell ; import org . eclipse . ui . IEditorDescriptor ; import org . eclipse . ui . IEditorRegistry ; import org . eclipse . ui . IWorkbenchPage ; import org . eclipse . ui . PartInitException ; import org . eclipse . ui . PlatformUI ; import org . eclipse . ui . dialogs . ResourceListSelectionDialog ; import org . eclipse . ui . ide . IDE ; import org . eclipse . ui . part . FileEditorInput ; import org . eclipse . ui . part . ViewPart ; import org . eclipse . zest . DotUiMessages ; import org . eclipse . zest . core . widgets . Graph ; public final class ZestGraphView extends ViewPart { public static final String ID = "<STR_LIT>" ; private static final RGB BACKGROUND = JFaceResources . getColorRegistry ( ) . getRGB ( "<STR_LIT>" ) ; private static final String ADD_EXPORT_QUESTION = DotUiMessages . ZestGraphView_0 ; private static final String ADD_EXPORT_MESSAGE = DotUiMessages . ZestGraphView_1 + DotUiMessages . ZestGraphView_2 + DotUiMessages . ZestGraphView_3 ; private static final String LOAD = DotUiMessages . ZestGraphView_4 ; private static final String RESET = DotUiMessages . ZestGraphView_5 ; private static final String LAYOUT = DotUiMessages . ZestGraphView_6 ; private static final String EXPORT = DotUiMessages . ZestGraphView_7 ; private static final String EXPORT_MODE = DotUiMessages . ZestGraphView_8 ; private static final String UPDATE_MODE = DotUiMessages . ZestGraphView_9 ; private static final String LINK_MODE = DotUiMessages . ZestGraphView_10 ; private static final String RESOURCES_ICONS_OPEN_GIF = "<STR_LIT>" ; private static final String RESOURCES_ICONS_EXPORT_GIF = "<STR_LIT>" ; private static final String RESOURCES_ICONS_RESET = "<STR_LIT>" ; private static final String RESOURCES_ICONS_LAYOUT = "<STR_LIT>" ; private static final String RESOURCES_ICONS_EXPORT_MODE = "<STR_LIT>" ; private static final String RESOURCES_ICONS_UPDATE_MODE = "<STR_LIT>" ; private static final String RESOURCES_ICONS_LINK_MODE = "<STR_LIT>" ; private static final String EXTENSION = "<STR_LIT>" ; private static final String FORMAT_PDF = "<STR_LIT>" ; private static final String FORMAT_PNG = "<STR_LIT>" ; private boolean exportFromZestGraph = true ; private boolean listenToDotContent = false ; private boolean linkImage = false ; private Composite composite ; private Graph graph ; private IFile file ; private String dotString = "<STR_LIT>" ; private boolean addReference = true ; private IResourceChangeListener resourceChangeListener = new IResourceChangeListener ( ) { public void resourceChanged ( final IResourceChangeEvent event ) { if ( event . getType ( ) != IResourceChangeEvent . POST_BUILD && event . getType ( ) != IResourceChangeEvent . POST_CHANGE ) { return ; } IResourceDelta rootDelta = event . getDelta ( ) ; try { rootDelta . accept ( resourceVisitor ) ; } catch ( CoreException e ) { e . printStackTrace ( ) ; } } } ; private IResourceDeltaVisitor resourceVisitor = new IResourceDeltaVisitor ( ) { public boolean visit ( final IResourceDelta delta ) { IResource resource = delta . getResource ( ) ; if ( resource . getType ( ) == IResource . FILE ) { try { final IFile f = ( IFile ) resource ; if ( ! listenToDotContent && ! f . getLocation ( ) . toString ( ) . endsWith ( EXTENSION ) ) { return true ; } IWorkspaceRunnable workspaceRunnable = new IWorkspaceRunnable ( ) { public void run ( final IProgressMonitor monitor ) throws CoreException { setGraph ( f ) ; } } ; IWorkspace workspace = ResourcesPlugin . getWorkspace ( ) ; if ( ! workspace . isTreeLocked ( ) ) { workspace . run ( workspaceRunnable , null ) ; } } catch ( Exception e ) { e . printStackTrace ( ) ; } } return true ; } } ; public void createPartControl ( final Composite parent ) { composite = new Composite ( parent , SWT . NULL ) ; GridLayout layout = new GridLayout ( ) ; composite . setLayout ( layout ) ; composite . setBackground ( new Color ( composite . getDisplay ( ) , BACKGROUND ) ) ; if ( file != null ) { try { updateGraph ( ) ; } catch ( MalformedURLException e ) { e . printStackTrace ( ) ; } } addUpdateModeButton ( ) ; addLoadButton ( ) ; addLayoutButton ( ) ; addResetButton ( ) ; addExportModeButton ( ) ; addExportButton ( ) ; addLinkModeButton ( ) ; } public Graph getGraph ( ) { return graph ; } public void setGraph ( final String dot , boolean async ) { dotString = dot ; Runnable runnable = new Runnable ( ) { public void run ( ) { updateZestGraph ( dot ) ; } private void updateZestGraph ( final String currentDot ) { if ( graph != null ) { graph . dispose ( ) ; } if ( composite != null ) { DotImport dotImport = new DotImport ( dotString ) ; if ( dotImport . getErrors ( ) . size ( ) > <NUM_LIT:0> ) { String message = String . format ( "<STR_LIT>" , dotImport . getErrors ( ) , dotString ) ; DotUiActivator . getDefault ( ) . getLog ( ) . log ( new Status ( Status . ERROR , DotUiActivator . PLUGIN_ID , message ) ) ; return ; } graph = dotImport . newGraphInstance ( composite , SWT . NONE ) ; setupLayout ( ) ; composite . layout ( ) ; graph . applyLayout ( ) ; } handleWikiText ( currentDot ) ; linkCorrespondingImage ( ) ; } } ; Display display = getViewSite ( ) . getShell ( ) . getDisplay ( ) ; if ( async ) { display . asyncExec ( runnable ) ; } else { display . syncExec ( runnable ) ; } } protected void linkCorrespondingImage ( ) { boolean canExportFromZest = exportFromZestGraph && graph != null ; boolean canExportFromDot = ! exportFromZestGraph && dotString != null ; if ( linkImage && ( canExportFromZest || canExportFromDot ) ) { File image = generateImageFromGraph ( true , FORMAT_PNG ) ; openFile ( image ) ; } } private void addUpdateModeButton ( ) { Action toggleUpdateModeAction = new Action ( UPDATE_MODE , SWT . TOGGLE ) { public void run ( ) { listenToDotContent = toggle ( this , listenToDotContent ) ; toggleResourceListener ( ) ; } private void toggleResourceListener ( ) { IWorkspace workspace = ResourcesPlugin . getWorkspace ( ) ; if ( listenToDotContent ) { workspace . addResourceChangeListener ( resourceChangeListener , IResourceChangeEvent . POST_BUILD | IResourceChangeEvent . POST_CHANGE ) ; } else { workspace . removeResourceChangeListener ( resourceChangeListener ) ; } } } ; toggleUpdateModeAction . setId ( toggleUpdateModeAction . getText ( ) ) ; toggleUpdateModeAction . setImageDescriptor ( DotUiActivator . getImageDescriptor ( RESOURCES_ICONS_UPDATE_MODE ) ) ; IToolBarManager mgr = getViewSite ( ) . getActionBars ( ) . getToolBarManager ( ) ; mgr . add ( toggleUpdateModeAction ) ; } private void addExportModeButton ( ) { Action toggleRenderingAction = new Action ( EXPORT_MODE , SWT . TOGGLE ) { public void run ( ) { exportFromZestGraph = toggle ( this , exportFromZestGraph ) ; } } ; toggleRenderingAction . setId ( toggleRenderingAction . getText ( ) ) ; toggleRenderingAction . setImageDescriptor ( DotUiActivator . getImageDescriptor ( RESOURCES_ICONS_EXPORT_MODE ) ) ; IToolBarManager mgr = getViewSite ( ) . getActionBars ( ) . getToolBarManager ( ) ; mgr . add ( toggleRenderingAction ) ; } private boolean toggle ( Action action , boolean input ) { action . setChecked ( ! action . isChecked ( ) ) ; IToolBarManager mgr = getViewSite ( ) . getActionBars ( ) . getToolBarManager ( ) ; for ( IContributionItem item : mgr . getItems ( ) ) { if ( item . getId ( ) != null && item . getId ( ) . equals ( action . getText ( ) ) ) { ActionContributionItem i = ( ActionContributionItem ) item ; i . getAction ( ) . setChecked ( ! i . getAction ( ) . isChecked ( ) ) ; return ! input ; } } return input ; } private void addLayoutButton ( ) { Action layoutAction = new Action ( LAYOUT ) { public void run ( ) { if ( graph != null ) { graph . applyLayout ( ) ; } } } ; layoutAction . setImageDescriptor ( DotUiActivator . getImageDescriptor ( RESOURCES_ICONS_LAYOUT ) ) ; IToolBarManager mgr = getViewSite ( ) . getActionBars ( ) . getToolBarManager ( ) ; mgr . add ( layoutAction ) ; mgr . add ( new Separator ( ) ) ; } private void addExportButton ( ) { Action exportAction = new Action ( EXPORT ) { public void run ( ) { if ( ( exportFromZestGraph && graph != null ) || ( ! exportFromZestGraph && dotString != null ) ) { File image = generateImageFromGraph ( true , FORMAT_PDF ) ; openFile ( image ) ; } } } ; exportAction . setImageDescriptor ( DotUiActivator . getImageDescriptor ( RESOURCES_ICONS_EXPORT_GIF ) ) ; getViewSite ( ) . getActionBars ( ) . getToolBarManager ( ) . add ( exportAction ) ; } private void openFile ( File file ) { if ( this . file == null ) { IFileStore fileStore = EFS . getLocalFileSystem ( ) . getStore ( new Path ( "<STR_LIT>" ) ) ; fileStore = fileStore . getChild ( file . getAbsolutePath ( ) ) ; if ( ! fileStore . fetchInfo ( ) . isDirectory ( ) && fileStore . fetchInfo ( ) . exists ( ) ) { IWorkbenchPage page = getSite ( ) . getPage ( ) ; try { IDE . openEditorOnFileStore ( page , fileStore ) ; } catch ( PartInitException e ) { e . printStackTrace ( ) ; } } } else { IWorkspace workspace = ResourcesPlugin . getWorkspace ( ) ; IPath location = Path . fromOSString ( file . getAbsolutePath ( ) ) ; IFile copy = workspace . getRoot ( ) . getFileForLocation ( location ) ; IEditorRegistry registry = PlatformUI . getWorkbench ( ) . getEditorRegistry ( ) ; if ( registry . isSystemExternalEditorAvailable ( copy . getName ( ) ) ) { try { getViewSite ( ) . getPage ( ) . openEditor ( new FileEditorInput ( copy ) , IEditorRegistry . SYSTEM_EXTERNAL_EDITOR_ID ) ; } catch ( PartInitException e ) { e . printStackTrace ( ) ; } } } } private void addLinkModeButton ( ) { Action linkModeAction = new Action ( LINK_MODE , SWT . TOGGLE ) { public void run ( ) { linkImage = toggle ( this , linkImage ) ; } } ; linkModeAction . setId ( linkModeAction . getText ( ) ) ; linkModeAction . setImageDescriptor ( DotUiActivator . getImageDescriptor ( RESOURCES_ICONS_LINK_MODE ) ) ; getViewSite ( ) . getActionBars ( ) . getToolBarManager ( ) . add ( linkModeAction ) ; } private void addResetButton ( ) { Action resetAction = new Action ( RESET ) { public void run ( ) { DotDirStore . setDotDirPath ( ) ; } } ; resetAction . setImageDescriptor ( DotUiActivator . getImageDescriptor ( RESOURCES_ICONS_RESET ) ) ; getViewSite ( ) . getActionBars ( ) . getToolBarManager ( ) . add ( resetAction ) ; } private void addLoadButton ( ) { Action loadAction = new Action ( LOAD ) { public void run ( ) { Shell shell = PlatformUI . getWorkbench ( ) . getActiveWorkbenchWindow ( ) . getShell ( ) ; IWorkspaceRoot root = ResourcesPlugin . getWorkspace ( ) . getRoot ( ) ; ResourceListSelectionDialog dialog = new ResourceListSelectionDialog ( shell , root , IResource . FILE ) ; if ( dialog . open ( ) == ResourceListSelectionDialog . OK ) { Object [ ] selected = dialog . getResult ( ) ; if ( selected != null ) { file = ( IFile ) selected [ <NUM_LIT:0> ] ; setGraph ( file ) ; } } } } ; loadAction . setImageDescriptor ( DotUiActivator . getImageDescriptor ( RESOURCES_ICONS_OPEN_GIF ) ) ; getViewSite ( ) . getActionBars ( ) . getToolBarManager ( ) . add ( loadAction ) ; } private void setGraph ( final IFile file ) { this . file = file ; try { updateGraph ( ) ; } catch ( MalformedURLException e ) { e . printStackTrace ( ) ; } } private void updateGraph ( ) throws MalformedURLException { if ( file == null || file . getLocationURI ( ) == null || ! file . exists ( ) ) { return ; } final String currentDot = dotExtraction ( ) ? new DotExtractor ( file ) . getDotString ( ) : DotFileUtils . read ( DotFileUtils . resolve ( file . getLocationURI ( ) . toURL ( ) ) ) ; if ( currentDot . equals ( dotString ) || currentDot . equals ( DotExtractor . NO_DOT ) ) { return ; } setGraph ( currentDot , true ) ; } private boolean dotExtraction ( ) { return ! file . getName ( ) . endsWith ( EXTENSION ) ; } private void handleWikiText ( final String dot ) { if ( file == null ) { return ; } try { IEditorDescriptor editor = IDE . getEditorDescriptor ( file ) ; if ( editor . getId ( ) . equals ( "<STR_LIT>" ) ) { try { File image = generateImageFromGraph ( true , FORMAT_PNG ) ; File wikiFile = DotFileUtils . resolve ( file . getLocationURI ( ) . toURL ( ) ) ; String imageLinkWiki = createImageLinkMarkup ( image ) ; if ( ! DotFileUtils . read ( wikiFile ) . contains ( imageLinkWiki ) && addReference && supported ( file ) ) { String message = String . format ( ADD_EXPORT_MESSAGE , file . getName ( ) ) ; if ( MessageDialog . openQuestion ( getSite ( ) . getShell ( ) , ADD_EXPORT_QUESTION , message ) ) { addReference ( dot , wikiFile , imageLinkWiki ) ; } else { addReference = false ; } } refreshParent ( file ) ; } catch ( MalformedURLException e ) { e . printStackTrace ( ) ; } } } catch ( PartInitException e ) { e . printStackTrace ( ) ; } } private boolean supported ( final IFile wikiFile ) { return wikiFile . getFileExtension ( ) . endsWith ( "<STR_LIT>" ) ; } private String createImageLinkMarkup ( final File image ) { return String . format ( "<STR_LIT>" , image . getName ( ) ) ; } private void addReference ( final String dot , final File wikiFile , final String imageLinkWiki ) { String content = DotFileUtils . read ( wikiFile ) . replace ( dot , dot + "<STR_LIT:n>" + imageLinkWiki ) ; DotFileUtils . write ( content , wikiFile ) ; } private void setupLayout ( ) { if ( graph != null ) { GridData gd = new GridData ( GridData . FILL_BOTH ) ; graph . setLayout ( new GridLayout ( ) ) ; graph . setLayoutData ( gd ) ; Color color = new Color ( graph . getDisplay ( ) , BACKGROUND ) ; graph . setBackground ( color ) ; graph . getParent ( ) . setBackground ( color ) ; } } private File generateImageFromGraph ( final boolean refresh , final String format ) { DotExport dotExport = exportFromZestGraph ? new DotExport ( graph ) : new DotExport ( dotString ) ; File image = dotExport . toImage ( DotDirStore . getDotDirPath ( ) , format , null ) ; if ( file == null ) { return image ; } try { URL url = file . getParent ( ) . getLocationURI ( ) . toURL ( ) ; File copy = DotFileUtils . copySingleFile ( DotFileUtils . resolve ( url ) , file . getName ( ) + "<STR_LIT:.>" + format , image ) ; return copy ; } catch ( MalformedURLException e ) { e . printStackTrace ( ) ; } if ( refresh ) { refreshParent ( file ) ; } return image ; } private void refreshParent ( final IFile file ) { try { file . getParent ( ) . refreshLocal ( IResource . DEPTH_ONE , null ) ; } catch ( CoreException e ) { e . printStackTrace ( ) ; } } public void dispose ( ) { super . dispose ( ) ; ResourcesPlugin . getWorkspace ( ) . removeResourceChangeListener ( resourceChangeListener ) ; if ( graph != null ) { graph . dispose ( ) ; } if ( composite != null ) { composite . dispose ( ) ; } } public void setFocus ( ) { if ( graph != null && ! graph . isDisposed ( ) ) { graph . setFocus ( ) ; } } } </s>
|
<s> package org . eclipse . zest . internal . dot ; import org . eclipse . jface . resource . ImageDescriptor ; import org . eclipse . ui . plugin . AbstractUIPlugin ; import org . eclipse . zest . internal . dot . parser . DotParserActivator ; import org . osgi . framework . BundleContext ; public final class DotUiActivator extends AbstractUIPlugin { public static final String PLUGIN_ID = "<STR_LIT>" ; private static DotUiActivator plugin ; private DotParserActivator parserActivator ; public DotUiActivator ( ) { parserActivator = new DotParserActivator ( ) ; } public void start ( final BundleContext context ) throws Exception { super . start ( context ) ; parserActivator . start ( context ) ; plugin = this ; } public void stop ( final BundleContext context ) throws Exception { plugin = null ; super . stop ( context ) ; parserActivator . stop ( context ) ; } public static DotUiActivator getDefault ( ) { return plugin ; } public static ImageDescriptor getImageDescriptor ( final String path ) { return AbstractUIPlugin . imageDescriptorFromPlugin ( PLUGIN_ID , path ) ; } } </s>
|
<s> package org . eclipse . zest ; import org . eclipse . osgi . util . NLS ; public class DotUiMessages extends NLS { private static final String BUNDLE_NAME = "<STR_LIT>" ; public static String DotDirStore_0 ; public static String DotDirStore_1 ; public static String DotDirStore_2 ; public static String DotDirStore_3 ; public static String ZestGraphWizard_0 ; public static String ZestGraphWizard_1 ; public static String ZestGraphWizard_2 ; public static String ZestGraphWizard_3 ; public static String ZestGraphWizard_4 ; public static String ZestGraphWizard_5 ; public static String DotExtractor_0 ; public static String GraphWizardPageTemplateSelection_0 ; public static String GraphWizardPageTemplateSelection_1 ; public static String GraphWizardPageTemplateSelection_2 ; public static String GraphWizardPageTemplateSelection_3 ; public static String GraphWizardPageTemplateSelection_4 ; public static String GraphWizardPageTemplateSelection_5 ; public static String GraphWizardPageTemplateSelection_6 ; public static String GraphWizardPageTemplateSelection_7 ; public static String GraphWizardPageTemplateSelection_8 ; public static String GraphWizardPageTemplateSelection_9 ; public static String GraphWizardPageTemplateSelection_10 ; public static String ZestGraphView_0 ; public static String ZestGraphView_1 ; public static String ZestGraphView_2 ; public static String ZestGraphView_3 ; public static String ZestGraphView_4 ; public static String ZestGraphView_5 ; public static String ZestGraphView_6 ; public static String ZestGraphView_7 ; public static String ZestGraphView_8 ; public static String ZestGraphView_9 ; public static String ZestGraphView_10 ; public static String ZestGraphWizardPageCustomize_0 ; public static String ZestGraphWizardPageCustomize_1 ; public static String ZestGraphWizardPageCustomize_2 ; public static String ZestProjectWizard_0 ; public static String ZestProjectWizard_1 ; public static String ZestProjectWizard_2 ; public static String ZestProjectWizard_3 ; public static String ZestProjectWizard_4 ; public static String ZestProjectWizard_5 ; public static String ZestProjectWizard_6 ; public static String ZestProjectWizard_7 ; static { NLS . initializeMessages ( BUNDLE_NAME , DotUiMessages . class ) ; } private DotUiMessages ( ) { } } </s>
|
<s> package org . eclipse . zest . cloudio ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . Collection ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; import org . eclipse . core . runtime . Assert ; import org . eclipse . jface . viewers . ColumnLabelProvider ; import org . eclipse . jface . viewers . IStructuredSelection ; import org . eclipse . jface . viewers . ITreeContentProvider ; import org . eclipse . jface . viewers . TreeViewer ; import org . eclipse . jface . viewers . Viewer ; import org . eclipse . swt . SWT ; import org . eclipse . swt . events . SelectionEvent ; import org . eclipse . swt . events . SelectionListener ; import org . eclipse . swt . graphics . Color ; import org . eclipse . swt . graphics . FontData ; import org . eclipse . swt . graphics . GC ; import org . eclipse . swt . graphics . Image ; import org . eclipse . swt . graphics . RGB ; import org . eclipse . swt . layout . GridData ; import org . eclipse . swt . layout . GridLayout ; import org . eclipse . swt . layout . RowLayout ; import org . eclipse . swt . widgets . Button ; import org . eclipse . swt . widgets . ColorDialog ; import org . eclipse . swt . widgets . Combo ; import org . eclipse . swt . widgets . Composite ; import org . eclipse . swt . widgets . Display ; import org . eclipse . swt . widgets . FontDialog ; import org . eclipse . swt . widgets . Group ; import org . eclipse . swt . widgets . Label ; public class CloudOptionsComposite extends Composite { protected TagCloudViewer viewer ; protected List < RGB > colors = new ArrayList < RGB > ( ) ; protected List < FontData > fonts = new ArrayList < FontData > ( ) ; protected List < List < RGB > > colorSchemes = new ArrayList < List < RGB > > ( ) ; protected int currentScheme ; private static class ListContentProvider implements ITreeContentProvider { @ Override public void dispose ( ) { } @ Override public void inputChanged ( Viewer viewer , Object oldInput , Object newInput ) { } @ Override public Object [ ] getElements ( Object inputElement ) { return ( ( List < ? > ) inputElement ) . toArray ( ) ; } @ Override public Object [ ] getChildren ( Object parentElement ) { return null ; } @ Override public Object getParent ( Object element ) { return null ; } @ Override public boolean hasChildren ( Object element ) { return false ; } } public CloudOptionsComposite ( Composite parent , int style , TagCloudViewer viewer ) { super ( parent , style ) ; Assert . isLegal ( viewer . getLabelProvider ( ) instanceof IEditableCloudLabelProvider , "<STR_LIT>" + IEditableCloudLabelProvider . class ) ; this . viewer = viewer ; setLayout ( new GridLayout ( ) ) ; addGroups ( ) ; } protected void addGroups ( ) { addLayoutButtons ( this ) ; addColorButtons ( this ) ; addFontButtons ( this ) ; } protected void addScheme ( RGB ... rgbs ) { List < RGB > colors = new ArrayList < RGB > ( ) ; for ( RGB rgb : rgbs ) { colors . add ( rgb ) ; } colorSchemes . add ( colors ) ; } protected void updateColors ( ) { IEditableCloudLabelProvider lp = ( IEditableCloudLabelProvider ) viewer . getLabelProvider ( ) ; lp . setColors ( colors ) ; List < Word > words = viewer . getCloud ( ) . getWords ( ) ; for ( Word word : words ) { word . setColor ( lp . getColor ( word . data ) ) ; } viewer . getCloud ( ) . redrawTextLayerImage ( ) ; } protected void updateFonts ( ) { IEditableCloudLabelProvider lp = ( IEditableCloudLabelProvider ) viewer . getLabelProvider ( ) ; lp . setFonts ( fonts ) ; } protected void initColors ( ) { addScheme ( new RGB ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) , new RGB ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:24> ) , new RGB ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) , new RGB ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:20> ) , new RGB ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:16> ) , new RGB ( <NUM_LIT> , <NUM_LIT:32> , <NUM_LIT> ) ) ; addScheme ( new RGB ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:255> ) , new RGB ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) , new RGB ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) , new RGB ( <NUM_LIT:30> , <NUM_LIT> , <NUM_LIT> ) ) ; addScheme ( new RGB ( <NUM_LIT:255> , <NUM_LIT> , <NUM_LIT> ) , new RGB ( <NUM_LIT:255> , <NUM_LIT:0> , <NUM_LIT:0> ) , new RGB ( <NUM_LIT:255> , <NUM_LIT> , <NUM_LIT> ) , new RGB ( <NUM_LIT> , <NUM_LIT:31> , <NUM_LIT:32> ) , new RGB ( <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:0> ) ) ; addScheme ( new RGB ( <NUM_LIT:255> , <NUM_LIT> , <NUM_LIT:0> ) , new RGB ( <NUM_LIT:255> , <NUM_LIT> , <NUM_LIT:0> ) , new RGB ( <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT> ) , new RGB ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT> ) ) ; addScheme ( new RGB ( <NUM_LIT:255> , <NUM_LIT> , <NUM_LIT:0> ) , new RGB ( <NUM_LIT:255> , <NUM_LIT:255> , <NUM_LIT> ) , new RGB ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) , new RGB ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) , new RGB ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) , new RGB ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) , new RGB ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) ) ; addScheme ( new RGB ( <NUM_LIT:255> , <NUM_LIT:0> , <NUM_LIT> ) , new RGB ( <NUM_LIT:255> , <NUM_LIT> , <NUM_LIT:0> ) , new RGB ( <NUM_LIT:0> , <NUM_LIT:255> , <NUM_LIT> ) ) ; addScheme ( new RGB ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) , new RGB ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) , new RGB ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) , new RGB ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) , new RGB ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) , new RGB ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) ) ; addScheme ( new RGB ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) , new RGB ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) , new RGB ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) , new RGB ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) ) ; addScheme ( new RGB ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) , new RGB ( <NUM_LIT:255> , <NUM_LIT> , <NUM_LIT:10> ) , new RGB ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0> ) , new RGB ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:3> ) , new RGB ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:8> ) , new RGB ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> ) , new RGB ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) ) ; addScheme ( new RGB ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) , new RGB ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) , new RGB ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) , new RGB ( <NUM_LIT:255> , <NUM_LIT> , <NUM_LIT> ) ) ; nextColors ( ) ; } protected void nextColors ( ) { currentScheme = ( currentScheme + <NUM_LIT:1> ) % colorSchemes . size ( ) ; colors = colorSchemes . get ( currentScheme ) ; } protected Group addFontButtons ( final Composite parent ) { Group buttons = new Group ( parent , SWT . SHADOW_IN ) ; buttons . setLayout ( new GridLayout ( <NUM_LIT:2> , false ) ) ; buttons . setLayoutData ( new GridData ( SWT . FILL , SWT . TOP , true , false ) ) ; Label l = new Label ( buttons , SWT . NONE ) ; l . setText ( "<STR_LIT>" ) ; GridData gd = new GridData ( ) ; gd . horizontalSpan = <NUM_LIT:2> ; l . setLayoutData ( gd ) ; final TreeViewer tv = new TreeViewer ( buttons ) ; Composite comp = new Composite ( buttons , SWT . NONE ) ; comp . setLayoutData ( new GridData ( SWT . FILL , SWT . TOP , false , true ) ) ; comp . setLayout ( new RowLayout ( SWT . VERTICAL ) ) ; tv . getTree ( ) . setLayoutData ( new GridData ( SWT . FILL , SWT . FILL , true , true ) ) ; ListContentProvider cp = new ListContentProvider ( ) ; tv . setContentProvider ( cp ) ; tv . setLabelProvider ( new ColumnLabelProvider ( ) { @ Override public String getText ( Object element ) { FontData fd = ( FontData ) element ; return fd . getName ( ) ; } } ) ; fonts . add ( getFont ( ) . getFontData ( ) [ <NUM_LIT:0> ] ) ; tv . setInput ( fonts ) ; Button add = new Button ( comp , SWT . FLAT ) ; add . setImage ( Activator . getDefault ( ) . getImageRegistry ( ) . get ( Activator . ADD ) ) ; add . setToolTipText ( "<STR_LIT>" ) ; add . addSelectionListener ( new SelectionListener ( ) { @ Override public void widgetSelected ( SelectionEvent e ) { FontDialog fd = new FontDialog ( parent . getShell ( ) ) ; FontData fontData = fd . open ( ) ; if ( fontData != null ) { fonts . add ( fontData ) ; tv . setInput ( fonts ) ; updateFonts ( ) ; } } @ Override public void widgetDefaultSelected ( SelectionEvent e ) { } } ) ; Button remove = new Button ( comp , SWT . FLAT ) ; remove . setToolTipText ( "<STR_LIT>" ) ; remove . addSelectionListener ( new SelectionListener ( ) { @ Override public void widgetSelected ( SelectionEvent e ) { IStructuredSelection selection = ( IStructuredSelection ) tv . getSelection ( ) ; fonts . removeAll ( selection . toList ( ) ) ; tv . setInput ( fonts ) ; updateFonts ( ) ; } @ Override public void widgetDefaultSelected ( SelectionEvent e ) { } } ) ; remove . setImage ( Activator . getDefault ( ) . getImageRegistry ( ) . get ( Activator . REMOVE ) ) ; return buttons ; } protected Image createImageFromColor ( RGB rgb , int size ) { Image image ; Color color = new Color ( Display . getDefault ( ) , rgb ) ; image = new Image ( Display . getDefault ( ) , size , size ) ; GC gc = new GC ( image ) ; gc . setBackground ( color ) ; gc . fillRoundRectangle ( <NUM_LIT:0> , <NUM_LIT:0> , size , size , <NUM_LIT:3> , <NUM_LIT:3> ) ; color . dispose ( ) ; gc . dispose ( ) ; return image ; } protected Group addColorButtons ( final Composite parent ) { Group buttons = new Group ( parent , SWT . SHADOW_IN ) ; buttons . setLayout ( new GridLayout ( <NUM_LIT:2> , false ) ) ; buttons . setLayoutData ( new GridData ( SWT . FILL , SWT . TOP , true , false ) ) ; Label l = new Label ( buttons , SWT . NONE ) ; l . setText ( "<STR_LIT>" ) ; GridData gd = new GridData ( ) ; gd . horizontalSpan = <NUM_LIT:2> ; l . setLayoutData ( gd ) ; final TreeViewer tv = new TreeViewer ( buttons ) ; Composite comp = new Composite ( buttons , SWT . NONE ) ; comp . setLayout ( new RowLayout ( SWT . VERTICAL ) ) ; comp . setLayoutData ( new GridData ( SWT . FILL , SWT . TOP , false , true ) ) ; tv . getTree ( ) . setLayoutData ( new GridData ( SWT . FILL , SWT . FILL , true , true ) ) ; ListContentProvider cp = new ListContentProvider ( ) ; tv . setContentProvider ( cp ) ; tv . setLabelProvider ( new ColumnLabelProvider ( ) { private Map < Object , Image > images = new HashMap < Object , Image > ( ) ; @ Override public Image getImage ( Object element ) { Image image = images . get ( element ) ; if ( image == null ) { RGB rgb = ( RGB ) element ; image = createImageFromColor ( rgb , <NUM_LIT:24> ) ; images . put ( element , image ) ; } return image ; } @ Override public void dispose ( ) { Collection < Image > images = this . images . values ( ) ; for ( Image image : images ) { image . dispose ( ) ; } this . images . clear ( ) ; } } ) ; initColors ( ) ; tv . setInput ( colors ) ; Button add = new Button ( comp , SWT . FLAT ) ; add . setImage ( Activator . getDefault ( ) . getImageRegistry ( ) . get ( Activator . ADD ) ) ; add . setToolTipText ( "<STR_LIT>" ) ; add . addSelectionListener ( new SelectionListener ( ) { @ Override public void widgetSelected ( SelectionEvent e ) { ColorDialog cd = new ColorDialog ( parent . getShell ( ) ) ; RGB color = cd . open ( ) ; if ( color != null ) { colors . add ( color ) ; tv . setInput ( colors ) ; updateColors ( ) ; } } @ Override public void widgetDefaultSelected ( SelectionEvent e ) { } } ) ; Button remove = new Button ( comp , SWT . FLAT ) ; remove . setToolTipText ( "<STR_LIT>" ) ; remove . addSelectionListener ( new SelectionListener ( ) { @ Override public void widgetSelected ( SelectionEvent e ) { IStructuredSelection selection = ( IStructuredSelection ) tv . getSelection ( ) ; colors . removeAll ( selection . toList ( ) ) ; tv . setInput ( colors ) ; updateColors ( ) ; } @ Override public void widgetDefaultSelected ( SelectionEvent e ) { } } ) ; remove . setImage ( Activator . getDefault ( ) . getImageRegistry ( ) . get ( Activator . REMOVE ) ) ; Button toggle = new Button ( comp , SWT . FLAT ) ; toggle . setToolTipText ( "<STR_LIT>" ) ; toggle . addSelectionListener ( new SelectionListener ( ) { @ Override public void widgetSelected ( SelectionEvent e ) { nextColors ( ) ; tv . setInput ( colors ) ; updateColors ( ) ; } @ Override public void widgetDefaultSelected ( SelectionEvent e ) { } } ) ; toggle . setImage ( Activator . getDefault ( ) . getImageRegistry ( ) . get ( Activator . TOGGLE_COLORS ) ) ; comp = new Composite ( buttons , SWT . NONE ) ; gd = new GridData ( SWT . FILL , SWT . FILL , true , false ) ; gd . horizontalSpan = <NUM_LIT:2> ; comp . setLayout ( new GridLayout ( <NUM_LIT:2> , true ) ) ; comp . setLayoutData ( gd ) ; final Button bg = new Button ( comp , SWT . FLAT ) ; bg . setLayoutData ( new GridData ( SWT . FILL , SWT . FILL , true , false ) ) ; bg . setText ( "<STR_LIT>" ) ; bg . setImage ( createImageFromColor ( viewer . getCloud ( ) . getBackground ( ) . getRGB ( ) , <NUM_LIT:16> ) ) ; bg . addSelectionListener ( new SelectionListener ( ) { @ Override public void widgetSelected ( SelectionEvent e ) { ColorDialog cd = new ColorDialog ( parent . getShell ( ) ) ; RGB color = cd . open ( ) ; if ( color == null ) return ; Color old = viewer . getCloud ( ) . getBackground ( ) ; Color c = new Color ( Display . getDefault ( ) , color ) ; viewer . getCloud ( ) . setBackground ( c ) ; old . dispose ( ) ; viewer . getCloud ( ) . redrawTextLayerImage ( ) ; Image oldImage = bg . getImage ( ) ; Image newImage = createImageFromColor ( color , <NUM_LIT:16> ) ; bg . setImage ( newImage ) ; oldImage . dispose ( ) ; } @ Override public void widgetDefaultSelected ( SelectionEvent e ) { } } ) ; final Button sel = new Button ( comp , SWT . FLAT ) ; sel . setLayoutData ( new GridData ( SWT . FILL , SWT . FILL , true , false ) ) ; sel . setText ( "<STR_LIT>" ) ; sel . setImage ( createImageFromColor ( viewer . getCloud ( ) . getSelectionColor ( ) . getRGB ( ) , <NUM_LIT:16> ) ) ; sel . addSelectionListener ( new SelectionListener ( ) { @ Override public void widgetSelected ( SelectionEvent e ) { ColorDialog cd = new ColorDialog ( parent . getShell ( ) ) ; RGB color = cd . open ( ) ; if ( color == null ) return ; Color old = viewer . getCloud ( ) . getSelectionColor ( ) ; Color c = new Color ( Display . getDefault ( ) , color ) ; viewer . getCloud ( ) . setSelectionColor ( c ) ; old . dispose ( ) ; viewer . getCloud ( ) . redrawTextLayerImage ( ) ; Image oldImage = sel . getImage ( ) ; Image newImage = createImageFromColor ( color , <NUM_LIT:16> ) ; sel . setImage ( newImage ) ; oldImage . dispose ( ) ; } @ Override public void widgetDefaultSelected ( SelectionEvent e ) { } } ) ; return buttons ; } protected Group addLayoutButtons ( Composite parent ) { Group buttons = new Group ( parent , SWT . SHADOW_IN ) ; buttons . setLayout ( new GridLayout ( <NUM_LIT:2> , true ) ) ; buttons . setLayoutData ( new GridData ( SWT . FILL , SWT . TOP , true , false ) ) ; Label l = new Label ( buttons , SWT . NONE ) ; l . setText ( "<STR_LIT>" ) ; final Combo words = new Combo ( buttons , SWT . DROP_DOWN | SWT . READ_ONLY ) ; words . setLayoutData ( new GridData ( SWT . FILL , SWT . TOP , true , false ) ) ; words . setItems ( 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>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ) ; words . select ( <NUM_LIT:2> ) ; words . addSelectionListener ( new SelectionListener ( ) { @ Override public void widgetSelected ( SelectionEvent e ) { String item = words . getItem ( words . getSelectionIndex ( ) ) ; viewer . setMaxWords ( Integer . parseInt ( item ) ) ; } @ Override public void widgetDefaultSelected ( SelectionEvent e ) { } } ) ; l = new Label ( buttons , SWT . NONE ) ; l . setText ( "<STR_LIT>" ) ; final Combo font = new Combo ( buttons , SWT . DROP_DOWN | SWT . READ_ONLY ) ; font . setLayoutData ( new GridData ( SWT . FILL , SWT . TOP , true , false ) ) ; font . setItems ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ) ; font . select ( <NUM_LIT:1> ) ; font . addSelectionListener ( new SelectionListener ( ) { @ Override public void widgetSelected ( SelectionEvent e ) { String item = font . getItem ( font . getSelectionIndex ( ) ) ; viewer . getCloud ( ) . setMaxFontSize ( Integer . parseInt ( item ) ) ; } @ Override public void widgetDefaultSelected ( SelectionEvent e ) { } } ) ; l = new Label ( buttons , SWT . NONE ) ; l . setText ( "<STR_LIT>" ) ; final Combo minFont = new Combo ( buttons , SWT . DROP_DOWN | SWT . READ_ONLY ) ; minFont . setLayoutData ( new GridData ( SWT . FILL , SWT . TOP , true , false ) ) ; minFont . setItems ( new String [ ] { "<STR_LIT:10>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ) ; minFont . select ( <NUM_LIT:1> ) ; minFont . addSelectionListener ( new SelectionListener ( ) { @ Override public void widgetSelected ( SelectionEvent e ) { String item = minFont . getItem ( minFont . getSelectionIndex ( ) ) ; viewer . getCloud ( ) . setMinFontSize ( Integer . parseInt ( item ) ) ; } @ Override public void widgetDefaultSelected ( SelectionEvent e ) { } } ) ; l = new Label ( buttons , SWT . NONE ) ; l . setText ( "<STR_LIT>" ) ; final Combo boost = new Combo ( buttons , SWT . DROP_DOWN | SWT . READ_ONLY ) ; boost . setLayoutData ( new GridData ( SWT . FILL , SWT . TOP , true , false ) ) ; boost . setItems ( new String [ ] { "<STR_LIT:0>" , "<STR_LIT:1>" , "<STR_LIT:2>" , "<STR_LIT:3>" , "<STR_LIT:4>" , "<STR_LIT:5>" , "<STR_LIT:6>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:10>" } ) ; boost . select ( <NUM_LIT:0> ) ; boost . addSelectionListener ( new SelectionListener ( ) { @ Override public void widgetSelected ( SelectionEvent e ) { String item = boost . getItem ( boost . getSelectionIndex ( ) ) ; viewer . setBoost ( Integer . parseInt ( item ) ) ; } @ Override public void widgetDefaultSelected ( SelectionEvent e ) { } } ) ; l = new Label ( buttons , SWT . NONE ) ; l . setText ( "<STR_LIT>" ) ; final Combo boostFactor = new Combo ( buttons , SWT . DROP_DOWN | SWT . READ_ONLY ) ; boostFactor . setLayoutData ( new GridData ( SWT . FILL , SWT . TOP , true , false ) ) ; boostFactor . setItems ( new String [ ] { "<STR_LIT:1>" , "<STR_LIT>" , "<STR_LIT:2>" , "<STR_LIT>" , "<STR_LIT:3>" , "<STR_LIT>" , "<STR_LIT:4>" , "<STR_LIT>" , "<STR_LIT:5>" } ) ; boostFactor . select ( <NUM_LIT:0> ) ; boostFactor . addSelectionListener ( new SelectionListener ( ) { @ Override public void widgetSelected ( SelectionEvent e ) { String item = boostFactor . getItem ( boostFactor . getSelectionIndex ( ) ) ; viewer . setBoostFactor ( Float . parseFloat ( item ) ) ; } @ Override public void widgetDefaultSelected ( SelectionEvent e ) { } } ) ; if ( viewer . getLabelProvider ( ) instanceof IEditableCloudLabelProvider ) { } l = new Label ( buttons , SWT . NONE ) ; l . setText ( "<STR_LIT>" ) ; final Combo angles = new Combo ( buttons , SWT . DROP_DOWN | SWT . READ_ONLY ) ; angles . setLayoutData ( new GridData ( SWT . FILL , SWT . TOP , true , false ) ) ; angles . setItems ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ) ; final List < List < Float > > anglesLists = new ArrayList < List < Float > > ( ) ; anglesLists . add ( Arrays . asList ( <NUM_LIT:0F> ) ) ; anglesLists . add ( Arrays . asList ( - <NUM_LIT> , <NUM_LIT> ) ) ; anglesLists . add ( Arrays . asList ( <NUM_LIT:0F> , - <NUM_LIT> , <NUM_LIT:0F> , <NUM_LIT> ) ) ; anglesLists . add ( Arrays . asList ( <NUM_LIT:0F> , - <NUM_LIT> , - <NUM_LIT> , <NUM_LIT:0F> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0F> , <NUM_LIT:0F> , <NUM_LIT:0F> , <NUM_LIT:0F> ) ) ; anglesLists . add ( Arrays . asList ( - <NUM_LIT> , - <NUM_LIT> , <NUM_LIT:0F> , <NUM_LIT> , <NUM_LIT> ) ) ; List < Float > tmp = new ArrayList < Float > ( ) ; for ( int i = - <NUM_LIT> ; i <= <NUM_LIT> ; i ++ ) { tmp . add ( ( float ) i ) ; } anglesLists . add ( tmp ) ; angles . select ( <NUM_LIT:0> ) ; angles . addSelectionListener ( new SelectionListener ( ) { @ Override public void widgetSelected ( SelectionEvent e ) { int index = angles . getSelectionIndex ( ) ; IEditableCloudLabelProvider lp = ( IEditableCloudLabelProvider ) viewer . getLabelProvider ( ) ; lp . setAngles ( anglesLists . get ( index ) ) ; } @ Override public void widgetDefaultSelected ( SelectionEvent e ) { } } ) ; return buttons ; } public List < RGB > getColors ( ) { return colors ; } public List < FontData > getFonts ( ) { return fonts ; } } </s>
|
<s> package org . eclipse . zest . cloudio . layout ; import java . util . Random ; import org . eclipse . core . runtime . Assert ; import org . eclipse . swt . graphics . Point ; import org . eclipse . swt . graphics . Rectangle ; import org . eclipse . zest . cloudio . Word ; import org . eclipse . zest . cloudio . util . CloudMatrix ; import org . eclipse . zest . cloudio . util . RectTree ; public class DefaultLayouter implements ILayouter { public static final String X_AXIS_VARIATION = "<STR_LIT>" ; public static final String Y_AXIS_VARIATION = "<STR_LIT>" ; private Random random = new Random ( ) ; private int xAxisVariation ; private int yAxisVariation ; public DefaultLayouter ( int i , int j ) { this . xAxisVariation = i ; this . yAxisVariation = j ; } public Point getInitialOffset ( Word word , Rectangle cloudArea ) { int xOff = <NUM_LIT:0> ; if ( xAxisVariation > <NUM_LIT:0> ) { int range = ( cloudArea . width - word . width ) / <NUM_LIT> * xAxisVariation ; if ( range > <NUM_LIT:0> ) { xOff = random . nextInt ( range ) ; if ( random . nextBoolean ( ) ) { xOff = - xOff ; } } } int yOff = <NUM_LIT:0> ; if ( yAxisVariation > <NUM_LIT:0> ) { int range = cloudArea . height / <NUM_LIT> * yAxisVariation ; if ( range > <NUM_LIT:0> ) { yOff = random . nextInt ( range ) ; if ( random . nextBoolean ( ) ) yOff = - yOff ; } } return new Point ( xOff , yOff ) ; } public boolean layout ( Point offset , final Word word , final Rectangle cloudArea , CloudMatrix mainTree ) { Assert . isLegal ( word != null , "<STR_LIT>" ) ; Point next = new Point ( - word . width / <NUM_LIT:2> , - word . height / <NUM_LIT:2> ) ; next . x += random . nextInt ( <NUM_LIT> ) ; next . y += random . nextInt ( <NUM_LIT> ) ; double growFactor = <NUM_LIT> ; offset . x += cloudArea . width / <NUM_LIT:2> ; offset . y += cloudArea . height / <NUM_LIT:2> ; final int accuracy = mainTree . getMinResolution ( ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT> ; i ++ ) { final double radius = Math . sqrt ( ( double ) ( next . x * next . x + next . y * next . y ) ) + growFactor ; double atan = Math . atan2 ( next . y , next . x ) ; if ( growFactor > <NUM_LIT> ) { growFactor -= <NUM_LIT> ; } if ( radius < <NUM_LIT> ) { atan += <NUM_LIT> ; } else { atan += <NUM_LIT:20> / radius ; } if ( growFactor < <NUM_LIT> ) { growFactor = <NUM_LIT> ; } next . x = ( int ) ( radius * Math . cos ( atan ) ) ; next . y = ( int ) ( radius * Math . sin ( atan ) ) ; word . x = ( ( next . x + offset . x ) / accuracy ) * accuracy ; word . y = ( ( next . y + offset . y ) / accuracy ) * accuracy ; RectTree rt = word . tree ; if ( rt == null ) break ; rt . move ( word . x , word . y ) ; if ( cloudArea . x <= word . x && cloudArea . y <= word . y && cloudArea . x + cloudArea . width >= word . x + word . width && cloudArea . y + cloudArea . height >= word . y + word . height ) { if ( rt . fits ( mainTree ) ) { rt . place ( mainTree , word . id ) ; return true ; } } } return false ; } public void setOption ( String optionName , Object object ) { if ( X_AXIS_VARIATION . equals ( optionName ) ) { Integer value = ( Integer ) object ; Assert . isLegal ( value >= <NUM_LIT:0> , "<STR_LIT>" + value ) ; Assert . isLegal ( value <= <NUM_LIT:100> , "<STR_LIT>" + value ) ; this . xAxisVariation = value ; return ; } if ( Y_AXIS_VARIATION . equals ( optionName ) ) { Integer value = ( Integer ) object ; Assert . isLegal ( value >= <NUM_LIT:0> , "<STR_LIT>" + value ) ; Assert . isLegal ( value <= <NUM_LIT:100> , "<STR_LIT>" + value ) ; this . yAxisVariation = value ; return ; } System . err . println ( "<STR_LIT>" + optionName ) ; } } </s>
|
<s> package org . eclipse . zest . cloudio . layout ; import org . eclipse . swt . graphics . Point ; import org . eclipse . swt . graphics . Rectangle ; import org . eclipse . zest . cloudio . Word ; import org . eclipse . zest . cloudio . util . CloudMatrix ; public interface ILayouter { public boolean layout ( Point initial , final Word word , final Rectangle cloudArea , CloudMatrix cloudMatrix ) ; public Point getInitialOffset ( Word word , Rectangle cloudArea ) ; public void setOption ( String optionName , Object object ) ; } </s>
|
<s> package org . eclipse . zest . cloudio ; import org . eclipse . jface . viewers . IBaseLabelProvider ; import org . eclipse . swt . graphics . Color ; import org . eclipse . swt . graphics . FontData ; public interface ICloudLabelProvider extends IBaseLabelProvider { public String getLabel ( Object element ) ; public double getWeight ( Object element ) ; public Color getColor ( Object element ) ; public FontData [ ] getFontData ( Object element ) ; public float getAngle ( Object element ) ; public String getToolTip ( Object element ) ; } </s>
|
<s> package org . eclipse . zest . cloudio ; import java . util . List ; import org . eclipse . swt . graphics . FontData ; import org . eclipse . swt . graphics . RGB ; public interface IEditableCloudLabelProvider extends ICloudLabelProvider { public void setColors ( List < RGB > colors ) ; public void setFonts ( List < FontData > fonts ) ; public void setAngles ( List < Float > list ) ; } </s>
|
<s> package org . eclipse . zest . cloudio ; import java . util . ArrayList ; import java . util . HashMap ; import java . util . HashSet ; import java . util . Iterator ; import java . util . List ; import java . util . Map ; import java . util . Set ; import org . eclipse . core . runtime . Assert ; import org . eclipse . core . runtime . IProgressMonitor ; import org . eclipse . jface . viewers . ContentViewer ; import org . eclipse . jface . viewers . IBaseLabelProvider ; import org . eclipse . jface . viewers . IContentProvider ; import org . eclipse . jface . viewers . ISelection ; import org . eclipse . jface . viewers . IStructuredContentProvider ; import org . eclipse . jface . viewers . IStructuredSelection ; import org . eclipse . jface . viewers . SelectionChangedEvent ; import org . eclipse . jface . viewers . StructuredSelection ; import org . eclipse . swt . events . MouseEvent ; import org . eclipse . swt . events . MouseListener ; import org . eclipse . swt . events . MouseTrackListener ; import org . eclipse . swt . events . MouseWheelListener ; import org . eclipse . swt . events . SelectionEvent ; import org . eclipse . swt . events . SelectionListener ; import org . eclipse . swt . widgets . Control ; import org . eclipse . zest . cloudio . layout . ILayouter ; public class TagCloudViewer extends ContentViewer { private TagCloud cloud ; private Set < Word > selection = new HashSet < Word > ( ) ; private Map < Object , Word > objectMap = new HashMap < Object , Word > ( ) ; private int maxWords = <NUM_LIT> ; private IProgressMonitor monitor ; public TagCloudViewer ( TagCloud cloud ) { Assert . isLegal ( cloud != null , "<STR_LIT>" ) ; Assert . isLegal ( ! cloud . isDisposed ( ) , "<STR_LIT>" ) ; this . cloud = cloud ; initListeners ( ) ; } protected void initListeners ( ) { initSelectionListener ( ) ; initMouseWheelListener ( ) ; initToolTipSupport ( ) ; } protected void initToolTipSupport ( ) { cloud . addMouseTrackListener ( new MouseTrackListener ( ) { @ Override public void mouseHover ( MouseEvent e ) { } @ Override public void mouseExit ( MouseEvent e ) { cloud . setToolTipText ( null ) ; } @ Override public void mouseEnter ( MouseEvent e ) { Word word = ( Word ) e . data ; ICloudLabelProvider labelProvider = ( ICloudLabelProvider ) getLabelProvider ( ) ; cloud . setToolTipText ( labelProvider . getToolTip ( word . data ) ) ; } } ) ; } protected void initMouseWheelListener ( ) { cloud . addMouseWheelListener ( new MouseWheelListener ( ) { @ Override public void mouseScrolled ( MouseEvent e ) { if ( e . count > <NUM_LIT:0> ) { cloud . zoomIn ( ) ; } else { cloud . zoomOut ( ) ; } } } ) ; } protected void initSelectionListener ( ) { cloud . addMouseListener ( new MouseListener ( ) { @ Override public void mouseUp ( MouseEvent e ) { Word word = ( Word ) e . data ; if ( word == null ) return ; boolean remove = selection . remove ( word ) ; if ( ! remove ) selection . add ( word ) ; cloud . setSelection ( selection ) ; } @ Override public void mouseDown ( MouseEvent e ) { } @ Override public void mouseDoubleClick ( MouseEvent e ) { } } ) ; cloud . addSelectionListener ( new SelectionListener ( ) { @ Override public void widgetSelected ( SelectionEvent e ) { List < Object > data = new ArrayList < Object > ( ) ; Set < Word > selected = ( Set < Word > ) e . data ; for ( Word word : selected ) { if ( word . data != null ) { data . add ( word . data ) ; } } StructuredSelection selection = new StructuredSelection ( data ) ; fireSelectionChanged ( new SelectionChangedEvent ( TagCloudViewer . this , selection ) ) ; } @ Override public void widgetDefaultSelected ( SelectionEvent e ) { } } ) ; } @ Override public Control getControl ( ) { return getCloud ( ) ; } @ Override public ISelection getSelection ( ) { List < Object > elements = new ArrayList < Object > ( ) ; for ( Word word : selection ) { elements . add ( word . data ) ; } return new StructuredSelection ( elements ) ; } @ Override public void refresh ( ) { } @ Override public void setSelection ( ISelection selection , boolean reveal ) { this . selection . clear ( ) ; IStructuredSelection sel = ( IStructuredSelection ) selection ; Iterator < ? > iterator = sel . iterator ( ) ; while ( iterator . hasNext ( ) ) { Object next = iterator . next ( ) ; Word word = objectMap . get ( next ) ; if ( word != null ) { this . selection . add ( word ) ; } } cloud . setSelection ( this . selection ) ; } public void reset ( IProgressMonitor monitor , boolean recalc ) { cloud . layoutCloud ( monitor , recalc ) ; } public TagCloud getCloud ( ) { return cloud ; } @ Override public void setLabelProvider ( IBaseLabelProvider labelProvider ) { super . setLabelProvider ( labelProvider ) ; Assert . isLegal ( labelProvider instanceof ICloudLabelProvider ) ; } @ Override public void setContentProvider ( IContentProvider contentProvider ) { Assert . isLegal ( contentProvider instanceof IStructuredContentProvider ) ; super . setContentProvider ( contentProvider ) ; } @ Override protected void inputChanged ( Object input , Object oldInput ) { selection . clear ( ) ; objectMap . clear ( ) ; IStructuredContentProvider contentProvider = ( IStructuredContentProvider ) getContentProvider ( ) ; Object [ ] elements = contentProvider . getElements ( input ) ; List < Word > words = new ArrayList < Word > ( ) ; ICloudLabelProvider labelProvider = ( ICloudLabelProvider ) getLabelProvider ( ) ; short i = <NUM_LIT:0> ; for ( Object element : elements ) { Word word = new Word ( labelProvider . getLabel ( element ) ) ; word . setColor ( labelProvider . getColor ( element ) ) ; word . weight = labelProvider . getWeight ( element ) ; word . setFontData ( labelProvider . getFontData ( element ) ) ; word . angle = labelProvider . getAngle ( element ) ; word . data = element ; Assert . isLegal ( word . string != null , "<STR_LIT>" ) ; Assert . isLegal ( word . getColor ( ) != null , "<STR_LIT>" ) ; Assert . isLegal ( word . getFontData ( ) != null , "<STR_LIT>" ) ; Assert . isLegal ( word . weight >= <NUM_LIT:0> , "<STR_LIT>" + word . weight ) ; Assert . isLegal ( word . weight <= <NUM_LIT:1> , "<STR_LIT>" + word . weight ) ; Assert . isLegal ( word . angle >= - <NUM_LIT> , "<STR_LIT>" + word . angle ) ; Assert . isLegal ( word . angle <= <NUM_LIT> , "<STR_LIT>" + word . angle ) ; words . add ( word ) ; i ++ ; word . id = i ; objectMap . put ( element , word ) ; if ( i == maxWords ) break ; } selection . clear ( ) ; if ( monitor != null ) { monitor . subTask ( "<STR_LIT>" ) ; } cloud . setWords ( words , monitor ) ; } public void setMaxWords ( int words ) { this . maxWords = words ; } public void zoomFit ( ) { cloud . zoomFit ( ) ; } public void zoomIn ( ) { cloud . zoomIn ( ) ; } public void zoomOut ( ) { cloud . zoomOut ( ) ; } public void zoomReset ( ) { cloud . zoomReset ( ) ; } public void setBoost ( int boost ) { cloud . setBoost ( boost ) ; } public int getMaxWords ( ) { return maxWords ; } public void setInput ( Object input , IProgressMonitor progressMonitor ) { this . monitor = progressMonitor ; super . setInput ( input ) ; this . monitor = null ; } public void setBoostFactor ( float boostFactor ) { cloud . setBoostFactor ( boostFactor ) ; } public void setLayouter ( ILayouter layouter ) { cloud . setLayouter ( layouter ) ; } public ILayouter getLayouter ( ) { return cloud . getLayouter ( ) ; } } </s>
|
<s> package org . eclipse . zest . cloudio ; import org . eclipse . core . runtime . Assert ; import org . eclipse . swt . graphics . Color ; import org . eclipse . swt . graphics . FontData ; import org . eclipse . swt . graphics . Point ; import org . eclipse . zest . cloudio . util . RectTree ; public class Word { public Word ( String string ) { this . string = string ; } public final String string ; public double weight ; public int x ; public int y ; private Color color ; public RectTree tree ; public float angle ; private FontData [ ] fontData ; public FontData [ ] getFontData ( ) { return fontData ; } public void setFontData ( FontData [ ] fontData ) { Assert . isLegal ( fontData != null , "<STR_LIT>" ) ; this . fontData = fontData . clone ( ) ; } public short id ; public int height ; public int width ; public Object data ; public Point stringExtent ; @ Override public String toString ( ) { return string ; } public void setColor ( Color color ) { Assert . isLegal ( color != null , "<STR_LIT>" ) ; Assert . isLegal ( ! color . isDisposed ( ) , "<STR_LIT>" ) ; this . color = color ; } public Color getColor ( ) { Assert . isLegal ( color != null , "<STR_LIT>" ) ; Assert . isLegal ( ! color . isDisposed ( ) , "<STR_LIT>" ) ; return color ; } } </s>
|
<s> package org . eclipse . zest . cloudio . util ; import java . util . Collection ; import java . util . HashSet ; import java . util . Iterator ; import java . util . LinkedList ; import java . util . List ; import java . util . Set ; import org . eclipse . swt . graphics . Point ; public class RectTree { private final int minResolution ; private short xOffset , yOffset ; private RectNode root ; private LinkedList < RectNode > leaves ; public static short EMPTY = - <NUM_LIT:3> , MISC = - <NUM_LIT:2> , BACKGROUND = - <NUM_LIT:1> ; class RectNode { final SmallRect rect ; private RectNode [ ] children ; private final SmallRect [ ] childAreas ; short filled = EMPTY ; public RectNode ( SmallRect rect ) { this . rect = rect ; final int width = rect . width / <NUM_LIT:2> ; final int height = rect . height / <NUM_LIT:2> ; if ( rect . width > minResolution ) { this . childAreas = new SmallRect [ <NUM_LIT:4> ] ; childAreas [ <NUM_LIT:0> ] = new SmallRect ( rect . x , rect . y , width , height ) ; childAreas [ <NUM_LIT:1> ] = new SmallRect ( rect . x + width , rect . y , width , height ) ; childAreas [ <NUM_LIT:2> ] = new SmallRect ( rect . x , rect . y + height , width , height ) ; childAreas [ <NUM_LIT:3> ] = new SmallRect ( rect . x + width , rect . y + height , width , height ) ; } else { this . childAreas = null ; } } private int getChildIndex ( SmallRect r ) { int index = <NUM_LIT:0> ; if ( r . y >= childAreas [ <NUM_LIT:3> ] . y ) { if ( r . x >= childAreas [ <NUM_LIT:3> ] . x ) { index = <NUM_LIT:3> ; } else { index = <NUM_LIT:2> ; } } else { if ( r . x >= childAreas [ <NUM_LIT:1> ] . x ) { index = <NUM_LIT:1> ; } } return index ; } public boolean insert ( SmallRect r , short id ) { if ( rect . width == minResolution ) { filled = id ; return true ; } int i = getChildIndex ( r ) ; if ( children == null ) { children = new RectNode [ <NUM_LIT:4> ] ; } if ( children [ i ] == null ) { children [ i ] = new RectNode ( childAreas [ i ] ) ; } boolean filledChild = children [ i ] . insert ( r , id ) ; if ( filledChild ) { Set < Short > ids = new HashSet < Short > ( ) ; boolean filled = true ; for ( int j = <NUM_LIT:0> ; j < children . length ; j ++ ) { if ( i == j ) continue ; if ( children [ j ] == null || children [ j ] . filled == EMPTY ) { filled = false ; break ; } ids . add ( children [ j ] . filled ) ; } if ( filled ) { if ( ids . size ( ) == <NUM_LIT:1> ) { this . filled = ids . iterator ( ) . next ( ) ; if ( this . filled == BACKGROUND ) { children = null ; } } else { this . filled = MISC ; } } return filled ; } return false ; } public boolean isAvailable ( final SmallRect oRect ) { if ( filled >= MISC ) return false ; if ( children == null ) { return filled == EMPTY ; } final int i = getChildIndex ( oRect ) ; if ( children [ i ] == null ) return true ; return children [ i ] . isAvailable ( oRect ) ; } public short getWordId ( int x , int y ) { if ( filled > BACKGROUND ) return filled ; if ( children == null ) { return filled ; } for ( int i = <NUM_LIT:0> ; i < childAreas . length ; i ++ ) { if ( childAreas [ i ] . intersects ( x , y , minResolution , minResolution ) && children [ i ] != null ) { return children [ i ] . getWordId ( x , y ) ; } } return EMPTY ; } public short getWordId ( Point position ) { return getWordId ( position . x , position . y ) ; } } public RectTree ( SmallRect root , int minResolution ) { this . minResolution = minResolution ; this . root = new RectNode ( root ) ; } public void insert ( SmallRect r , short id ) { root . insert ( r , id ) ; } public void move ( int x , int y ) { this . xOffset = ( short ) x ; this . yOffset = ( short ) y ; } public boolean fits ( final CloudMatrix mainTree ) { LinkedList < RectNode > leaves = getLeaves ( ) ; Iterator < RectNode > nodes = leaves . iterator ( ) ; while ( nodes . hasNext ( ) ) { RectNode node = nodes . next ( ) ; if ( ! mainTree . isEmpty ( ( node . rect . x + xOffset ) / minResolution , ( node . rect . y + yOffset ) / minResolution ) ) { nodes . remove ( ) ; leaves . addFirst ( node ) ; return false ; } } return true ; } LinkedList < RectNode > getLeaves ( ) { if ( leaves == null ) { leaves = new LinkedList < RectNode > ( ) ; addLeaves ( leaves , root ) ; } return leaves ; } private void addLeaves ( List < RectNode > leaves , RectNode current ) { if ( current . children == null ) { if ( current . filled != EMPTY ) { leaves . add ( current ) ; } } else { for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:4> ; i ++ ) { if ( current . children [ i ] == null ) continue ; addLeaves ( leaves , current . children [ i ] ) ; } } } public void place ( final CloudMatrix mainTree , short id ) { Collection < RectNode > leaves = getLeaves ( ) ; for ( RectNode node : leaves ) { mainTree . set ( node , id , xOffset , yOffset , minResolution ) ; } } public void releaseRects ( ) { getLeaves ( ) ; root . children = null ; } public RectNode getRoot ( ) { return root ; } public void reset ( ) { root = new RectNode ( root . rect ) ; } } </s>
|
<s> package org . eclipse . zest . cloudio . util ; import org . eclipse . swt . SWT ; import org . eclipse . swt . graphics . Rectangle ; public class SmallRect { final short x , y , width , height ; @ Override public int hashCode ( ) { final int prime = <NUM_LIT:31> ; int result = <NUM_LIT:1> ; result = prime * result + height ; result = prime * result + width ; result = prime * result + x ; result = prime * result + y ; return result ; } @ Override public boolean equals ( Object obj ) { if ( this == obj ) return true ; if ( obj == null ) return false ; if ( getClass ( ) != obj . getClass ( ) ) return false ; SmallRect other = ( SmallRect ) obj ; if ( height != other . height ) return false ; if ( width != other . width ) return false ; if ( x != other . x ) return false ; if ( y != other . y ) return false ; return true ; } public SmallRect ( int x , int y , int width , int height ) { this . x = ( short ) x ; this . y = ( short ) y ; this . width = ( short ) width ; this . height = ( short ) height ; } public boolean intersects ( SmallRect rect ) { if ( rect == null ) SWT . error ( SWT . ERROR_NULL_ARGUMENT ) ; return rect == this || intersects ( rect . x , rect . y , rect . width , rect . height ) ; } public boolean intersects ( final int x , final int y , final int width , final int height ) { return ( x < this . x + this . width ) && ( y < this . y + this . height ) && ( x + width > this . x ) && ( y + height > this . y ) ; } public String toString ( ) { return "<STR_LIT>" + x + "<STR_LIT:U+002CU+0020>" + y + "<STR_LIT:U+002CU+0020>" + width + "<STR_LIT:U+002CU+0020>" + height + "<STR_LIT:}>" ; } } </s>
|
<s> package org . eclipse . zest . cloudio . util ; import org . eclipse . zest . cloudio . util . RectTree . RectNode ; public class CloudMatrix { private RectTree tree ; private final int max ; private final int minResolution ; public int getMinResolution ( ) { return minResolution ; } public CloudMatrix ( int maxSize , int minResolution ) { this . max = maxSize ; this . minResolution = minResolution ; reset ( ) ; } public short get ( int x , int y ) { return tree . getRoot ( ) . getWordId ( x * minResolution , y * minResolution ) ; } public boolean isEmpty ( int x , int y ) { short id = tree . getRoot ( ) . getWordId ( x * minResolution , y * minResolution ) ; return id == RectTree . EMPTY ; } public void reset ( ) { SmallRect root = new SmallRect ( <NUM_LIT:0> , <NUM_LIT:0> , max , max ) ; tree = new RectTree ( root , minResolution ) ; } public void set ( RectNode node , short id , short xOffset , short yOffset , int minResolution ) { int cleanX = ( ( xOffset + node . rect . x ) / minResolution ) * minResolution ; int cleanY = ( ( yOffset + node . rect . y ) / minResolution ) * minResolution ; SmallRect rect = new SmallRect ( cleanX , cleanY , minResolution , minResolution ) ; tree . insert ( rect , id ) ; } } </s>
|
<s> package org . eclipse . zest . cloudio ; import java . io . IOException ; import java . io . InputStream ; import org . eclipse . swt . graphics . Image ; import org . eclipse . swt . graphics . ImageData ; import org . eclipse . swt . graphics . ImageLoader ; import org . eclipse . swt . widgets . Display ; import org . eclipse . ui . plugin . AbstractUIPlugin ; import org . osgi . framework . BundleContext ; public class Activator extends AbstractUIPlugin { public static final String PLUGIN_ID = "<STR_LIT>" ; private static Activator plugin ; public static final String ADD = "<STR_LIT>" ; public static final String REMOVE = "<STR_LIT>" ; public static final String TOGGLE_COLORS = "<STR_LIT>" ; public Activator ( ) { } public void start ( BundleContext context ) throws Exception { super . start ( context ) ; plugin = this ; ImageLoader il = new ImageLoader ( ) ; loadImage ( il , ADD ) ; loadImage ( il , REMOVE ) ; loadImage ( il , TOGGLE_COLORS ) ; } private void loadImage ( ImageLoader il , String fileName ) throws IOException { InputStream stream = getBundle ( ) . getResource ( "<STR_LIT>" + fileName ) . openStream ( ) ; ImageData [ ] data = il . load ( stream ) ; Image image = new Image ( Display . getDefault ( ) , data [ <NUM_LIT:0> ] ) ; getImageRegistry ( ) . put ( fileName , image ) ; } public void stop ( BundleContext context ) throws Exception { plugin = null ; super . stop ( context ) ; } public static Activator getDefault ( ) { return plugin ; } } </s>
|
<s> package org . eclipse . zest . cloudio ; import java . util . ArrayList ; import java . util . Collection ; import java . util . Collections ; import java . util . Comparator ; import java . util . EventListener ; import java . util . HashSet ; import java . util . List ; import java . util . Set ; import java . util . concurrent . ExecutorService ; import java . util . concurrent . Executors ; import java . util . concurrent . TimeUnit ; import org . eclipse . core . runtime . Assert ; import org . eclipse . core . runtime . IProgressMonitor ; import org . eclipse . jface . dialogs . MessageDialog ; import org . eclipse . swt . SWT ; import org . eclipse . swt . events . DisposeEvent ; import org . eclipse . swt . events . DisposeListener ; import org . eclipse . swt . events . MouseEvent ; import org . eclipse . swt . events . MouseListener ; import org . eclipse . swt . events . MouseMoveListener ; import org . eclipse . swt . events . MouseTrackListener ; import org . eclipse . swt . events . MouseWheelListener ; import org . eclipse . swt . events . SelectionEvent ; import org . eclipse . swt . events . SelectionListener ; import org . eclipse . swt . graphics . Color ; import org . eclipse . swt . graphics . Font ; import org . eclipse . swt . graphics . FontData ; import org . eclipse . swt . graphics . FontMetrics ; import org . eclipse . swt . graphics . GC ; import org . eclipse . swt . graphics . Image ; import org . eclipse . swt . graphics . ImageData ; import org . eclipse . swt . graphics . PaletteData ; import org . eclipse . swt . graphics . Path ; import org . eclipse . swt . graphics . Point ; import org . eclipse . swt . graphics . Rectangle ; import org . eclipse . swt . graphics . Transform ; import org . eclipse . swt . widgets . Canvas ; import org . eclipse . swt . widgets . Composite ; import org . eclipse . swt . widgets . Display ; import org . eclipse . swt . widgets . Event ; import org . eclipse . swt . widgets . Listener ; import org . eclipse . swt . widgets . ScrollBar ; import org . eclipse . zest . cloudio . layout . DefaultLayouter ; import org . eclipse . zest . cloudio . layout . ILayouter ; import org . eclipse . zest . cloudio . util . CloudMatrix ; import org . eclipse . zest . cloudio . util . RectTree ; import org . eclipse . zest . cloudio . util . SmallRect ; public class TagCloud extends Canvas { private final int accuracy ; private final int maxSize ; private final Rectangle cloudArea ; private int maxFontSize = <NUM_LIT:100> ; private final GC gc ; private Color highlightColor ; private Word currentWord ; private int opacity = <NUM_LIT:255> ; private final Point origin = new Point ( <NUM_LIT:0> , <NUM_LIT:0> ) ; private Image textLayerImage ; private Image selectionLayerImage ; private Image zoomLayerImage ; private List < Word > wordsToUse ; private boolean initialized = false ; private double currentZoom = <NUM_LIT:1> ; private int minFontSize = <NUM_LIT:12> ; private Set < Word > selection = new HashSet < Word > ( ) ; private CloudMatrix cloudMatrix ; private ExecutorService executors ; private ILayouter layouter ; private int boost ; private Point regionOffset ; private int antialias = SWT . ON ; private float boostFactor ; private Listener hBarListener ; private Listener resizeListener ; private Listener paintListener ; private Listener mouseTrackListener ; private Listener mouseMoveListener ; private Listener mouseUpListener ; private Listener mouseDCListener ; private Listener mouseDownListener ; private Listener mouseWheelListener ; private Listener vBarListener ; private Set < EventListener > mouseWheelListeners = new HashSet < EventListener > ( ) ; private Set < EventListener > mouseTrackListeners = new HashSet < EventListener > ( ) ; private Set < EventListener > mouseMoveListeners = new HashSet < EventListener > ( ) ; private Set < EventListener > mouseListeners = new HashSet < EventListener > ( ) ; private Set < SelectionListener > selectionListeners = new HashSet < SelectionListener > ( ) ; private ImageData mask ; public TagCloud ( Composite parent , int style , int accuracy , int maxSize ) { super ( parent , style ) ; Assert . isLegal ( accuracy > <NUM_LIT:0> , "<STR_LIT>" + accuracy ) ; Assert . isLegal ( maxSize > <NUM_LIT:0> , "<STR_LIT>" + maxSize ) ; int tmp = maxSize ; while ( tmp > accuracy ) { tmp /= <NUM_LIT:2> ; } Assert . isLegal ( tmp == accuracy , "<STR_LIT>" ) ; this . accuracy = accuracy ; this . maxSize = maxSize ; cloudArea = new Rectangle ( <NUM_LIT:0> , <NUM_LIT:0> , maxSize , maxSize ) ; highlightColor = new Color ( getDisplay ( ) , Display . getDefault ( ) . getSystemColor ( SWT . COLOR_RED ) . getRGB ( ) ) ; gc = new GC ( this ) ; layouter = new DefaultLayouter ( accuracy , accuracy ) ; setBackground ( new Color ( getDisplay ( ) , Display . getDefault ( ) . getSystemColor ( SWT . COLOR_BLACK ) . getRGB ( ) ) ) ; initListeners ( ) ; textLayerImage = new Image ( getDisplay ( ) , <NUM_LIT:100> , <NUM_LIT:100> ) ; zoomFit ( ) ; addDisposeListener ( new DisposeListener ( ) { @ Override public void widgetDisposed ( DisposeEvent e ) { internalDispose ( ) ; } } ) ; } public TagCloud ( Composite parent , int style ) { this ( parent , style , <NUM_LIT:5> , <NUM_LIT> ) ; } private void internalDispose ( ) { removeListeners ( ) ; textLayerImage . dispose ( ) ; if ( selectionLayerImage != null ) { selectionLayerImage . dispose ( ) ; } if ( zoomLayerImage != null ) { zoomLayerImage . dispose ( ) ; } if ( ! this . isDisposed ( ) ) { gc . dispose ( ) ; } super . dispose ( ) ; } private void removeListeners ( ) { if ( isDisposed ( ) ) return ; removeListener ( SWT . Paint , paintListener ) ; if ( hBarListener != null ) { removeListener ( SWT . H_SCROLL , hBarListener ) ; } if ( vBarListener != null ) { removeListener ( SWT . V_SCROLL , vBarListener ) ; } removeListener ( SWT . MouseDoubleClick , mouseDCListener ) ; removeListener ( SWT . MouseDown , mouseDownListener ) ; removeListener ( SWT . MouseMove , mouseTrackListener ) ; removeListener ( SWT . MouseUp , mouseUpListener ) ; removeListener ( SWT . Resize , resizeListener ) ; removeListener ( SWT . MouseMove , mouseMoveListener ) ; removeListener ( SWT . MouseWheel , mouseWheelListener ) ; } public void zoomReset ( ) { checkWidget ( ) ; if ( selectionLayerImage == null ) return ; zoomLayerImage = new Image ( getDisplay ( ) , selectionLayerImage . getBounds ( ) . width , selectionLayerImage . getBounds ( ) . height ) ; GC gc = new GC ( zoomLayerImage ) ; gc . drawImage ( selectionLayerImage , <NUM_LIT:0> , <NUM_LIT:0> ) ; gc . dispose ( ) ; currentZoom = <NUM_LIT:1> ; updateScrollbars ( ) ; redraw ( ) ; } public double getZoom ( ) { checkWidget ( ) ; return currentZoom ; } public void zoomFit ( ) { checkWidget ( ) ; if ( selectionLayerImage == null ) return ; Rectangle imageBound = selectionLayerImage . getBounds ( ) ; Rectangle destRect = getClientArea ( ) ; double sx = ( double ) destRect . width / ( double ) imageBound . width ; double sy = ( double ) destRect . height / ( double ) imageBound . height ; currentZoom = Math . min ( sx , sy ) ; zoom ( currentZoom ) ; } private void zoom ( double s ) { checkWidget ( ) ; if ( selectionLayerImage == null ) return ; if ( s < <NUM_LIT> ) s = <NUM_LIT> ; if ( s > <NUM_LIT:3> ) s = <NUM_LIT:3> ; int width = ( int ) ( selectionLayerImage . getBounds ( ) . width * s ) ; int height = ( int ) ( selectionLayerImage . getBounds ( ) . height * s ) ; if ( width == <NUM_LIT:0> || height == <NUM_LIT:0> ) return ; zoomLayerImage = new Image ( getDisplay ( ) , width , height ) ; Transform tf = new Transform ( getDisplay ( ) ) ; tf . scale ( ( float ) s , ( float ) s ) ; GC gc = new GC ( zoomLayerImage ) ; gc . setTransform ( tf ) ; gc . drawImage ( selectionLayerImage , <NUM_LIT:0> , <NUM_LIT:0> ) ; gc . dispose ( ) ; tf . dispose ( ) ; currentZoom = s ; updateScrollbars ( ) ; redraw ( ) ; } public void zoomIn ( ) { checkWidget ( ) ; zoom ( currentZoom * <NUM_LIT> ) ; redraw ( ) ; } public void zoomOut ( ) { checkWidget ( ) ; zoom ( currentZoom * <NUM_LIT> ) ; redraw ( ) ; } protected Rectangle getCloudArea ( ) { return cloudArea ; } private float getFontSize ( Word word ) { float size = ( float ) ( word . weight * maxFontSize ) ; size += minFontSize ; return size ; } private void drawWord ( final GC gc , final Word word , final Color color ) { gc . setForeground ( color ) ; Font font = new Font ( gc . getDevice ( ) , word . getFontData ( ) ) ; gc . setFont ( font ) ; gc . setAntialias ( antialias ) ; gc . setAlpha ( opacity ) ; Point stringExtent = word . stringExtent ; gc . setForeground ( color ) ; int xOffset = word . x - regionOffset . x ; int yOffset = word . y - regionOffset . y ; double radian = Math . toRadians ( word . angle ) ; final double sin = Math . abs ( Math . sin ( radian ) ) ; final double cos = Math . abs ( Math . cos ( radian ) ) ; int y = ( int ) ( ( cos * stringExtent . y ) + ( sin * stringExtent . x ) ) ; Transform t = new Transform ( gc . getDevice ( ) ) ; if ( word . angle < <NUM_LIT:0> ) { t . translate ( xOffset , yOffset + y - ( int ) ( cos * stringExtent . y ) ) ; } else { t . translate ( xOffset + ( int ) ( sin * stringExtent . y ) , yOffset ) ; } t . rotate ( word . angle ) ; gc . setTransform ( t ) ; gc . drawString ( word . string , <NUM_LIT:0> , <NUM_LIT:0> , true ) ; gc . setTransform ( null ) ; t . dispose ( ) ; font . dispose ( ) ; } protected void calcExtents ( IProgressMonitor monitor ) { checkWidget ( ) ; if ( monitor != null ) { monitor . subTask ( "<STR_LIT>" ) ; } if ( wordsToUse == null ) return ; double step = <NUM_LIT> / wordsToUse . size ( ) ; double current = <NUM_LIT:0> ; int next = <NUM_LIT:10> ; executors = Executors . newFixedThreadPool ( getNumberOfThreads ( ) ) ; final Color color = gc . getDevice ( ) . getSystemColor ( SWT . COLOR_BLACK ) ; for ( final Word word : wordsToUse ) { FontData [ ] fontData = word . getFontData ( ) ; int fontSize = ( int ) getFontSize ( word ) ; for ( FontData data : fontData ) { data . setHeight ( ( int ) fontSize ) ; } final Font font = new Font ( gc . getDevice ( ) , fontData ) ; gc . setFont ( font ) ; final Point stringExtent = gc . stringExtent ( word . string ) ; FontMetrics fm = gc . getFontMetrics ( ) ; stringExtent . y = fm . getHeight ( ) ; executors . execute ( new Runnable ( ) { @ Override public void run ( ) { double radian = Math . toRadians ( word . angle ) ; final double sin = Math . abs ( Math . sin ( radian ) ) ; final double cos = Math . abs ( Math . cos ( radian ) ) ; final int x = ( int ) ( ( cos * stringExtent . x ) + ( sin * stringExtent . y ) ) ; final int y = ( int ) ( ( cos * stringExtent . y ) + ( sin * stringExtent . x ) ) ; ImageData id = createImageData ( word , font , stringExtent , sin , cos , x , y , color ) ; calcWordExtents ( word , id ) ; font . dispose ( ) ; } } ) ; if ( monitor != null ) { current += step ; if ( current > next ) { monitor . worked ( <NUM_LIT:5> ) ; next += <NUM_LIT:5> ; } } } executors . shutdown ( ) ; try { executors . awaitTermination ( Integer . MAX_VALUE , TimeUnit . SECONDS ) ; } catch ( InterruptedException e ) { e . printStackTrace ( ) ; } Collections . sort ( wordsToUse , new Comparator < Word > ( ) { @ Override public int compare ( Word o1 , Word o2 ) { return ( o2 . width * o2 . height ) - ( o1 . width * o1 . height ) ; } } ) ; short i = <NUM_LIT:1> ; for ( Word word : wordsToUse ) { word . id = i ++ ; } } private ImageData createImageData ( final Word word , Font font , Point stringExtent , final double sin , final double cos , int x , int y , Color color ) { Image img = new Image ( null , x , y ) ; word . width = x ; word . height = y ; word . stringExtent = stringExtent ; GC g = new GC ( img ) ; g . setAntialias ( antialias ) ; g . setForeground ( color ) ; Transform t = new Transform ( img . getDevice ( ) ) ; if ( word . angle < <NUM_LIT:0> ) { t . translate ( <NUM_LIT:0> , img . getBounds ( ) . height - ( int ) ( cos * stringExtent . y ) ) ; } else { t . translate ( ( int ) ( sin * stringExtent . y ) , <NUM_LIT:0> ) ; } t . rotate ( word . angle ) ; g . setTransform ( t ) ; g . setFont ( font ) ; g . drawString ( word . string , <NUM_LIT:0> , <NUM_LIT:0> , false ) ; int max = Math . max ( x , y ) ; int tmp = maxSize ; while ( max < tmp ) { tmp = tmp / <NUM_LIT:2> ; } tmp = tmp * <NUM_LIT:2> ; SmallRect root = new SmallRect ( <NUM_LIT:0> , <NUM_LIT:0> , tmp , tmp ) ; word . tree = new RectTree ( root , accuracy ) ; final ImageData id = img . getImageData ( ) ; g . dispose ( ) ; img . dispose ( ) ; return id ; } private void calcWordExtents ( final Word word , final ImageData id ) { final int [ ] pixels = new int [ id . width ] ; final PaletteData palette = id . palette ; Set < SmallRect > inserted = new HashSet < SmallRect > ( ) ; for ( int y = <NUM_LIT:0> ; y < id . height ; y ++ ) { id . getPixels ( <NUM_LIT:0> , y , id . width , pixels , <NUM_LIT:0> ) ; for ( int i = <NUM_LIT:0> ; i < pixels . length ; i ++ ) { int pixel = pixels [ i ] ; int r = pixel & palette . redMask ; r = ( palette . redShift < <NUM_LIT:0> ) ? r > > > - palette . redShift : r << palette . redShift ; int g = pixel & palette . greenMask ; g = ( palette . greenShift < <NUM_LIT:0> ) ? g > > > - palette . greenShift : g << palette . greenShift ; int b = pixel & palette . blueMask ; b = ( palette . blueShift < <NUM_LIT:0> ) ? b > > > - palette . blueShift : b << palette . blueShift ; if ( r < <NUM_LIT> || g < <NUM_LIT> || b < <NUM_LIT> ) { SmallRect rect = new SmallRect ( ( i / accuracy ) * accuracy , ( y / accuracy ) * accuracy , accuracy , accuracy ) ; if ( ! inserted . contains ( rect ) ) { word . tree . insert ( rect , word . id ) ; inserted . add ( rect ) ; } i += accuracy - <NUM_LIT:1> ; } } } word . tree . releaseRects ( ) ; } protected int layoutWords ( Collection < Word > wordsToUse , IProgressMonitor monitor ) { checkWidget ( ) ; if ( monitor != null ) { monitor . subTask ( "<STR_LIT>" ) ; } Rectangle r = new Rectangle ( Integer . MAX_VALUE , Integer . MAX_VALUE , <NUM_LIT:0> , <NUM_LIT:0> ) ; final Rectangle cloudArea = getCloudArea ( ) ; int w = cloudArea . width ; int h = cloudArea . height ; double current = <NUM_LIT:0> ; int next = <NUM_LIT:10> ; final Image tmpImage = new Image ( getDisplay ( ) , w , h ) ; GC gc = new GC ( tmpImage ) ; gc . setBackground ( getBackground ( ) ) ; gc . setTextAntialias ( SWT . ON ) ; gc . setBackground ( getBackground ( ) ) ; gc . fillRectangle ( tmpImage . getBounds ( ) ) ; executors = Executors . newFixedThreadPool ( <NUM_LIT:1> ) ; int success = <NUM_LIT:0> ; if ( wordsToUse != null ) { double step = <NUM_LIT> / wordsToUse . size ( ) ; final GC g = gc ; for ( Word word : wordsToUse ) { Point point = layouter . getInitialOffset ( word , cloudArea ) ; boolean result = layouter . layout ( point , word , cloudArea , cloudMatrix ) ; if ( ! result ) { System . err . println ( "<STR_LIT>" + word . string ) ; continue ; } success ++ ; if ( word . x < r . x ) { r . x = word . x ; } if ( word . y < r . y ) { r . y = word . y ; } if ( word . x + word . width > r . width ) { r . width = word . x + word . width ; } if ( word . y + word . height > r . height ) { r . height = word . y + word . height ; } final Word wrd = word ; executors . execute ( new Runnable ( ) { @ Override public void run ( ) { drawWord ( g , wrd , wrd . getColor ( ) ) ; } } ) ; current += step ; if ( current > next ) { next += <NUM_LIT:5> ; if ( monitor != null ) { monitor . worked ( <NUM_LIT:5> ) ; } } } executors . shutdown ( ) ; try { executors . awaitTermination ( Integer . MAX_VALUE , TimeUnit . SECONDS ) ; } catch ( InterruptedException e ) { e . printStackTrace ( ) ; } } gc . dispose ( ) ; if ( success == <NUM_LIT:0> ) return success ; if ( textLayerImage != null ) { textLayerImage . dispose ( ) ; } textLayerImage = new Image ( getDisplay ( ) , r . width - r . x , r . height - r . y ) ; gc = new GC ( textLayerImage ) ; gc . drawImage ( tmpImage , r . x , r . y , r . width - r . x , r . height - r . y , <NUM_LIT:0> , <NUM_LIT:0> , textLayerImage . getBounds ( ) . width , textLayerImage . getBounds ( ) . height ) ; this . regionOffset = new Point ( r . x , r . y ) ; tmpImage . dispose ( ) ; gc . dispose ( ) ; selectionLayerImage = new Image ( getDisplay ( ) , textLayerImage . getBounds ( ) ) ; gc = new GC ( selectionLayerImage ) ; gc . drawImage ( textLayerImage , <NUM_LIT:0> , <NUM_LIT:0> ) ; gc . dispose ( ) ; zoomFit ( ) ; if ( monitor != null ) { monitor . worked ( <NUM_LIT:10> ) ; } return success ; } private void drawRects ( GC gc ) { gc . setBackground ( Display . getDefault ( ) . getSystemColor ( SWT . COLOR_RED ) ) ; gc . setAlpha ( <NUM_LIT> ) ; for ( int i = <NUM_LIT:0> ; i < maxSize ; i += accuracy ) { for ( int j = <NUM_LIT:0> ; j < maxSize ; j += accuracy ) { if ( ! cloudMatrix . isEmpty ( i / accuracy , j / accuracy ) ) { gc . fillRectangle ( ( i ) , ( j ) , accuracy , accuracy ) ; } } } } public int setWords ( List < Word > values , IProgressMonitor monitor ) { checkWidget ( ) ; Assert . isLegal ( values != null , "<STR_LIT>" ) ; for ( Word word : values ) { Assert . isLegal ( word != null , "<STR_LIT>" ) ; Assert . isLegal ( word . string != null , "<STR_LIT>" ) ; Assert . isLegal ( word . getColor ( ) != null , "<STR_LIT>" ) ; Assert . isLegal ( word . getFontData ( ) != null , "<STR_LIT>" ) ; Assert . isLegal ( word . weight >= <NUM_LIT:0> , "<STR_LIT>" + word . weight ) ; Assert . isLegal ( word . weight <= <NUM_LIT:1> , "<STR_LIT>" + word . weight ) ; Assert . isLegal ( word . angle >= - <NUM_LIT> , "<STR_LIT>" + word . angle ) ; Assert . isLegal ( word . angle <= <NUM_LIT> , "<STR_LIT>" + word . angle ) ; } this . wordsToUse = new ArrayList < Word > ( values ) ; if ( boost > <NUM_LIT:0> ) { double factor = boostFactor ; int i = boost ; for ( Word word : values ) { if ( factor <= <NUM_LIT:1> ) { break ; } word . weight *= factor ; factor -= <NUM_LIT> ; i -- ; if ( i == <NUM_LIT:0> ) break ; } } return layoutCloud ( monitor , true ) ; } private void resetLayout ( ) { if ( cloudMatrix == null ) { cloudMatrix = new CloudMatrix ( maxSize , accuracy ) ; } else { cloudMatrix . reset ( ) ; } if ( mask != null ) { resetMask ( ) ; } } public void setBackgroundMask ( ImageData bgData ) { if ( mask != null ) { mask = null ; } if ( bgData != null ) { Image img = new Image ( null , cloudArea . width , cloudArea . height ) ; GC gc = new GC ( img ) ; Image tmp = new Image ( null , bgData ) ; gc . drawImage ( tmp , <NUM_LIT:0> , <NUM_LIT:0> , tmp . getBounds ( ) . width , tmp . getBounds ( ) . height , <NUM_LIT:0> , <NUM_LIT:0> , cloudArea . width , cloudArea . height ) ; ImageData id = img . getImageData ( ) ; tmp . dispose ( ) ; img . dispose ( ) ; gc . dispose ( ) ; mask = id ; } } private void resetMask ( ) { Word word = new Word ( "<STR_LIT>" ) ; word . tree = new RectTree ( new SmallRect ( <NUM_LIT:0> , <NUM_LIT:0> , cloudArea . width , cloudArea . height ) , accuracy ) ; calcWordExtents ( word , mask ) ; word . tree . place ( cloudMatrix , RectTree . BACKGROUND ) ; } private int getNumberOfThreads ( ) { return Runtime . getRuntime ( ) . availableProcessors ( ) ; } private void initListeners ( ) { if ( initialized ) return ; initialized = true ; final ScrollBar hBar = this . getHorizontalBar ( ) ; if ( hBar != null ) { hBarListener = new Listener ( ) { @ Override public void handleEvent ( Event e ) { int hSelection = hBar . getSelection ( ) ; int destX = - hSelection - origin . x ; Rectangle rect = zoomLayerImage . getBounds ( ) ; TagCloud . this . scroll ( destX , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , rect . width , rect . height , false ) ; origin . x = - hSelection ; } } ; hBar . addListener ( SWT . Selection , hBarListener ) ; } final ScrollBar vBar = this . getVerticalBar ( ) ; if ( vBar != null ) { vBarListener = new Listener ( ) { @ Override public void handleEvent ( Event e ) { int vSelection = vBar . getSelection ( ) ; int destY = - vSelection - origin . y ; Rectangle rect = zoomLayerImage . getBounds ( ) ; TagCloud . this . scroll ( <NUM_LIT:0> , destY , <NUM_LIT:0> , <NUM_LIT:0> , rect . width , rect . height , false ) ; origin . y = - vSelection ; } } ; vBar . addListener ( SWT . Selection , vBarListener ) ; } resizeListener = new Listener ( ) { @ Override public void handleEvent ( Event e ) { updateScrollbars ( ) ; TagCloud . this . redraw ( ) ; } } ; this . addListener ( SWT . Resize , resizeListener ) ; paintListener = new Listener ( ) { @ Override public void handleEvent ( Event e ) { GC gc = e . gc ; if ( zoomLayerImage == null ) return ; Rectangle rect = zoomLayerImage . getBounds ( ) ; Rectangle client = TagCloud . this . getClientArea ( ) ; int marginWidth = client . width - rect . width ; gc . setBackground ( getBackground ( ) ) ; if ( marginWidth > <NUM_LIT:0> ) { gc . fillRectangle ( rect . width , <NUM_LIT:0> , marginWidth , client . height ) ; } int marginHeight = client . height - rect . height ; if ( marginHeight > <NUM_LIT:0> ) { gc . fillRectangle ( <NUM_LIT:0> , rect . height , client . width , marginHeight ) ; } gc . drawImage ( zoomLayerImage , origin . x , origin . y ) ; } } ; this . addListener ( SWT . Paint , paintListener ) ; mouseTrackListener = new Listener ( ) { @ Override public void handleEvent ( Event event ) { Word word = getWordAt ( new Point ( event . x , event . y ) ) ; MouseEvent me = createMouseEvent ( event , word ) ; if ( currentWord != null ) { if ( word == currentWord ) { fireMouseEvent ( me , SWT . MouseHover , mouseTrackListeners ) ; } else { currentWord = null ; fireMouseEvent ( me , SWT . MouseExit , mouseTrackListeners ) ; } } if ( currentWord == null && word != null ) { currentWord = word ; fireMouseEvent ( me , SWT . MouseEnter , mouseTrackListeners ) ; } } } ; this . addListener ( SWT . MouseMove , mouseTrackListener ) ; mouseMoveListener = new Listener ( ) { @ Override public void handleEvent ( Event event ) { Word word = getWordAt ( new Point ( event . x , event . y ) ) ; MouseEvent me = createMouseEvent ( event , word ) ; fireMouseEvent ( me , SWT . MouseMove , mouseMoveListeners ) ; } } ; this . addListener ( SWT . MouseMove , mouseMoveListener ) ; mouseUpListener = new Listener ( ) { @ Override public void handleEvent ( Event event ) { Word word = getWordAt ( new Point ( event . x , event . y ) ) ; MouseEvent me = createMouseEvent ( event , word ) ; fireMouseEvent ( me , SWT . MouseUp , mouseListeners ) ; } } ; this . addListener ( SWT . MouseUp , mouseUpListener ) ; mouseDCListener = new Listener ( ) { @ Override public void handleEvent ( Event event ) { Word word = getWordAt ( new Point ( event . x , event . y ) ) ; MouseEvent me = createMouseEvent ( event , word ) ; fireMouseEvent ( me , SWT . MouseDoubleClick , mouseListeners ) ; } } ; this . addListener ( SWT . MouseDoubleClick , mouseDCListener ) ; mouseDownListener = new Listener ( ) { @ Override public void handleEvent ( Event event ) { Word word = getWordAt ( new Point ( event . x , event . y ) ) ; MouseEvent me = createMouseEvent ( event , word ) ; fireMouseEvent ( me , SWT . MouseDown , mouseListeners ) ; } } ; this . addListener ( SWT . MouseDown , mouseDownListener ) ; mouseWheelListener = new Listener ( ) { @ Override public void handleEvent ( Event event ) { Word word = getWordAt ( new Point ( event . x , event . y ) ) ; MouseEvent me = createMouseEvent ( event , word ) ; fireMouseEvent ( me , SWT . MouseWheel , mouseWheelListeners ) ; } } ; this . addListener ( SWT . MouseWheel , mouseWheelListener ) ; } private Word getWordAt ( Point point ) { if ( cloudMatrix == null || regionOffset == null ) return null ; Point translatedMousePos = translateMousePos ( point . x , point . y ) ; translatedMousePos . x += regionOffset . x ; translatedMousePos . y += regionOffset . y ; int x = translatedMousePos . x / accuracy ; int y = translatedMousePos . y / accuracy ; if ( x >= maxSize || y >= maxSize ) { return null ; } short wordId = cloudMatrix . get ( x , y ) ; if ( wordId > <NUM_LIT:0> ) { Word clicked = wordsToUse . get ( wordId - <NUM_LIT:1> ) ; return clicked ; } return null ; } private Point translateMousePos ( final int x , final int y ) { final Point point = new Point ( x - origin . x , y - origin . y ) ; point . x /= currentZoom ; point . y /= currentZoom ; return point ; } @ Override public void addMouseListener ( MouseListener listener ) { checkWidget ( ) ; Assert . isLegal ( listener != null ) ; mouseListeners . add ( listener ) ; } @ Override public void addMouseMoveListener ( MouseMoveListener listener ) { checkWidget ( ) ; Assert . isLegal ( listener != null ) ; mouseMoveListeners . add ( listener ) ; } @ Override public void addMouseTrackListener ( MouseTrackListener listener ) { checkWidget ( ) ; Assert . isLegal ( listener != null ) ; mouseTrackListeners . add ( listener ) ; } @ Override public void addMouseWheelListener ( MouseWheelListener listener ) { checkWidget ( ) ; Assert . isLegal ( listener != null ) ; mouseWheelListeners . add ( listener ) ; } public void addSelectionListener ( SelectionListener listener ) { checkWidget ( ) ; Assert . isLegal ( listener != null ) ; selectionListeners . add ( listener ) ; } @ Override public void removeMouseListener ( MouseListener listener ) { checkWidget ( ) ; mouseListeners . remove ( listener ) ; } @ Override public void removeMouseMoveListener ( MouseMoveListener listener ) { checkWidget ( ) ; mouseMoveListeners . remove ( listener ) ; } @ Override public void removeMouseTrackListener ( MouseTrackListener listener ) { checkWidget ( ) ; mouseTrackListeners . remove ( listener ) ; } @ Override public void removeMouseWheelListener ( MouseWheelListener listener ) { checkWidget ( ) ; mouseWheelListeners . remove ( listener ) ; } public void removeSelectionListener ( SelectionListener listener ) { checkWidget ( ) ; selectionListeners . remove ( listener ) ; } private MouseEvent createMouseEvent ( Event event , Word word ) { MouseEvent me = new MouseEvent ( event ) ; me . x = event . x - origin . x ; me . y = event . y - origin . y ; me . data = word ; me . widget = TagCloud . this ; me . display = Display . getCurrent ( ) ; return me ; } private void fireMouseEvent ( MouseEvent me , int type , Set < EventListener > listeners ) { for ( EventListener listener : listeners ) { if ( listener instanceof MouseListener ) { MouseListener ml = ( MouseListener ) listener ; switch ( type ) { case SWT . MouseUp : ml . mouseUp ( me ) ; break ; case SWT . MouseDoubleClick : ml . mouseDoubleClick ( me ) ; break ; case SWT . MouseDown : ml . mouseDown ( me ) ; break ; } } if ( listener instanceof MouseTrackListener ) { MouseTrackListener ml = ( MouseTrackListener ) listener ; switch ( type ) { case SWT . MouseEnter : ml . mouseEnter ( me ) ; break ; case SWT . MouseExit : ml . mouseExit ( me ) ; break ; case SWT . MouseHover : ml . mouseHover ( me ) ; break ; } } if ( listener instanceof MouseMoveListener ) { MouseMoveListener ml = ( MouseMoveListener ) listener ; switch ( type ) { case SWT . MouseMove : ml . mouseMove ( me ) ; break ; } } if ( listener instanceof MouseWheelListener ) { MouseWheelListener ml = ( MouseWheelListener ) listener ; switch ( type ) { case SWT . MouseWheel : ml . mouseScrolled ( me ) ; break ; } } } } public void setSelection ( Set < Word > words ) { checkWidget ( ) ; Assert . isNotNull ( words , "<STR_LIT>" ) ; if ( wordsToUse == null ) return ; Set < Word > selection = new HashSet < Word > ( words ) ; selection . retainAll ( wordsToUse ) ; int w = textLayerImage . getBounds ( ) . width ; int h = textLayerImage . getBounds ( ) . height ; if ( selectionLayerImage != null ) { selectionLayerImage . dispose ( ) ; } selectionLayerImage = new Image ( getDisplay ( ) , w , h ) ; GC gc = new GC ( selectionLayerImage ) ; gc . drawImage ( textLayerImage , <NUM_LIT:0> , <NUM_LIT:0> ) ; for ( Word word : selection ) { drawWord ( gc , word , highlightColor ) ; } if ( ! selection . equals ( this . selection ) ) { this . selection = selection ; fireSelectionChanged ( ) ; } gc . dispose ( ) ; zoom ( currentZoom ) ; redraw ( ) ; } private void fireSelectionChanged ( ) { Event e = new Event ( ) ; e . widget = this ; final SelectionEvent event = new SelectionEvent ( e ) ; event . data = getSelection ( ) ; event . widget = this ; event . display = Display . getCurrent ( ) ; for ( SelectionListener listener : selectionListeners ) { listener . widgetSelected ( event ) ; } } public void redrawTextLayerImage ( ) { if ( wordsToUse == null ) return ; GC gc = new GC ( textLayerImage ) ; gc . setBackground ( getBackground ( ) ) ; gc . fillRectangle ( <NUM_LIT:0> , <NUM_LIT:0> , textLayerImage . getBounds ( ) . width , textLayerImage . getBounds ( ) . height ) ; for ( Word word : wordsToUse ) { drawWord ( gc , word , word . getColor ( ) ) ; } gc . dispose ( ) ; setSelection ( getSelection ( ) ) ; } public Set < Word > getSelection ( ) { checkWidget ( ) ; Set < Word > copy = new HashSet < Word > ( selection ) ; return copy ; } public void setSelectionColor ( Color color ) { checkWidget ( ) ; Assert . isLegal ( color != null , "<STR_LIT>" ) ; this . highlightColor = color ; } @ Override public void setBackground ( Color color ) { checkWidget ( ) ; Assert . isLegal ( color != null , "<STR_LIT>" ) ; super . setBackground ( color ) ; } public int layoutCloud ( IProgressMonitor monitor , boolean recalc ) { checkWidget ( ) ; resetLayout ( ) ; if ( selectionLayerImage != null ) { selectionLayerImage . dispose ( ) ; selectionLayerImage = null ; } regionOffset = new Point ( <NUM_LIT:0> , <NUM_LIT:0> ) ; if ( textLayerImage != null ) textLayerImage . dispose ( ) ; int placedWords = <NUM_LIT:0> ; try { if ( recalc ) { calcExtents ( monitor ) ; } placedWords = layoutWords ( wordsToUse , monitor ) ; } catch ( Exception e ) { MessageDialog . openError ( getShell ( ) , "<STR_LIT>" , "<STR_LIT>" + e . getMessage ( ) ) ; e . printStackTrace ( ) ; } redraw ( ) ; updateScrollbars ( ) ; return placedWords ; } private void updateScrollbars ( ) { if ( zoomLayerImage == null ) { return ; } Rectangle rect = zoomLayerImage . getBounds ( ) ; Rectangle client = getClientArea ( ) ; ScrollBar hBar = getHorizontalBar ( ) ; ScrollBar vBar = getVerticalBar ( ) ; if ( hBar != null ) { hBar . setMaximum ( rect . width ) ; hBar . setThumb ( Math . min ( rect . width , client . width ) ) ; int hPage = rect . width - client . width ; int hSelection = hBar . getSelection ( ) ; if ( hSelection >= hPage ) { if ( hPage <= <NUM_LIT:0> ) hSelection = <NUM_LIT:0> ; origin . x = - hSelection ; } } if ( vBar != null ) { vBar . setMaximum ( rect . height ) ; vBar . setThumb ( Math . min ( rect . height , client . height ) ) ; int vPage = rect . height - client . height ; int vSelection = vBar . getSelection ( ) ; if ( vSelection >= vPage ) { if ( vPage <= <NUM_LIT:0> ) vSelection = <NUM_LIT:0> ; origin . y = - vSelection ; } } } public void setMaxFontSize ( int maxSize ) { checkWidget ( ) ; Assert . isLegal ( maxSize > <NUM_LIT:0> , "<STR_LIT>" + maxSize + "<STR_LIT:!>" ) ; maxFontSize = maxSize ; } public void setOpacity ( int opacity ) { checkWidget ( ) ; Assert . isLegal ( opacity > <NUM_LIT:0> , "<STR_LIT>" + opacity ) ; Assert . isLegal ( opacity < <NUM_LIT> , "<STR_LIT>" + opacity ) ; this . opacity = opacity ; } public void setMinFontSize ( int size ) { checkWidget ( ) ; Assert . isLegal ( size > <NUM_LIT:0> , "<STR_LIT>" + size ) ; this . minFontSize = size ; } public ImageData getImageData ( ) { checkWidget ( ) ; if ( textLayerImage == null ) return null ; return textLayerImage . getImageData ( ) ; } public void setBoost ( int boost ) { checkWidget ( ) ; Assert . isLegal ( boost >= <NUM_LIT:0> , "<STR_LIT>" ) ; this . boost = boost ; } public void setAntiAlias ( boolean enabled ) { checkWidget ( ) ; if ( enabled ) { antialias = SWT . ON ; } else { antialias = SWT . OFF ; } } public void setBoostFactor ( float boostFactor ) { Assert . isLegal ( boostFactor != <NUM_LIT:0> ) ; this . boostFactor = boostFactor ; } public Color getSelectionColor ( ) { return highlightColor ; } public void setLayouter ( ILayouter layouter ) { checkWidget ( ) ; Assert . isLegal ( layouter != null , "<STR_LIT>" ) ; this . layouter = layouter ; } public int getMaxFontSize ( ) { checkWidget ( ) ; return maxFontSize ; } public int getMinFontSize ( ) { checkWidget ( ) ; return minFontSize ; } public int getBoost ( ) { checkWidget ( ) ; return boost ; } public float getBoostFactor ( ) { checkWidget ( ) ; return boostFactor ; } public List < Word > getWords ( ) { return wordsToUse ; } public ILayouter getLayouter ( ) { return layouter ; } } </s>
|
<s> package org . eclipse . zest . examples . jface ; import java . util . Iterator ; import org . eclipse . jface . viewers . ISelectionChangedListener ; import org . eclipse . jface . viewers . LabelProvider ; import org . eclipse . jface . viewers . SelectionChangedEvent ; import org . eclipse . jface . viewers . StructuredSelection ; import org . eclipse . jface . viewers . Viewer ; import org . eclipse . swt . SWT ; import org . eclipse . swt . graphics . Image ; import org . eclipse . swt . layout . FillLayout ; import org . eclipse . swt . widgets . Display ; import org . eclipse . swt . widgets . Shell ; import org . eclipse . zest . core . viewers . GraphViewer ; import org . eclipse . zest . core . viewers . IGraphContentProvider ; import org . eclipse . zest . layouts . algorithms . SpringLayoutAlgorithm ; public class GraphJFaceSnippet4 { static class MyContentProvider implements IGraphContentProvider { public Object getDestination ( Object rel ) { if ( "<STR_LIT>" . equals ( rel ) ) { return "<STR_LIT>" ; } else if ( "<STR_LIT>" . equals ( rel ) ) { return "<STR_LIT>" ; } else if ( "<STR_LIT>" . equals ( rel ) ) { return "<STR_LIT>" ; } return null ; } public Object [ ] getElements ( Object input ) { return new Object [ ] { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ; } public Object getSource ( Object rel ) { if ( "<STR_LIT>" . equals ( rel ) ) { return "<STR_LIT>" ; } else if ( "<STR_LIT>" . equals ( rel ) ) { return "<STR_LIT>" ; } else if ( "<STR_LIT>" . equals ( rel ) ) { return "<STR_LIT>" ; } return null ; } public double getWeight ( Object connection ) { return <NUM_LIT:0> ; } public void dispose ( ) { } public void inputChanged ( Viewer viewer , Object oldInput , Object newInput ) { } } static class MyLabelProvider extends LabelProvider { final Image image = Display . getDefault ( ) . getSystemImage ( SWT . ICON_WARNING ) ; public Image getImage ( Object element ) { if ( element . equals ( "<STR_LIT>" ) || element . equals ( "<STR_LIT>" ) || element . equals ( "<STR_LIT>" ) ) { return image ; } return null ; } public String getText ( Object element ) { return element . toString ( ) ; } } static GraphViewer viewer = null ; public static void main ( String [ ] args ) { Display d = new Display ( ) ; Shell shell = new Shell ( d ) ; shell . setText ( "<STR_LIT>" ) ; shell . setLayout ( new FillLayout ( SWT . VERTICAL ) ) ; shell . setSize ( <NUM_LIT> , <NUM_LIT> ) ; viewer = new GraphViewer ( shell , SWT . NONE ) ; viewer . setContentProvider ( new MyContentProvider ( ) ) ; viewer . setLabelProvider ( new MyLabelProvider ( ) ) ; viewer . setLayoutAlgorithm ( new SpringLayoutAlgorithm ( ) ) ; viewer . setInput ( new Object ( ) ) ; viewer . addSelectionChangedListener ( new ISelectionChangedListener ( ) { public void selectionChanged ( SelectionChangedEvent event ) { System . out . println ( "<STR_LIT>" + selectionToString ( ( StructuredSelection ) event . getSelection ( ) ) ) ; } private String selectionToString ( StructuredSelection selection ) { StringBuffer stringBuffer = new StringBuffer ( ) ; Iterator iterator = selection . iterator ( ) ; boolean first = true ; while ( iterator . hasNext ( ) ) { if ( first ) { first = false ; } else { stringBuffer . append ( "<STR_LIT:U+0020:U+0020>" ) ; } stringBuffer . append ( iterator . next ( ) ) ; } return stringBuffer . toString ( ) ; } } ) ; shell . open ( ) ; while ( ! shell . isDisposed ( ) ) { while ( ! d . readAndDispatch ( ) ) { d . sleep ( ) ; } } } } </s>
|
<s> package org . eclipse . zest . examples . jface ; import org . eclipse . jface . viewers . LabelProvider ; import org . eclipse . jface . viewers . Viewer ; import org . eclipse . swt . SWT ; import org . eclipse . swt . graphics . Image ; import org . eclipse . swt . layout . FillLayout ; import org . eclipse . swt . widgets . Display ; import org . eclipse . swt . widgets . Shell ; import org . eclipse . zest . core . viewers . GraphViewer ; import org . eclipse . zest . core . viewers . IGraphContentProvider ; import org . eclipse . zest . layouts . algorithms . SpringLayoutAlgorithm ; public class GraphJFaceSnippet2 { static class MyContentProvider implements IGraphContentProvider { public Object getDestination ( Object rel ) { if ( "<STR_LIT>" . equals ( rel ) ) { return "<STR_LIT>" ; } else if ( "<STR_LIT>" . equals ( rel ) ) { return "<STR_LIT>" ; } else if ( "<STR_LIT>" . equals ( rel ) ) { return "<STR_LIT>" ; } return null ; } public Object [ ] getElements ( Object input ) { return new Object [ ] { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ; } public Object getSource ( Object rel ) { if ( "<STR_LIT>" . equals ( rel ) ) { return "<STR_LIT>" ; } else if ( "<STR_LIT>" . equals ( rel ) ) { return "<STR_LIT>" ; } else if ( "<STR_LIT>" . equals ( rel ) ) { return "<STR_LIT>" ; } return null ; } public double getWeight ( Object connection ) { return <NUM_LIT:0> ; } public void dispose ( ) { } public void inputChanged ( Viewer viewer , Object oldInput , Object newInput ) { } } static class MyLabelProvider extends LabelProvider { final Image image = Display . getDefault ( ) . getSystemImage ( SWT . ICON_WARNING ) ; public Image getImage ( Object element ) { if ( element . equals ( "<STR_LIT>" ) || element . equals ( "<STR_LIT>" ) || element . equals ( "<STR_LIT>" ) ) { return image ; } return null ; } public String getText ( Object element ) { return element . toString ( ) ; } } static GraphViewer viewer = null ; public static void main ( String [ ] args ) { Display d = new Display ( ) ; Shell shell = new Shell ( d ) ; shell . setText ( "<STR_LIT>" ) ; shell . setLayout ( new FillLayout ( SWT . VERTICAL ) ) ; shell . setSize ( <NUM_LIT> , <NUM_LIT> ) ; viewer = new GraphViewer ( shell , SWT . NONE ) ; viewer . setContentProvider ( new MyContentProvider ( ) ) ; viewer . setLabelProvider ( new MyLabelProvider ( ) ) ; viewer . setLayoutAlgorithm ( new SpringLayoutAlgorithm ( ) ) ; viewer . setInput ( new Object ( ) ) ; shell . open ( ) ; while ( ! shell . isDisposed ( ) ) { while ( ! d . readAndDispatch ( ) ) { d . sleep ( ) ; } } } } </s>
|
<s> package org . eclipse . zest . examples . jface ; import java . io . BufferedReader ; import java . io . File ; import java . io . FileReader ; import java . io . IOException ; import java . util . ArrayList ; import java . util . StringTokenizer ; import org . eclipse . jface . viewers . LabelProvider ; import org . eclipse . jface . viewers . Viewer ; import org . eclipse . swt . SWT ; import org . eclipse . swt . layout . FillLayout ; import org . eclipse . swt . widgets . Display ; import org . eclipse . swt . widgets . FileDialog ; import org . eclipse . swt . widgets . Shell ; import org . eclipse . zest . core . viewers . GraphViewer ; import org . eclipse . zest . core . viewers . IGraphContentProvider ; import org . eclipse . zest . layouts . algorithms . RadialLayoutAlgorithm ; public class GraphJFaceSnippet3 { public static final String graph = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; static class SimpleGraphContentProvider implements IGraphContentProvider { private StringTokenizer graph ; public Object getDestination ( Object rel ) { String string = ( String ) rel ; String [ ] parts = string . split ( "<STR_LIT:U+0020>" ) ; return parts [ <NUM_LIT:2> ] ; } public Object [ ] getElements ( Object input ) { ArrayList listOfEdges = new ArrayList ( ) ; while ( graph . hasMoreTokens ( ) ) { listOfEdges . add ( graph . nextToken ( ) ) ; } return listOfEdges . toArray ( ) ; } public Object getSource ( Object rel ) { String string = ( String ) rel ; String [ ] parts = string . split ( "<STR_LIT:U+0020>" ) ; return parts [ <NUM_LIT:0> ] ; } public double getWeight ( Object connection ) { return <NUM_LIT:0> ; } public void dispose ( ) { } public void inputChanged ( Viewer viewer , Object oldInput , Object newInput ) { if ( newInput != null ) { graph = new StringTokenizer ( ( String ) newInput , "<STR_LIT:n>" ) ; } } } public static void main ( String [ ] args ) throws IOException { Display display = new Display ( ) ; Shell shell = new Shell ( display ) ; shell . setText ( "<STR_LIT>" ) ; FileDialog dialog = new FileDialog ( shell , SWT . OPEN ) ; dialog . setFilterNames ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" } ) ; dialog . setFilterExtensions ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" } ) ; String directory = System . getProperty ( "<STR_LIT>" ) + "<STR_LIT>" ; System . out . println ( directory ) ; dialog . setFilterPath ( directory ) ; shell . setLayout ( new FillLayout ( SWT . VERTICAL ) ) ; shell . setSize ( <NUM_LIT> , <NUM_LIT> ) ; GraphViewer viewer = null ; viewer = new GraphViewer ( shell , SWT . NONE ) ; viewer . setContentProvider ( new SimpleGraphContentProvider ( ) ) ; viewer . setLabelProvider ( new LabelProvider ( ) ) ; viewer . setLayoutAlgorithm ( new RadialLayoutAlgorithm ( ) ) ; shell . open ( ) ; String fileName = dialog . open ( ) ; if ( fileName == null ) { viewer . setInput ( graph ) ; } else { FileReader fileReader = new FileReader ( new File ( fileName ) ) ; BufferedReader bufferedReader = new BufferedReader ( fileReader ) ; StringBuffer stringBuffer = new StringBuffer ( ) ; while ( bufferedReader . ready ( ) ) { stringBuffer . append ( bufferedReader . readLine ( ) + "<STR_LIT:n>" ) ; } viewer . setInput ( stringBuffer . toString ( ) ) ; } while ( ! shell . isDisposed ( ) ) { if ( ! display . readAndDispatch ( ) ) { display . sleep ( ) ; } } display . dispose ( ) ; } } </s>
|
<s> package org . eclipse . zest . examples . jface ; import org . eclipse . draw2d . Graphics ; import org . eclipse . draw2d . GridData ; import org . eclipse . draw2d . GridLayout ; import org . eclipse . draw2d . IFigure ; import org . eclipse . draw2d . Label ; import org . eclipse . draw2d . RectangleFigure ; import org . eclipse . jface . viewers . LabelProvider ; import org . eclipse . jface . viewers . Viewer ; import org . eclipse . swt . SWT ; import org . eclipse . swt . graphics . Color ; import org . eclipse . swt . graphics . Image ; import org . eclipse . swt . layout . FillLayout ; import org . eclipse . swt . widgets . Display ; import org . eclipse . swt . widgets . Shell ; import org . eclipse . zest . core . viewers . EntityConnectionData ; import org . eclipse . zest . core . viewers . GraphViewer ; import org . eclipse . zest . core . viewers . IFigureProvider ; import org . eclipse . zest . core . viewers . IGraphEntityContentProvider ; import org . eclipse . zest . core . widgets . ILabeledFigure ; import org . eclipse . zest . core . widgets . IStyleableFigure ; import org . eclipse . zest . layouts . algorithms . SpringLayoutAlgorithm ; public class CustomFigureJFaceSnippet { public static class RectLabelFigure extends RectangleFigure implements ILabeledFigure , IStyleableFigure { private Label label ; private Color borderColor ; public RectLabelFigure ( ) { super ( ) ; setLayoutManager ( new GridLayout ( <NUM_LIT:1> , true ) ) ; label = new Label ( ) ; add ( label ) ; GridData gd = new GridData ( GridData . FILL , GridData . FILL , true , true ) ; setConstraint ( label , gd ) ; } protected void outlineShape ( Graphics graphics ) { graphics . setForegroundColor ( borderColor ) ; super . outlineShape ( graphics ) ; } public void setBorderColor ( Color borderColor ) { this . borderColor = borderColor ; } public void setBorderWidth ( int borderWidth ) { setLineWidth ( borderWidth ) ; } public void setText ( String text ) { label . setText ( text ) ; adjustSize ( ) ; } public String getText ( ) { return label . getText ( ) ; } public void setIcon ( Image icon ) { label . setIcon ( icon ) ; adjustSize ( ) ; } public Image getIcon ( ) { return label . getIcon ( ) ; } protected void adjustSize ( ) { setSize ( getPreferredSize ( ) ) ; } } static class MyContentProvider implements IGraphEntityContentProvider { public Object [ ] getConnectedTo ( Object entity ) { if ( entity . equals ( "<STR_LIT>" ) ) { return new Object [ ] { "<STR_LIT>" } ; } if ( entity . equals ( "<STR_LIT>" ) ) { return new Object [ ] { "<STR_LIT>" } ; } if ( entity . equals ( "<STR_LIT>" ) ) { return new Object [ ] { "<STR_LIT>" } ; } return null ; } public Object [ ] getElements ( Object inputElement ) { return new String [ ] { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ; } public void dispose ( ) { } public void inputChanged ( Viewer viewer , Object oldInput , Object newInput ) { } } static class MyLabelProvider extends LabelProvider implements IFigureProvider { final Image image = Display . getDefault ( ) . getSystemImage ( SWT . ICON_INFORMATION ) ; public Image getImage ( Object element ) { if ( element instanceof EntityConnectionData ) { return null ; } return image ; } public String getText ( Object element ) { if ( element instanceof EntityConnectionData ) { return null ; } return element . toString ( ) ; } public IFigure getFigure ( Object element ) { return new RectLabelFigure ( ) ; } } static GraphViewer viewer = null ; public static void main ( String [ ] args ) { Display d = new Display ( ) ; Shell shell = new Shell ( d ) ; shell . setText ( "<STR_LIT>" ) ; shell . setLayout ( new FillLayout ( SWT . VERTICAL ) ) ; shell . setSize ( <NUM_LIT> , <NUM_LIT> ) ; viewer = new GraphViewer ( shell , SWT . NONE ) ; viewer . setContentProvider ( new MyContentProvider ( ) ) ; viewer . setLabelProvider ( new MyLabelProvider ( ) ) ; viewer . setLayoutAlgorithm ( new SpringLayoutAlgorithm ( ) ) ; viewer . setInput ( new Object ( ) ) ; shell . open ( ) ; while ( ! shell . isDisposed ( ) ) { while ( ! d . readAndDispatch ( ) ) { d . sleep ( ) ; } } } } </s>
|
<s> package org . eclipse . zest . examples . jface ; import org . eclipse . jface . viewers . ISelectionChangedListener ; import org . eclipse . jface . viewers . LabelProvider ; import org . eclipse . jface . viewers . SelectionChangedEvent ; import org . eclipse . jface . viewers . Viewer ; import org . eclipse . swt . SWT ; import org . eclipse . swt . events . SelectionAdapter ; import org . eclipse . swt . events . SelectionEvent ; import org . eclipse . swt . graphics . Image ; import org . eclipse . swt . layout . FillLayout ; import org . eclipse . swt . widgets . Button ; import org . eclipse . swt . widgets . Display ; import org . eclipse . swt . widgets . Shell ; import org . eclipse . zest . core . viewers . GraphViewer ; import org . eclipse . zest . core . viewers . IGraphEntityContentProvider ; import org . eclipse . zest . layouts . algorithms . SpringLayoutAlgorithm ; public class GraphJFaceSnippet1 { static class MyContentProvider implements IGraphEntityContentProvider { public Object [ ] getConnectedTo ( Object entity ) { if ( entity . equals ( "<STR_LIT>" ) ) { return new Object [ ] { "<STR_LIT>" } ; } if ( entity . equals ( "<STR_LIT>" ) ) { return new Object [ ] { "<STR_LIT>" } ; } if ( entity . equals ( "<STR_LIT>" ) ) { return new Object [ ] { "<STR_LIT>" } ; } return null ; } public Object [ ] getElements ( Object inputElement ) { return new String [ ] { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ; } public double getWeight ( Object entity1 , Object entity2 ) { return <NUM_LIT:0> ; } public void dispose ( ) { } public void inputChanged ( Viewer viewer , Object oldInput , Object newInput ) { } } static class MyLabelProvider extends LabelProvider { final Image image = Display . getDefault ( ) . getSystemImage ( SWT . ICON_WARNING ) ; public Image getImage ( Object element ) { if ( element instanceof String ) { return image ; } return null ; } public String getText ( Object element ) { if ( element instanceof String ) { return element . toString ( ) ; } return null ; } } static GraphViewer viewer = null ; public static void main ( String [ ] args ) { Display d = new Display ( ) ; Shell shell = new Shell ( d ) ; shell . setLayout ( new FillLayout ( SWT . VERTICAL ) ) ; shell . setSize ( <NUM_LIT> , <NUM_LIT> ) ; Button button = new Button ( shell , SWT . PUSH ) ; button . setText ( "<STR_LIT>" ) ; button . addSelectionListener ( new SelectionAdapter ( ) { public void widgetSelected ( SelectionEvent e ) { viewer . setInput ( new Object ( ) ) ; } } ) ; viewer = new GraphViewer ( shell , SWT . NONE ) ; viewer . setContentProvider ( new MyContentProvider ( ) ) ; viewer . setLabelProvider ( new MyLabelProvider ( ) ) ; viewer . setLayoutAlgorithm ( new SpringLayoutAlgorithm ( ) ) ; viewer . addSelectionChangedListener ( new ISelectionChangedListener ( ) { public void selectionChanged ( SelectionChangedEvent event ) { System . out . println ( "<STR_LIT>" + ( event . getSelection ( ) ) ) ; } } ) ; viewer . setInput ( new Object ( ) ) ; shell . open ( ) ; while ( ! shell . isDisposed ( ) ) { while ( ! d . readAndDispatch ( ) ) { d . sleep ( ) ; } } } } </s>
|
<s> package org . eclipse . zest . examples . jface ; import org . eclipse . jface . viewers . LabelProvider ; import org . eclipse . jface . viewers . Viewer ; import org . eclipse . zest . layouts . algorithms . SpringLayoutAlgorithm ; import org . eclipse . zest . core . viewers . GraphViewer ; import org . eclipse . zest . core . viewers . IGraphContentProvider ; import org . eclipse . swt . SWT ; import org . eclipse . swt . events . SelectionAdapter ; import org . eclipse . swt . events . SelectionEvent ; import org . eclipse . swt . graphics . Image ; import org . eclipse . swt . layout . FillLayout ; import org . eclipse . swt . layout . GridData ; import org . eclipse . swt . layout . GridLayout ; import org . eclipse . swt . widgets . Button ; import org . eclipse . swt . widgets . Composite ; import org . eclipse . swt . widgets . Display ; import org . eclipse . swt . widgets . Shell ; public class GraphJFaceSnippet5 { static class MyContentProvider implements IGraphContentProvider { Object [ ] elements = new Object [ ] { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ; public Object getDestination ( Object rel ) { if ( "<STR_LIT>" . equals ( rel ) ) { return "<STR_LIT>" ; } else if ( "<STR_LIT>" . equals ( rel ) || "<STR_LIT>" . equals ( rel ) ) { return "<STR_LIT>" ; } else if ( "<STR_LIT>" . equals ( rel ) ) { return "<STR_LIT>" ; } return null ; } public Object [ ] getElements ( Object input ) { return elements ; } public Object getSource ( Object rel ) { if ( "<STR_LIT>" . equals ( rel ) ) { return "<STR_LIT>" ; } else if ( "<STR_LIT>" . equals ( rel ) || "<STR_LIT>" . equals ( rel ) ) { return "<STR_LIT>" ; } else if ( "<STR_LIT>" . equals ( rel ) ) { return "<STR_LIT>" ; } return null ; } public void setElements ( Object [ ] elements ) { this . elements = elements ; } public double getWeight ( Object connection ) { return <NUM_LIT:0> ; } public void dispose ( ) { } public void inputChanged ( Viewer viewer , Object oldInput , Object newInput ) { } } static class MyLabelProvider extends LabelProvider { final Image image = Display . getDefault ( ) . getSystemImage ( SWT . ICON_WARNING ) ; public MyLabelProvider ( ) { } public String getText ( Object element ) { return element . toString ( ) ; } public Image getImage ( Object element ) { return image ; } } static GraphViewer viewer = null ; private static MyContentProvider contentProvider ; public static void main ( String [ ] args ) { Display d = new Display ( ) ; Shell shell = new Shell ( d ) ; shell . setText ( "<STR_LIT>" ) ; shell . setLayout ( new FillLayout ( SWT . VERTICAL ) ) ; shell . setSize ( <NUM_LIT> , <NUM_LIT> ) ; Composite parent = new Composite ( shell , SWT . NONE ) ; parent . setLayout ( new GridLayout ( <NUM_LIT:2> , false ) ) ; buildViewer ( parent ) ; buildButton ( parent ) ; shell . open ( ) ; while ( ! shell . isDisposed ( ) ) { while ( ! d . readAndDispatch ( ) ) { d . sleep ( ) ; } } } private static void buildButton ( Composite parent ) { Button button = new Button ( parent , SWT . PUSH ) ; button . setText ( "<STR_LIT>" ) ; button . addSelectionListener ( new SelectionAdapter ( ) { public void widgetSelected ( SelectionEvent e ) { contentProvider . setElements ( new Object [ ] { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ) ; viewer . refresh ( ) ; } } ) ; } private static void buildViewer ( Composite parent ) { viewer = new GraphViewer ( parent , SWT . NONE ) ; viewer . getGraphControl ( ) . setLayoutData ( new GridData ( SWT . FILL , SWT . FILL , true , true ) ) ; contentProvider = new MyContentProvider ( ) ; viewer . setContentProvider ( contentProvider ) ; viewer . setLabelProvider ( new MyLabelProvider ( ) ) ; viewer . setLayoutAlgorithm ( new SpringLayoutAlgorithm ( ) ) ; viewer . setInput ( new Object ( ) ) ; } } </s>
|
<s> package org . eclipse . zest . examples . jface ; import java . util . Iterator ; import org . eclipse . draw2d . ConnectionRouter ; import org . eclipse . draw2d . IFigure ; import org . eclipse . draw2d . ManhattanConnectionRouter ; import org . eclipse . jface . viewers . ISelectionChangedListener ; import org . eclipse . jface . viewers . LabelProvider ; import org . eclipse . jface . viewers . SelectionChangedEvent ; import org . eclipse . jface . viewers . StructuredSelection ; import org . eclipse . jface . viewers . Viewer ; import org . eclipse . swt . SWT ; import org . eclipse . swt . graphics . Color ; import org . eclipse . swt . graphics . Image ; import org . eclipse . swt . layout . FillLayout ; import org . eclipse . swt . widgets . Display ; import org . eclipse . swt . widgets . Shell ; import org . eclipse . zest . core . viewers . GraphViewer ; import org . eclipse . zest . core . viewers . IConnectionStyleProvider ; import org . eclipse . zest . core . viewers . IEntityConnectionStyleProvider ; import org . eclipse . zest . core . viewers . IGraphContentProvider ; import org . eclipse . zest . layouts . algorithms . SpringLayoutAlgorithm ; public class ManhattanLayoutJFaceSnippet { static class MyContentProvider implements IGraphContentProvider { public Object getDestination ( Object rel ) { if ( "<STR_LIT>" . equals ( rel ) ) { return "<STR_LIT>" ; } else if ( "<STR_LIT>" . equals ( rel ) ) { return "<STR_LIT>" ; } else if ( "<STR_LIT>" . equals ( rel ) ) { return "<STR_LIT>" ; } return null ; } public Object [ ] getElements ( Object input ) { return new Object [ ] { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ; } public Object getSource ( Object rel ) { if ( "<STR_LIT>" . equals ( rel ) ) { return "<STR_LIT>" ; } else if ( "<STR_LIT>" . equals ( rel ) ) { return "<STR_LIT>" ; } else if ( "<STR_LIT>" . equals ( rel ) ) { return "<STR_LIT>" ; } return null ; } public double getWeight ( Object connection ) { return <NUM_LIT:0> ; } public void dispose ( ) { } public void inputChanged ( Viewer viewer , Object oldInput , Object newInput ) { } } static class MyConnectionRelationLabelProvider extends LabelProvider implements IConnectionStyleProvider { final Image image = Display . getDefault ( ) . getSystemImage ( SWT . ICON_WARNING ) ; public Image getImage ( Object element ) { if ( element . equals ( "<STR_LIT>" ) || element . equals ( "<STR_LIT>" ) || element . equals ( "<STR_LIT>" ) ) { return image ; } return null ; } public String getText ( Object element ) { return element . toString ( ) ; } public ConnectionRouter getRouter ( Object rel ) { if ( ! rel . equals ( "<STR_LIT>" ) ) return new ManhattanConnectionRouter ( ) ; else return null ; } public int getConnectionStyle ( Object rel ) { return SWT . NONE ; } public Color getColor ( Object rel ) { return null ; } public Color getHighlightColor ( Object rel ) { return null ; } public int getLineWidth ( Object rel ) { return - <NUM_LIT:1> ; } public IFigure getTooltip ( Object entity ) { return null ; } } static class MyEndpointEntityLabelProvider extends LabelProvider implements IEntityConnectionStyleProvider { final Image image = Display . getDefault ( ) . getSystemImage ( SWT . ICON_WARNING ) ; public Image getImage ( Object element ) { if ( element . equals ( "<STR_LIT>" ) || element . equals ( "<STR_LIT>" ) || element . equals ( "<STR_LIT>" ) ) { return image ; } return null ; } public String getText ( Object element ) { return element . toString ( ) ; } public ConnectionRouter getRouter ( Object src , Object dest ) { System . out . println ( src + "<STR_LIT>" + dest ) ; if ( ! ( src . equals ( "<STR_LIT>" ) && dest . equals ( "<STR_LIT>" ) ) ) return new ManhattanConnectionRouter ( ) ; else return null ; } public int getConnectionStyle ( Object src , Object dest ) { return SWT . NONE ; } public Color getColor ( Object src , Object dest ) { return null ; } public Color getHighlightColor ( Object src , Object dest ) { return null ; } public int getLineWidth ( Object src , Object dest ) { return - <NUM_LIT:1> ; } public IFigure getTooltip ( Object src , Object dest ) { return null ; } } static GraphViewer viewer = null ; public static void main ( String [ ] args ) { Display d = new Display ( ) ; Shell shell = new Shell ( d ) ; shell . setText ( "<STR_LIT>" ) ; shell . setLayout ( new FillLayout ( SWT . VERTICAL ) ) ; shell . setSize ( <NUM_LIT> , <NUM_LIT> ) ; viewer = new GraphViewer ( shell , SWT . NONE ) ; viewer . setContentProvider ( new MyContentProvider ( ) ) ; viewer . setLabelProvider ( new MyConnectionRelationLabelProvider ( ) ) ; viewer . setLayoutAlgorithm ( new SpringLayoutAlgorithm ( ) ) ; viewer . setInput ( new Object ( ) ) ; viewer . addSelectionChangedListener ( new ISelectionChangedListener ( ) { public void selectionChanged ( SelectionChangedEvent event ) { System . out . println ( "<STR_LIT>" + selectionToString ( ( StructuredSelection ) event . getSelection ( ) ) ) ; } private String selectionToString ( StructuredSelection selection ) { StringBuffer stringBuffer = new StringBuffer ( ) ; Iterator iterator = selection . iterator ( ) ; boolean first = true ; while ( iterator . hasNext ( ) ) { if ( first ) { first = false ; } else { stringBuffer . append ( "<STR_LIT:U+0020:U+0020>" ) ; } stringBuffer . append ( iterator . next ( ) ) ; } return stringBuffer . toString ( ) ; } } ) ; shell . open ( ) ; while ( ! shell . isDisposed ( ) ) { while ( ! d . readAndDispatch ( ) ) { d . sleep ( ) ; } } } } </s>
|
<s> package org . eclipse . zest . examples . jface ; import org . eclipse . draw2d . IFigure ; import org . eclipse . draw2d . Label ; import org . eclipse . jface . viewers . LabelProvider ; import org . eclipse . jface . viewers . Viewer ; import org . eclipse . swt . SWT ; import org . eclipse . swt . events . SelectionEvent ; import org . eclipse . swt . events . SelectionListener ; import org . eclipse . swt . graphics . Font ; import org . eclipse . swt . graphics . Image ; import org . eclipse . swt . layout . FillLayout ; import org . eclipse . swt . widgets . Button ; import org . eclipse . swt . widgets . Display ; import org . eclipse . swt . widgets . Shell ; import org . eclipse . zest . core . viewers . EntityConnectionData ; import org . eclipse . zest . core . viewers . GraphViewer ; import org . eclipse . zest . core . viewers . IFigureProvider ; import org . eclipse . zest . core . viewers . IGraphEntityContentProvider ; import org . eclipse . zest . core . viewers . INestedContentProvider ; import org . eclipse . zest . examples . uml . UMLClassFigure ; import org . eclipse . zest . layouts . algorithms . SpringLayoutAlgorithm ; public class GraphJFaceSnippet7 { public static IFigure createClassFigure1 ( Font classFont , Image classImage , Image publicField , Image privateField ) { Label classLabel1 = new Label ( "<STR_LIT>" , classImage ) ; classLabel1 . setFont ( classFont ) ; UMLClassFigure classFigure = new UMLClassFigure ( classLabel1 ) ; Label attribute1 = new Label ( "<STR_LIT>" , privateField ) ; Label attribute2 = new Label ( "<STR_LIT>" , privateField ) ; Label method1 = new Label ( "<STR_LIT>" , publicField ) ; Label method2 = new Label ( "<STR_LIT>" , publicField ) ; classFigure . getAttributesCompartment ( ) . add ( attribute1 ) ; classFigure . getAttributesCompartment ( ) . add ( attribute2 ) ; classFigure . getMethodsCompartment ( ) . add ( method1 ) ; classFigure . getMethodsCompartment ( ) . add ( method2 ) ; classFigure . setSize ( - <NUM_LIT:1> , - <NUM_LIT:1> ) ; return classFigure ; } static class MyContentProvider implements IGraphEntityContentProvider , INestedContentProvider { public Object [ ] getConnectedTo ( Object entity ) { if ( entity . equals ( "<STR_LIT>" ) ) { return new Object [ ] { "<STR_LIT>" } ; } if ( entity . equals ( "<STR_LIT>" ) ) { return new Object [ ] { "<STR_LIT>" , "<STR_LIT>" } ; } if ( entity . equals ( "<STR_LIT>" ) ) { return new Object [ ] { "<STR_LIT>" } ; } if ( entity . equals ( "<STR_LIT>" ) ) { return new Object [ ] { "<STR_LIT>" } ; } return null ; } public Object [ ] getElements ( Object inputElement ) { return new String [ ] { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ; } public double getWeight ( Object entity1 , Object entity2 ) { return <NUM_LIT:0> ; } public void dispose ( ) { } public void inputChanged ( Viewer viewer , Object oldInput , Object newInput ) { } public Object [ ] getChildren ( Object element ) { return new Object [ ] { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ; } public boolean hasChildren ( Object element ) { if ( element . equals ( "<STR_LIT>" ) ) return true ; return false ; } } static class MyLabelProvider extends LabelProvider implements IFigureProvider { final Image image = Display . getDefault ( ) . getSystemImage ( SWT . ICON_WARNING ) ; public Image getImage ( Object element ) { if ( element . equals ( "<STR_LIT>" ) || element . equals ( "<STR_LIT>" ) || element . equals ( "<STR_LIT>" ) ) { return image ; } return null ; } public String getText ( Object element ) { if ( element instanceof EntityConnectionData ) return "<STR_LIT>" ; return element . toString ( ) ; } public IFigure getFigure ( Object element ) { Font classFont = new Font ( null , "<STR_LIT>" , <NUM_LIT:12> , SWT . BOLD ) ; Image classImage = new Image ( Display . getDefault ( ) , UMLClassFigure . class . getResourceAsStream ( "<STR_LIT>" ) ) ; Image privateField = new Image ( Display . getDefault ( ) , UMLClassFigure . class . getResourceAsStream ( "<STR_LIT>" ) ) ; Image publicField = new Image ( Display . getDefault ( ) , UMLClassFigure . class . getResourceAsStream ( "<STR_LIT>" ) ) ; return createClassFigure1 ( classFont , classImage , publicField , privateField ) ; } } static GraphViewer viewer = null ; public static void main ( String [ ] args ) { Display d = new Display ( ) ; Shell shell = new Shell ( d ) ; shell . setText ( "<STR_LIT>" ) ; shell . setLayout ( new FillLayout ( SWT . VERTICAL ) ) ; shell . setSize ( <NUM_LIT> , <NUM_LIT> ) ; viewer = new GraphViewer ( shell , SWT . NONE ) ; viewer . setContentProvider ( new MyContentProvider ( ) ) ; viewer . setLabelProvider ( new MyLabelProvider ( ) ) ; viewer . setLayoutAlgorithm ( new SpringLayoutAlgorithm ( ) ) ; viewer . setInput ( new Object ( ) ) ; Button button = new Button ( shell , SWT . PUSH ) ; button . setText ( "<STR_LIT>" ) ; button . addSelectionListener ( new SelectionListener ( ) { public void widgetDefaultSelected ( SelectionEvent e ) { } public void widgetSelected ( SelectionEvent e ) { viewer . setInput ( new Object ( ) ) ; } } ) ; shell . open ( ) ; while ( ! shell . isDisposed ( ) ) { while ( ! d . readAndDispatch ( ) ) { d . sleep ( ) ; } } } } </s>
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.