text
stringlengths 30
1.67M
|
|---|
<s> package org . eclipse . zest . examples . jface ; import org . eclipse . jface . viewers . ISelectionChangedListener ; import org . eclipse . jface . viewers . ITreeContentProvider ; 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 . layouts . algorithms . TreeLayoutAlgorithm ; public class GraphJFaceSnippet9 { static class MyContentProvider implements ITreeContentProvider { private static final String n1 = "<STR_LIT>" , n2 = "<STR_LIT>" , n3 = "<STR_LIT>" , n4 = "<STR_LIT>" ; public Object [ ] getElements ( Object inputElement ) { return new String [ ] { n1 } ; } public void dispose ( ) { } public void inputChanged ( Viewer viewer , Object oldInput , Object newInput ) { } public Object [ ] getChildren ( Object parentElement ) { if ( parentElement . equals ( n1 ) ) { return new Object [ ] { n2 , n3 } ; } if ( parentElement . equals ( n2 ) ) { return new Object [ ] { n4 } ; } return null ; } public Object getParent ( Object element ) { if ( element . equals ( n2 ) ) { return n1 ; } else if ( element . equals ( n3 ) ) { return n1 ; } else if ( element . equals ( n4 ) ) { return new Object [ ] { n2 } ; } return null ; } public boolean hasChildren ( Object element ) { return element . equals ( "<STR_LIT>" ) || element . equals ( "<STR_LIT>" ) ; } } 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 TreeLayoutAlgorithm ( ) ) ; 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 . draw2d . ColorConstants ; import org . eclipse . draw2d . Graphics ; import org . eclipse . draw2d . PolygonDecoration ; import org . eclipse . draw2d . PolylineConnection ; 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 . GraphViewer ; import org . eclipse . zest . core . viewers . IGraphEntityContentProvider ; import org . eclipse . zest . core . viewers . ISelfStyleProvider ; import org . eclipse . zest . core . widgets . GraphConnection ; import org . eclipse . zest . core . widgets . GraphNode ; import org . eclipse . zest . layouts . algorithms . SpringLayoutAlgorithm ; public class GraphJFaceSnippet8 { static class MyContentProvider implements IGraphEntityContentProvider { public Object [ ] getConnectedTo ( Object entity ) { 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 ) { } } static class MyLabelProvider extends LabelProvider implements ISelfStyleProvider { public Image getImage ( Object element ) { return null ; } public String getText ( Object element ) { return element . toString ( ) ; } public void selfStyleConnection ( Object element , GraphConnection connection ) { connection . setLineStyle ( SWT . LINE_CUSTOM ) ; PolylineConnection pc = ( PolylineConnection ) connection . getConnectionFigure ( ) ; pc . setLineDash ( new float [ ] { <NUM_LIT:4> } ) ; pc . setTargetDecoration ( createDecoration ( ColorConstants . white ) ) ; pc . setSourceDecoration ( createDecoration ( ColorConstants . green ) ) ; } private PolygonDecoration createDecoration ( final Color color ) { PolygonDecoration decoration = new PolygonDecoration ( ) { protected void fillShape ( Graphics g ) { g . setBackgroundColor ( color ) ; super . fillShape ( g ) ; } } ; decoration . setScale ( <NUM_LIT:10> , <NUM_LIT:5> ) ; decoration . setBackgroundColor ( color ) ; return decoration ; } public void selfStyleNode ( Object element , GraphNode node ) { } } 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> ) ; 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 . 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 . 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 . IGraphEntityContentProvider ; import org . eclipse . zest . core . viewers . INestedContentProvider ; import org . eclipse . zest . layouts . algorithms . SpringLayoutAlgorithm ; public class GraphJFaceSnippet6 { 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 { 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 ( ) ; } } 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>
|
<s> package org . eclipse . zest . examples . uml ; import org . eclipse . draw2d . ColorConstants ; import org . eclipse . draw2d . Figure ; import org . eclipse . draw2d . Label ; import org . eclipse . draw2d . LineBorder ; import org . eclipse . draw2d . ToolbarLayout ; public class UMLClassFigure extends Figure { private CompartmentFigure attributeFigure = new CompartmentFigure ( ) ; private CompartmentFigure methodFigure = new CompartmentFigure ( ) ; public UMLClassFigure ( Label name ) { ToolbarLayout layout = new ToolbarLayout ( ) ; setLayoutManager ( layout ) ; setBorder ( new LineBorder ( ColorConstants . black , <NUM_LIT:1> ) ) ; setBackgroundColor ( UMLExample . classColor ) ; setOpaque ( true ) ; add ( name ) ; add ( attributeFigure ) ; add ( methodFigure ) ; } public CompartmentFigure getAttributesCompartment ( ) { return attributeFigure ; } public CompartmentFigure getMethodsCompartment ( ) { return methodFigure ; } } </s>
|
<s> package org . eclipse . zest . examples . uml ; import org . eclipse . draw2d . IFigure ; import org . eclipse . draw2d . Label ; import org . eclipse . swt . SWT ; import org . eclipse . swt . graphics . Color ; import org . eclipse . swt . graphics . Font ; 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 . 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 . IContainer ; import org . eclipse . zest . core . widgets . ZestStyles ; import org . eclipse . zest . layouts . algorithms . SpringLayoutAlgorithm ; public class UMLExample { public static Color classColor = null ; 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 ; } public static IFigure createClassFigure2 ( Font classFont , Image classImage , Image publicField , Image privateField ) { Label classLabel2 = new Label ( "<STR_LIT>" , classImage ) ; classLabel2 . setFont ( classFont ) ; UMLClassFigure classFigure = new UMLClassFigure ( classLabel2 ) ; Label attribute3 = new Label ( "<STR_LIT>" , privateField ) ; Label attribute4 = new Label ( "<STR_LIT>" , privateField ) ; Label method3 = new Label ( "<STR_LIT>" , publicField ) ; Label method4 = new Label ( "<STR_LIT>" , publicField ) ; classFigure . getAttributesCompartment ( ) . add ( attribute3 ) ; classFigure . getAttributesCompartment ( ) . add ( attribute4 ) ; classFigure . getMethodsCompartment ( ) . add ( method3 ) ; classFigure . getMethodsCompartment ( ) . add ( method4 ) ; classFigure . setSize ( - <NUM_LIT:1> , - <NUM_LIT:1> ) ; return classFigure ; } static class UMLNode extends GraphNode { IFigure customFigure = null ; public UMLNode ( IContainer graphModel , int style , IFigure figure ) { super ( graphModel , style , figure ) ; } protected IFigure createFigureForModel ( ) { return ( IFigure ) this . getData ( ) ; } } public static void main ( String [ ] args ) { Display d = new Display ( ) ; Shell shell = new Shell ( d ) ; shell . setLayout ( new FillLayout ( ) ) ; shell . setSize ( <NUM_LIT> , <NUM_LIT> ) ; classColor = new Color ( null , <NUM_LIT:255> , <NUM_LIT:255> , <NUM_LIT> ) ; 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>" ) ) ; Graph g = new Graph ( shell , SWT . NONE ) ; g . setConnectionStyle ( ZestStyles . CONNECTIONS_DIRECTED ) ; GraphContainer c = new GraphContainer ( g , SWT . NONE ) ; c . setText ( "<STR_LIT>" ) ; UMLNode n = new UMLNode ( c , SWT . NONE , createClassFigure1 ( classFont , classImage , publicField , privateField ) ) ; GraphNode n1 = new UMLNode ( g , SWT . NONE , createClassFigure1 ( classFont , classImage , publicField , privateField ) ) ; GraphNode n2 = new UMLNode ( g , SWT . NONE , createClassFigure2 ( classFont , classImage , publicField , privateField ) ) ; new GraphConnection ( g , SWT . NONE , n1 , n2 ) ; new GraphConnection ( g , SWT . NONE , n , n1 ) ; c . setLayoutAlgorithm ( new SpringLayoutAlgorithm ( ) , true ) ; g . setLayoutAlgorithm ( new SpringLayoutAlgorithm ( ) , true ) ; shell . open ( ) ; while ( ! shell . isDisposed ( ) ) { while ( ! d . readAndDispatch ( ) ) { d . sleep ( ) ; } } classColor . dispose ( ) ; classFont . dispose ( ) ; classImage . dispose ( ) ; publicField . dispose ( ) ; privateField . dispose ( ) ; } } </s>
|
<s> package org . eclipse . zest . examples . uml ; import org . eclipse . draw2d . AbstractBorder ; import org . eclipse . draw2d . Figure ; import org . eclipse . draw2d . Graphics ; import org . eclipse . draw2d . IFigure ; import org . eclipse . draw2d . ToolbarLayout ; import org . eclipse . draw2d . geometry . Insets ; public class CompartmentFigure extends Figure { public CompartmentFigure ( ) { ToolbarLayout layout = new ToolbarLayout ( ) ; layout . setMinorAlignment ( ToolbarLayout . ALIGN_TOPLEFT ) ; layout . setStretchMinorAxis ( false ) ; layout . setSpacing ( <NUM_LIT:2> ) ; setLayoutManager ( layout ) ; setBorder ( new CompartmentFigureBorder ( ) ) ; } class CompartmentFigureBorder extends AbstractBorder { public Insets getInsets ( IFigure figure ) { return new Insets ( <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) ; } public void paint ( IFigure figure , Graphics graphics , Insets insets ) { graphics . drawLine ( getPaintRectangle ( figure , insets ) . getTopLeft ( ) , tempRect . getTopRight ( ) ) ; } } } </s>
|
<s> package org . eclipse . zest . examples . layouts ; import java . util . List ; import org . eclipse . jface . action . Action ; import org . eclipse . jface . action . MenuManager ; import org . eclipse . swt . SWT ; import org . eclipse . swt . events . SelectionAdapter ; import org . eclipse . swt . events . SelectionEvent ; import org . eclipse . swt . layout . GridData ; import org . eclipse . swt . layout . GridLayout ; import org . eclipse . swt . widgets . Button ; import org . eclipse . swt . widgets . Display ; 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 . ZestStyles ; import org . eclipse . zest . layouts . LayoutAlgorithm ; import org . eclipse . zest . layouts . algorithms . DirectedGraphLayoutAlgorithm ; public class DAGExample { public static void main ( String [ ] args ) { Display d = new Display ( ) ; Shell shell = new Shell ( d ) ; shell . setText ( "<STR_LIT>" ) ; GridLayout gridLayout = new GridLayout ( ) ; gridLayout . numColumns = <NUM_LIT:10> ; shell . setLayout ( gridLayout ) ; shell . setSize ( <NUM_LIT> , <NUM_LIT> ) ; final Graph g = new Graph ( shell , SWT . NONE ) ; LayoutAlgorithm algorithm = new DirectedGraphLayoutAlgorithm ( ) ; g . setLayoutData ( new GridData ( SWT . FILL , SWT . FILL , true , true , <NUM_LIT:10> , <NUM_LIT:10> ) ) ; g . setSize ( <NUM_LIT> , <NUM_LIT> ) ; g . setSubgraphFactory ( new DefaultSubgraph . PrunedSuccessorsSubgraphFactory ( ) ) ; g . setLayoutAlgorithm ( algorithm , false ) ; g . setExpandCollapseManager ( new DAGExpandCollapseManager ( ) ) ; GraphNode root = new GraphNode ( g , SWT . NONE , "<STR_LIT>" ) ; GraphNode a = new GraphNode ( g , SWT . NONE , "<STR_LIT:A>" ) ; GraphNode b = new GraphNode ( g , SWT . NONE , "<STR_LIT:B>" ) ; GraphNode c = new GraphNode ( g , SWT . NONE , "<STR_LIT:C>" ) ; GraphNode e = new GraphNode ( g , SWT . NONE , "<STR_LIT:D>" ) ; GraphNode f = new GraphNode ( g , SWT . NONE , "<STR_LIT:E>" ) ; GraphNode h = new GraphNode ( g , SWT . NONE , "<STR_LIT:F>" ) ; new GraphConnection ( g , ZestStyles . CONNECTIONS_DIRECTED , root , a ) ; new GraphConnection ( g , ZestStyles . CONNECTIONS_DIRECTED , root , b ) ; new GraphConnection ( g , ZestStyles . CONNECTIONS_DIRECTED , root , c ) ; new GraphConnection ( g , ZestStyles . CONNECTIONS_DIRECTED , a , c ) ; new GraphConnection ( g , ZestStyles . CONNECTIONS_DIRECTED , c , e ) ; new GraphConnection ( g , ZestStyles . CONNECTIONS_DIRECTED , e , f ) ; new GraphConnection ( g , ZestStyles . CONNECTIONS_DIRECTED , e , h ) ; new GraphConnection ( g , ZestStyles . CONNECTIONS_DIRECTED , root , h ) ; hookMenu ( g ) ; final Button buttonTopDown = new Button ( shell , SWT . FLAT ) ; buttonTopDown . setText ( "<STR_LIT>" ) ; final Button buttonBottomUp = new Button ( shell , SWT . FLAT ) ; buttonBottomUp . setText ( "<STR_LIT>" ) ; buttonBottomUp . setLayoutData ( new GridData ( ) ) ; final Button buttonLeftRight = new Button ( shell , SWT . FLAT ) ; buttonLeftRight . setText ( "<STR_LIT>" ) ; final Button buttonRightLeft = new Button ( shell , SWT . FLAT ) ; buttonRightLeft . setText ( "<STR_LIT>" ) ; SelectionAdapter buttonListener = new SelectionAdapter ( ) { public void widgetSelected ( SelectionEvent e ) { g . applyLayout ( ) ; } } ; buttonTopDown . addSelectionListener ( buttonListener ) ; buttonBottomUp . addSelectionListener ( buttonListener ) ; buttonLeftRight . addSelectionListener ( buttonListener ) ; buttonRightLeft . addSelectionListener ( buttonListener ) ; shell . open ( ) ; while ( ! shell . isDisposed ( ) ) { while ( ! d . readAndDispatch ( ) ) { d . sleep ( ) ; } } } private static void hookMenu ( final Graph g ) { MenuManager menuMgr = new MenuManager ( "<STR_LIT>" ) ; Action expandAction = new Action ( ) { public void run ( ) { List selection = g . getSelection ( ) ; if ( ! selection . isEmpty ( ) ) { GraphNode selected = ( GraphNode ) selection . get ( <NUM_LIT:0> ) ; g . setExpanded ( ( GraphNode ) selected , true ) ; } } } ; expandAction . setText ( "<STR_LIT>" ) ; menuMgr . add ( expandAction ) ; Action collapseAction = new Action ( ) { public void run ( ) { List selection = g . getSelection ( ) ; if ( ! selection . isEmpty ( ) ) { GraphItem selected = ( GraphItem ) selection . get ( <NUM_LIT:0> ) ; g . setExpanded ( ( GraphNode ) selected , false ) ; } } } ; collapseAction . setText ( "<STR_LIT>" ) ; menuMgr . add ( collapseAction ) ; g . setMenu ( menuMgr . createContextMenu ( g ) ) ; } } </s>
|
<s> package org . eclipse . zest . examples . layouts ; 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 . 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 . GridLayoutAlgorithm ; public class FisheyeGraphSnippet { public static void main ( String [ ] args ) { Display d = new Display ( ) ; Shell shell = new Shell ( d ) ; shell . setText ( "<STR_LIT>" ) ; Image image1 = Display . getDefault ( ) . getSystemImage ( SWT . ICON_INFORMATION ) ; Image image2 = Display . getDefault ( ) . getSystemImage ( SWT . ICON_WARNING ) ; Image image3 = Display . getDefault ( ) . getSystemImage ( SWT . ICON_ERROR ) ; shell . setLayout ( new FillLayout ( ) ) ; shell . setSize ( <NUM_LIT> , <NUM_LIT> ) ; Graph g = new Graph ( shell , SWT . NONE ) ; g . setConnectionStyle ( ZestStyles . CONNECTIONS_DIRECTED ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT> ; i ++ ) { GraphNode n1 = new GraphNode ( g , ZestStyles . NODES_HIDE_TEXT | ZestStyles . NODES_FISHEYE , "<STR_LIT>" ) ; n1 . setImage ( image1 ) ; GraphNode n2 = new GraphNode ( g , ZestStyles . NODES_HIDE_TEXT | ZestStyles . NODES_FISHEYE , "<STR_LIT>" ) ; n2 . setImage ( image2 ) ; GraphNode n3 = new GraphNode ( g , ZestStyles . NODES_HIDE_TEXT | ZestStyles . NODES_FISHEYE , "<STR_LIT>" ) ; n3 . setImage ( image3 ) ; new GraphConnection ( g , SWT . NONE , n1 , n2 ) ; new GraphConnection ( g , SWT . NONE , n2 , n3 ) ; new GraphConnection ( g , SWT . NONE , n3 , n3 ) ; } g . setLayoutAlgorithm ( new GridLayoutAlgorithm ( ) , true ) ; shell . open ( ) ; while ( ! shell . isDisposed ( ) ) { while ( ! d . readAndDispatch ( ) ) { d . sleep ( ) ; } } image1 . dispose ( ) ; image2 . dispose ( ) ; image3 . dispose ( ) ; } } </s>
|
<s> package org . eclipse . zest . examples . layouts ; import java . util . List ; import org . eclipse . jface . action . Action ; import org . eclipse . jface . action . MenuManager ; 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 . 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 . layouts . algorithms . SpaceTreeLayoutAlgorithm ; public class SpaceTreeBuilding { private static GraphNode parentNode = null ; private static GraphNode childNode = null ; public static void main ( String [ ] args ) { Display d = new Display ( ) ; Shell shell = new Shell ( d ) ; shell . setText ( "<STR_LIT>" ) ; shell . setLayout ( new FillLayout ( ) ) ; shell . setSize ( <NUM_LIT> , <NUM_LIT> ) ; final Graph g = new Graph ( shell , SWT . NONE ) ; hookMenu ( g ) ; SpaceTreeLayoutAlgorithm spaceTreeLayoutAlgorithm = new SpaceTreeLayoutAlgorithm ( ) ; g . setLayoutAlgorithm ( spaceTreeLayoutAlgorithm , false ) ; g . setExpandCollapseManager ( spaceTreeLayoutAlgorithm . getExpandCollapseManager ( ) ) ; g . setSubgraphFactory ( new DefaultSubgraph . LabelSubgraphFactory ( ) ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:20> ; i ++ ) { GraphNode graphNode = new GraphNode ( g , SWT . NONE ) ; graphNode . setText ( "<STR_LIT>" + i ) ; } shell . open ( ) ; while ( ! shell . isDisposed ( ) ) { while ( ! d . readAndDispatch ( ) ) { d . sleep ( ) ; } } } private static void tryToAddConnection ( Graph g ) { if ( parentNode != null && childNode != null ) { new GraphConnection ( g , SWT . NONE , parentNode , childNode ) ; parentNode = childNode = null ; } } private static void hookMenu ( final Graph g ) { MenuManager menuMgr = new MenuManager ( "<STR_LIT>" ) ; Action parentAction = new Action ( ) { public void run ( ) { List selection = g . getSelection ( ) ; if ( ! selection . isEmpty ( ) ) { GraphNode selected = ( GraphNode ) selection . get ( <NUM_LIT:0> ) ; parentNode = selected ; tryToAddConnection ( g ) ; } } } ; parentAction . setText ( "<STR_LIT>" ) ; menuMgr . add ( parentAction ) ; Action childAction = new Action ( ) { public void run ( ) { List selection = g . getSelection ( ) ; if ( ! selection . isEmpty ( ) ) { GraphNode selected = ( GraphNode ) selection . get ( <NUM_LIT:0> ) ; childNode = selected ; tryToAddConnection ( g ) ; } } } ; childAction . setText ( "<STR_LIT>" ) ; menuMgr . add ( childAction ) ; Action expandAction = new Action ( ) { public void run ( ) { List selection = g . getSelection ( ) ; if ( ! selection . isEmpty ( ) ) { GraphNode selected = ( GraphNode ) selection . get ( <NUM_LIT:0> ) ; g . setExpanded ( ( GraphNode ) selected , true ) ; } } } ; expandAction . setText ( "<STR_LIT>" ) ; menuMgr . add ( expandAction ) ; Action collapseAction = new Action ( ) { public void run ( ) { List selection = g . getSelection ( ) ; if ( ! selection . isEmpty ( ) ) { GraphItem selected = ( GraphItem ) selection . get ( <NUM_LIT:0> ) ; g . setExpanded ( ( GraphNode ) selected , false ) ; } } } ; collapseAction . setText ( "<STR_LIT>" ) ; menuMgr . add ( collapseAction ) ; g . setMenu ( menuMgr . createContextMenu ( g ) ) ; } } </s>
|
<s> package org . eclipse . zest . examples . layouts ; import java . util . List ; import org . eclipse . draw2d . geometry . Dimension ; import org . eclipse . jface . action . Action ; import org . eclipse . jface . action . MenuManager ; import org . eclipse . swt . SWT ; import org . eclipse . swt . events . SelectionAdapter ; import org . eclipse . swt . events . SelectionEvent ; import org . eclipse . swt . layout . GridData ; import org . eclipse . swt . layout . GridLayout ; import org . eclipse . swt . widgets . Button ; import org . eclipse . swt . widgets . Display ; 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 . layouts . algorithms . TreeLayoutAlgorithm ; public class TreeLayoutExample { public static void main ( String [ ] args ) { Display d = new Display ( ) ; Shell shell = new Shell ( d ) ; shell . setText ( "<STR_LIT>" ) ; GridLayout gridLayout = new GridLayout ( ) ; gridLayout . numColumns = <NUM_LIT:10> ; shell . setLayout ( gridLayout ) ; shell . setSize ( <NUM_LIT> , <NUM_LIT> ) ; final Graph g = new Graph ( shell , SWT . NONE ) ; final TreeLayoutAlgorithm algorithm = new TreeLayoutAlgorithm ( ) ; g . setSubgraphFactory ( new DefaultSubgraph . PrunedSuccessorsSubgraphFactory ( ) ) ; g . setLayoutAlgorithm ( algorithm , false ) ; g . setExpandCollapseManager ( new DAGExpandCollapseManager ( ) ) ; g . setLayoutData ( new GridData ( SWT . FILL , SWT . FILL , true , true , <NUM_LIT:10> , <NUM_LIT:10> ) ) ; g . setSize ( <NUM_LIT> , <NUM_LIT> ) ; GraphNode root = new GraphNode ( g , SWT . NONE , "<STR_LIT>" ) ; GraphNode lastNode = null ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:3> ; i ++ ) { GraphNode n = new GraphNode ( g , SWT . NONE , "<STR_LIT>" + i ) ; if ( lastNode != null ) new GraphConnection ( g , SWT . NONE , n , lastNode ) . setDirected ( true ) ; for ( int j = <NUM_LIT:0> ; j < <NUM_LIT:1> ; j ++ ) { GraphNode n2 = new GraphNode ( g , SWT . NONE , "<STR_LIT>" + j ) ; GraphConnection c = new GraphConnection ( g , SWT . NONE , n , n2 ) ; c . setWeight ( - <NUM_LIT:1> ) ; c . setDirected ( true ) ; lastNode = n2 ; } new GraphConnection ( g , SWT . NONE , root , n ) . setDirected ( true ) ; } hookMenu ( g ) ; final Button buttonTopDown = new Button ( shell , SWT . FLAT ) ; buttonTopDown . setText ( "<STR_LIT>" ) ; final Button buttonBottomUp = new Button ( shell , SWT . FLAT ) ; buttonBottomUp . setText ( "<STR_LIT>" ) ; buttonBottomUp . setLayoutData ( new GridData ( ) ) ; final Button buttonLeftRight = new Button ( shell , SWT . FLAT ) ; buttonLeftRight . setText ( "<STR_LIT>" ) ; final Button buttonRightLeft = new Button ( shell , SWT . FLAT ) ; buttonRightLeft . setText ( "<STR_LIT>" ) ; SelectionAdapter buttonListener = new SelectionAdapter ( ) { public void widgetSelected ( SelectionEvent e ) { if ( e . widget == buttonTopDown ) algorithm . setDirection ( TreeLayoutAlgorithm . TOP_DOWN ) ; if ( e . widget == buttonBottomUp ) algorithm . setDirection ( TreeLayoutAlgorithm . BOTTOM_UP ) ; if ( e . widget == buttonLeftRight ) algorithm . setDirection ( TreeLayoutAlgorithm . LEFT_RIGHT ) ; if ( e . widget == buttonRightLeft ) algorithm . setDirection ( TreeLayoutAlgorithm . RIGHT_LEFT ) ; g . applyLayout ( ) ; } } ; buttonTopDown . addSelectionListener ( buttonListener ) ; buttonBottomUp . addSelectionListener ( buttonListener ) ; buttonLeftRight . addSelectionListener ( buttonListener ) ; buttonRightLeft . addSelectionListener ( buttonListener ) ; final Button resizeButton = new Button ( shell , SWT . CHECK ) ; resizeButton . setText ( "<STR_LIT>" ) ; resizeButton . addSelectionListener ( new SelectionAdapter ( ) { public void widgetSelected ( SelectionEvent e ) { algorithm . setResizing ( resizeButton . getSelection ( ) ) ; } } ) ; final Button nodeSpaceButton = new Button ( shell , SWT . CHECK ) ; nodeSpaceButton . setText ( "<STR_LIT>" ) ; nodeSpaceButton . addSelectionListener ( new SelectionAdapter ( ) { public void widgetSelected ( SelectionEvent e ) { algorithm . setNodeSpace ( nodeSpaceButton . getSelection ( ) ? new Dimension ( <NUM_LIT:100> , <NUM_LIT:100> ) : null ) ; } } ) ; shell . open ( ) ; while ( ! shell . isDisposed ( ) ) { while ( ! d . readAndDispatch ( ) ) { d . sleep ( ) ; } } } private static void hookMenu ( final Graph g ) { MenuManager menuMgr = new MenuManager ( "<STR_LIT>" ) ; Action expandAction = new Action ( ) { public void run ( ) { List selection = g . getSelection ( ) ; if ( ! selection . isEmpty ( ) ) { GraphNode selected = ( GraphNode ) selection . get ( <NUM_LIT:0> ) ; g . setExpanded ( ( GraphNode ) selected , true ) ; } } } ; expandAction . setText ( "<STR_LIT>" ) ; menuMgr . add ( expandAction ) ; Action collapseAction = new Action ( ) { public void run ( ) { List selection = g . getSelection ( ) ; if ( ! selection . isEmpty ( ) ) { GraphItem selected = ( GraphItem ) selection . get ( <NUM_LIT:0> ) ; g . setExpanded ( ( GraphNode ) selected , false ) ; } } } ; collapseAction . setText ( "<STR_LIT>" ) ; menuMgr . add ( collapseAction ) ; g . setMenu ( menuMgr . createContextMenu ( g ) ) ; } } </s>
|
<s> package org . eclipse . zest . examples . layouts ; import java . util . List ; import org . eclipse . draw2d . ColorConstants ; import org . eclipse . jface . action . Action ; import org . eclipse . jface . action . IMenuListener ; import org . eclipse . jface . action . IMenuManager ; import org . eclipse . jface . action . MenuManager ; 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 . DefaultSubgraph ; 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 . core . widgets . DefaultSubgraph . TriangleSubgraphFactory ; import org . eclipse . zest . layouts . algorithms . SpaceTreeLayoutAlgorithm ; public class SpaceTreeExample { static Graph g ; static GraphNode source ; static GraphNode target ; static boolean changesSeries = false ; public static void main ( String [ ] args ) { Display d = new Display ( ) ; Shell shell = new Shell ( d ) ; shell . setText ( "<STR_LIT>" ) ; shell . setLayout ( new FillLayout ( ) ) ; shell . setSize ( <NUM_LIT> , <NUM_LIT> ) ; g = new Graph ( shell , SWT . NONE ) ; g . setConnectionStyle ( ZestStyles . CONNECTIONS_DIRECTED ) ; g . setNodeStyle ( ZestStyles . NODES_FISHEYE ) ; TriangleSubgraphFactory factory = new DefaultSubgraph . TriangleSubgraphFactory ( ) ; factory . setColor ( ColorConstants . green ) ; g . setSubgraphFactory ( factory ) ; SpaceTreeLayoutAlgorithm spaceTreeLayoutAlgorithm = new SpaceTreeLayoutAlgorithm ( ) ; g . setExpandCollapseManager ( spaceTreeLayoutAlgorithm . getExpandCollapseManager ( ) ) ; g . setLayoutAlgorithm ( spaceTreeLayoutAlgorithm , false ) ; createTree ( g , "<STR_LIT:!>" , <NUM_LIT:5> , <NUM_LIT:5> ) ; hookMenu ( g ) ; shell . open ( ) ; while ( ! shell . isDisposed ( ) ) { while ( ! d . readAndDispatch ( ) ) { d . sleep ( ) ; } } } private static GraphNode createTree ( Graph g , String rootTitle , int depth , int breadth ) { GraphNode root = new GraphNode ( g , SWT . NONE , rootTitle ) ; if ( depth > <NUM_LIT:0> ) { for ( int i = <NUM_LIT:0> ; i < breadth ; i ++ ) { GraphNode child = createTree ( g , rootTitle + i , depth - <NUM_LIT:1> - i , breadth - i ) ; new GraphConnection ( g , SWT . NONE , root , child ) ; } } return root ; } private static void hookMenu ( final Graph g ) { MenuManager menuMgr = new MenuManager ( "<STR_LIT>" ) ; menuMgr . setRemoveAllWhenShown ( true ) ; menuMgr . addMenuListener ( new IMenuListener ( ) { public void menuAboutToShow ( IMenuManager manager ) { fillContextMenu ( manager ) ; } } ) ; g . setMenu ( menuMgr . createContextMenu ( g ) ) ; } private static void fillContextMenu ( IMenuManager menuMgr ) { List selection = g . getSelection ( ) ; if ( selection . size ( ) == <NUM_LIT:1> ) { if ( selection . get ( <NUM_LIT:0> ) instanceof GraphNode ) { final GraphNode node = ( GraphNode ) selection . get ( <NUM_LIT:0> ) ; if ( g . canExpand ( node ) ) { Action expandAction = new Action ( ) { public void run ( ) { g . setExpanded ( node , true ) ; } } ; expandAction . setText ( "<STR_LIT>" ) ; menuMgr . add ( expandAction ) ; } if ( g . canCollapse ( node ) ) { Action collapseAction = new Action ( ) { public void run ( ) { g . setExpanded ( node , false ) ; } } ; collapseAction . setText ( "<STR_LIT>" ) ; menuMgr . add ( collapseAction ) ; } Action disposeAction = new Action ( ) { public void run ( ) { node . dispose ( ) ; } } ; disposeAction . setText ( "<STR_LIT>" ) ; menuMgr . add ( disposeAction ) ; Action asSourceAction = new Action ( ) { public void run ( ) { source = node ; addConnection ( ) ; } } ; asSourceAction . setText ( "<STR_LIT>" ) ; menuMgr . add ( asSourceAction ) ; Action asTargetAction = new Action ( ) { public void run ( ) { target = node ; addConnection ( ) ; } } ; asTargetAction . setText ( "<STR_LIT>" ) ; menuMgr . add ( asTargetAction ) ; } if ( selection . get ( <NUM_LIT:0> ) instanceof GraphConnection ) { final GraphConnection connection = ( GraphConnection ) selection . get ( <NUM_LIT:0> ) ; Action removeAction = new Action ( ) { public void run ( ) { connection . dispose ( ) ; } } ; removeAction . setText ( "<STR_LIT>" ) ; menuMgr . add ( removeAction ) ; } } if ( selection . size ( ) == <NUM_LIT:0> ) { Action addNode = new Action ( ) { public void run ( ) { new GraphNode ( g , SWT . NONE , "<STR_LIT>" ) ; } } ; addNode . setText ( "<STR_LIT>" ) ; menuMgr . add ( addNode ) ; if ( ! changesSeries ) { Action startChangesSeries = new Action ( ) { public void run ( ) { g . setDynamicLayout ( false ) ; changesSeries = true ; } } ; startChangesSeries . setText ( "<STR_LIT>" ) ; menuMgr . add ( startChangesSeries ) ; } else { Action endChangesSeries = new Action ( ) { public void run ( ) { g . setDynamicLayout ( true ) ; changesSeries = false ; } } ; endChangesSeries . setText ( "<STR_LIT>" ) ; menuMgr . add ( endChangesSeries ) ; } } } private static void addConnection ( ) { if ( source != null && target != null ) { new GraphConnection ( g , SWT . NONE , source , target ) ; source = target = null ; } } ; } </s>
|
<s> package org . eclipse . zest . examples . layouts ; import org . eclipse . draw2d . Figure ; import org . eclipse . draw2d . FlowLayout ; import org . eclipse . draw2d . IFigure ; import org . eclipse . draw2d . ImageFigure ; import org . eclipse . draw2d . Label ; import org . eclipse . draw2d . MarginBorder ; 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 . 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 . layouts . algorithms . SpringLayoutAlgorithm ; public class ContainersGraphSnippet { public static void main ( String [ ] args ) { final Display d = new Display ( ) ; Shell shell = new Shell ( d ) ; shell . setText ( "<STR_LIT>" ) ; shell . setLayout ( new FillLayout ( ) ) ; shell . setSize ( <NUM_LIT> , <NUM_LIT> ) ; final Graph g = new Graph ( shell , SWT . NONE ) ; Image zx = new Image ( d , "<STR_LIT>" ) ; IFigure tooltip = new Figure ( ) ; tooltip . setBorder ( new MarginBorder ( <NUM_LIT:5> , <NUM_LIT:5> , <NUM_LIT:5> , <NUM_LIT:5> ) ) ; FlowLayout layout = new FlowLayout ( false ) ; layout . setMajorSpacing ( <NUM_LIT:3> ) ; layout . setMinorAlignment ( <NUM_LIT:3> ) ; tooltip . setLayoutManager ( new FlowLayout ( false ) ) ; tooltip . add ( new ImageFigure ( zx ) ) ; tooltip . add ( new Label ( "<STR_LIT>" ) ) ; tooltip . add ( new Label ( "<STR_LIT>" ) ) ; GraphContainer c1 = new GraphContainer ( g , SWT . NONE ) ; c1 . setText ( "<STR_LIT>" ) ; GraphContainer c2 = new GraphContainer ( g , SWT . NONE ) ; c2 . setText ( "<STR_LIT>" ) ; GraphNode n1 = new GraphNode ( c1 , SWT . NONE , "<STR_LIT>" ) ; n1 . setSize ( <NUM_LIT> , <NUM_LIT:100> ) ; GraphNode n2 = new GraphNode ( c2 , SWT . NONE , "<STR_LIT>" ) ; n2 . setTooltip ( tooltip ) ; GraphConnection connection = new GraphConnection ( g , ZestStyles . CONNECTIONS_DIRECTED , n1 , n2 ) ; connection . setCurveDepth ( - <NUM_LIT:30> ) ; GraphConnection connection2 = new GraphConnection ( g , ZestStyles . CONNECTIONS_DIRECTED , n2 , n1 ) ; connection2 . setCurveDepth ( - <NUM_LIT:30> ) ; g . setLayoutAlgorithm ( new SpringLayoutAlgorithm ( ) , true ) ; shell . open ( ) ; while ( ! shell . isDisposed ( ) ) { while ( ! d . readAndDispatch ( ) ) { d . sleep ( ) ; } } zx . dispose ( ) ; } } </s>
|
<s> package org . eclipse . zest . examples . layouts ; 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 . layouts . algorithms . SpringLayoutAlgorithm ; public class SimpleGraphSnippet { public static void main ( String [ ] args ) { Display d = new Display ( ) ; Shell shell = new Shell ( d ) ; shell . setText ( "<STR_LIT>" ) ; shell . setLayout ( new FillLayout ( ) ) ; shell . setSize ( <NUM_LIT> , <NUM_LIT> ) ; Graph g = new Graph ( shell , SWT . NONE ) ; GraphNode n = new GraphNode ( g , SWT . NONE , "<STR_LIT>" ) ; GraphNode n2 = new GraphNode ( g , SWT . NONE , "<STR_LIT>" ) ; GraphNode n3 = new GraphNode ( g , SWT . NONE , "<STR_LIT>" ) ; new GraphConnection ( g , SWT . NONE , n , n2 ) ; new GraphConnection ( g , SWT . NONE , n2 , n3 ) ; new GraphConnection ( g , SWT . NONE , n3 , n ) ; g . setLayoutAlgorithm ( new SpringLayoutAlgorithm ( ) , true ) ; shell . open ( ) ; while ( ! shell . isDisposed ( ) ) { while ( ! d . readAndDispatch ( ) ) { d . sleep ( ) ; } } } } </s>
|
<s> package org . eclipse . zest . examples . layouts ; import org . eclipse . swt . SWT ; import org . eclipse . swt . events . KeyEvent ; import org . eclipse . swt . events . KeyListener ; 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 . 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 . layouts . LayoutAlgorithm ; import org . eclipse . zest . layouts . algorithms . CompositeLayoutAlgorithm ; import org . eclipse . zest . layouts . algorithms . GridLayoutAlgorithm ; import org . eclipse . zest . layouts . algorithms . HorizontalShiftAlgorithm ; import org . eclipse . zest . layouts . algorithms . RadialLayoutAlgorithm ; import org . eclipse . zest . layouts . algorithms . TreeLayoutAlgorithm ; public class ContainerResizeGraphSnippet { private static Image image1 ; private static Image classImage ; public static void createContainer ( Graph g ) { GraphContainer a = new GraphContainer ( g , SWT . NONE ) ; a . setText ( "<STR_LIT>" ) ; a . setImage ( classImage ) ; int r = ( int ) ( ( Math . random ( ) * <NUM_LIT:3> ) + <NUM_LIT:1> ) ; r = <NUM_LIT:2> ; populateContainer ( a , g , r , true ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:4> ; i ++ ) { GraphContainer b = new GraphContainer ( g , SWT . NONE ) ; b . setText ( "<STR_LIT>" ) ; b . setImage ( classImage ) ; r = ( int ) ( ( Math . random ( ) * <NUM_LIT:3> ) + <NUM_LIT:1> ) ; r = <NUM_LIT:2> ; populateContainer ( b , g , r , false ) ; new GraphConnection ( g , SWT . NONE , a , b ) ; for ( int j = <NUM_LIT:0> ; j < <NUM_LIT:4> ; j ++ ) { GraphContainer c = new GraphContainer ( g , SWT . NONE ) ; c . setText ( "<STR_LIT>" ) ; c . setImage ( classImage ) ; r = ( int ) ( ( Math . random ( ) * <NUM_LIT:3> ) + <NUM_LIT:1> ) ; r = <NUM_LIT:2> ; populateContainer ( c , g , r , true ) ; new GraphConnection ( g , SWT . NONE , b , c ) ; } } } public static void populateContainer ( GraphContainer c , Graph g , int number , boolean radial ) { GraphNode a = new GraphNode ( c , ZestStyles . NODES_FISHEYE | ZestStyles . NODES_HIDE_TEXT ) ; a . setText ( "<STR_LIT>" ) ; a . setImage ( classImage ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:4> ; i ++ ) { GraphNode b = new GraphNode ( c , ZestStyles . NODES_FISHEYE | ZestStyles . NODES_HIDE_TEXT ) ; b . setText ( "<STR_LIT>" ) ; b . setImage ( classImage ) ; new GraphConnection ( g , SWT . NONE , a , b ) ; for ( int j = <NUM_LIT:0> ; j < <NUM_LIT:4> ; j ++ ) { GraphNode d = new GraphNode ( c , ZestStyles . NODES_FISHEYE | ZestStyles . NODES_HIDE_TEXT ) ; d . setText ( "<STR_LIT>" ) ; d . setImage ( classImage ) ; new GraphConnection ( g , SWT . NONE , b , d ) ; if ( number > <NUM_LIT:2> ) { for ( int k = <NUM_LIT:0> ; k < <NUM_LIT:4> ; k ++ ) { GraphNode e = new GraphNode ( c , ZestStyles . NODES_FISHEYE | ZestStyles . NODES_HIDE_TEXT ) ; e . setText ( "<STR_LIT>" ) ; e . setImage ( classImage ) ; new GraphConnection ( g , SWT . NONE , d , e ) ; if ( number > <NUM_LIT:3> ) { for ( int l = <NUM_LIT:0> ; l < <NUM_LIT:4> ; l ++ ) { GraphNode f = new GraphNode ( c , ZestStyles . NODES_FISHEYE | ZestStyles . NODES_HIDE_TEXT ) ; f . setText ( "<STR_LIT>" ) ; f . setImage ( classImage ) ; new GraphConnection ( g , SWT . NONE , e , f ) ; } } } } } } if ( number == <NUM_LIT:1> ) { c . setScale ( <NUM_LIT> ) ; } else if ( number == <NUM_LIT:2> ) { c . setScale ( <NUM_LIT> ) ; } else { c . setScale ( <NUM_LIT> ) ; } if ( radial ) { c . setLayoutAlgorithm ( new RadialLayoutAlgorithm ( ) , true ) ; } else { c . setLayoutAlgorithm ( new TreeLayoutAlgorithm ( ) , true ) ; } } public static void main ( String [ ] args ) { Display d = new Display ( ) ; image1 = new Image ( Display . getDefault ( ) , ContainerResizeGraphSnippet . class . getResourceAsStream ( "<STR_LIT>" ) ) ; classImage = new Image ( Display . getDefault ( ) , ContainerResizeGraphSnippet . class . getResourceAsStream ( "<STR_LIT>" ) ) ; Shell shell = new Shell ( d ) ; shell . setText ( "<STR_LIT>" ) ; shell . setLayout ( new FillLayout ( ) ) ; shell . setSize ( <NUM_LIT> , <NUM_LIT> ) ; final Graph g = new Graph ( shell , SWT . NONE ) ; createContainer ( g ) ; CompositeLayoutAlgorithm compositeLayoutAlgorithm = new CompositeLayoutAlgorithm ( new LayoutAlgorithm [ ] { new GridLayoutAlgorithm ( ) , new HorizontalShiftAlgorithm ( ) } ) ; g . setLayoutAlgorithm ( compositeLayoutAlgorithm , true ) ; g . addKeyListener ( new KeyListener ( ) { boolean flip = true ; public void keyPressed ( KeyEvent e ) { if ( g . getSelection ( ) . size ( ) == <NUM_LIT:1> ) { GraphNode item = ( GraphNode ) g . getSelection ( ) . get ( <NUM_LIT:0> ) ; if ( item . getItemType ( ) == GraphItem . CONTAINER ) { if ( flip ) { ( item ) . setSize ( <NUM_LIT> , <NUM_LIT:100> ) ; } else { ( item ) . setSize ( <NUM_LIT:0> , <NUM_LIT:0> ) ; } flip = ! flip ; } } } public void keyReleased ( KeyEvent e ) { } } ) ; shell . open ( ) ; while ( ! shell . isDisposed ( ) ) { while ( ! d . readAndDispatch ( ) ) { d . sleep ( ) ; } } image1 . dispose ( ) ; } } </s>
|
<s> package org . eclipse . zest . examples . layouts ; 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 . layouts . LayoutAlgorithm ; import org . eclipse . zest . layouts . interfaces . EntityLayout ; import org . eclipse . zest . layouts . interfaces . LayoutContext ; public class CustomLayout { public static void main ( String [ ] args ) { Display d = new Display ( ) ; Shell shell = new Shell ( d ) ; shell . setText ( "<STR_LIT>" ) ; shell . setLayout ( new FillLayout ( ) ) ; shell . setSize ( <NUM_LIT> , <NUM_LIT> ) ; Graph g = new Graph ( shell , SWT . NONE ) ; GraphNode n = new GraphNode ( g , SWT . NONE , "<STR_LIT>" ) ; GraphNode n2 = new GraphNode ( g , SWT . NONE , "<STR_LIT>" ) ; GraphNode n3 = new GraphNode ( g , SWT . NONE , "<STR_LIT>" ) ; new GraphConnection ( g , SWT . NONE , n , n2 ) ; new GraphConnection ( g , SWT . NONE , n2 , n3 ) ; new GraphConnection ( g , SWT . NONE , n3 , n ) ; LayoutAlgorithm layoutAlgorithm = new LayoutAlgorithm ( ) { private LayoutContext context ; public void setLayoutContext ( LayoutContext context ) { this . context = context ; } public void applyLayout ( boolean clean ) { EntityLayout [ ] entitiesToLayout = context . getEntities ( ) ; int totalSteps = entitiesToLayout . length ; double distance = context . getBounds ( ) . width / totalSteps ; int xLocation = <NUM_LIT:0> ; for ( int currentStep = <NUM_LIT:0> ; currentStep < entitiesToLayout . length ; currentStep ++ ) { EntityLayout layoutEntity = entitiesToLayout [ currentStep ] ; layoutEntity . setLocation ( xLocation , layoutEntity . getLocation ( ) . y ) ; xLocation += distance ; } } } ; g . setLayoutAlgorithm ( layoutAlgorithm , true ) ; shell . open ( ) ; while ( ! shell . isDisposed ( ) ) { while ( ! d . readAndDispatch ( ) ) { d . sleep ( ) ; } } } } </s>
|
<s> package org . eclipse . zest . examples . layouts ; 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 . layouts . LayoutAlgorithm ; import org . eclipse . zest . layouts . algorithms . RadialLayoutAlgorithm ; public class RadialLayoutExample { public static void main ( String [ ] args ) { Display d = new Display ( ) ; Shell shell = new Shell ( d ) ; shell . setText ( "<STR_LIT>" ) ; shell . setLayout ( new FillLayout ( ) ) ; shell . setSize ( <NUM_LIT> , <NUM_LIT> ) ; final Graph g = new Graph ( shell , SWT . NONE ) ; g . setSize ( <NUM_LIT> , <NUM_LIT> ) ; GraphNode root = new GraphNode ( g , SWT . NONE , "<STR_LIT>" ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:3> ; i ++ ) { GraphNode n = new GraphNode ( g , SWT . NONE , "<STR_LIT>" + i ) ; for ( int j = <NUM_LIT:0> ; j < <NUM_LIT:3> ; j ++ ) { GraphNode n2 = new GraphNode ( g , SWT . NONE , "<STR_LIT>" + j ) ; new GraphConnection ( g , SWT . NONE , n , n2 ) . setWeight ( - <NUM_LIT:1> ) ; } new GraphConnection ( g , SWT . NONE , root , n ) ; } final LayoutAlgorithm layoutAlgorithm = new RadialLayoutAlgorithm ( ) ; g . setLayoutAlgorithm ( layoutAlgorithm , true ) ; shell . open ( ) ; while ( ! shell . isDisposed ( ) ) { while ( ! d . readAndDispatch ( ) ) { d . sleep ( ) ; } } } } </s>
|
<s> package org . eclipse . zest . examples . layouts ; import org . eclipse . jface . layout . GridDataFactory ; import org . eclipse . swt . SWT ; import org . eclipse . swt . layout . GridLayout ; import org . eclipse . swt . widgets . Button ; 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 . LayoutAlgorithm ; import org . eclipse . zest . layouts . algorithms . SpringLayoutAlgorithm ; public class SpringLayoutExample { public static void main ( String [ ] args ) { Display d = new Display ( ) ; Shell shell = new Shell ( d ) ; shell . setText ( "<STR_LIT>" ) ; shell . setLayout ( new GridLayout ( <NUM_LIT:2> , false ) ) ; shell . setSize ( <NUM_LIT> , <NUM_LIT> ) ; final Graph g = new Graph ( shell , SWT . BORDER ) ; g . setSize ( <NUM_LIT> , <NUM_LIT> ) ; GraphNode root = new GraphNode ( g , SWT . NONE , "<STR_LIT>" ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:3> ; i ++ ) { GraphNode n = new GraphNode ( g , SWT . NONE , "<STR_LIT>" + i ) ; for ( int j = <NUM_LIT:0> ; j < <NUM_LIT:3> ; j ++ ) { GraphNode n2 = new GraphNode ( g , SWT . NONE , "<STR_LIT>" + j ) ; new GraphConnection ( g , SWT . NONE , n , n2 ) . setWeight ( - <NUM_LIT:1> ) ; } new GraphConnection ( g , SWT . NONE , root , n ) ; } GridDataFactory . fillDefaults ( ) . grab ( true , true ) . applyTo ( g ) ; new Button ( shell , SWT . PUSH ) . setText ( "<STR_LIT>" ) ; final LayoutAlgorithm layoutAlgorithm = new SpringLayoutAlgorithm ( ) ; g . setLayoutAlgorithm ( layoutAlgorithm , true ) ; shell . open ( ) ; while ( ! shell . isDisposed ( ) ) { while ( ! d . readAndDispatch ( ) ) { d . sleep ( ) ; } } } } </s>
|
<s> package org . eclipse . zest . examples . layouts ; 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 . layouts . algorithms . SugiyamaLayoutAlgorithm ; public class SugiyamaLayoutExample { public static void main ( String [ ] args ) { Display d = new Display ( ) ; Shell shell = new Shell ( d ) ; shell . setLayout ( new FillLayout ( ) ) ; shell . setSize ( <NUM_LIT> , <NUM_LIT> ) ; Graph g = new Graph ( shell , SWT . NONE ) ; g . setConnectionStyle ( ZestStyles . CONNECTIONS_DIRECTED ) ; GraphNode coal = new GraphNode ( g , SWT . NONE , "<STR_LIT>" ) ; GraphNode ore = new GraphNode ( g , SWT . NONE , "<STR_LIT>" ) ; GraphNode stone = new GraphNode ( g , SWT . NONE , "<STR_LIT>" ) ; GraphNode metal = new GraphNode ( g , SWT . NONE , "<STR_LIT>" ) ; GraphNode concrete = new GraphNode ( g , SWT . NONE , "<STR_LIT>" ) ; GraphNode machine = new GraphNode ( g , SWT . NONE , "<STR_LIT>" ) ; GraphNode building = new GraphNode ( g , SWT . NONE , "<STR_LIT>" ) ; new GraphConnection ( g , SWT . NONE , coal , metal ) ; new GraphConnection ( g , SWT . NONE , coal , concrete ) ; new GraphConnection ( g , SWT . NONE , metal , machine ) ; new GraphConnection ( g , SWT . NONE , metal , building ) ; new GraphConnection ( g , SWT . NONE , concrete , building ) ; new GraphConnection ( g , SWT . NONE , ore , metal ) ; new GraphConnection ( g , SWT . NONE , stone , concrete ) ; g . setLayoutAlgorithm ( new SugiyamaLayoutAlgorithm ( ) , true ) ; shell . open ( ) ; while ( ! shell . isDisposed ( ) ) { while ( ! d . readAndDispatch ( ) ) { d . sleep ( ) ; } } } } </s>
|
<s> package org . eclipse . zest . examples . layouts ; import org . eclipse . draw2d . ColorConstants ; 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 . GraphItem ; import org . eclipse . zest . core . widgets . GraphNode ; import org . eclipse . zest . core . widgets . LayoutFilter ; import org . eclipse . zest . core . widgets . ZestStyles ; import org . eclipse . zest . layouts . algorithms . TreeLayoutAlgorithm ; public class FilterGraphSnippet { public static void main ( String [ ] args ) { Display display = new Display ( ) ; Shell shell = new Shell ( display ) ; shell . setText ( "<STR_LIT>" ) ; shell . setLayout ( new FillLayout ( ) ) ; shell . setSize ( <NUM_LIT> , <NUM_LIT> ) ; final Graph graph = new Graph ( shell , SWT . NONE ) ; GraphNode a = new GraphNode ( graph , SWT . NONE , "<STR_LIT>" ) ; GraphNode b = new GraphNode ( graph , SWT . NONE , "<STR_LIT:B>" ) ; GraphNode c = new GraphNode ( graph , SWT . NONE , "<STR_LIT:C>" ) ; GraphNode d = new GraphNode ( graph , SWT . NONE , "<STR_LIT:D>" ) ; GraphNode e = new GraphNode ( graph , SWT . NONE , "<STR_LIT:E>" ) ; GraphNode f = new GraphNode ( graph , SWT . NONE , "<STR_LIT:F>" ) ; GraphNode g = new GraphNode ( graph , SWT . NONE , "<STR_LIT>" ) ; GraphNode h = new GraphNode ( graph , SWT . NONE , "<STR_LIT>" ) ; GraphConnection connection = new GraphConnection ( graph , ZestStyles . CONNECTIONS_DIRECTED , a , b ) ; connection . setData ( Boolean . TRUE ) ; connection = new GraphConnection ( graph , ZestStyles . CONNECTIONS_DIRECTED , a , c ) ; connection . setData ( Boolean . TRUE ) ; connection = new GraphConnection ( graph , ZestStyles . CONNECTIONS_DIRECTED , a , c ) ; connection . setData ( Boolean . TRUE ) ; connection = new GraphConnection ( graph , ZestStyles . CONNECTIONS_DIRECTED , a , d ) ; connection . setData ( Boolean . TRUE ) ; connection = new GraphConnection ( graph , ZestStyles . CONNECTIONS_DIRECTED , b , e ) ; connection . setData ( Boolean . FALSE ) ; connection = new GraphConnection ( graph , ZestStyles . CONNECTIONS_DIRECTED , b , f ) ; connection . setData ( Boolean . FALSE ) ; connection = new GraphConnection ( graph , ZestStyles . CONNECTIONS_DIRECTED , c , g ) ; connection . setData ( Boolean . FALSE ) ; connection = new GraphConnection ( graph , ZestStyles . CONNECTIONS_DIRECTED , d , h ) ; connection . setData ( Boolean . FALSE ) ; connection = new GraphConnection ( graph , ZestStyles . CONNECTIONS_DIRECTED , b , c ) ; connection . setLineColor ( ColorConstants . red ) ; connection . setLineWidth ( <NUM_LIT:3> ) ; connection = new GraphConnection ( graph , ZestStyles . CONNECTIONS_DIRECTED , c , d ) ; connection . setLineColor ( ColorConstants . red ) ; connection . setLineWidth ( <NUM_LIT:3> ) ; connection = new GraphConnection ( graph , ZestStyles . CONNECTIONS_DIRECTED , e , f ) ; connection . setLineColor ( ColorConstants . red ) ; connection . setLineWidth ( <NUM_LIT:3> ) ; connection = new GraphConnection ( graph , ZestStyles . CONNECTIONS_DIRECTED , f , g ) ; connection . setLineColor ( ColorConstants . red ) ; connection . setLineWidth ( <NUM_LIT:3> ) ; connection = new GraphConnection ( graph , ZestStyles . CONNECTIONS_DIRECTED , h , e ) ; connection . setLineColor ( ColorConstants . red ) ; connection . setLineWidth ( <NUM_LIT:3> ) ; TreeLayoutAlgorithm treeLayoutAlgorithm = new TreeLayoutAlgorithm ( ) ; LayoutFilter filter = new LayoutFilter ( ) { public boolean isObjectFiltered ( GraphItem item ) { if ( item instanceof GraphConnection ) { GraphConnection connection = ( GraphConnection ) item ; Object data = connection . getData ( ) ; if ( data != null && data instanceof Boolean ) { return ( ( Boolean ) data ) . booleanValue ( ) ; } return true ; } return false ; } } ; graph . addLayoutFilter ( filter ) ; graph . setLayoutAlgorithm ( treeLayoutAlgorithm , true ) ; shell . open ( ) ; while ( ! shell . isDisposed ( ) ) { while ( ! display . readAndDispatch ( ) ) { display . sleep ( ) ; } } } } </s>
|
<s> package org . eclipse . zest . examples . layouts ; import java . util . Iterator ; import java . util . List ; 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 . events . SelectionListener ; import org . eclipse . swt . layout . GridData ; import org . eclipse . swt . layout . GridLayout ; import org . eclipse . swt . widgets . Button ; import org . eclipse . swt . widgets . Display ; import org . eclipse . swt . widgets . Label ; 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 . LayoutFilter ; import org . eclipse . zest . layouts . algorithms . SpringLayoutAlgorithm ; public class SpringLayoutProgress { static Runnable r = null ; static boolean MouseDown = false ; static boolean first = true ; public static void main ( String [ ] args ) { Display d = new Display ( ) ; Shell shell = new Shell ( d ) ; shell . setText ( "<STR_LIT>" ) ; GridLayout gridLayout = new GridLayout ( ) ; gridLayout . numColumns = <NUM_LIT:5> ; shell . setLayout ( gridLayout ) ; shell . setSize ( <NUM_LIT> , <NUM_LIT> ) ; final Graph g = new Graph ( shell , SWT . NONE ) ; g . setLayoutData ( new GridData ( SWT . FILL , SWT . FILL , true , true , <NUM_LIT:5> , <NUM_LIT:5> ) ) ; g . setSize ( <NUM_LIT> , <NUM_LIT> ) ; GraphNode aa = new GraphNode ( g , SWT . NONE , "<STR_LIT:A>" ) ; GraphNode bb = new GraphNode ( g , SWT . NONE , "<STR_LIT:B>" ) ; GraphNode cc = new GraphNode ( g , SWT . NONE , "<STR_LIT:C>" ) ; GraphNode dd = new GraphNode ( g , SWT . NONE , "<STR_LIT:D>" ) ; GraphNode ee = new GraphNode ( g , SWT . NONE , "<STR_LIT:E>" ) ; GraphNode ff = new GraphNode ( g , SWT . NONE , "<STR_LIT:F>" ) ; GraphNode root = new GraphNode ( g , SWT . NONE , "<STR_LIT>" ) ; new GraphConnection ( g , SWT . NONE , root , aa ) ; new GraphConnection ( g , SWT . NONE , root , bb ) ; new GraphConnection ( g , SWT . NONE , root , cc ) ; new GraphConnection ( g , SWT . NONE , aa , bb ) ; new GraphConnection ( g , SWT . NONE , bb , cc ) ; new GraphConnection ( g , SWT . NONE , cc , aa ) ; new GraphConnection ( g , SWT . NONE , aa , dd ) ; new GraphConnection ( g , SWT . NONE , bb , ee ) ; new GraphConnection ( g , SWT . NONE , cc , ff ) ; new GraphConnection ( g , SWT . NONE , cc , dd ) ; new GraphConnection ( g , SWT . NONE , dd , ee ) ; new GraphConnection ( g , SWT . NONE , ee , ff ) ; GraphNode nodes [ ] = new GraphNode [ <NUM_LIT:3> ] ; nodes [ <NUM_LIT:0> ] = aa ; nodes [ <NUM_LIT:1> ] = bb ; nodes [ <NUM_LIT:2> ] = cc ; for ( int k = <NUM_LIT:0> ; k < <NUM_LIT:1> ; k ++ ) { for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:8> ; i ++ ) { GraphNode n = new GraphNode ( g , SWT . NONE , "<STR_LIT>" + i ) ; for ( int j = <NUM_LIT:0> ; j < <NUM_LIT:5> ; j ++ ) { GraphNode n2 = new GraphNode ( g , SWT . NONE , "<STR_LIT>" + j ) ; new GraphConnection ( g , SWT . NONE , n , n2 ) . setWeight ( - <NUM_LIT:1> ) ; new GraphConnection ( g , SWT . NONE , nodes [ j % <NUM_LIT:3> ] , n2 ) ; } new GraphConnection ( g , SWT . NONE , root , n ) ; } } List nodes2 = g . getNodes ( ) ; for ( Iterator iterator = nodes2 . iterator ( ) ; iterator . hasNext ( ) ; ) { GraphNode node = ( GraphNode ) iterator . next ( ) ; node . setLocation ( <NUM_LIT> , <NUM_LIT> ) ; } g . addMouseListener ( new MouseListener ( ) { public void mouseUp ( MouseEvent e ) { MouseDown = false ; } public void mouseDown ( MouseEvent e ) { MouseDown = true ; } public void mouseDoubleClick ( MouseEvent e ) { } } ) ; g . addSelectionListener ( new SelectionListener ( ) { public void widgetSelected ( SelectionEvent e ) { List selection = g . getSelection ( ) ; List graphNodes = g . getNodes ( ) ; for ( Iterator iterator = graphNodes . iterator ( ) ; iterator . hasNext ( ) ; ) { GraphNode node = ( GraphNode ) iterator . next ( ) ; if ( ! g . getSelection ( ) . contains ( node ) ) node . unhighlight ( ) ; } List connctions = g . getConnections ( ) ; for ( Iterator iterator = connctions . iterator ( ) ; iterator . hasNext ( ) ; ) { GraphConnection connection = ( GraphConnection ) iterator . next ( ) ; connection . unhighlight ( ) ; connection . setWeight ( - <NUM_LIT:1> ) ; } for ( Iterator iterator = selection . iterator ( ) ; iterator . hasNext ( ) ; ) { Object object = iterator . next ( ) ; if ( object instanceof GraphNode ) { GraphNode node = ( GraphNode ) object ; List sourceConnections = node . getSourceConnections ( ) ; for ( Iterator iterator2 = sourceConnections . iterator ( ) ; iterator2 . hasNext ( ) ; ) { GraphConnection connection = ( GraphConnection ) iterator2 . next ( ) ; connection . getDestination ( ) . highlight ( ) ; connection . highlight ( ) ; connection . setWeight ( <NUM_LIT:10> ) ; } List target = node . getTargetConnections ( ) ; for ( Iterator iterator2 = target . iterator ( ) ; iterator2 . hasNext ( ) ; ) { GraphConnection connection = ( GraphConnection ) iterator2 . next ( ) ; connection . getSource ( ) . highlight ( ) ; connection . highlight ( ) ; connection . setWeight ( <NUM_LIT:10> ) ; } } } } public void widgetDefaultSelected ( SelectionEvent e ) { } } ) ; final SpringLayoutAlgorithm springLayoutAlgorithm = new SpringLayoutAlgorithm ( ) ; g . addLayoutFilter ( new LayoutFilter ( ) { public boolean isObjectFiltered ( GraphItem item ) { if ( item instanceof GraphNode ) { return item . getGraphModel ( ) . getSelection ( ) . contains ( item ) && MouseDown ; } return false ; } } ) ; g . setLayoutAlgorithm ( springLayoutAlgorithm , false ) ; g . applyLayoutNow ( ) ; Button b = new Button ( shell , SWT . FLAT ) ; b . setText ( "<STR_LIT>" ) ; final Label label = new Label ( shell , SWT . LEFT ) ; label . setText ( "<STR_LIT>" ) ; label . setLayoutData ( new GridData ( SWT . FILL , SWT . CENTER , true , false ) ) ; b . addSelectionListener ( new SelectionAdapter ( ) { int steps = <NUM_LIT:0> ; public void widgetSelected ( SelectionEvent e ) { r = new Runnable ( ) { public void run ( ) { springLayoutAlgorithm . performNIteration ( <NUM_LIT:1> ) ; g . redraw ( ) ; label . setText ( "<STR_LIT>" + ++ steps ) ; try { Thread . sleep ( <NUM_LIT:10> ) ; } catch ( InterruptedException e ) { e . printStackTrace ( ) ; } Display . getCurrent ( ) . asyncExec ( r ) ; } } ; Display . getCurrent ( ) . asyncExec ( r ) ; } } ) ; shell . open ( ) ; while ( ! shell . isDisposed ( ) ) { while ( ! d . readAndDispatch ( ) ) { d . sleep ( ) ; } } } } </s>
|
<s> package org . eclipse . zest . examples . layouts ; import java . util . Iterator ; import org . eclipse . draw2d . ColorConstants ; import org . eclipse . draw2d . Ellipse ; import org . eclipse . draw2d . Figure ; import org . eclipse . draw2d . FreeformLayout ; import org . eclipse . draw2d . IFigure ; import org . eclipse . draw2d . ImageFigure ; import org . eclipse . draw2d . PolylineShape ; import org . eclipse . draw2d . geometry . Point ; import org . eclipse . draw2d . geometry . Rectangle ; import org . eclipse . swt . SWT ; import org . eclipse . swt . events . SelectionEvent ; import org . eclipse . swt . events . SelectionListener ; 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 . widgets . Graph ; import org . eclipse . zest . core . widgets . GraphConnection ; import org . eclipse . zest . core . widgets . GraphNode ; import org . eclipse . zest . core . widgets . custom . CGraphNode ; import org . eclipse . zest . layouts . algorithms . SpringLayoutAlgorithm ; public class CustomFigureGraphSnippet { public static IFigure createPersonFigure ( Image headImage ) { Figure person = new Figure ( ) ; person . setLayoutManager ( new FreeformLayout ( ) ) ; IFigure head = null ; if ( headImage != null ) { headImage = new Image ( headImage . getDevice ( ) , headImage . getImageData ( ) . scaledTo ( <NUM_LIT> , <NUM_LIT> ) ) ; head = new ImageFigure ( headImage ) ; } else head = new Ellipse ( ) ; head . setSize ( <NUM_LIT> , <NUM_LIT> ) ; PolylineShape body = new PolylineShape ( ) ; body . setLineWidth ( <NUM_LIT:1> ) ; body . setStart ( new Point ( <NUM_LIT:20> , <NUM_LIT> ) ) ; body . setEnd ( new Point ( <NUM_LIT:20> , <NUM_LIT:100> ) ) ; body . setBounds ( new Rectangle ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:100> ) ) ; PolylineShape leftLeg = new PolylineShape ( ) ; leftLeg . setLineWidth ( <NUM_LIT:1> ) ; leftLeg . setStart ( new Point ( <NUM_LIT:20> , <NUM_LIT:100> ) ) ; leftLeg . setEnd ( new Point ( <NUM_LIT:0> , <NUM_LIT> ) ) ; leftLeg . setBounds ( new Rectangle ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT> ) ) ; PolylineShape rightLeg = new PolylineShape ( ) ; rightLeg . setLineWidth ( <NUM_LIT:1> ) ; rightLeg . setStart ( new Point ( <NUM_LIT:20> , <NUM_LIT:100> ) ) ; rightLeg . setEnd ( new Point ( <NUM_LIT> , <NUM_LIT> ) ) ; rightLeg . setBounds ( new Rectangle ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT> ) ) ; PolylineShape leftArm = new PolylineShape ( ) ; leftArm . setLineWidth ( <NUM_LIT:1> ) ; leftArm . setStart ( new Point ( <NUM_LIT:20> , <NUM_LIT> ) ) ; leftArm . setEnd ( new Point ( <NUM_LIT:0> , <NUM_LIT> ) ) ; leftArm . setBounds ( new Rectangle ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT> ) ) ; PolylineShape rightArm = new PolylineShape ( ) ; rightArm . setLineWidth ( <NUM_LIT:1> ) ; rightArm . setStart ( new Point ( <NUM_LIT:20> , <NUM_LIT> ) ) ; rightArm . setEnd ( new Point ( <NUM_LIT> , <NUM_LIT> ) ) ; rightArm . setBounds ( new Rectangle ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT> ) ) ; person . add ( head ) ; person . add ( body ) ; person . add ( leftLeg ) ; person . add ( rightLeg ) ; person . add ( leftArm ) ; person . add ( rightArm ) ; person . setSize ( <NUM_LIT> , <NUM_LIT> ) ; return person ; } public static void main ( String [ ] args ) { final Display d = new Display ( ) ; Shell shell = new Shell ( d ) ; shell . setText ( "<STR_LIT>" ) ; shell . setLayout ( new FillLayout ( ) ) ; shell . setSize ( <NUM_LIT> , <NUM_LIT> ) ; final Graph g = new Graph ( shell , SWT . NONE ) ; g . addSelectionListener ( new SelectionListener ( ) { public void widgetSelected ( SelectionEvent e ) { Iterator iter = g . getSelection ( ) . iterator ( ) ; while ( iter . hasNext ( ) ) { Object o = iter . next ( ) ; if ( o instanceof CGraphNode ) { IFigure figure = ( ( CGraphNode ) o ) . getFigure ( ) ; figure . setBackgroundColor ( ColorConstants . blue ) ; figure . setForegroundColor ( ColorConstants . blue ) ; } } iter = g . getNodes ( ) . iterator ( ) ; while ( iter . hasNext ( ) ) { Object o = iter . next ( ) ; if ( o instanceof CGraphNode ) { if ( ! g . getSelection ( ) . contains ( o ) ) { ( ( CGraphNode ) o ) . getFigure ( ) . setBackgroundColor ( ColorConstants . black ) ; ( ( CGraphNode ) o ) . getFigure ( ) . setForegroundColor ( ColorConstants . black ) ; } } } } public void widgetDefaultSelected ( SelectionEvent e ) { } } ) ; Image zx = new Image ( d , "<STR_LIT>" ) ; Image ibull = new Image ( d , "<STR_LIT>" ) ; CGraphNode n = new CGraphNode ( g , SWT . NONE , createPersonFigure ( zx ) ) ; CGraphNode n2 = new CGraphNode ( g , SWT . NONE , createPersonFigure ( ibull ) ) ; GraphNode n3 = new GraphNode ( g , SWT . NONE , "<STR_LIT>" ) ; GraphNode n4 = new GraphNode ( g , SWT . NONE , "<STR_LIT>" ) ; GraphNode n5 = new GraphNode ( g , SWT . NONE , "<STR_LIT>" ) ; new GraphConnection ( g , SWT . NONE , n , n2 ) ; new GraphConnection ( g , SWT . NONE , n , n3 ) ; new GraphConnection ( g , SWT . NONE , n2 , n4 ) ; new GraphConnection ( g , SWT . NONE , n , n5 ) ; new GraphConnection ( g , SWT . NONE , n2 , n5 ) ; new GraphConnection ( g , SWT . NONE , n3 , n5 ) ; new GraphConnection ( g , SWT . NONE , n4 , n5 ) ; g . setLayoutAlgorithm ( new SpringLayoutAlgorithm ( ) , true ) ; shell . open ( ) ; while ( ! shell . isDisposed ( ) ) { while ( ! d . readAndDispatch ( ) ) { d . sleep ( ) ; } } zx . dispose ( ) ; ibull . dispose ( ) ; } } </s>
|
<s> package org . eclipse . zest . examples . swt ; 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 . layouts . algorithms . SpringLayoutAlgorithm ; public class HelloWorld { public static void main ( String [ ] args ) { Display d = new Display ( ) ; Shell shell = new Shell ( d ) ; shell . setText ( "<STR_LIT>" ) ; shell . setLayout ( new FillLayout ( ) ) ; shell . setSize ( <NUM_LIT> , <NUM_LIT> ) ; Graph g = new Graph ( shell , SWT . NONE ) ; GraphNode hello = new GraphNode ( g , SWT . NONE , "<STR_LIT:Hello>" ) ; GraphNode world = new GraphNode ( g , SWT . NONE , "<STR_LIT>" ) ; new GraphConnection ( g , SWT . NONE , hello , world ) ; g . setLayoutAlgorithm ( new SpringLayoutAlgorithm ( ) , true ) ; shell . open ( ) ; while ( ! shell . isDisposed ( ) ) { while ( ! d . readAndDispatch ( ) ) { d . sleep ( ) ; } } } } </s>
|
<s> package org . eclipse . zest . examples . swt ; import org . eclipse . draw2d . ConnectionRouter ; import org . eclipse . draw2d . ManhattanConnectionRouter ; import org . eclipse . swt . SWT ; import org . eclipse . swt . events . SelectionAdapter ; import org . eclipse . swt . events . SelectionEvent ; 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 . widgets . Graph ; import org . eclipse . zest . core . widgets . GraphConnection ; import org . eclipse . zest . core . widgets . GraphNode ; import org . eclipse . zest . layouts . algorithms . SpringLayoutAlgorithm ; public class ManhattanLayoutGraphSnippet { public static void main ( String [ ] args ) { final Display d = new Display ( ) ; final Shell shell = new Shell ( d ) ; shell . setText ( "<STR_LIT>" ) ; shell . setLayout ( new FillLayout ( ) ) ; shell . setSize ( <NUM_LIT> , <NUM_LIT> ) ; Button b = new Button ( shell , SWT . PUSH ) ; b . setText ( "<STR_LIT>" ) ; final Graph g = new Graph ( shell , SWT . NONE ) ; GraphNode n = new GraphNode ( g , SWT . NONE , "<STR_LIT>" ) ; GraphNode n2 = new GraphNode ( g , SWT . NONE , "<STR_LIT>" ) ; GraphNode n3 = new GraphNode ( g , SWT . NONE , "<STR_LIT>" ) ; new GraphConnection ( g , SWT . NONE , n , n2 ) ; new GraphConnection ( g , SWT . NONE , n2 , n3 ) ; new GraphConnection ( g , SWT . NONE , n3 , n ) ; g . setLayoutAlgorithm ( new SpringLayoutAlgorithm ( ) , true ) ; b . addSelectionListener ( new SelectionAdapter ( ) { ConnectionRouter router = null ; public void widgetSelected ( SelectionEvent e ) { if ( router == null ) { router = new ManhattanConnectionRouter ( ) ; } else { router = null ; } g . setRouter ( router ) ; } } ) ; shell . open ( ) ; while ( ! shell . isDisposed ( ) ) { while ( ! d . readAndDispatch ( ) ) { d . sleep ( ) ; } } } } </s>
|
<s> package org . eclipse . zest . examples . swt ; 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 . layouts . algorithms . SpringLayoutAlgorithm ; public class GraphSnippet1 { public static void main ( String [ ] args ) { Display d = new Display ( ) ; Shell shell = new Shell ( d ) ; shell . setText ( "<STR_LIT>" ) ; shell . setLayout ( new FillLayout ( ) ) ; shell . setSize ( <NUM_LIT> , <NUM_LIT> ) ; Graph g = new Graph ( shell , SWT . NONE ) ; GraphNode n = new GraphNode ( g , SWT . NONE , "<STR_LIT>" ) ; GraphNode n2 = new GraphNode ( g , SWT . NONE , "<STR_LIT>" ) ; GraphNode n3 = new GraphNode ( g , SWT . NONE , "<STR_LIT>" ) ; new GraphConnection ( g , SWT . NONE , n , n2 ) ; new GraphConnection ( g , SWT . NONE , n2 , n3 ) ; new GraphConnection ( g , SWT . NONE , n3 , n ) ; g . setLayoutAlgorithm ( new SpringLayoutAlgorithm ( ) , true ) ; shell . open ( ) ; while ( ! shell . isDisposed ( ) ) { while ( ! d . readAndDispatch ( ) ) { d . sleep ( ) ; } } } } </s>
|
<s> package org . eclipse . zest . examples . swt ; 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 ; public class GraphSnippet9 { public static void main ( String [ ] args ) { Display display = new Display ( ) ; Shell shell = new Shell ( display ) ; shell . setText ( "<STR_LIT>" ) ; shell . setLayout ( new FillLayout ( ) ) ; shell . setSize ( <NUM_LIT> , <NUM_LIT> ) ; final Graph graph = new Graph ( shell , SWT . NONE ) ; GraphNode a = new GraphNode ( graph , ZestStyles . CONNECTIONS_DIRECTED , "<STR_LIT>" ) ; GraphConnection connection = new GraphConnection ( graph , SWT . NONE , a , a ) ; connection . setText ( "<STR_LIT>" ) ; a . setLocation ( <NUM_LIT:100> , <NUM_LIT:100> ) ; shell . open ( ) ; while ( ! shell . isDisposed ( ) ) { while ( ! display . readAndDispatch ( ) ) { display . sleep ( ) ; } } } } </s>
|
<s> package org . eclipse . zest . examples . swt ; 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 . 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 . SpringLayoutAlgorithm ; public class GraphSnippet2 { public static void main ( String [ ] args ) { Display d = new Display ( ) ; Shell shell = new Shell ( d ) ; Image image1 = Display . getDefault ( ) . getSystemImage ( SWT . ICON_INFORMATION ) ; Image image2 = Display . getDefault ( ) . getSystemImage ( SWT . ICON_WARNING ) ; Image image3 = Display . getDefault ( ) . getSystemImage ( SWT . ICON_ERROR ) ; shell . setLayout ( new FillLayout ( ) ) ; shell . setSize ( <NUM_LIT> , <NUM_LIT> ) ; Graph g = new Graph ( shell , SWT . NONE ) ; g . setConnectionStyle ( ZestStyles . CONNECTIONS_DIRECTED ) ; GraphNode n1 = new GraphNode ( g , SWT . NONE ) ; n1 . setText ( "<STR_LIT>" ) ; n1 . setImage ( image1 ) ; GraphNode n2 = new GraphNode ( g , SWT . NONE ) ; n2 . setText ( "<STR_LIT>" ) ; n2 . setImage ( image2 ) ; GraphNode n3 = new GraphNode ( g , SWT . NONE ) ; n3 . setText ( "<STR_LIT>" ) ; n3 . setImage ( image3 ) ; new GraphConnection ( g , SWT . NONE , n1 , n2 ) ; new GraphConnection ( g , SWT . NONE , n2 , n3 ) ; new GraphConnection ( g , SWT . NONE , n3 , n3 ) ; g . setLayoutAlgorithm ( new SpringLayoutAlgorithm ( ) , true ) ; shell . open ( ) ; while ( ! shell . isDisposed ( ) ) { while ( ! d . readAndDispatch ( ) ) { d . sleep ( ) ; } } image1 . dispose ( ) ; image2 . dispose ( ) ; image3 . dispose ( ) ; } } </s>
|
<s> package org . eclipse . zest . examples . swt ; import org . eclipse . draw2d . Animation ; import org . eclipse . swt . SWT ; import org . eclipse . swt . events . SelectionEvent ; import org . eclipse . swt . events . SelectionListener ; 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 . widgets . Graph ; import org . eclipse . zest . core . widgets . GraphConnection ; import org . eclipse . zest . core . widgets . GraphNode ; public class AnimationSnippet { public static void main ( String [ ] args ) { Display d = new Display ( ) ; final Shell shell = new Shell ( d ) ; shell . setText ( "<STR_LIT>" ) ; shell . setLayout ( new FillLayout ( SWT . VERTICAL ) ) ; shell . setSize ( <NUM_LIT> , <NUM_LIT> ) ; Button b = new Button ( shell , SWT . PUSH ) ; b . setText ( "<STR_LIT>" ) ; final Graph g = new Graph ( shell , SWT . NONE ) ; final GraphNode n = new GraphNode ( g , SWT . NONE , "<STR_LIT>" ) ; final GraphNode n2 = new GraphNode ( g , SWT . NONE , "<STR_LIT>" ) ; b . addSelectionListener ( new SelectionListener ( ) { public void widgetDefaultSelected ( SelectionEvent e ) { } public void widgetSelected ( SelectionEvent e ) { Animation . markBegin ( ) ; n2 . setLocation ( <NUM_LIT:0> , <NUM_LIT:0> ) ; n . setLocation ( g . getSize ( ) . x - n2 . getSize ( ) . width - <NUM_LIT:5> , <NUM_LIT:0> ) ; Animation . run ( <NUM_LIT:1000> ) ; } } ) ; new GraphConnection ( g , SWT . NONE , n , n2 ) ; int centerX = shell . getSize ( ) . x / <NUM_LIT:2> ; int centerY = shell . getSize ( ) . y / <NUM_LIT:4> ; n . setLocation ( centerX , centerY ) ; n2 . setLocation ( centerX , centerY ) ; shell . open ( ) ; while ( ! shell . isDisposed ( ) ) { while ( ! d . readAndDispatch ( ) ) { d . sleep ( ) ; } } } } </s>
|
<s> package org . eclipse . zest . examples . swt ; 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 . 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 . GridLayoutAlgorithm ; public class GraphSnippet6 { public static void main ( String [ ] args ) { Display d = new Display ( ) ; Shell shell = new Shell ( d ) ; shell . setText ( "<STR_LIT>" ) ; Image image1 = Display . getDefault ( ) . getSystemImage ( SWT . ICON_INFORMATION ) ; Image image2 = Display . getDefault ( ) . getSystemImage ( SWT . ICON_WARNING ) ; Image image3 = Display . getDefault ( ) . getSystemImage ( SWT . ICON_ERROR ) ; shell . setLayout ( new FillLayout ( ) ) ; shell . setSize ( <NUM_LIT> , <NUM_LIT> ) ; Graph g = new Graph ( shell , SWT . NONE ) ; g . setConnectionStyle ( ZestStyles . CONNECTIONS_DIRECTED ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT> ; i ++ ) { GraphNode n1 = new GraphNode ( g , ZestStyles . NODES_HIDE_TEXT | ZestStyles . NODES_FISHEYE ) ; n1 . setText ( "<STR_LIT>" ) ; n1 . setImage ( image1 ) ; GraphNode n2 = new GraphNode ( g , ZestStyles . NODES_HIDE_TEXT | ZestStyles . NODES_FISHEYE ) ; n2 . setText ( "<STR_LIT>" ) ; n2 . setImage ( image2 ) ; GraphNode n3 = new GraphNode ( g , ZestStyles . NODES_HIDE_TEXT | ZestStyles . NODES_FISHEYE ) ; n3 . setText ( "<STR_LIT>" ) ; n3 . setImage ( image3 ) ; new GraphConnection ( g , SWT . NONE , n1 , n2 ) ; new GraphConnection ( g , SWT . NONE , n2 , n3 ) ; new GraphConnection ( g , SWT . NONE , n3 , n3 ) ; } g . setLayoutAlgorithm ( new GridLayoutAlgorithm ( ) , true ) ; shell . open ( ) ; while ( ! shell . isDisposed ( ) ) { while ( ! d . readAndDispatch ( ) ) { d . sleep ( ) ; } } image1 . dispose ( ) ; image2 . dispose ( ) ; image3 . dispose ( ) ; } } </s>
|
<s> package org . eclipse . zest . examples . swt ; 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 . 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 . layouts . LayoutAlgorithm ; import org . eclipse . zest . layouts . algorithms . CompositeLayoutAlgorithm ; import org . eclipse . zest . layouts . algorithms . GridLayoutAlgorithm ; import org . eclipse . zest . layouts . algorithms . HorizontalShiftAlgorithm ; import org . eclipse . zest . layouts . algorithms . RadialLayoutAlgorithm ; import org . eclipse . zest . layouts . algorithms . TreeLayoutAlgorithm ; public class NestedGraphSnippet { private static Image image1 ; private static Image classImage ; public static void createContainer ( Graph g ) { GraphContainer a = new GraphContainer ( g , SWT . NONE ) ; a . setText ( "<STR_LIT>" ) ; a . setImage ( classImage ) ; int r = ( int ) ( ( Math . random ( ) * <NUM_LIT:3> ) + <NUM_LIT:1> ) ; r = <NUM_LIT:2> ; populateContainer ( a , g , r , true ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:4> ; i ++ ) { GraphContainer b = new GraphContainer ( g , SWT . NONE ) ; b . setText ( "<STR_LIT>" ) ; b . setImage ( classImage ) ; r = ( int ) ( ( Math . random ( ) * <NUM_LIT:3> ) + <NUM_LIT:1> ) ; r = <NUM_LIT:2> ; populateContainer ( b , g , r , false ) ; new GraphConnection ( g , SWT . NONE , a , b ) ; for ( int j = <NUM_LIT:0> ; j < <NUM_LIT:4> ; j ++ ) { GraphContainer c = new GraphContainer ( g , SWT . NONE ) ; c . setText ( "<STR_LIT>" ) ; c . setImage ( classImage ) ; r = ( int ) ( ( Math . random ( ) * <NUM_LIT:3> ) + <NUM_LIT:1> ) ; r = <NUM_LIT:2> ; populateContainer ( c , g , r , true ) ; new GraphConnection ( g , SWT . NONE , b , c ) ; } } } public static void populateContainer ( GraphContainer c , Graph g , int number , boolean radial ) { GraphNode a = new GraphNode ( c , ZestStyles . NODES_FISHEYE | ZestStyles . NODES_HIDE_TEXT ) ; a . setText ( "<STR_LIT>" ) ; a . setImage ( classImage ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:4> ; i ++ ) { GraphNode b = new GraphNode ( c , ZestStyles . NODES_FISHEYE | ZestStyles . NODES_HIDE_TEXT ) ; b . setText ( "<STR_LIT>" ) ; b . setImage ( classImage ) ; new GraphConnection ( g , SWT . NONE , a , b ) ; for ( int j = <NUM_LIT:0> ; j < <NUM_LIT:4> ; j ++ ) { GraphNode d = new GraphNode ( c , ZestStyles . NODES_FISHEYE | ZestStyles . NODES_HIDE_TEXT ) ; d . setText ( "<STR_LIT>" ) ; d . setImage ( classImage ) ; new GraphConnection ( g , SWT . NONE , b , d ) ; if ( number > <NUM_LIT:2> ) { for ( int k = <NUM_LIT:0> ; k < <NUM_LIT:4> ; k ++ ) { GraphNode e = new GraphNode ( c , ZestStyles . NODES_FISHEYE | ZestStyles . NODES_HIDE_TEXT ) ; e . setText ( "<STR_LIT>" ) ; e . setImage ( classImage ) ; new GraphConnection ( g , SWT . NONE , d , e ) ; if ( number > <NUM_LIT:3> ) { for ( int l = <NUM_LIT:0> ; l < <NUM_LIT:4> ; l ++ ) { GraphNode f = new GraphNode ( c , ZestStyles . NODES_FISHEYE | ZestStyles . NODES_HIDE_TEXT ) ; f . setText ( "<STR_LIT>" ) ; f . setImage ( classImage ) ; new GraphConnection ( g , SWT . NONE , e , f ) ; } } } } } } if ( number == <NUM_LIT:1> ) { c . setScale ( <NUM_LIT> ) ; } else if ( number == <NUM_LIT:2> ) { c . setScale ( <NUM_LIT> ) ; } else { c . setScale ( <NUM_LIT> ) ; } if ( radial ) { c . setLayoutAlgorithm ( new RadialLayoutAlgorithm ( ) , true ) ; } else { c . setLayoutAlgorithm ( new TreeLayoutAlgorithm ( ) , true ) ; } } public static void main ( String [ ] args ) { Display d = new Display ( ) ; image1 = new Image ( Display . getDefault ( ) , NestedGraphSnippet . class . getResourceAsStream ( "<STR_LIT>" ) ) ; classImage = new Image ( Display . getDefault ( ) , NestedGraphSnippet . class . getResourceAsStream ( "<STR_LIT>" ) ) ; Shell shell = new Shell ( d ) ; shell . setText ( "<STR_LIT>" ) ; shell . setLayout ( new FillLayout ( ) ) ; shell . setSize ( <NUM_LIT> , <NUM_LIT> ) ; Graph g = new Graph ( shell , SWT . NONE ) ; createContainer ( g ) ; CompositeLayoutAlgorithm compositeLayoutAlgorithm = new CompositeLayoutAlgorithm ( new LayoutAlgorithm [ ] { new GridLayoutAlgorithm ( ) , new HorizontalShiftAlgorithm ( ) } ) ; g . setLayoutAlgorithm ( compositeLayoutAlgorithm , true ) ; shell . open ( ) ; while ( ! shell . isDisposed ( ) ) { while ( ! d . readAndDispatch ( ) ) { d . sleep ( ) ; } } image1 . dispose ( ) ; } } </s>
|
<s> package org . eclipse . zest . examples . swt ; import org . eclipse . swt . SWT ; import org . eclipse . swt . events . KeyEvent ; import org . eclipse . swt . events . KeyListener ; 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 . 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 . layouts . LayoutAlgorithm ; import org . eclipse . zest . layouts . algorithms . CompositeLayoutAlgorithm ; import org . eclipse . zest . layouts . algorithms . GridLayoutAlgorithm ; import org . eclipse . zest . layouts . algorithms . HorizontalShiftAlgorithm ; import org . eclipse . zest . layouts . algorithms . RadialLayoutAlgorithm ; import org . eclipse . zest . layouts . algorithms . TreeLayoutAlgorithm ; public class ZoomSnippet { private static Image image1 ; private static Image classImage ; public static void createContainer ( Graph g ) { GraphContainer a = new GraphContainer ( g , SWT . NONE ) ; a . setText ( "<STR_LIT>" ) ; a . setImage ( classImage ) ; int r = ( int ) ( ( Math . random ( ) * <NUM_LIT:3> ) + <NUM_LIT:1> ) ; r = <NUM_LIT:2> ; populateContainer ( a , g , r , true ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:4> ; i ++ ) { GraphContainer b = new GraphContainer ( g , SWT . NONE ) ; b . setText ( "<STR_LIT>" ) ; b . setImage ( classImage ) ; r = ( int ) ( ( Math . random ( ) * <NUM_LIT:3> ) + <NUM_LIT:1> ) ; r = <NUM_LIT:2> ; populateContainer ( b , g , r , false ) ; new GraphConnection ( g , SWT . NONE , a , b ) ; for ( int j = <NUM_LIT:0> ; j < <NUM_LIT:4> ; j ++ ) { GraphContainer c = new GraphContainer ( g , SWT . NONE ) ; c . setText ( "<STR_LIT>" ) ; c . setImage ( classImage ) ; r = ( int ) ( ( Math . random ( ) * <NUM_LIT:3> ) + <NUM_LIT:1> ) ; r = <NUM_LIT:2> ; populateContainer ( c , g , r , true ) ; new GraphConnection ( g , SWT . NONE , b , c ) ; } } } public static void populateContainer ( GraphContainer c , Graph g , int number , boolean radial ) { GraphNode a = new GraphNode ( c , ZestStyles . NODES_FISHEYE | ZestStyles . NODES_HIDE_TEXT ) ; a . setText ( "<STR_LIT>" ) ; a . setImage ( classImage ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:4> ; i ++ ) { GraphNode b = new GraphNode ( c , ZestStyles . NODES_FISHEYE | ZestStyles . NODES_HIDE_TEXT ) ; b . setText ( "<STR_LIT>" ) ; b . setImage ( classImage ) ; new GraphConnection ( g , SWT . NONE , a , b ) ; for ( int j = <NUM_LIT:0> ; j < <NUM_LIT:4> ; j ++ ) { GraphNode d = new GraphNode ( c , ZestStyles . NODES_FISHEYE | ZestStyles . NODES_HIDE_TEXT ) ; d . setText ( "<STR_LIT>" ) ; d . setImage ( classImage ) ; new GraphConnection ( g , SWT . NONE , b , d ) ; if ( number > <NUM_LIT:2> ) { for ( int k = <NUM_LIT:0> ; k < <NUM_LIT:4> ; k ++ ) { GraphNode e = new GraphNode ( c , ZestStyles . NODES_FISHEYE | ZestStyles . NODES_HIDE_TEXT ) ; e . setText ( "<STR_LIT>" ) ; e . setImage ( classImage ) ; new GraphConnection ( g , SWT . NONE , d , e ) ; if ( number > <NUM_LIT:3> ) { for ( int l = <NUM_LIT:0> ; l < <NUM_LIT:4> ; l ++ ) { GraphNode f = new GraphNode ( c , ZestStyles . NODES_FISHEYE | ZestStyles . NODES_HIDE_TEXT ) ; f . setText ( "<STR_LIT>" ) ; f . setImage ( classImage ) ; new GraphConnection ( g , SWT . NONE , e , f ) ; } } } } } } if ( number == <NUM_LIT:1> ) { c . setScale ( <NUM_LIT> ) ; } else if ( number == <NUM_LIT:2> ) { c . setScale ( <NUM_LIT> ) ; } else { c . setScale ( <NUM_LIT> ) ; } if ( radial ) { c . setLayoutAlgorithm ( new RadialLayoutAlgorithm ( ) , true ) ; } else { c . setLayoutAlgorithm ( new TreeLayoutAlgorithm ( ) , true ) ; } } public static void main ( String [ ] args ) { Display d = new Display ( ) ; image1 = new Image ( Display . getDefault ( ) , ZoomSnippet . class . getResourceAsStream ( "<STR_LIT>" ) ) ; classImage = new Image ( Display . getDefault ( ) , ZoomSnippet . class . getResourceAsStream ( "<STR_LIT>" ) ) ; Shell shell = new Shell ( d ) ; shell . setText ( "<STR_LIT>" ) ; shell . setLayout ( new FillLayout ( ) ) ; shell . setSize ( <NUM_LIT> , <NUM_LIT> ) ; final Graph g = new Graph ( shell , SWT . NONE ) ; createContainer ( g ) ; CompositeLayoutAlgorithm compositeLayoutAlgorithm = new CompositeLayoutAlgorithm ( new LayoutAlgorithm [ ] { new GridLayoutAlgorithm ( ) , new HorizontalShiftAlgorithm ( ) } ) ; g . setLayoutAlgorithm ( compositeLayoutAlgorithm , true ) ; g . addKeyListener ( new KeyListener ( ) { boolean flip = true ; public void keyPressed ( KeyEvent e ) { if ( g . getSelection ( ) . size ( ) == <NUM_LIT:1> ) { GraphNode item = ( GraphNode ) g . getSelection ( ) . get ( <NUM_LIT:0> ) ; if ( item . getItemType ( ) == GraphItem . CONTAINER ) { if ( flip ) { ( item ) . setSize ( <NUM_LIT> , <NUM_LIT:100> ) ; } else { ( item ) . setSize ( <NUM_LIT:0> , <NUM_LIT:0> ) ; } flip = ! flip ; } } } public void keyReleased ( KeyEvent e ) { } } ) ; shell . open ( ) ; while ( ! shell . isDisposed ( ) ) { while ( ! d . readAndDispatch ( ) ) { d . sleep ( ) ; } } image1 . dispose ( ) ; } } </s>
|
<s> package org . eclipse . zest . examples . swt ; 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 . 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 . SpringLayoutAlgorithm ; public class GraphSnippet3 { public static void main ( String [ ] args ) { Display d = new Display ( ) ; Shell shell = new Shell ( d ) ; Image image1 = Display . getDefault ( ) . getSystemImage ( SWT . ICON_INFORMATION ) ; Image image2 = Display . getDefault ( ) . getSystemImage ( SWT . ICON_WARNING ) ; Image image3 = Display . getDefault ( ) . getSystemImage ( SWT . ICON_ERROR ) ; shell . setLayout ( new FillLayout ( ) ) ; shell . setSize ( <NUM_LIT> , <NUM_LIT> ) ; Graph g = new Graph ( shell , SWT . NONE ) ; g . addSelectionListener ( new SelectionAdapter ( ) { public void widgetSelected ( SelectionEvent e ) { System . out . println ( ( ( Graph ) e . widget ) . getSelection ( ) ) ; } } ) ; g . setConnectionStyle ( ZestStyles . CONNECTIONS_DIRECTED ) ; GraphNode n1 = new GraphNode ( g , SWT . NONE ) ; n1 . setText ( "<STR_LIT>" ) ; n1 . setImage ( image1 ) ; GraphNode n2 = new GraphNode ( g , SWT . NONE ) ; n2 . setText ( "<STR_LIT>" ) ; n2 . setImage ( image2 ) ; GraphNode n3 = new GraphNode ( g , SWT . NONE ) ; n3 . setText ( "<STR_LIT>" ) ; n3 . setImage ( image3 ) ; new GraphConnection ( g , SWT . NONE , n1 , n2 ) ; new GraphConnection ( g , SWT . NONE , n2 , n3 ) ; g . setLayoutAlgorithm ( new SpringLayoutAlgorithm ( ) , true ) ; shell . open ( ) ; while ( ! shell . isDisposed ( ) ) { while ( ! d . readAndDispatch ( ) ) { d . sleep ( ) ; } } image1 . dispose ( ) ; image2 . dispose ( ) ; image3 . dispose ( ) ; } } </s>
|
<s> package org . eclipse . zest . examples . swt ; import java . util . ArrayList ; import java . util . HashMap ; import java . util . Iterator ; import java . util . List ; import java . util . Map ; import org . eclipse . draw2d . ColorConstants ; import org . eclipse . swt . SWT ; import org . eclipse . swt . events . KeyAdapter ; import org . eclipse . swt . events . KeyEvent ; import org . eclipse . swt . events . PaintEvent ; import org . eclipse . swt . events . PaintListener ; import org . eclipse . swt . graphics . Font ; import org . eclipse . swt . graphics . FontData ; import org . eclipse . swt . graphics . Image ; import org . eclipse . swt . graphics . Region ; 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 . GraphItem ; import org . eclipse . zest . core . widgets . GraphNode ; import org . eclipse . zest . core . widgets . ZestStyles ; public class GraphSnippet5 { public static final int BACKSPACE = <NUM_LIT:8> ; public static final int ENTER = <NUM_LIT> ; public static void main ( String [ ] args ) { final Map figureListing = new HashMap ( ) ; final StringBuffer stringBuffer = new StringBuffer ( ) ; final Display d = new Display ( ) ; FontData fontData = d . getSystemFont ( ) . getFontData ( ) [ <NUM_LIT:0> ] ; fontData . height = <NUM_LIT> ; final Font font = new Font ( d , fontData ) ; Shell shell = new Shell ( d ) ; shell . setText ( "<STR_LIT>" ) ; Image image1 = Display . getDefault ( ) . getSystemImage ( SWT . ICON_INFORMATION ) ; Image image2 = Display . getDefault ( ) . getSystemImage ( SWT . ICON_WARNING ) ; Image image3 = Display . getDefault ( ) . getSystemImage ( SWT . ICON_ERROR ) ; shell . setLayout ( new FillLayout ( ) ) ; shell . setSize ( <NUM_LIT> , <NUM_LIT> ) ; final Graph g = new Graph ( shell , SWT . NONE ) ; g . setConnectionStyle ( ZestStyles . CONNECTIONS_DIRECTED ) ; GraphNode n1 = new GraphNode ( g , SWT . NONE ) ; n1 . setText ( "<STR_LIT>" ) ; n1 . setImage ( image1 ) ; GraphNode n2 = new GraphNode ( g , SWT . NONE ) ; n2 . setText ( "<STR_LIT>" ) ; n2 . setImage ( image2 ) ; GraphNode n3 = new GraphNode ( g , SWT . NONE ) ; n3 . setText ( "<STR_LIT>" ) ; n3 . setImage ( image3 ) ; figureListing . put ( n1 . getText ( ) . toLowerCase ( ) , n1 ) ; figureListing . put ( n2 . getText ( ) . toLowerCase ( ) , n2 ) ; figureListing . put ( n3 . getText ( ) . toLowerCase ( ) , n3 ) ; new GraphConnection ( g , SWT . NONE , n1 , n2 ) ; new GraphConnection ( g , SWT . NONE , n2 , n3 ) ; n1 . setLocation ( <NUM_LIT:10> , <NUM_LIT:10> ) ; n2 . setLocation ( <NUM_LIT> , <NUM_LIT:10> ) ; n3 . setLocation ( <NUM_LIT> , <NUM_LIT> ) ; g . addKeyListener ( new KeyAdapter ( ) { public void keyPressed ( KeyEvent e ) { boolean complete = false ; if ( e . keyCode == BACKSPACE ) { if ( stringBuffer . length ( ) > <NUM_LIT:0> ) { stringBuffer . deleteCharAt ( stringBuffer . length ( ) - <NUM_LIT:1> ) ; } } else if ( e . keyCode == ENTER ) { complete = true ; } else if ( ( e . character >= '<CHAR_LIT:a>' && e . character <= '<CHAR_LIT>' ) || ( e . character >= '<CHAR_LIT:A>' && e . character <= '<CHAR_LIT:Z>' ) || ( e . character == '<CHAR_LIT:.>' ) || ( e . character >= '<CHAR_LIT:0>' && e . character <= '<CHAR_LIT:9>' ) ) { stringBuffer . append ( e . character ) ; } Iterator iterator = figureListing . keySet ( ) . iterator ( ) ; List list = new ArrayList ( ) ; if ( stringBuffer . length ( ) > <NUM_LIT:0> ) { while ( iterator . hasNext ( ) ) { String string = ( String ) iterator . next ( ) ; if ( string . indexOf ( stringBuffer . toString ( ) . toLowerCase ( ) ) >= <NUM_LIT:0> ) { list . add ( figureListing . get ( string ) ) ; } } } g . setSelection ( ( GraphItem [ ] ) list . toArray ( new GraphItem [ list . size ( ) ] ) ) ; if ( complete && stringBuffer . length ( ) > <NUM_LIT:0> ) { stringBuffer . delete ( <NUM_LIT:0> , stringBuffer . length ( ) ) ; } g . redraw ( ) ; } } ) ; g . addPaintListener ( new PaintListener ( ) { public void paintControl ( PaintEvent e ) { e . gc . setFont ( font ) ; e . gc . setClipping ( ( Region ) null ) ; e . gc . setForeground ( ColorConstants . black ) ; e . gc . drawText ( stringBuffer . toString ( ) , <NUM_LIT> , <NUM_LIT> , true ) ; } } ) ; shell . open ( ) ; while ( ! shell . isDisposed ( ) ) { while ( ! d . readAndDispatch ( ) ) { d . sleep ( ) ; } } image1 . dispose ( ) ; image2 . dispose ( ) ; image3 . dispose ( ) ; font . dispose ( ) ; } } </s>
|
<s> package org . eclipse . zest . examples . swt ; 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 . layouts . LayoutAlgorithm ; import org . eclipse . zest . layouts . interfaces . EntityLayout ; import org . eclipse . zest . layouts . interfaces . LayoutContext ; public class CustomLayout { public static void main ( String [ ] args ) { Display d = new Display ( ) ; Shell shell = new Shell ( d ) ; shell . setText ( "<STR_LIT>" ) ; shell . setLayout ( new FillLayout ( ) ) ; shell . setSize ( <NUM_LIT> , <NUM_LIT> ) ; Graph g = new Graph ( shell , SWT . NONE ) ; GraphNode n = new GraphNode ( g , SWT . NONE , "<STR_LIT>" ) ; GraphNode n2 = new GraphNode ( g , SWT . NONE , "<STR_LIT>" ) ; GraphNode n3 = new GraphNode ( g , SWT . NONE , "<STR_LIT>" ) ; new GraphConnection ( g , SWT . NONE , n , n2 ) ; new GraphConnection ( g , SWT . NONE , n2 , n3 ) ; new GraphConnection ( g , SWT . NONE , n3 , n ) ; LayoutAlgorithm layoutAlgorithm = new LayoutAlgorithm ( ) { private LayoutContext context ; public void setLayoutContext ( LayoutContext context ) { this . context = context ; } public void applyLayout ( boolean clean ) { EntityLayout [ ] entitiesToLayout = context . getEntities ( ) ; int totalSteps = entitiesToLayout . length ; double distance = context . getBounds ( ) . width / totalSteps ; int xLocation = <NUM_LIT:0> ; for ( int currentStep = <NUM_LIT:0> ; currentStep < entitiesToLayout . length ; currentStep ++ ) { EntityLayout layoutEntity = entitiesToLayout [ currentStep ] ; layoutEntity . setLocation ( xLocation , layoutEntity . getLocation ( ) . y ) ; xLocation += distance ; } } } ; g . setLayoutAlgorithm ( layoutAlgorithm , true ) ; shell . open ( ) ; while ( ! shell . isDisposed ( ) ) { while ( ! d . readAndDispatch ( ) ) { d . sleep ( ) ; } } } } </s>
|
<s> package org . eclipse . zest . examples . swt ; import org . eclipse . draw2d . SWTGraphics ; import org . eclipse . swt . SWT ; import org . eclipse . swt . events . PaintEvent ; import org . eclipse . swt . events . PaintListener ; import org . eclipse . swt . events . SelectionEvent ; import org . eclipse . swt . events . SelectionListener ; import org . eclipse . swt . graphics . GC ; import org . eclipse . swt . graphics . Image ; import org . eclipse . swt . graphics . Point ; import org . eclipse . swt . layout . FillLayout ; import org . eclipse . swt . widgets . Button ; import org . eclipse . swt . widgets . Canvas ; import org . eclipse . swt . widgets . Display ; import org . eclipse . swt . widgets . Event ; import org . eclipse . swt . widgets . Listener ; 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 . SpringLayoutAlgorithm ; public class PaintSnippet { public static void main ( String [ ] args ) { final Display d = new Display ( ) ; final Shell shell = new Shell ( d ) ; shell . setText ( "<STR_LIT>" ) ; shell . setLayout ( new FillLayout ( ) ) ; shell . setSize ( <NUM_LIT> , <NUM_LIT> ) ; Button b = new Button ( shell , SWT . PUSH ) ; b . setText ( "<STR_LIT>" ) ; final Graph g = new Graph ( shell , SWT . NONE ) ; GraphNode n = new GraphNode ( g , SWT . NONE , "<STR_LIT>" ) ; GraphNode n2 = new GraphNode ( g , SWT . NONE , "<STR_LIT>" ) ; GraphNode n3 = new GraphNode ( g , SWT . NONE , "<STR_LIT>" ) ; new GraphConnection ( g , SWT . NONE , n , n2 ) ; new GraphConnection ( g , SWT . NONE , n2 , n3 ) ; new GraphConnection ( g , SWT . NONE , n3 , n ) ; g . setLayoutAlgorithm ( new SpringLayoutAlgorithm ( ) , true ) ; b . addSelectionListener ( new SelectionListener ( ) { public void widgetDefaultSelected ( SelectionEvent e ) { } public void widgetSelected ( SelectionEvent e ) { Point size = new Point ( g . getContents ( ) . getSize ( ) . width , g . getContents ( ) . getSize ( ) . height ) ; final Image image = new Image ( null , size . x , size . y ) ; GC gc = new GC ( image ) ; SWTGraphics swtGraphics = new SWTGraphics ( gc ) ; g . getContents ( ) . paint ( swtGraphics ) ; gc . copyArea ( image , <NUM_LIT:0> , <NUM_LIT:0> ) ; gc . dispose ( ) ; Shell popup = new Shell ( shell ) ; popup . setText ( "<STR_LIT>" ) ; popup . addListener ( SWT . Close , new Listener ( ) { public void handleEvent ( Event e ) { image . dispose ( ) ; } } ) ; Canvas canvas = new Canvas ( popup , SWT . NONE ) ; canvas . setBounds ( <NUM_LIT:10> , <NUM_LIT:10> , size . x + <NUM_LIT:10> , size . y + <NUM_LIT:10> ) ; canvas . addPaintListener ( new PaintListener ( ) { public void paintControl ( PaintEvent e ) { e . gc . drawImage ( image , <NUM_LIT:0> , <NUM_LIT:0> ) ; } } ) ; popup . pack ( ) ; popup . open ( ) ; } } ) ; shell . open ( ) ; while ( ! shell . isDisposed ( ) ) { while ( ! d . readAndDispatch ( ) ) { d . sleep ( ) ; } } } } </s>
|
<s> package org . eclipse . zest . examples . swt ; import org . eclipse . draw2d . ColorConstants ; 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 . GraphItem ; import org . eclipse . zest . core . widgets . GraphNode ; import org . eclipse . zest . core . widgets . LayoutFilter ; import org . eclipse . zest . core . widgets . ZestStyles ; import org . eclipse . zest . layouts . algorithms . TreeLayoutAlgorithm ; public class GraphSnippet8 { public static void main ( String [ ] args ) { Display display = new Display ( ) ; Shell shell = new Shell ( display ) ; shell . setText ( "<STR_LIT>" ) ; shell . setLayout ( new FillLayout ( ) ) ; shell . setSize ( <NUM_LIT> , <NUM_LIT> ) ; final Graph graph = new Graph ( shell , SWT . NONE ) ; GraphNode a = new GraphNode ( graph , SWT . NONE , "<STR_LIT>" ) ; GraphNode b = new GraphNode ( graph , SWT . NONE , "<STR_LIT:B>" ) ; GraphNode c = new GraphNode ( graph , SWT . NONE , "<STR_LIT:C>" ) ; GraphNode d = new GraphNode ( graph , SWT . NONE , "<STR_LIT:D>" ) ; GraphNode e = new GraphNode ( graph , SWT . NONE , "<STR_LIT:E>" ) ; GraphNode f = new GraphNode ( graph , SWT . NONE , "<STR_LIT:F>" ) ; GraphNode g = new GraphNode ( graph , SWT . NONE , "<STR_LIT>" ) ; GraphNode h = new GraphNode ( graph , SWT . NONE , "<STR_LIT>" ) ; GraphConnection connection = new GraphConnection ( graph , ZestStyles . CONNECTIONS_DIRECTED , a , b ) ; connection . setData ( Boolean . TRUE ) ; connection = new GraphConnection ( graph , ZestStyles . CONNECTIONS_DIRECTED , a , c ) ; connection . setData ( Boolean . TRUE ) ; connection = new GraphConnection ( graph , ZestStyles . CONNECTIONS_DIRECTED , a , c ) ; connection . setData ( Boolean . TRUE ) ; connection = new GraphConnection ( graph , ZestStyles . CONNECTIONS_DIRECTED , a , d ) ; connection . setData ( Boolean . TRUE ) ; connection = new GraphConnection ( graph , ZestStyles . CONNECTIONS_DIRECTED , b , e ) ; connection . setData ( Boolean . FALSE ) ; connection = new GraphConnection ( graph , ZestStyles . CONNECTIONS_DIRECTED , b , f ) ; connection . setData ( Boolean . FALSE ) ; connection = new GraphConnection ( graph , ZestStyles . CONNECTIONS_DIRECTED , c , g ) ; connection . setData ( Boolean . FALSE ) ; connection = new GraphConnection ( graph , ZestStyles . CONNECTIONS_DIRECTED , d , h ) ; connection . setData ( Boolean . FALSE ) ; connection = new GraphConnection ( graph , ZestStyles . CONNECTIONS_DIRECTED , b , c ) ; connection . setLineColor ( ColorConstants . red ) ; connection . setLineWidth ( <NUM_LIT:3> ) ; connection = new GraphConnection ( graph , ZestStyles . CONNECTIONS_DIRECTED , c , d ) ; connection . setLineColor ( ColorConstants . red ) ; connection . setLineWidth ( <NUM_LIT:3> ) ; connection = new GraphConnection ( graph , ZestStyles . CONNECTIONS_DIRECTED , e , f ) ; connection . setLineColor ( ColorConstants . red ) ; connection . setLineWidth ( <NUM_LIT:3> ) ; connection = new GraphConnection ( graph , ZestStyles . CONNECTIONS_DIRECTED , f , g ) ; connection . setLineColor ( ColorConstants . red ) ; connection . setLineWidth ( <NUM_LIT:3> ) ; connection = new GraphConnection ( graph , ZestStyles . CONNECTIONS_DIRECTED , h , e ) ; connection . setLineColor ( ColorConstants . red ) ; connection . setLineWidth ( <NUM_LIT:3> ) ; TreeLayoutAlgorithm treeLayoutAlgorithm = new TreeLayoutAlgorithm ( ) ; LayoutFilter filter = new LayoutFilter ( ) { public boolean isObjectFiltered ( GraphItem item ) { if ( item instanceof GraphConnection ) { GraphConnection connection = ( GraphConnection ) item ; Object data = connection . getData ( ) ; if ( data != null && data instanceof Boolean ) { return ( ( Boolean ) data ) . booleanValue ( ) ; } return true ; } return false ; } } ; graph . addLayoutFilter ( filter ) ; graph . setLayoutAlgorithm ( treeLayoutAlgorithm , true ) ; shell . open ( ) ; while ( ! shell . isDisposed ( ) ) { while ( ! display . readAndDispatch ( ) ) { display . sleep ( ) ; } } } } </s>
|
<s> package org . eclipse . zest . examples . swt ; import org . eclipse . draw2d . IFigure ; import org . eclipse . draw2d . Label ; import org . eclipse . swt . SWT ; import org . eclipse . swt . graphics . GC ; 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 . widgets . Graph ; import org . eclipse . zest . core . widgets . GraphConnection ; import org . eclipse . zest . core . widgets . GraphNode ; import org . eclipse . zest . core . widgets . ZestStyles ; public class GraphSnippet4 { public static Image mergeImages ( Image image1 , Image image2 ) { Image mergedImage = new Image ( Display . getDefault ( ) , image1 . getBounds ( ) . width + image2 . getBounds ( ) . width , image1 . getBounds ( ) . height ) ; GC gc = new GC ( mergedImage ) ; gc . drawImage ( image1 , <NUM_LIT:0> , <NUM_LIT:0> ) ; gc . drawImage ( image2 , image1 . getBounds ( ) . width , <NUM_LIT:0> ) ; gc . dispose ( ) ; return mergedImage ; } public static void main ( String [ ] args ) { Display d = new Display ( ) ; Shell shell = new Shell ( d ) ; shell . setText ( "<STR_LIT>" ) ; Image image1 = Display . getDefault ( ) . getSystemImage ( SWT . ICON_INFORMATION ) ; Image image2 = Display . getDefault ( ) . getSystemImage ( SWT . ICON_WARNING ) ; Image image3 = Display . getDefault ( ) . getSystemImage ( SWT . ICON_ERROR ) ; shell . setLayout ( new FillLayout ( ) ) ; shell . setSize ( <NUM_LIT> , <NUM_LIT> ) ; Graph g = new Graph ( shell , SWT . NONE ) ; g . setConnectionStyle ( ZestStyles . CONNECTIONS_DIRECTED ) ; GraphNode n1 = new GraphNode ( g , SWT . NONE ) ; n1 . setText ( "<STR_LIT>" ) ; n1 . setImage ( image1 ) ; GraphNode n2 = new GraphNode ( g , SWT . NONE ) ; n2 . setText ( "<STR_LIT>" ) ; n2 . setImage ( image2 ) ; GraphNode n3 = new GraphNode ( g , SWT . NONE ) ; n3 . setText ( "<STR_LIT>" ) ; n3 . setImage ( image3 ) ; GraphConnection connection1 = new GraphConnection ( g , SWT . NONE , n1 , n2 ) ; GraphConnection connection2 = new GraphConnection ( g , SWT . NONE , n2 , n3 ) ; Image information2warningImage = mergeImages ( image1 , image2 ) ; Image warning2error = mergeImages ( image2 , image3 ) ; IFigure tooltip1 = new Label ( "<STR_LIT>" , information2warningImage ) ; IFigure tooltip2 = new Label ( "<STR_LIT>" , warning2error ) ; connection1 . setTooltip ( tooltip1 ) ; connection2 . setTooltip ( tooltip2 ) ; n1 . setLocation ( <NUM_LIT:10> , <NUM_LIT:10> ) ; n2 . setLocation ( <NUM_LIT> , <NUM_LIT:10> ) ; n3 . setLocation ( <NUM_LIT> , <NUM_LIT> ) ; shell . open ( ) ; while ( ! shell . isDisposed ( ) ) { while ( ! d . readAndDispatch ( ) ) { d . sleep ( ) ; } } image1 . dispose ( ) ; image2 . dispose ( ) ; image3 . dispose ( ) ; information2warningImage . dispose ( ) ; warning2error . dispose ( ) ; } } </s>
|
<s> package org . eclipse . zest . examples . swt ; import org . eclipse . swt . SWT ; import org . eclipse . swt . events . MouseEvent ; import org . eclipse . swt . events . MouseMoveListener ; 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 . layouts . algorithms . SpringLayoutAlgorithm ; public class GraphSnippet7 { public static void main ( String [ ] args ) { Display d = new Display ( ) ; Shell shell = new Shell ( d ) ; shell . setText ( "<STR_LIT>" ) ; shell . setLayout ( new FillLayout ( ) ) ; shell . setSize ( <NUM_LIT> , <NUM_LIT> ) ; final Graph g = new Graph ( shell , SWT . NONE ) ; GraphNode n = new GraphNode ( g , SWT . NONE , "<STR_LIT>" ) ; GraphNode n2 = new GraphNode ( g , SWT . NONE , "<STR_LIT>" ) ; GraphNode n3 = new GraphNode ( g , SWT . NONE , "<STR_LIT>" ) ; new GraphConnection ( g , SWT . NONE , n , n2 ) ; new GraphConnection ( g , SWT . NONE , n2 , n3 ) ; new GraphConnection ( g , SWT . NONE , n3 , n ) ; g . setLayoutAlgorithm ( new SpringLayoutAlgorithm ( ) , true ) ; g . addMouseMoveListener ( new MouseMoveListener ( ) { public void mouseMove ( MouseEvent e ) { Object o = g . getFigureAt ( e . x , e . y ) ; if ( o != null ) { System . out . println ( o + "<STR_LIT>" + e . x + "<STR_LIT:U+002C>" + e . y + "<STR_LIT:)>" ) ; } } } ) ; shell . open ( ) ; while ( ! shell . isDisposed ( ) ) { while ( ! d . readAndDispatch ( ) ) { d . sleep ( ) ; } } } } </s>
|
<s> package org . eclipse . zest . examples . swt ; import java . util . Iterator ; import org . eclipse . draw2d . ColorConstants ; import org . eclipse . draw2d . Ellipse ; import org . eclipse . draw2d . Figure ; import org . eclipse . draw2d . FlowLayout ; import org . eclipse . draw2d . FreeformLayout ; import org . eclipse . draw2d . IFigure ; import org . eclipse . draw2d . ImageFigure ; import org . eclipse . draw2d . Label ; import org . eclipse . draw2d . MarginBorder ; import org . eclipse . draw2d . PolylineShape ; import org . eclipse . draw2d . geometry . Point ; import org . eclipse . draw2d . geometry . Rectangle ; import org . eclipse . swt . SWT ; import org . eclipse . swt . events . SelectionEvent ; import org . eclipse . swt . events . SelectionListener ; 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 . 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 . core . widgets . custom . CGraphNode ; import org . eclipse . zest . layouts . algorithms . SpringLayoutAlgorithm ; public class GraphSnippet13 { public static IFigure createPersonFigure ( Image headImage ) { Figure person = new Figure ( ) ; person . setLayoutManager ( new FreeformLayout ( ) ) ; IFigure head = null ; if ( headImage != null ) { headImage = new Image ( headImage . getDevice ( ) , headImage . getImageData ( ) . scaledTo ( <NUM_LIT> , <NUM_LIT> ) ) ; head = new ImageFigure ( headImage ) ; } else head = new Ellipse ( ) ; head . setSize ( <NUM_LIT> , <NUM_LIT> ) ; PolylineShape body = new PolylineShape ( ) ; body . setLineWidth ( <NUM_LIT:1> ) ; body . setStart ( new Point ( <NUM_LIT:20> , <NUM_LIT> ) ) ; body . setEnd ( new Point ( <NUM_LIT:20> , <NUM_LIT:100> ) ) ; body . setBounds ( new Rectangle ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:100> ) ) ; PolylineShape leftLeg = new PolylineShape ( ) ; leftLeg . setLineWidth ( <NUM_LIT:1> ) ; leftLeg . setStart ( new Point ( <NUM_LIT:20> , <NUM_LIT:100> ) ) ; leftLeg . setEnd ( new Point ( <NUM_LIT:0> , <NUM_LIT> ) ) ; leftLeg . setBounds ( new Rectangle ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT> ) ) ; PolylineShape rightLeg = new PolylineShape ( ) ; rightLeg . setLineWidth ( <NUM_LIT:1> ) ; rightLeg . setStart ( new Point ( <NUM_LIT:20> , <NUM_LIT:100> ) ) ; rightLeg . setEnd ( new Point ( <NUM_LIT> , <NUM_LIT> ) ) ; rightLeg . setBounds ( new Rectangle ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT> ) ) ; PolylineShape leftArm = new PolylineShape ( ) ; leftArm . setLineWidth ( <NUM_LIT:1> ) ; leftArm . setStart ( new Point ( <NUM_LIT:20> , <NUM_LIT> ) ) ; leftArm . setEnd ( new Point ( <NUM_LIT:0> , <NUM_LIT> ) ) ; leftArm . setBounds ( new Rectangle ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT> ) ) ; PolylineShape rightArm = new PolylineShape ( ) ; rightArm . setLineWidth ( <NUM_LIT:1> ) ; rightArm . setStart ( new Point ( <NUM_LIT:20> , <NUM_LIT> ) ) ; rightArm . setEnd ( new Point ( <NUM_LIT> , <NUM_LIT> ) ) ; rightArm . setBounds ( new Rectangle ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT> ) ) ; person . add ( head ) ; person . add ( body ) ; person . add ( leftLeg ) ; person . add ( rightLeg ) ; person . add ( leftArm ) ; person . add ( rightArm ) ; person . setSize ( <NUM_LIT> , <NUM_LIT> ) ; return person ; } public static void main ( String [ ] args ) { final Display d = new Display ( ) ; Shell shell = new Shell ( d ) ; shell . setText ( "<STR_LIT>" ) ; shell . setLayout ( new FillLayout ( ) ) ; shell . setSize ( <NUM_LIT> , <NUM_LIT> ) ; final Graph g = new Graph ( shell , SWT . NONE ) ; g . addSelectionListener ( new SelectionListener ( ) { public void widgetSelected ( SelectionEvent e ) { Iterator iter = g . getSelection ( ) . iterator ( ) ; while ( iter . hasNext ( ) ) { Object o = iter . next ( ) ; if ( o instanceof CGraphNode ) { IFigure figure = ( ( CGraphNode ) o ) . getFigure ( ) ; figure . setBackgroundColor ( ColorConstants . blue ) ; figure . setForegroundColor ( ColorConstants . blue ) ; } } iter = g . getNodes ( ) . iterator ( ) ; while ( iter . hasNext ( ) ) { Object o = iter . next ( ) ; if ( o instanceof CGraphNode ) { if ( ! g . getSelection ( ) . contains ( o ) ) { ( ( CGraphNode ) o ) . getFigure ( ) . setBackgroundColor ( ColorConstants . black ) ; ( ( CGraphNode ) o ) . getFigure ( ) . setForegroundColor ( ColorConstants . black ) ; } } } } public void widgetDefaultSelected ( SelectionEvent e ) { } } ) ; Image zx = new Image ( d , "<STR_LIT>" ) ; IFigure tooltip = new Figure ( ) ; tooltip . setBorder ( new MarginBorder ( <NUM_LIT:5> , <NUM_LIT:5> , <NUM_LIT:5> , <NUM_LIT:5> ) ) ; FlowLayout layout = new FlowLayout ( false ) ; layout . setMajorSpacing ( <NUM_LIT:3> ) ; layout . setMinorAlignment ( <NUM_LIT:3> ) ; tooltip . setLayoutManager ( new FlowLayout ( false ) ) ; tooltip . add ( new ImageFigure ( zx ) ) ; tooltip . add ( new Label ( "<STR_LIT>" + "<STR_LIT>" ) ) ; tooltip . add ( new Label ( "<STR_LIT>" + "<STR_LIT>" ) ) ; Image ibull = new Image ( d , "<STR_LIT>" ) ; GraphContainer c1 = new GraphContainer ( g , SWT . NONE ) ; c1 . setText ( "<STR_LIT>" ) ; GraphContainer c2 = new GraphContainer ( g , SWT . NONE ) ; c2 . setText ( "<STR_LIT>" ) ; GraphNode n1 = new GraphNode ( c1 , SWT . NONE , "<STR_LIT>" ) ; n1 . setSize ( <NUM_LIT> , <NUM_LIT:100> ) ; GraphNode n2 = new GraphNode ( c2 , SWT . NONE , "<STR_LIT>" ) ; n2 . setTooltip ( tooltip ) ; GraphConnection connection = new GraphConnection ( g , ZestStyles . CONNECTIONS_DIRECTED , n1 , n2 ) ; connection . setCurveDepth ( - <NUM_LIT:30> ) ; GraphConnection connection2 = new GraphConnection ( g , ZestStyles . CONNECTIONS_DIRECTED , n2 , n1 ) ; connection2 . setCurveDepth ( - <NUM_LIT:30> ) ; g . setLayoutAlgorithm ( new SpringLayoutAlgorithm ( ) , true ) ; shell . open ( ) ; while ( ! shell . isDisposed ( ) ) { while ( ! d . readAndDispatch ( ) ) { d . sleep ( ) ; } } zx . dispose ( ) ; ibull . dispose ( ) ; } } </s>
|
<s> package org . eclipse . zest . examples . swt ; import org . eclipse . swt . SWT ; import org . eclipse . swt . events . SelectionAdapter ; import org . eclipse . swt . events . SelectionEvent ; 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 . widgets . Graph ; import org . eclipse . zest . core . widgets . GraphConnection ; import org . eclipse . zest . core . widgets . GraphNode ; import org . eclipse . zest . layouts . algorithms . SpringLayoutAlgorithm ; public class GraphSnippet10 { public static void main ( String [ ] args ) { Display d = new Display ( ) ; Shell shell = new Shell ( d ) ; shell . setText ( "<STR_LIT>" ) ; shell . setLayout ( new FillLayout ( ) ) ; shell . setSize ( <NUM_LIT> , <NUM_LIT> ) ; final Graph g = new Graph ( shell , SWT . NONE ) ; GraphNode n = new GraphNode ( g , SWT . NONE , "<STR_LIT>" ) ; n . setBorderColor ( org . eclipse . draw2d . ColorConstants . yellow ) ; n . setBorderWidth ( <NUM_LIT:3> ) ; GraphNode n2 = new GraphNode ( g , SWT . NONE , "<STR_LIT>" ) ; GraphNode n3 = new GraphNode ( g , SWT . NONE , "<STR_LIT>" ) ; final GraphConnection connection = new GraphConnection ( g , SWT . NONE , n , n2 ) ; connection . setLineWidth ( <NUM_LIT:3> ) ; new GraphConnection ( g , SWT . NONE , n2 , n3 ) ; new GraphConnection ( g , SWT . NONE , n3 , n ) ; g . setLayoutAlgorithm ( new SpringLayoutAlgorithm ( ) , true ) ; Button button = new Button ( shell , SWT . PUSH ) ; button . setText ( "<STR_LIT>" ) ; button . addSelectionListener ( new SelectionAdapter ( ) { int count = <NUM_LIT:0> ; public void widgetSelected ( SelectionEvent e ) { count = ++ count % <NUM_LIT:16> ; if ( count > <NUM_LIT:8> ) { connection . setCurveDepth ( ( - <NUM_LIT:16> + count ) * <NUM_LIT:10> ) ; } else { connection . setCurveDepth ( count * <NUM_LIT:10> ) ; } } } ) ; shell . open ( ) ; while ( ! shell . isDisposed ( ) ) { while ( ! d . readAndDispatch ( ) ) { d . sleep ( ) ; } } } } </s>
|
<s> package org . eclipse . zest . examples . swt ; import java . util . Iterator ; import org . eclipse . draw2d . ColorConstants ; import org . eclipse . draw2d . Ellipse ; import org . eclipse . draw2d . Figure ; import org . eclipse . draw2d . FreeformLayout ; import org . eclipse . draw2d . IFigure ; import org . eclipse . draw2d . ImageFigure ; import org . eclipse . draw2d . PolylineShape ; import org . eclipse . draw2d . geometry . Point ; import org . eclipse . draw2d . geometry . Rectangle ; import org . eclipse . swt . SWT ; import org . eclipse . swt . events . SelectionEvent ; import org . eclipse . swt . events . SelectionListener ; 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 . widgets . Graph ; import org . eclipse . zest . core . widgets . GraphConnection ; import org . eclipse . zest . core . widgets . GraphNode ; import org . eclipse . zest . core . widgets . custom . CGraphNode ; import org . eclipse . zest . layouts . algorithms . SpringLayoutAlgorithm ; public class GraphSnippet12 { public static IFigure createPersonFigure ( Image headImage ) { Figure person = new Figure ( ) ; person . setLayoutManager ( new FreeformLayout ( ) ) ; IFigure head = null ; if ( headImage != null ) { headImage = new Image ( headImage . getDevice ( ) , headImage . getImageData ( ) . scaledTo ( <NUM_LIT> , <NUM_LIT> ) ) ; head = new ImageFigure ( headImage ) ; } else head = new Ellipse ( ) ; head . setSize ( <NUM_LIT> , <NUM_LIT> ) ; PolylineShape body = new PolylineShape ( ) ; body . setLineWidth ( <NUM_LIT:1> ) ; body . setStart ( new Point ( <NUM_LIT:20> , <NUM_LIT> ) ) ; body . setEnd ( new Point ( <NUM_LIT:20> , <NUM_LIT:100> ) ) ; body . setBounds ( new Rectangle ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:100> ) ) ; PolylineShape leftLeg = new PolylineShape ( ) ; leftLeg . setLineWidth ( <NUM_LIT:1> ) ; leftLeg . setStart ( new Point ( <NUM_LIT:20> , <NUM_LIT:100> ) ) ; leftLeg . setEnd ( new Point ( <NUM_LIT:0> , <NUM_LIT> ) ) ; leftLeg . setBounds ( new Rectangle ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT> ) ) ; PolylineShape rightLeg = new PolylineShape ( ) ; rightLeg . setLineWidth ( <NUM_LIT:1> ) ; rightLeg . setStart ( new Point ( <NUM_LIT:20> , <NUM_LIT:100> ) ) ; rightLeg . setEnd ( new Point ( <NUM_LIT> , <NUM_LIT> ) ) ; rightLeg . setBounds ( new Rectangle ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT> ) ) ; PolylineShape leftArm = new PolylineShape ( ) ; leftArm . setLineWidth ( <NUM_LIT:1> ) ; leftArm . setStart ( new Point ( <NUM_LIT:20> , <NUM_LIT> ) ) ; leftArm . setEnd ( new Point ( <NUM_LIT:0> , <NUM_LIT> ) ) ; leftArm . setBounds ( new Rectangle ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT> ) ) ; PolylineShape rightArm = new PolylineShape ( ) ; rightArm . setLineWidth ( <NUM_LIT:1> ) ; rightArm . setStart ( new Point ( <NUM_LIT:20> , <NUM_LIT> ) ) ; rightArm . setEnd ( new Point ( <NUM_LIT> , <NUM_LIT> ) ) ; rightArm . setBounds ( new Rectangle ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT> ) ) ; person . add ( head ) ; person . add ( body ) ; person . add ( leftLeg ) ; person . add ( rightLeg ) ; person . add ( leftArm ) ; person . add ( rightArm ) ; person . setSize ( <NUM_LIT> , <NUM_LIT> ) ; return person ; } public static void main ( String [ ] args ) { final Display d = new Display ( ) ; Shell shell = new Shell ( d ) ; shell . setText ( "<STR_LIT>" ) ; shell . setLayout ( new FillLayout ( ) ) ; shell . setSize ( <NUM_LIT> , <NUM_LIT> ) ; final Graph g = new Graph ( shell , SWT . NONE ) ; g . addSelectionListener ( new SelectionListener ( ) { public void widgetSelected ( SelectionEvent e ) { Iterator iter = g . getSelection ( ) . iterator ( ) ; while ( iter . hasNext ( ) ) { Object o = iter . next ( ) ; if ( o instanceof CGraphNode ) { IFigure figure = ( ( CGraphNode ) o ) . getFigure ( ) ; figure . setBackgroundColor ( ColorConstants . blue ) ; figure . setForegroundColor ( ColorConstants . blue ) ; } } iter = g . getNodes ( ) . iterator ( ) ; while ( iter . hasNext ( ) ) { Object o = iter . next ( ) ; if ( o instanceof CGraphNode ) { if ( ! g . getSelection ( ) . contains ( o ) ) { ( ( CGraphNode ) o ) . getFigure ( ) . setBackgroundColor ( ColorConstants . black ) ; ( ( CGraphNode ) o ) . getFigure ( ) . setForegroundColor ( ColorConstants . black ) ; } } } } public void widgetDefaultSelected ( SelectionEvent e ) { } } ) ; Image zx = new Image ( d , "<STR_LIT>" ) ; Image ibull = new Image ( d , "<STR_LIT>" ) ; CGraphNode n = new CGraphNode ( g , SWT . NONE , createPersonFigure ( zx ) ) ; CGraphNode n2 = new CGraphNode ( g , SWT . NONE , createPersonFigure ( ibull ) ) ; GraphNode n3 = new GraphNode ( g , SWT . NONE , "<STR_LIT>" ) ; GraphNode n4 = new GraphNode ( g , SWT . NONE , "<STR_LIT>" ) ; GraphNode n5 = new GraphNode ( g , SWT . NONE , "<STR_LIT>" ) ; new GraphConnection ( g , SWT . NONE , n , n2 ) ; new GraphConnection ( g , SWT . NONE , n , n3 ) ; new GraphConnection ( g , SWT . NONE , n2 , n4 ) ; new GraphConnection ( g , SWT . NONE , n , n5 ) ; new GraphConnection ( g , SWT . NONE , n2 , n5 ) ; new GraphConnection ( g , SWT . NONE , n3 , n5 ) ; new GraphConnection ( g , SWT . NONE , n4 , n5 ) ; g . setLayoutAlgorithm ( new SpringLayoutAlgorithm ( ) , true ) ; shell . open ( ) ; while ( ! shell . isDisposed ( ) ) { while ( ! d . readAndDispatch ( ) ) { d . sleep ( ) ; } } zx . dispose ( ) ; ibull . dispose ( ) ; } } </s>
|
<s> package org . eclipse . zest . examples . swt ; import org . eclipse . draw2d . ColorConstants ; import org . eclipse . swt . SWT ; import org . eclipse . swt . graphics . Color ; 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 . layouts . algorithms . SpringLayoutAlgorithm ; public class GraphSnippet11 { public static void createConnection ( Graph g , GraphNode n1 , GraphNode n2 , Color color , int curve ) { GraphConnection connection = new GraphConnection ( g , SWT . NONE , n1 , n2 ) ; connection . setLineColor ( color ) ; connection . setCurveDepth ( curve ) ; connection . setLineWidth ( <NUM_LIT:1> ) ; } public static void main ( String [ ] args ) { Display d = new Display ( ) ; Shell shell = new Shell ( d ) ; shell . setText ( "<STR_LIT>" ) ; shell . setLayout ( new FillLayout ( ) ) ; shell . setSize ( <NUM_LIT> , <NUM_LIT> ) ; final Graph g = new Graph ( shell , SWT . NONE ) ; GraphNode n = new GraphNode ( g , SWT . NONE , "<STR_LIT>" ) ; GraphNode n2 = new GraphNode ( g , SWT . NONE , "<STR_LIT>" ) ; createConnection ( g , n , n2 , ColorConstants . darkGreen , <NUM_LIT:20> ) ; createConnection ( g , n , n2 , ColorConstants . darkGreen , - <NUM_LIT:20> ) ; createConnection ( g , n , n2 , ColorConstants . darkBlue , <NUM_LIT> ) ; createConnection ( g , n , n2 , ColorConstants . darkBlue , - <NUM_LIT> ) ; createConnection ( g , n , n2 , ColorConstants . darkGray , <NUM_LIT> ) ; createConnection ( g , n , n2 , ColorConstants . darkGray , - <NUM_LIT> ) ; createConnection ( g , n , n2 , ColorConstants . black , <NUM_LIT:0> ) ; g . setLayoutAlgorithm ( new SpringLayoutAlgorithm ( ) , true ) ; shell . open ( ) ; while ( ! shell . isDisposed ( ) ) { while ( ! d . readAndDispatch ( ) ) { d . sleep ( ) ; } } } } </s>
|
<s> package org . eclipse . zest . internal . dot ; import org . eclipse . zest . core . widgets . * ; import org . eclipse . swt . SWT ; import org . eclipse . zest . layouts . algorithms . * ; import org . eclipse . zest . layouts . * ; public class DotTemplate { protected static String nl ; public static synchronized DotTemplate create ( String lineSeparator ) { nl = lineSeparator ; DotTemplate result = new DotTemplate ( ) ; nl = null ; return result ; } public final String NL = nl == null ? ( System . getProperties ( ) . getProperty ( "<STR_LIT>" ) ) : nl ; protected final String TEXT_1 = "<STR_LIT>" ; protected final String TEXT_2 = NL ; protected final String TEXT_3 = "<STR_LIT:U+0020>" ; protected final String TEXT_4 = "<STR_LIT:{>" + NL + "<STR_LIT>" + NL + "<STR_LIT>" + NL + "<STR_LIT>" ; protected final String TEXT_5 = "<STR_LIT:]>" + NL + "<STR_LIT>" + NL + "<STR_LIT>" ; protected final String TEXT_6 = NL + "<STR_LIT:t>" + NL + "<STR_LIT>" + NL + "<STR_LIT:t>" ; protected final String TEXT_7 = "<STR_LIT:U+0020>" + NL + "<STR_LIT:t>" ; protected final String TEXT_8 = "<STR_LIT>" ; protected final String TEXT_9 = "<STR_LIT>" ; protected final String TEXT_10 = NL + "<STR_LIT:t>" ; protected final String TEXT_11 = "<STR_LIT:U+0020>" + NL + "<STR_LIT>" ; protected final String TEXT_12 = "<STR_LIT:U+0020>" ; protected final String TEXT_13 = NL + "<STR_LIT>" ; protected final String TEXT_14 = "<STR_LIT>" ; protected final String TEXT_15 = "<STR_LIT>" ; protected final String TEXT_16 = NL + "<STR_LIT:t>" ; protected final String TEXT_17 = NL + "<STR_LIT:t>" ; protected final String TEXT_18 = NL + "<STR_LIT:t>" + NL + "<STR_LIT>" + NL + "<STR_LIT:t>" ; protected final String TEXT_19 = "<STR_LIT:U+0020>" + NL + "<STR_LIT:t>" ; protected final String TEXT_20 = "<STR_LIT:U+0020>" + NL + "<STR_LIT:t>" ; protected final String TEXT_21 = "<STR_LIT:U+0020>" ; protected final String TEXT_22 = "<STR_LIT:U+0020>" ; protected final String TEXT_23 = "<STR_LIT>" ; protected final String TEXT_24 = "<STR_LIT>" ; protected final String TEXT_25 = "<STR_LIT>" + NL + "<STR_LIT:t>" ; protected final String TEXT_26 = NL + "<STR_LIT:}>" ; public String generate ( Object argument ) { final StringBuffer stringBuffer = new StringBuffer ( ) ; Graph graph = ( Graph ) argument ; boolean small = graph . getNodes ( ) . size ( ) < <NUM_LIT:100> ; LayoutAlgorithm algo = graph . getLayoutAlgorithm ( ) != null ? graph . getLayoutAlgorithm ( ) : new TreeLayoutAlgorithm ( ) ; boolean digraph = graph . getConnectionStyle ( ) == ZestStyles . CONNECTIONS_DIRECTED ; String simpleClassName = graph . getClass ( ) . getSimpleName ( ) ; simpleClassName = simpleClassName . equals ( "<STR_LIT>" ) ? "<STR_LIT>" + simpleClassName : simpleClassName ; stringBuffer . append ( TEXT_1 ) ; stringBuffer . append ( TEXT_2 ) ; stringBuffer . append ( digraph ? "<STR_LIT>" : "<STR_LIT>" ) ; stringBuffer . append ( TEXT_3 ) ; stringBuffer . append ( simpleClassName ) ; stringBuffer . append ( TEXT_4 ) ; stringBuffer . append ( ( algo . getClass ( ) == RadialLayoutAlgorithm . class ) ? "<STR_LIT>" : ( algo . getClass ( ) == GridLayoutAlgorithm . class ) ? "<STR_LIT>" : ( algo . getClass ( ) == SpringLayoutAlgorithm . class ) ? ( small ? "<STR_LIT>" : "<STR_LIT>" ) : "<STR_LIT>" ) ; stringBuffer . append ( TEXT_5 ) ; stringBuffer . append ( ( graph . getLayoutAlgorithm ( ) != null && graph . getLayoutAlgorithm ( ) . getClass ( ) == TreeLayoutAlgorithm . class && ( ( TreeLayoutAlgorithm ) graph . getLayoutAlgorithm ( ) ) . getDirection ( ) == TreeLayoutAlgorithm . LEFT_RIGHT ) ? "<STR_LIT>" : "<STR_LIT>" ) ; stringBuffer . append ( TEXT_6 ) ; for ( Object nodeObject : graph . getNodes ( ) ) { GraphNode node = ( GraphNode ) nodeObject ; stringBuffer . append ( TEXT_7 ) ; if ( ! ( node instanceof GraphContainer ) ) { stringBuffer . append ( node . hashCode ( ) ) ; stringBuffer . append ( TEXT_8 ) ; stringBuffer . append ( node . getText ( ) ) ; stringBuffer . append ( TEXT_9 ) ; } stringBuffer . append ( TEXT_10 ) ; if ( node instanceof GraphContainer ) { stringBuffer . append ( TEXT_11 ) ; for ( Object o : ( ( GraphContainer ) node ) . getNodes ( ) ) { GraphNode n = ( GraphNode ) o ; stringBuffer . append ( TEXT_12 ) ; stringBuffer . append ( TEXT_13 ) ; stringBuffer . append ( n . hashCode ( ) ) ; stringBuffer . append ( TEXT_14 ) ; stringBuffer . append ( n . getText ( ) ) ; stringBuffer . append ( TEXT_15 ) ; } stringBuffer . append ( TEXT_16 ) ; } stringBuffer . append ( TEXT_17 ) ; } stringBuffer . append ( TEXT_18 ) ; for ( Object edgeObject : graph . getConnections ( ) ) { GraphConnection edge = ( GraphConnection ) edgeObject ; stringBuffer . append ( TEXT_19 ) ; boolean dashed = edge . getLineStyle ( ) == SWT . LINE_DASH ; boolean dotted = edge . getLineStyle ( ) == SWT . LINE_DOT ; stringBuffer . append ( TEXT_20 ) ; stringBuffer . append ( edge . getSource ( ) . hashCode ( ) ) ; stringBuffer . append ( TEXT_21 ) ; stringBuffer . append ( digraph ? "<STR_LIT>" : "<STR_LIT:-->" ) ; stringBuffer . append ( TEXT_22 ) ; stringBuffer . append ( edge . getDestination ( ) . hashCode ( ) ) ; stringBuffer . append ( TEXT_23 ) ; stringBuffer . append ( dashed ? "<STR_LIT>" : dotted ? "<STR_LIT>" : "<STR_LIT>" ) ; stringBuffer . append ( TEXT_24 ) ; stringBuffer . append ( edge . getText ( ) ) ; stringBuffer . append ( TEXT_25 ) ; } stringBuffer . append ( TEXT_26 ) ; return stringBuffer . toString ( ) ; } } </s>
|
<s> package org . eclipse . zest . internal . dot ; import java . io . Closeable ; import java . io . File ; import java . io . FileNotFoundException ; import java . io . FileOutputStream ; import java . io . FileWriter ; import java . io . IOException ; import java . io . InputStream ; import java . net . MalformedURLException ; import java . net . URISyntaxException ; import java . net . URL ; import java . util . Scanner ; import org . eclipse . core . runtime . FileLocator ; public final class DotFileUtils { private DotFileUtils ( ) { } public static File resolve ( final URL url ) { File resultFile = null ; URL resolved = url ; if ( ! url . getProtocol ( ) . equals ( "<STR_LIT:file>" ) ) { try { resolved = FileLocator . resolve ( resolved ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } try { resultFile = new File ( resolved . toURI ( ) ) ; } catch ( URISyntaxException e ) { e . printStackTrace ( ) ; } return resultFile ; } public static File write ( final String text ) { try { return write ( text , File . createTempFile ( "<STR_LIT>" , "<STR_LIT>" ) ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } return null ; } public static File write ( final String text , final File destination ) { try { FileWriter writer = new FileWriter ( destination ) ; writer . write ( text ) ; writer . flush ( ) ; writer . close ( ) ; return destination ; } catch ( IOException e ) { e . printStackTrace ( ) ; } return null ; } public static String read ( final File file ) { StringBuilder builder = new StringBuilder ( ) ; try { Scanner s = new Scanner ( file ) ; while ( s . hasNextLine ( ) ) { builder . append ( s . nextLine ( ) ) . append ( "<STR_LIT:n>" ) ; } } catch ( FileNotFoundException e ) { e . printStackTrace ( ) ; } return builder . toString ( ) ; } public static void close ( final Closeable closeable ) { if ( closeable != null ) { try { closeable . close ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } } public static void copyAllFiles ( final File sourceRootFolder , final File destinationRootFolder ) { for ( String name : sourceRootFolder . list ( ) ) { File source = new File ( sourceRootFolder , name ) ; if ( source . getName ( ) . equals ( "<STR_LIT>" ) ) { continue ; } if ( source . isDirectory ( ) ) { File destinationFolder = new File ( destinationRootFolder , source . getName ( ) ) ; if ( ! destinationFolder . mkdirs ( ) && ! destinationFolder . exists ( ) ) { throw new IllegalStateException ( DotMessages . DotFileUtils_0 + "<STR_LIT::U+0020>" + destinationFolder ) ; } copyAllFiles ( source , destinationFolder ) ; } else { copySingleFile ( destinationRootFolder , name , source ) ; } } } public static File copySingleFile ( final File destinationFolder , final String newFileName , final File sourceFile ) { File destinationFile = new File ( destinationFolder , newFileName ) ; InputStream sourceStream = null ; FileOutputStream destinationStream = null ; try { sourceStream = sourceFile . toURI ( ) . toURL ( ) . openStream ( ) ; destinationStream = new FileOutputStream ( destinationFile ) ; byte [ ] buffer = new byte [ <NUM_LIT> ] ; int bytesRead ; while ( ( bytesRead = sourceStream . read ( buffer ) ) != - <NUM_LIT:1> ) { destinationStream . write ( buffer , <NUM_LIT:0> , bytesRead ) ; } } catch ( MalformedURLException e ) { e . printStackTrace ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } finally { close ( sourceStream ) ; close ( destinationStream ) ; } return destinationFile ; } } </s>
|
<s> package org . eclipse . zest . internal . dot ; import java . io . File ; import java . io . IOException ; import java . io . InputStream ; import java . util . Arrays ; final class DotDrawer { private DotDrawer ( ) { } static File renderImage ( final File dotExecutableDir , final File dotInputFile , final String format , final String imageResultFile ) { String outputFormat = "<STR_LIT>" + format ; String resultFile = imageResultFile == null ? dotInputFile . getName ( ) + "<STR_LIT:.>" + format : imageResultFile ; String dotFile = dotInputFile . getName ( ) ; String inputFolder = new File ( dotInputFile . getParent ( ) ) . getAbsolutePath ( ) + File . separator ; String outputFolder = imageResultFile == null ? inputFolder : new File ( new File ( imageResultFile ) . getAbsolutePath ( ) ) . getParentFile ( ) . getAbsolutePath ( ) + File . separator ; String dotExecutable = "<STR_LIT>" + ( runningOnWindows ( ) ? "<STR_LIT>" : "<STR_LIT>" ) ; String [ ] commands = new String [ ] { dotExecutableDir . getAbsolutePath ( ) + File . separator + dotExecutable , outputFormat , "<STR_LIT>" , outputFolder + resultFile , inputFolder + dotFile } ; call ( commands ) ; return new File ( outputFolder , resultFile ) ; } private static void call ( final String [ ] commands ) { System . out . print ( "<STR_LIT>" + Arrays . asList ( commands ) ) ; Runtime runtime = Runtime . getRuntime ( ) ; Process p = null ; try { p = runtime . exec ( commands ) ; p . waitFor ( ) ; } catch ( Exception x ) { x . printStackTrace ( ) ; } System . out . println ( "<STR_LIT:U+002CU+0020>" + "<STR_LIT>" + "<STR_LIT::U+0020>" + p . exitValue ( ) ) ; String errors = read ( p . getErrorStream ( ) ) ; String output = read ( p . getInputStream ( ) ) ; if ( errors . trim ( ) . length ( ) > <NUM_LIT:0> ) { System . err . println ( "<STR_LIT>" + errors ) ; } if ( output . trim ( ) . length ( ) > <NUM_LIT:0> ) { System . out . println ( "<STR_LIT>" + output ) ; } } private static String read ( InputStream s ) { StringBuilder builder = new StringBuilder ( ) ; try { int current = - <NUM_LIT:1> ; while ( ( current = s . read ( ) ) != - <NUM_LIT:1> ) { builder . append ( ( char ) current ) ; } } catch ( IOException e ) { e . printStackTrace ( ) ; } return builder . toString ( ) ; } private static boolean runningOnWindows ( ) { return System . getProperty ( "<STR_LIT>" ) . toLowerCase ( ) . contains ( "<STR_LIT>" ) ; } } </s>
|
<s> package org . eclipse . zest . internal . dot ; import org . eclipse . osgi . util . NLS ; public class DotMessages extends NLS { private static final String BUNDLE_NAME = "<STR_LIT>" ; public static String GraphCreatorInterpreter_0 ; public static String DotFileUtils_0 ; public static String DotImport_0 ; public static String DotImport_1 ; public static String DotImport_2 ; public static String DotImport_3 ; public static String DotAst_0 ; static { NLS . initializeMessages ( BUNDLE_NAME , DotMessages . class ) ; } private DotMessages ( ) { } } </s>
|
<s> package org . eclipse . zest . internal . dot ; import java . io . File ; import java . util . Scanner ; import org . eclipse . draw2d . SWTGraphics ; import org . eclipse . draw2d . geometry . Rectangle ; import org . eclipse . swt . SWT ; import org . eclipse . swt . graphics . GC ; import org . eclipse . swt . graphics . Image ; import org . eclipse . swt . graphics . ImageData ; import org . eclipse . swt . graphics . ImageLoader ; import org . eclipse . swt . graphics . Point ; import org . eclipse . zest . core . widgets . Graph ; public final class DotExport { public static final String DOT_BIN_DIR_KEY = "<STR_LIT>" ; private static final String DEFAULT_OUTPUT_FORMAT = "<STR_LIT>" ; private String dotString ; private String graphName = "<STR_LIT>" + System . currentTimeMillis ( ) ; private Graph graph ; public DotExport ( final Graph graph ) { this . dotString = graphToDot ( graph ) ; this . graphName = graph . getClass ( ) . getSimpleName ( ) ; this . graph = graph ; } public DotExport ( String dotString ) { this . dotString = dotString ; } public String toDotString ( ) { return dotString ; } public File toDotFile ( final File destination ) { DotFileUtils . write ( dotString , destination ) ; return destination ; } public File toImage ( String dotBinDir , String resultFile ) { return toImage ( dotBinDir , resultFile == null ? DEFAULT_OUTPUT_FORMAT : resultFile . substring ( resultFile . lastIndexOf ( '<CHAR_LIT:.>' ) + <NUM_LIT:1> ) , resultFile ) ; } public File toImage ( String resultFile ) { Rectangle bounds = graph . getContents ( ) . getBounds ( ) ; Point size = new Point ( graph . getContents ( ) . getSize ( ) . width , graph . getContents ( ) . getSize ( ) . height ) ; org . eclipse . draw2d . geometry . Point viewLocation = graph . getViewport ( ) . getViewLocation ( ) ; final Image image = new Image ( null , size . x , size . y ) ; GC gc = new GC ( image ) ; SWTGraphics swtGraphics = new SWTGraphics ( gc ) ; swtGraphics . translate ( - <NUM_LIT:1> * bounds . x + viewLocation . x , - <NUM_LIT:1> * bounds . y + viewLocation . y ) ; graph . getViewport ( ) . paint ( swtGraphics ) ; gc . copyArea ( image , <NUM_LIT:0> , <NUM_LIT:0> ) ; gc . dispose ( ) ; ImageLoader loader = new ImageLoader ( ) ; loader . data = new ImageData [ ] { image . getImageData ( ) } ; loader . save ( resultFile , SWT . IMAGE_PNG ) ; return new File ( resultFile ) ; } public File toImage ( final String dotDir , final String format , final String resultFile ) { File dotFile = DotFileUtils . write ( dotString ) ; File image = DotDrawer . renderImage ( new File ( dotDir ) , dotFile , format , resultFile ) ; return image ; } @ Override public String toString ( ) { return graphName . equals ( "<STR_LIT>" ) ? "<STR_LIT>" + graphName : graphName ; } private static String graphToDot ( final Graph graph ) { String raw = new DotTemplate ( ) . generate ( graph ) ; raw = removeBlankLines ( raw ) ; return raw ; } private static String removeBlankLines ( final String raw ) { Scanner scanner = new Scanner ( raw ) ; StringBuilder builder = new StringBuilder ( ) ; while ( scanner . hasNextLine ( ) ) { String line = scanner . nextLine ( ) ; if ( ! line . trim ( ) . equals ( "<STR_LIT>" ) ) { builder . append ( line + "<STR_LIT:n>" ) ; } } return builder . toString ( ) ; } } </s>
|
<s> package org . eclipse . zest . core . widgets . internal ; import org . eclipse . draw2d . ColorConstants ; import org . eclipse . draw2d . FigureUtilities ; import org . eclipse . draw2d . Graphics ; import org . eclipse . draw2d . MarginBorder ; import org . eclipse . draw2d . ScaledGraphics ; import org . eclipse . draw2d . StackLayout ; import org . eclipse . draw2d . geometry . Dimension ; import org . eclipse . draw2d . geometry . Rectangle ; import org . eclipse . swt . graphics . Color ; import org . eclipse . swt . graphics . Font ; import org . eclipse . swt . graphics . Image ; import org . eclipse . swt . graphics . RGB ; import org . eclipse . swt . widgets . Display ; import org . eclipse . zest . core . widgets . IStyleableFigure ; public class GraphLabel extends CachedLabel implements IStyleableFigure { private Color borderColor ; private int borderWidth ; private int arcWidth ; private boolean painting = false ; public GraphLabel ( boolean cacheLabel ) { this ( "<STR_LIT>" , cacheLabel ) ; } public GraphLabel ( String text , boolean cacheLabel ) { this ( text , null , cacheLabel ) ; } public GraphLabel ( Image i , boolean cacheLabel ) { this ( "<STR_LIT>" , i , cacheLabel ) ; } public GraphLabel ( String text , Image i , boolean cacheLabel ) { super ( cacheLabel ) ; initLabel ( ) ; setText ( text ) ; setIcon ( i ) ; adjustBoundsToFit ( ) ; } protected void initLabel ( ) { super . setFont ( Display . getDefault ( ) . getSystemFont ( ) ) ; this . borderColor = ColorConstants . black ; this . borderWidth = <NUM_LIT:0> ; this . arcWidth = <NUM_LIT:8> ; this . setLayoutManager ( new StackLayout ( ) ) ; this . setBorder ( new MarginBorder ( <NUM_LIT:1> ) ) ; } public void setFont ( Font f ) { super . setFont ( f ) ; adjustBoundsToFit ( ) ; } protected void adjustBoundsToFit ( ) { String text = getText ( ) ; int safeBorderWidth = borderWidth > <NUM_LIT:0> ? borderWidth : <NUM_LIT:1> ; if ( ( text != null ) ) { Font font = getFont ( ) ; if ( font != null ) { Dimension minSize = FigureUtilities . getTextExtents ( text , font ) ; if ( getIcon ( ) != null ) { org . eclipse . swt . graphics . Rectangle imageRect = getIcon ( ) . getBounds ( ) ; int expandHeight = Math . max ( imageRect . height - minSize . height , <NUM_LIT:0> ) ; minSize . expand ( imageRect . width + <NUM_LIT:4> , expandHeight ) ; } minSize . expand ( <NUM_LIT:10> + ( <NUM_LIT:2> * safeBorderWidth ) , <NUM_LIT:4> + ( <NUM_LIT:2> * safeBorderWidth ) ) ; setBounds ( new Rectangle ( getLocation ( ) , minSize ) ) ; } } } public void paint ( Graphics graphics ) { int blue = getBackgroundColor ( ) . getBlue ( ) ; blue = ( int ) ( blue - ( blue * <NUM_LIT> ) ) ; blue = blue > <NUM_LIT:0> ? blue : <NUM_LIT:0> ; int red = getBackgroundColor ( ) . getRed ( ) ; red = ( int ) ( red - ( red * <NUM_LIT> ) ) ; red = red > <NUM_LIT:0> ? red : <NUM_LIT:0> ; int green = getBackgroundColor ( ) . getGreen ( ) ; green = ( int ) ( green - ( green * <NUM_LIT> ) ) ; green = green > <NUM_LIT:0> ? green : <NUM_LIT:0> ; Color lightenColor = new Color ( Display . getCurrent ( ) , new RGB ( red , green , blue ) ) ; graphics . setForegroundColor ( lightenColor ) ; graphics . setBackgroundColor ( getBackgroundColor ( ) ) ; int safeBorderWidth = borderWidth > <NUM_LIT:0> ? borderWidth : <NUM_LIT:1> ; graphics . pushState ( ) ; double scale = <NUM_LIT:1> ; if ( graphics instanceof ScaledGraphics ) { scale = ( ( ScaledGraphics ) graphics ) . getAbsoluteScale ( ) ; } Rectangle rect = getBounds ( ) . getCopy ( ) ; rect . height /= <NUM_LIT:2> ; graphics . setForegroundColor ( getBackgroundColor ( ) ) ; graphics . setBackgroundColor ( getBackgroundColor ( ) ) ; graphics . fillRoundRectangle ( rect , arcWidth * safeBorderWidth , arcWidth * <NUM_LIT:2> * safeBorderWidth ) ; rect . y = rect . y + rect . height ; rect . height += <NUM_LIT:1> ; graphics . setForegroundColor ( lightenColor ) ; graphics . setBackgroundColor ( lightenColor ) ; graphics . fillRoundRectangle ( rect , arcWidth * safeBorderWidth , arcWidth * <NUM_LIT:2> * safeBorderWidth ) ; rect = bounds . getCopy ( ) ; rect . height -= <NUM_LIT:2> ; rect . y += ( safeBorderWidth ) / <NUM_LIT:2> ; rect . y += ( arcWidth / <NUM_LIT:2> ) ; rect . height -= arcWidth / <NUM_LIT:2> ; rect . height -= safeBorderWidth ; graphics . setBackgroundColor ( lightenColor ) ; graphics . setForegroundColor ( getBackgroundColor ( ) ) ; graphics . fillGradient ( rect , true ) ; if ( borderWidth > <NUM_LIT:0> ) { rect = getBounds ( ) . getCopy ( ) ; rect . x += safeBorderWidth / <NUM_LIT:2> ; rect . y += safeBorderWidth / <NUM_LIT:2> ; rect . width -= safeBorderWidth ; rect . height -= safeBorderWidth ; graphics . setForegroundColor ( borderColor ) ; graphics . setBackgroundColor ( borderColor ) ; graphics . setLineWidth ( ( int ) ( safeBorderWidth * scale ) ) ; graphics . drawRoundRectangle ( rect , arcWidth , arcWidth ) ; } super . paint ( graphics ) ; graphics . popState ( ) ; lightenColor . dispose ( ) ; } protected Color getBackgroundTextColor ( ) { return getBackgroundColor ( ) ; } public void invalidate ( ) { if ( ! painting ) { super . invalidate ( ) ; } } public void setText ( String s ) { super . setText ( s ) ; adjustBoundsToFit ( ) ; } public void setIcon ( Image image ) { super . setIcon ( image ) ; adjustBoundsToFit ( ) ; } public Color getBorderColor ( ) { return borderColor ; } public void setBorderColor ( Color c ) { this . borderColor = c ; } public int getBorderWidth ( ) { return borderWidth ; } public void setBorderWidth ( int width ) { this . borderWidth = width ; } public int getArcWidth ( ) { return arcWidth ; } public void setArcWidth ( int arcWidth ) { this . arcWidth = arcWidth ; } } </s>
|
<s> package org . eclipse . zest . core . widgets . internal ; import org . eclipse . draw2d . ActionEvent ; import org . eclipse . draw2d . ActionListener ; import org . eclipse . draw2d . Clickable ; import org . eclipse . draw2d . ColorConstants ; import org . eclipse . draw2d . Figure ; import org . eclipse . draw2d . FigureUtilities ; import org . eclipse . draw2d . FreeformLayout ; import org . eclipse . draw2d . Graphics ; import org . eclipse . draw2d . Label ; import org . eclipse . draw2d . ToolbarLayout ; import org . eclipse . draw2d . Triangle ; import org . eclipse . draw2d . geometry . Dimension ; import org . eclipse . draw2d . geometry . Point ; import org . eclipse . draw2d . geometry . Rectangle ; import org . eclipse . swt . graphics . Color ; import org . eclipse . swt . graphics . Font ; import org . eclipse . swt . graphics . Image ; import org . eclipse . swt . graphics . RGB ; import org . eclipse . swt . widgets . Display ; import org . eclipse . zest . core . widgets . GraphContainer ; public class ExpandGraphLabel extends Figure implements ActionListener { public static final int OPEN = <NUM_LIT:1> ; public static final int CLOSED = <NUM_LIT:2> ; private int state = CLOSED ; private Expander expander = null ; class Expander extends Clickable { private Triangle triangle ; public Expander ( ) { setStyle ( Clickable . STYLE_TOGGLE ) ; triangle = new Triangle ( ) ; triangle . setSize ( <NUM_LIT:10> , <NUM_LIT:10> ) ; triangle . setBackgroundColor ( ColorConstants . black ) ; triangle . setForegroundColor ( ColorConstants . black ) ; triangle . setFill ( true ) ; triangle . setDirection ( Triangle . EAST ) ; triangle . setLocation ( new Point ( <NUM_LIT:5> , <NUM_LIT:3> ) ) ; this . setLayoutManager ( new FreeformLayout ( ) ) ; this . add ( triangle ) ; this . setPreferredSize ( <NUM_LIT:15> , <NUM_LIT:15> ) ; this . addActionListener ( ExpandGraphLabel . this ) ; } public void open ( ) { triangle . setDirection ( Triangle . SOUTH ) ; } public void close ( ) { triangle . setDirection ( Triangle . EAST ) ; } } public void setExpandedState ( int state ) { if ( state == OPEN ) { expander . open ( ) ; } else { expander . close ( ) ; } this . state = state ; } public void actionPerformed ( ActionEvent event ) { if ( state == OPEN ) { container . close ( true ) ; } else { container . open ( true ) ; } } private int arcWidth ; private Label label = null ; private final GraphContainer container ; private ToolbarLayout layout ; public ExpandGraphLabel ( GraphContainer container , boolean cacheLabel ) { this ( container , "<STR_LIT>" , null , cacheLabel ) ; } public ExpandGraphLabel ( GraphContainer container , Image i , boolean cacheLabel ) { this ( container , "<STR_LIT>" , i , cacheLabel ) ; } public ExpandGraphLabel ( GraphContainer container , String text , boolean cacheLabel ) { this ( container , text , null , cacheLabel ) ; } public ExpandGraphLabel ( GraphContainer container , String text , Image image , boolean cacheLabel ) { this . label = new Label ( text ) { protected void paintFigure ( Graphics graphics ) { if ( isOpaque ( ) ) { super . paintFigure ( graphics ) ; } Rectangle bounds = getBounds ( ) ; graphics . translate ( bounds . x , bounds . y ) ; if ( getIcon ( ) != null ) { graphics . drawImage ( getIcon ( ) , getIconLocation ( ) ) ; } if ( ! isEnabled ( ) ) { graphics . translate ( <NUM_LIT:1> , <NUM_LIT:1> ) ; graphics . setForegroundColor ( ColorConstants . buttonLightest ) ; graphics . drawText ( getSubStringText ( ) , getTextLocation ( ) ) ; graphics . translate ( - <NUM_LIT:1> , - <NUM_LIT:1> ) ; graphics . setForegroundColor ( ColorConstants . buttonDarker ) ; } graphics . drawText ( getText ( ) , getTextLocation ( ) ) ; graphics . translate ( - bounds . x , - bounds . y ) ; } } ; this . setText ( text ) ; this . setImage ( image ) ; this . container = container ; this . expander = new Expander ( ) ; this . arcWidth = <NUM_LIT:8> ; this . setFont ( Display . getDefault ( ) . getSystemFont ( ) ) ; layout = new ToolbarLayout ( true ) ; layout . setSpacing ( <NUM_LIT:5> ) ; layout . setMinorAlignment ( ToolbarLayout . ALIGN_CENTER ) ; this . setLayoutManager ( layout ) ; this . add ( this . expander ) ; this . add ( this . label ) ; } protected void adjustBoundsToFit ( ) { String text = getText ( ) ; if ( ( text != null ) && ( text . length ( ) > <NUM_LIT:0> ) ) { Font font = getFont ( ) ; if ( font != null ) { Dimension minSize = FigureUtilities . getTextExtents ( text , font ) ; if ( getIcon ( ) != null ) { org . eclipse . swt . graphics . Rectangle imageRect = getIcon ( ) . getBounds ( ) ; int expandHeight = Math . max ( imageRect . height - minSize . height , <NUM_LIT:0> ) ; minSize . expand ( imageRect . width + <NUM_LIT:4> , expandHeight ) ; } minSize . expand ( <NUM_LIT:10> + ( <NUM_LIT:2> * <NUM_LIT:1> ) + <NUM_LIT:100> , <NUM_LIT:4> + ( <NUM_LIT:2> * <NUM_LIT:1> ) ) ; label . setBounds ( new Rectangle ( getLocation ( ) , minSize ) ) ; } } } private Image getIcon ( ) { return this . label . getIcon ( ) ; } private String getText ( ) { return this . label . getText ( ) ; } public void paint ( Graphics graphics ) { int blue = getBackgroundColor ( ) . getBlue ( ) ; blue = ( int ) ( blue - ( blue * <NUM_LIT> ) ) ; blue = blue > <NUM_LIT:0> ? blue : <NUM_LIT:0> ; int red = getBackgroundColor ( ) . getRed ( ) ; red = ( int ) ( red - ( red * <NUM_LIT> ) ) ; red = red > <NUM_LIT:0> ? red : <NUM_LIT:0> ; int green = getBackgroundColor ( ) . getGreen ( ) ; green = ( int ) ( green - ( green * <NUM_LIT> ) ) ; green = green > <NUM_LIT:0> ? green : <NUM_LIT:0> ; Color lightenColor = new Color ( Display . getCurrent ( ) , new RGB ( red , green , blue ) ) ; graphics . setForegroundColor ( lightenColor ) ; graphics . setBackgroundColor ( getBackgroundColor ( ) ) ; graphics . pushState ( ) ; Rectangle bounds = getBounds ( ) . getCopy ( ) ; Rectangle r = bounds . getCopy ( ) ; r . y += arcWidth / <NUM_LIT:2> ; r . height -= arcWidth ; Rectangle top = bounds . getCopy ( ) ; top . height /= <NUM_LIT:2> ; graphics . setForegroundColor ( getBackgroundColor ( ) ) ; graphics . setBackgroundColor ( getBackgroundColor ( ) ) ; graphics . fillRoundRectangle ( top , arcWidth , arcWidth ) ; top . y = top . y + top . height ; graphics . setForegroundColor ( lightenColor ) ; graphics . setBackgroundColor ( lightenColor ) ; graphics . fillRoundRectangle ( top , arcWidth , arcWidth ) ; graphics . setBackgroundColor ( lightenColor ) ; graphics . setForegroundColor ( getBackgroundColor ( ) ) ; graphics . fillGradient ( r , true ) ; super . paint ( graphics ) ; graphics . popState ( ) ; graphics . setForegroundColor ( lightenColor ) ; graphics . setBackgroundColor ( lightenColor ) ; bounds . setSize ( bounds . width - <NUM_LIT:1> , bounds . height - <NUM_LIT:1> ) ; graphics . drawRoundRectangle ( bounds , arcWidth , arcWidth ) ; lightenColor . dispose ( ) ; } public void setTextT ( String string ) { this . setPreferredSize ( null ) ; this . label . setText ( string ) ; this . add ( label ) ; this . layout . layout ( this ) ; this . invalidate ( ) ; this . revalidate ( ) ; this . validate ( ) ; } public void setText ( String string ) { this . label . setText ( string ) ; } public void setImage ( Image image ) { this . label . setIcon ( image ) ; } public void setLocation ( Point p ) { super . setLocation ( p ) ; } public void setBounds ( Rectangle rect ) { super . setBounds ( rect ) ; } } </s>
|
<s> package org . eclipse . zest . core . widgets . internal ; import org . eclipse . draw2d . FreeformFigure ; import org . eclipse . draw2d . FreeformLayer ; import org . eclipse . draw2d . FreeformLayout ; import org . eclipse . draw2d . Graphics ; import org . eclipse . draw2d . MarginBorder ; import org . eclipse . draw2d . ScalableFigure ; import org . eclipse . draw2d . geometry . Dimension ; import org . eclipse . draw2d . geometry . Point ; import org . eclipse . draw2d . geometry . PointList ; import org . eclipse . draw2d . geometry . PrecisionDimension ; import org . eclipse . draw2d . geometry . PrecisionPoint ; import org . eclipse . draw2d . geometry . PrecisionRectangle ; import org . eclipse . draw2d . geometry . Rectangle ; import org . eclipse . draw2d . geometry . Translatable ; import org . eclipse . draw2d . text . CaretInfo ; public class AspectRatioFreeformLayer extends FreeformLayer implements ScalableFigure , FreeformFigure { private double widthScale = <NUM_LIT:1.0> ; private double heigthScale = <NUM_LIT:1.0> ; public AspectRatioFreeformLayer ( String debugLabel ) { widthScale = <NUM_LIT> ; heigthScale = <NUM_LIT> ; setLayoutManager ( new FreeformLayout ( ) ) ; setBorder ( new MarginBorder ( <NUM_LIT:5> ) ) ; } protected boolean isValidationRoot ( ) { return true ; } public void setScale ( double wScale , double hScale ) { this . widthScale = wScale ; this . heigthScale = hScale ; } public double getWidthScale ( ) { return this . widthScale ; } public double getHeightScale ( ) { return this . heigthScale ; } public double getScale ( ) { throw new RuntimeException ( "<STR_LIT>" ) ; } public void setScale ( double scale ) { this . widthScale = scale ; this . heigthScale = scale ; revalidate ( ) ; repaint ( ) ; } public Rectangle getClientArea ( Rectangle rect ) { rect . width /= widthScale ; rect . height /= heigthScale ; rect . x /= widthScale ; rect . y /= heigthScale ; return rect ; } public Dimension getPreferredSize ( int wHint , int hHint ) { Dimension d = super . getPreferredSize ( wHint , hHint ) ; int w = getInsets ( ) . getWidth ( ) ; int h = getInsets ( ) . getHeight ( ) ; return d . getExpanded ( - w , - h ) . scale ( widthScale , heigthScale ) . expand ( w , h ) ; } public void translateFromParent ( Translatable t ) { super . translateFromParent ( t ) ; if ( t instanceof PrecisionRectangle ) { PrecisionRectangle r = ( PrecisionRectangle ) t ; r . setPreciseX ( r . preciseX ( ) * ( <NUM_LIT:1> / widthScale ) ) ; r . setPreciseY ( r . preciseY ( ) * ( <NUM_LIT:1> / heigthScale ) ) ; r . setPreciseWidth ( r . preciseWidth ( ) * ( <NUM_LIT:1> / widthScale ) ) ; r . setPreciseHeight ( r . preciseHeight ( ) * ( <NUM_LIT:1> / heigthScale ) ) ; } else if ( t instanceof Rectangle ) { Rectangle r = ( Rectangle ) t ; r . scale ( <NUM_LIT:1> / widthScale , <NUM_LIT:1> / heigthScale ) ; } else if ( t instanceof CaretInfo ) { CaretInfo c = ( CaretInfo ) t ; c . performScale ( <NUM_LIT:1> / heigthScale ) ; } else if ( t instanceof PrecisionDimension ) { PrecisionDimension d = ( PrecisionDimension ) t ; d . setPreciseWidth ( d . preciseWidth ( ) * ( <NUM_LIT:1> / widthScale ) ) ; d . setPreciseHeight ( d . preciseHeight ( ) * ( <NUM_LIT:1> / heigthScale ) ) ; } else if ( t instanceof Dimension ) { Dimension d = ( Dimension ) t ; d . scale ( <NUM_LIT:1> / widthScale , <NUM_LIT:1> / heigthScale ) ; } else if ( t instanceof PrecisionPoint ) { PrecisionPoint p = ( PrecisionPoint ) t ; p . setPreciseX ( p . preciseX ( ) * ( <NUM_LIT:1> / widthScale ) ) ; p . setPreciseY ( p . preciseY ( ) * ( <NUM_LIT:1> / heigthScale ) ) ; } else if ( t instanceof Point ) { Point p = ( Point ) t ; p . scale ( <NUM_LIT:1> / widthScale , <NUM_LIT:1> / heigthScale ) ; } else if ( t instanceof PointList ) { throw new RuntimeException ( "<STR_LIT>" ) ; } else { throw new RuntimeException ( t . toString ( ) + "<STR_LIT>" ) ; } } public void translateToParent ( Translatable t ) { if ( t instanceof PrecisionRectangle ) { PrecisionRectangle r = ( PrecisionRectangle ) t ; r . setPreciseX ( r . preciseX ( ) * widthScale ) ; r . setPreciseY ( r . preciseY ( ) * heigthScale ) ; r . setPreciseWidth ( r . preciseWidth ( ) * widthScale ) ; r . setPreciseHeight ( r . preciseHeight ( ) * heigthScale ) ; } else if ( t instanceof Rectangle ) { Rectangle r = ( Rectangle ) t ; r . scale ( widthScale , heigthScale ) ; } else if ( t instanceof CaretInfo ) { CaretInfo c = ( CaretInfo ) t ; c . performScale ( heigthScale ) ; } else if ( t instanceof PrecisionDimension ) { PrecisionDimension d = ( PrecisionDimension ) t ; d . setPreciseWidth ( d . preciseWidth ( ) * widthScale ) ; d . setPreciseHeight ( d . preciseHeight ( ) * heigthScale ) ; } else if ( t instanceof Dimension ) { Dimension d = ( Dimension ) t ; d . scale ( widthScale , heigthScale ) ; } else if ( t instanceof PrecisionPoint ) { PrecisionPoint p = ( PrecisionPoint ) t ; p . setPreciseX ( p . preciseX ( ) * widthScale ) ; p . setPreciseY ( p . preciseY ( ) * heigthScale ) ; } else if ( t instanceof Point ) { Point p = ( Point ) t ; p . scale ( widthScale , heigthScale ) ; } else if ( t instanceof PointList ) { throw new RuntimeException ( "<STR_LIT>" ) ; } else { throw new RuntimeException ( t . toString ( ) + "<STR_LIT>" ) ; } super . translateToParent ( t ) ; } protected void paintClientArea ( Graphics graphics ) { if ( getChildren ( ) . isEmpty ( ) ) { return ; } XYScaledGraphics g = null ; boolean disposeGraphics = false ; if ( graphics instanceof XYScaledGraphics ) { g = ( XYScaledGraphics ) graphics ; } else { g = new XYScaledGraphics ( graphics ) ; disposeGraphics = true ; } boolean optimizeClip = getBorder ( ) == null || getBorder ( ) . isOpaque ( ) ; if ( ! optimizeClip ) { g . clipRect ( getBounds ( ) . getShrinked ( getInsets ( ) ) ) ; } g . scale ( widthScale , heigthScale ) ; g . pushState ( ) ; paintChildren ( g ) ; g . popState ( ) ; if ( disposeGraphics ) { g . dispose ( ) ; graphics . restoreState ( ) ; } } } </s>
|
<s> package org . eclipse . zest . core . widgets . internal ; import org . eclipse . draw2d . AbstractLocator ; import org . eclipse . draw2d . Connection ; import org . eclipse . draw2d . IFigure ; import org . eclipse . draw2d . PositionConstants ; import org . eclipse . draw2d . geometry . Dimension ; import org . eclipse . draw2d . geometry . Point ; import org . eclipse . draw2d . geometry . PointList ; public class AligningBendpointLocator extends AbstractLocator { public static final int MIDDLE = <NUM_LIT:0> ; public static final int ABOVE = <NUM_LIT:1> ; public static final int BELOW = <NUM_LIT:2> ; public static final int CENTER = <NUM_LIT:0> ; public static final int BEGINNING = <NUM_LIT:1> ; public static final int END = <NUM_LIT:2> ; public static final int CENTER_BEGINNING = <NUM_LIT:3> ; public static final int CENTER_END = <NUM_LIT:4> ; private int horizontal ; private int vertical ; private Connection connection ; public AligningBendpointLocator ( Connection connection ) { this ( connection , CENTER , MIDDLE ) ; } public AligningBendpointLocator ( Connection connection , int horizontal , int vertical ) { this . connection = connection ; this . horizontal = horizontal ; this . vertical = vertical ; } protected Point getReferencePoint ( ) { PointList points = getConnection ( ) . getPoints ( ) ; Point p = points . getMidpoint ( ) . getCopy ( ) ; PointList tempPoints = new PointList ( ) ; switch ( horizontal ) { case BEGINNING : p = points . getFirstPoint ( ) . getCopy ( ) ; break ; case END : p = points . getLastPoint ( ) . getCopy ( ) ; break ; case CENTER_BEGINNING : tempPoints . addPoint ( points . getFirstPoint ( ) . getCopy ( ) ) ; tempPoints . addPoint ( points . getPoint ( <NUM_LIT:1> ) . getCopy ( ) ) ; p = tempPoints . getMidpoint ( ) . getCopy ( ) ; break ; case CENTER_END : tempPoints = new PointList ( ) ; int s = points . size ( ) ; tempPoints . addPoint ( points . getLastPoint ( ) . getCopy ( ) ) ; tempPoints . addPoint ( points . getPoint ( s - <NUM_LIT:2> ) . getCopy ( ) ) ; p = tempPoints . getMidpoint ( ) . getCopy ( ) ; case CENTER : default : p = points . getMidpoint ( ) . getCopy ( ) ; } return p ; } public void relocate ( IFigure target ) { Dimension prefSize = target . getPreferredSize ( ) ; Point center = getReferencePoint ( ) ; calculatePosition ( ) ; target . setBounds ( getNewBounds ( prefSize , center ) ) ; } private void calculatePosition ( ) { PointList points = getConnection ( ) . getPoints ( ) ; int position = <NUM_LIT:0> ; switch ( horizontal ) { case BEGINNING : Point first = points . getFirstPoint ( ) ; Point next = points . getPoint ( <NUM_LIT:1> ) ; if ( first . x <= next . x ) { position |= PositionConstants . EAST ; } else { position |= PositionConstants . WEST ; } break ; case END : Point last = points . getLastPoint ( ) ; int s = points . size ( ) ; Point before = points . getPoint ( s - <NUM_LIT:1> ) ; if ( last . x <= before . x ) { position |= PositionConstants . EAST ; } else { position |= PositionConstants . WEST ; } break ; } if ( position == <NUM_LIT:0> ) { position = PositionConstants . CENTER ; } switch ( vertical ) { case ABOVE : position |= PositionConstants . NORTH ; break ; case BELOW : position |= PositionConstants . SOUTH ; break ; case MIDDLE : position |= PositionConstants . MIDDLE ; } setRelativePosition ( position ) ; } public int getHorizontalAlignment ( ) { return horizontal ; } public void setHorizontalAlignment ( int horizontal ) { this . horizontal = horizontal ; } public void setVerticalAlginment ( int vertical ) { this . vertical = vertical ; } public int getVerticalAlignment ( ) { return vertical ; } public Connection getConnection ( ) { return connection ; } } </s>
|
<s> package org . eclipse . zest . core . widgets . internal ; import java . util . ArrayList ; import java . util . HashSet ; import java . util . Iterator ; import org . eclipse . draw2d . FreeformLayer ; import org . eclipse . draw2d . IFigure ; public class ZestRootLayer extends FreeformLayer { public static final int CONNECTIONS_LAYER = <NUM_LIT:0> ; public static final int SUBGRAPHS_LAYER = <NUM_LIT:1> ; public static final int NODES_LAYER = <NUM_LIT:2> ; public static final int CONNECTIONS_HIGHLIGHTED_LAYER = <NUM_LIT:3> ; public static final int NODES_HIGHLIGHTED_LAYER = <NUM_LIT:4> ; public static final int TOP_LAYER = <NUM_LIT:5> ; public static final int NUMBER_OF_LAYERS = <NUM_LIT:6> ; private final int [ ] itemsInLayer = new int [ NUMBER_OF_LAYERS ] ; private HashSet decoratingFigures = new HashSet ( ) ; private boolean isLayerKnown = false ; public void addNode ( IFigure nodeFigure ) { addFigure ( nodeFigure , NODES_LAYER ) ; } public void addConnection ( IFigure connectionFigure ) { addFigure ( connectionFigure , CONNECTIONS_LAYER ) ; } public void addSubgraph ( IFigure subgraphFigrue ) { addFigure ( subgraphFigrue , SUBGRAPHS_LAYER ) ; } public void highlightNode ( IFigure nodeFigure ) { changeFigureLayer ( nodeFigure , NODES_HIGHLIGHTED_LAYER ) ; } public void highlightConnection ( IFigure connectionFigure ) { changeFigureLayer ( connectionFigure , CONNECTIONS_HIGHLIGHTED_LAYER ) ; } public void unHighlightNode ( IFigure nodeFigure ) { changeFigureLayer ( nodeFigure , NODES_LAYER ) ; } public void unHighlightConnection ( IFigure connectionFigure ) { changeFigureLayer ( connectionFigure , CONNECTIONS_LAYER ) ; } private void changeFigureLayer ( IFigure figure , int newLayer ) { ArrayList decorations = getDecorations ( figure ) ; remove ( figure ) ; addFigure ( figure , newLayer ) ; for ( Iterator iterator = decorations . iterator ( ) ; iterator . hasNext ( ) ; ) { addDecoration ( figure , ( IFigure ) iterator . next ( ) ) ; } this . invalidate ( ) ; this . repaint ( ) ; } private ArrayList getDecorations ( IFigure figure ) { ArrayList result = new ArrayList ( ) ; int index = getChildren ( ) . indexOf ( figure ) ; if ( index == - <NUM_LIT:1> ) { return result ; } for ( index ++ ; index < getChildren ( ) . size ( ) ; index ++ ) { Object nextFigure = getChildren ( ) . get ( index ) ; if ( decoratingFigures . contains ( nextFigure ) ) { result . add ( nextFigure ) ; } else { break ; } } return result ; } private int getPosition ( int layer ) { int result = <NUM_LIT:0> ; for ( int i = <NUM_LIT:0> ; i <= layer ; i ++ ) { result += itemsInLayer [ i ] ; } return result ; } private int getLayer ( int position ) { int layer = <NUM_LIT:0> ; int positionInLayer = itemsInLayer [ <NUM_LIT:0> ] ; while ( layer < NUMBER_OF_LAYERS - <NUM_LIT:1> && positionInLayer <= position ) { layer ++ ; positionInLayer += itemsInLayer [ layer ] ; } return layer ; } public void addFigure ( IFigure figure , int layer ) { int position = getPosition ( layer ) ; itemsInLayer [ layer ] ++ ; isLayerKnown = true ; add ( figure , position ) ; } public void add ( IFigure child , Object constraint , int index ) { super . add ( child , constraint , index ) ; if ( ! isLayerKnown ) { int layer = <NUM_LIT:0> , positionInLayer = itemsInLayer [ <NUM_LIT:0> ] ; while ( positionInLayer < index ) { layer ++ ; positionInLayer += itemsInLayer [ layer ] ; } if ( index == - <NUM_LIT:1> ) { layer = NUMBER_OF_LAYERS - <NUM_LIT:1> ; } itemsInLayer [ layer ] ++ ; } isLayerKnown = false ; } public void remove ( IFigure child ) { int position = this . getChildren ( ) . indexOf ( child ) ; if ( position == - <NUM_LIT:1> ) { return ; } itemsInLayer [ getLayer ( position ) ] -- ; if ( decoratingFigures . contains ( child ) ) { decoratingFigures . remove ( child ) ; super . remove ( child ) ; } else { ArrayList decorations = getDecorations ( child ) ; super . remove ( child ) ; for ( Iterator iterator = decorations . iterator ( ) ; iterator . hasNext ( ) ; ) { remove ( ( IFigure ) iterator . next ( ) ) ; } } } public void addDecoration ( IFigure decorated , IFigure decorating ) { int position = this . getChildren ( ) . indexOf ( decorated ) ; if ( position == - <NUM_LIT:1> ) { throw new RuntimeException ( "<STR_LIT>" ) ; } itemsInLayer [ getLayer ( position ) ] ++ ; isLayerKnown = true ; do { position ++ ; } while ( position < getChildren ( ) . size ( ) && decoratingFigures . contains ( getChildren ( ) . get ( position ) ) ) ; decoratingFigures . add ( decorating ) ; add ( decorating , position ) ; } } </s>
|
<s> package org . eclipse . zest . core . widgets . internal ; import org . eclipse . draw2d . ChopboxAnchor ; import org . eclipse . draw2d . IFigure ; import org . eclipse . draw2d . geometry . Point ; import org . eclipse . draw2d . geometry . Rectangle ; public class RoundedChopboxAnchor extends ChopboxAnchor { private int arcRadius = <NUM_LIT:10> ; private int shift = <NUM_LIT:7> ; public RoundedChopboxAnchor ( int arcRadius ) { super ( ) ; this . arcRadius = arcRadius ; this . shift = arcRadius - ( int ) ( <NUM_LIT> * arcRadius ) ; } public RoundedChopboxAnchor ( IFigure owner , int arcRadius ) { super ( owner ) ; this . arcRadius = arcRadius ; this . shift = arcRadius - ( int ) ( <NUM_LIT> * arcRadius ) ; } public Point getLocation ( Point reference ) { Point p = super . getLocation ( reference ) ; Rectangle bounds = getBox ( ) ; boolean done = getTranslatedPoint ( bounds . getTopLeft ( ) , p , shift , shift ) ; if ( ! done ) { done = getTranslatedPoint ( bounds . getTopRight ( ) , p , - shift , shift ) ; } if ( ! done ) { done = getTranslatedPoint ( bounds . getBottomLeft ( ) , p , shift , - shift ) ; } if ( ! done ) { done = getTranslatedPoint ( bounds . getBottomRight ( ) , p , - shift , - shift ) ; } return p ; } private boolean getTranslatedPoint ( Point corner , Point p , int dx , int dy ) { int diff = ( int ) corner . getDistance ( p ) ; if ( diff < arcRadius ) { Point t = corner . getTranslated ( dx , dy ) ; p . setLocation ( t . x , t . y ) ; return true ; } return false ; } } </s>
|
<s> package org . eclipse . zest . core . widgets . internal ; import org . eclipse . draw2d . PolylineConnection ; import org . eclipse . draw2d . RectangleFigure ; import org . eclipse . draw2d . geometry . Point ; import org . eclipse . draw2d . geometry . PointList ; public class PolylineArcConnection extends PolylineConnection { private int depth ; private boolean inverse = false ; private static final float PI = ( float ) <NUM_LIT> ; private RectangleFigure center ; { this . depth = <NUM_LIT:0> ; center = new RectangleFigure ( ) ; } public void setPoints ( PointList points ) { updateArc ( points ) ; } public void addPoint ( Point pt ) { } public void setDepth ( int depth ) { this . inverse = depth < <NUM_LIT:0> ? true : false ; this . depth = depth ; updateArc ( getPoints ( ) ) ; } protected void updateArc ( PointList pointList ) { if ( pointList . size ( ) < <NUM_LIT:2> ) { return ; } if ( center . getParent ( ) == this ) { remove ( center ) ; } Point start = pointList . getFirstPoint ( ) ; Point end = pointList . getLastPoint ( ) ; if ( depth == <NUM_LIT:0> ) { super . setPoints ( pointList ) ; return ; } PointList points = new PointList ( ) ; float arcStart = <NUM_LIT:0> ; float arcEnd = <NUM_LIT:0> ; float arcLength = <NUM_LIT:0> ; float cartCenterX = <NUM_LIT:0> ; float cartCenterY = <NUM_LIT:0> ; float r = <NUM_LIT:0> ; float x1 = start . x ; float y1 = - start . y ; float x2 = end . x ; float y2 = - end . y ; float depth = this . depth ; if ( start . equals ( end ) ) { arcStart = - PI / <NUM_LIT:2> ; arcLength = PI * <NUM_LIT:2> ; cartCenterX = x1 ; cartCenterY = y1 + depth / <NUM_LIT:2> ; r = depth / <NUM_LIT:2> ; } else { if ( x1 >= x2 ) { depth = - depth ; } float cartChordX = ( x2 + x1 ) / <NUM_LIT:2> ; float cartChordY = ( y2 + y1 ) / <NUM_LIT:2> ; float chordLength = ( float ) Math . sqrt ( ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ) ) ; if ( Math . abs ( depth ) >= chordLength / <NUM_LIT:2> ) { depth = ( chordLength / <NUM_LIT:3> ) * ( depth / Math . abs ( depth ) ) ; } r = ( ( ( ( chordLength / <NUM_LIT:2> ) * ( chordLength / <NUM_LIT:2> ) ) + ( depth * depth ) ) / ( <NUM_LIT:2> * depth ) ) ; float chordNormal = <NUM_LIT:0> ; if ( Math . abs ( x1 - x2 ) <= <NUM_LIT> ) { chordNormal = Float . NaN ; } else if ( Math . abs ( y1 - y2 ) <= <NUM_LIT> ) { chordNormal = Float . POSITIVE_INFINITY ; } else { chordNormal = - <NUM_LIT:1> * ( y2 - y1 ) / ( x2 - x1 ) ; } float th1 ; if ( Float . isNaN ( chordNormal ) ) { cartCenterX = ( y1 > y2 ) ? ( cartChordX - r + ( depth ) ) : ( cartChordX + r - ( depth ) ) ; cartCenterY = cartChordY ; th1 = PI / <NUM_LIT:2> ; } else if ( Float . isInfinite ( chordNormal ) ) { cartCenterX = cartChordX ; cartCenterY = cartChordY + r - ( depth ) ; th1 = <NUM_LIT:0> ; } else { th1 = ( float ) Math . atan ( chordNormal ) ; cartCenterX = ( r - ( depth ) ) * ( float ) Math . sin ( th1 ) + cartChordX ; cartCenterY = ( r - ( depth ) ) * ( float ) Math . cos ( th1 ) + cartChordY ; } float cartArcX1 = x1 - cartCenterX ; float cartArcY1 = y1 - cartCenterY ; float cartArcX2 = x2 - cartCenterX ; float cartArcY2 = y2 - cartCenterY ; arcStart = angleRadians ( cartArcX1 , cartArcY1 ) ; arcEnd = angleRadians ( cartArcX2 , cartArcY2 ) ; if ( arcEnd < arcStart ) { arcEnd = arcEnd + PI + PI ; } arcLength = arcEnd - arcStart ; float pad = PI / Math . abs ( r ) ; arcStart += pad ; arcEnd -= pad ; arcLength = ( arcEnd ) - ( arcStart ) ; if ( inverse ) { arcLength = ( <NUM_LIT:2> * PI - arcLength ) ; } } r = Math . abs ( r ) ; float x = <NUM_LIT:0> , y = <NUM_LIT:0> ; Point p = null ; points . addPoint ( start ) ; float length = arcLength * r ; int steps = ( int ) length / <NUM_LIT:16> ; if ( steps < <NUM_LIT:10> && length > <NUM_LIT:10> ) { steps = <NUM_LIT:10> ; } if ( arcLength < PI / <NUM_LIT:4> && steps > <NUM_LIT:6> ) { steps = <NUM_LIT:6> ; } if ( steps < <NUM_LIT:4> && length > <NUM_LIT:4> ) { steps = <NUM_LIT:4> ; } float stepSize = arcLength / steps ; if ( inverse ) { float step = arcStart - stepSize ; for ( int i = <NUM_LIT:1> ; i < steps ; i ++ , step -= stepSize ) { x = ( r ) * ( float ) Math . cos ( step ) + cartCenterX ; y = ( r ) * ( float ) Math . sin ( step ) + cartCenterY ; p = new Point ( Math . round ( x ) , Math . round ( - y ) ) ; points . addPoint ( p ) ; } } else { float step = stepSize + arcStart ; for ( int i = <NUM_LIT:1> ; i < steps ; i ++ , step += stepSize ) { x = ( r ) * ( float ) Math . cos ( step ) + cartCenterX ; y = ( r ) * ( float ) Math . sin ( step ) + cartCenterY ; p = new Point ( Math . round ( x ) , Math . round ( - y ) ) ; points . addPoint ( p ) ; } } points . addPoint ( end ) ; super . setPoints ( points ) ; } float angleRadians ( float x , float y ) { float theta = ( float ) Math . atan ( y / x ) ; switch ( findQuadrant ( x , y ) ) { case <NUM_LIT:1> : return theta ; case <NUM_LIT:2> : return ( theta + PI ) ; case <NUM_LIT:4> : theta = ( theta + PI ) ; case <NUM_LIT:3> : return ( theta + PI ) ; default : return theta ; } } protected int findQuadrant ( float x , float y ) { if ( y > <NUM_LIT:0> ) { if ( x > <NUM_LIT:0> ) { return <NUM_LIT:1> ; } else { return <NUM_LIT:2> ; } } else { if ( x > <NUM_LIT:0> ) { return <NUM_LIT:4> ; } else { return <NUM_LIT:3> ; } } } } </s>
|
<s> package org . eclipse . zest . core . widgets . internal ; import org . eclipse . swt . widgets . Control ; public interface RevealListener { public void revealed ( Control c ) ; } </s>
|
<s> package org . eclipse . zest . core . widgets . internal ; import org . eclipse . draw2d . Animation ; import org . eclipse . draw2d . ColorConstants ; import org . eclipse . draw2d . Graphics ; import org . eclipse . draw2d . Label ; import org . eclipse . draw2d . SWTGraphics ; import org . eclipse . draw2d . ScaledGraphics ; import org . eclipse . draw2d . geometry . Point ; import org . eclipse . draw2d . geometry . Rectangle ; import org . eclipse . swt . graphics . Color ; import org . eclipse . swt . graphics . Font ; import org . eclipse . swt . graphics . GC ; import org . eclipse . swt . graphics . Image ; import org . eclipse . swt . widgets . Display ; import org . eclipse . zest . core . widgets . ILabeledFigure ; public abstract class CachedLabel extends Label implements ILabeledFigure { Image cachedImage = null ; boolean cacheLabel = false ; boolean invalidationRequired = false ; public CachedLabel ( boolean cacheLabel ) { this . cacheLabel = cacheLabel ; } public void setIcon ( Image image ) { updateInvalidation ( ) ; super . setIcon ( image ) ; } public void setForegroundColor ( Color fg ) { updateInvalidation ( ) ; super . setForegroundColor ( fg ) ; } public void setBackgroundColor ( Color bg ) { updateInvalidation ( ) ; super . setBackgroundColor ( bg ) ; } public void setFont ( Font f ) { updateInvalidation ( ) ; super . setFont ( f ) ; } public void setText ( String s ) { updateInvalidation ( ) ; super . setText ( s ) ; } public void setSize ( int w , int h ) { updateInvalidation ( ) ; if ( cachedImage != null && shouldInvalidateCache ( ) ) { cleanImage ( ) ; } super . setSize ( w , h ) ; } public void setBounds ( Rectangle rect ) { boolean resize = ( rect . width != bounds . width ) || ( rect . height != bounds . height ) ; if ( resize && Animation . isAnimating ( ) ) { updateInvalidation ( ) ; } if ( resize && shouldInvalidateCache ( ) && cachedImage != null ) { cleanImage ( ) ; } super . setBounds ( rect ) ; } protected abstract Color getBackgroundTextColor ( ) ; static Rectangle tempRect = new Rectangle ( ) ; protected void paintFigure ( Graphics graphics ) { if ( graphics . getClass ( ) == ScaledGraphics . class ) { if ( ( ( ScaledGraphics ) graphics ) . getAbsoluteScale ( ) < <NUM_LIT> ) { return ; } } if ( ! cacheLabel ) { if ( isOpaque ( ) ) { super . paintFigure ( graphics ) ; } Rectangle bounds = getBounds ( ) ; graphics . translate ( bounds . x , bounds . y ) ; if ( getIcon ( ) != null ) { graphics . drawImage ( getIcon ( ) , getIconLocation ( ) ) ; } if ( ! isEnabled ( ) ) { graphics . translate ( <NUM_LIT:1> , <NUM_LIT:1> ) ; graphics . setForegroundColor ( ColorConstants . buttonLightest ) ; graphics . drawText ( getSubStringText ( ) , getTextLocation ( ) ) ; graphics . translate ( - <NUM_LIT:1> , - <NUM_LIT:1> ) ; graphics . setForegroundColor ( ColorConstants . buttonDarker ) ; } graphics . drawText ( getText ( ) , getTextLocation ( ) ) ; graphics . translate ( - bounds . x , - bounds . y ) ; return ; } if ( isOpaque ( ) ) { graphics . fillRectangle ( getBounds ( ) ) ; } Rectangle bounds = getBounds ( ) ; graphics . translate ( bounds . x , bounds . y ) ; Image icon = getIcon ( ) ; if ( icon != null ) { graphics . drawImage ( icon , getIconLocation ( ) ) ; } int width = getSubStringTextSize ( ) . width ; int height = getSubStringTextSize ( ) . height ; if ( cachedImage == null || shouldInvalidateCache ( ) ) { invalidationRequired = false ; cleanImage ( ) ; cachedImage = new Image ( Display . getCurrent ( ) , width , height ) ; GC gc = new GC ( cachedImage ) ; Graphics graphics2 = new SWTGraphics ( gc ) ; graphics2 . setBackgroundColor ( getBackgroundTextColor ( ) ) ; graphics2 . fillRectangle ( <NUM_LIT:0> , <NUM_LIT:0> , width , height ) ; graphics2 . setForegroundColor ( getForegroundColor ( ) ) ; graphics2 . drawText ( getText ( ) , new Point ( <NUM_LIT:0> , <NUM_LIT:0> ) ) ; gc . dispose ( ) ; } graphics . drawImage ( cachedImage , getTextLocation ( ) ) ; graphics . translate ( - bounds . x , - bounds . y ) ; this . paintBorder ( graphics ) ; } private boolean shouldInvalidateCache ( ) { if ( invalidationRequired && ! Animation . isAnimating ( ) ) { return true ; } else { return false ; } } private void updateInvalidation ( ) { invalidationRequired = true ; } protected void cleanImage ( ) { if ( cachedImage != null ) { cachedImage . dispose ( ) ; cachedImage = null ; } } } </s>
|
<s> package org . eclipse . zest . core . widgets . internal ; import org . eclipse . draw2d . Figure ; public class ContainerFigure extends Figure { } </s>
|
<s> package org . eclipse . zest . core . widgets . internal ; import java . util . ArrayList ; import java . util . HashMap ; import java . util . Iterator ; import java . util . List ; import java . util . Map ; import org . eclipse . draw2d . FigureUtilities ; import org . eclipse . draw2d . Graphics ; import org . eclipse . draw2d . ScaledGraphics ; import org . eclipse . draw2d . geometry . Point ; import org . eclipse . draw2d . geometry . PointList ; import org . eclipse . draw2d . geometry . Rectangle ; 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 . Image ; import org . eclipse . swt . graphics . TextLayout ; import org . eclipse . swt . graphics . TextStyle ; import org . eclipse . swt . widgets . Display ; public class XYScaledGraphics extends ScaledGraphics { public static final double MAX_TEXT_SIZE = <NUM_LIT> ; private static class FontHeightCache { Font font ; int height ; } static class FontKey { Font font ; int height ; protected FontKey ( ) { } protected FontKey ( Font font , int height ) { this . font = font ; this . height = height ; } public boolean equals ( Object obj ) { return ( ( ( FontKey ) obj ) . font . equals ( font ) && ( ( FontKey ) obj ) . height == height ) ; } public int hashCode ( ) { return font . hashCode ( ) ^ height ; } protected void setValues ( Font font , int height ) { this . font = font ; this . height = height ; } } protected static class State { private double appliedX ; private double appliedY ; private Font font ; private int lineWidth ; private double xZoom ; private double yZoom ; protected State ( ) { } protected State ( double xZoom , double yZoom , double x , double y , Font font , int lineWidth ) { this . xZoom = xZoom ; this . yZoom = yZoom ; this . appliedX = x ; this . appliedY = y ; this . font = font ; this . lineWidth = lineWidth ; } protected void setValues ( double xZoom , double yZoom , double x , double y , Font font , int lineWidth ) { this . xZoom = xZoom ; this . yZoom = yZoom ; this . appliedX = x ; this . appliedY = y ; this . font = font ; this . lineWidth = lineWidth ; } } private static int [ ] [ ] intArrayCache = new int [ <NUM_LIT:8> ] [ ] ; private final Rectangle tempRECT = new Rectangle ( ) ; static { for ( int i = <NUM_LIT:0> ; i < intArrayCache . length ; i ++ ) { intArrayCache [ i ] = new int [ i + <NUM_LIT:1> ] ; } } private boolean allowText = true ; private Map fontCache = new HashMap ( ) ; private Map fontDataCache = new HashMap ( ) ; private FontKey fontKey = new FontKey ( ) ; private double fractionalX ; private double fractionalY ; private Graphics graphics ; private FontHeightCache localCache = new FontHeightCache ( ) ; private Font localFont ; private int localLineWidth ; private List stack = new ArrayList ( ) ; private int stackPointer = <NUM_LIT:0> ; private FontHeightCache targetCache = new FontHeightCache ( ) ; double xZoom = <NUM_LIT:1.0> ; double yZoom = <NUM_LIT:1.0> ; public XYScaledGraphics ( Graphics g ) { super ( g ) ; graphics = g ; localFont = g . getFont ( ) ; localLineWidth = g . getLineWidth ( ) ; } public void clipRect ( Rectangle r ) { graphics . clipRect ( zoomClipRect ( r ) ) ; } Font createFont ( FontData data ) { return new Font ( Display . getCurrent ( ) , data ) ; } public void dispose ( ) { while ( stackPointer > <NUM_LIT:0> ) { popState ( ) ; } Iterator iter = fontCache . values ( ) . iterator ( ) ; while ( iter . hasNext ( ) ) { Font font = ( ( Font ) iter . next ( ) ) ; font . dispose ( ) ; } } public void drawArc ( int x , int y , int w , int h , int offset , int sweep ) { Rectangle z = zoomRect ( x , y , w , h ) ; if ( z . isEmpty ( ) || sweep == <NUM_LIT:0> ) { return ; } graphics . drawArc ( z , offset , sweep ) ; } public void drawFocus ( int x , int y , int w , int h ) { graphics . drawFocus ( zoomRect ( x , y , w , h ) ) ; } public void drawImage ( Image srcImage , int x , int y ) { org . eclipse . swt . graphics . Rectangle size = srcImage . getBounds ( ) ; double imageZoom = Math . min ( xZoom , yZoom ) ; graphics . drawImage ( srcImage , <NUM_LIT:0> , <NUM_LIT:0> , size . width , size . height , ( int ) ( Math . floor ( ( x * xZoom + fractionalX ) ) ) , ( int ) ( Math . floor ( ( y * yZoom + fractionalY ) ) ) , ( int ) ( Math . floor ( ( size . width * imageZoom + fractionalX ) ) ) , ( int ) ( Math . floor ( ( size . height * imageZoom + fractionalY ) ) ) ) ; } public void drawImage ( Image srcImage , int sx , int sy , int sw , int sh , int tx , int ty , int tw , int th ) { Rectangle t = zoomRect ( tx , ty , tw , th ) ; if ( ! t . isEmpty ( ) ) { graphics . drawImage ( srcImage , sx , sy , sw , sh , t . x , t . y , t . width , t . height ) ; } } public void drawLine ( int x1 , int y1 , int x2 , int y2 ) { graphics . drawLine ( ( int ) ( Math . floor ( ( x1 * xZoom + fractionalX ) ) ) , ( int ) ( Math . floor ( ( y1 * yZoom + fractionalY ) ) ) , ( int ) ( Math . floor ( ( x2 * xZoom + fractionalX ) ) ) , ( int ) ( Math . floor ( ( y2 * yZoom + fractionalY ) ) ) ) ; } public void drawOval ( int x , int y , int w , int h ) { graphics . drawOval ( zoomRect ( x , y , w , h ) ) ; } public void drawPoint ( int x , int y ) { graphics . drawPoint ( ( int ) Math . floor ( x * xZoom + fractionalX ) , ( int ) Math . floor ( y * yZoom + fractionalY ) ) ; } public void drawPolygon ( int [ ] points ) { graphics . drawPolygon ( zoomPointList ( points ) ) ; } public void drawPolygon ( PointList points ) { graphics . drawPolygon ( zoomPointList ( points . toIntArray ( ) ) ) ; } public void drawPolyline ( int [ ] points ) { graphics . drawPolyline ( zoomPointList ( points ) ) ; } public void drawPolyline ( PointList points ) { graphics . drawPolyline ( zoomPointList ( points . toIntArray ( ) ) ) ; } public void drawRectangle ( int x , int y , int w , int h ) { graphics . drawRectangle ( zoomRect ( x , y , w , h ) ) ; } public void drawRoundRectangle ( Rectangle r , int arcWidth , int arcHeight ) { graphics . drawRoundRectangle ( zoomRect ( r . x , r . y , r . width , r . height ) , ( int ) ( arcWidth * xZoom ) , ( int ) ( arcHeight * yZoom ) ) ; } public void drawString ( String s , int x , int y ) { if ( allowText ) { graphics . drawString ( s , zoomTextPoint ( x , y ) ) ; } } public void drawText ( String s , int x , int y ) { if ( allowText ) { graphics . drawText ( s , zoomTextPoint ( x , y ) ) ; } } public void drawText ( String s , int x , int y , int style ) { if ( allowText ) { graphics . drawText ( s , zoomTextPoint ( x , y ) , style ) ; } } public void drawTextLayout ( TextLayout layout , int x , int y , int selectionStart , int selectionEnd , Color selectionForeground , Color selectionBackground ) { TextLayout scaled = zoomTextLayout ( layout ) ; graphics . drawTextLayout ( scaled , ( int ) Math . floor ( x * xZoom + fractionalX ) , ( int ) Math . floor ( y * yZoom + fractionalY ) , selectionStart , selectionEnd , selectionBackground , selectionForeground ) ; scaled . dispose ( ) ; } public void fillArc ( int x , int y , int w , int h , int offset , int sweep ) { Rectangle z = zoomFillRect ( x , y , w , h ) ; if ( z . isEmpty ( ) || sweep == <NUM_LIT:0> ) { return ; } graphics . fillArc ( z , offset , sweep ) ; } public void fillGradient ( int x , int y , int w , int h , boolean vertical ) { graphics . fillGradient ( zoomFillRect ( x , y , w , h ) , vertical ) ; } public void fillOval ( int x , int y , int w , int h ) { graphics . fillOval ( zoomFillRect ( x , y , w , h ) ) ; } public void fillPolygon ( int [ ] points ) { graphics . fillPolygon ( zoomPointList ( points ) ) ; } public void fillPolygon ( PointList points ) { graphics . fillPolygon ( zoomPointList ( points . toIntArray ( ) ) ) ; } public void fillRectangle ( int x , int y , int w , int h ) { graphics . fillRectangle ( zoomFillRect ( x , y , w , h ) ) ; } public void fillRoundRectangle ( Rectangle r , int arcWidth , int arcHeight ) { graphics . fillRoundRectangle ( zoomFillRect ( r . x , r . y , r . width , r . height ) , ( int ) ( arcWidth * xZoom ) , ( int ) ( arcHeight * yZoom ) ) ; } public void fillString ( String s , int x , int y ) { if ( allowText ) { graphics . fillString ( s , zoomTextPoint ( x , y ) ) ; } } public void fillText ( String s , int x , int y ) { if ( allowText ) { graphics . fillText ( s , zoomTextPoint ( x , y ) ) ; } } public double getAbsoluteScale ( ) { return xZoom * graphics . getAbsoluteScale ( ) ; } public int getAlpha ( ) { return graphics . getAlpha ( ) ; } public int getAntialias ( ) { return graphics . getAntialias ( ) ; } public Color getBackgroundColor ( ) { return graphics . getBackgroundColor ( ) ; } Font getCachedFont ( FontKey key ) { Font font = ( Font ) fontCache . get ( key ) ; if ( font != null ) { return font ; } key = new FontKey ( key . font , key . height ) ; FontData data = key . font . getFontData ( ) [ <NUM_LIT:0> ] ; data . setHeight ( key . height ) ; Font zoomedFont = createFont ( data ) ; fontCache . put ( key , zoomedFont ) ; return zoomedFont ; } FontData getCachedFontData ( Font f ) { FontData data = ( FontData ) fontDataCache . get ( f ) ; if ( data != null ) { return data ; } data = getLocalFont ( ) . getFontData ( ) [ <NUM_LIT:0> ] ; fontDataCache . put ( f , data ) ; return data ; } public Rectangle getClip ( Rectangle rect ) { graphics . getClip ( rect ) ; int x = ( int ) ( rect . x / xZoom ) ; int y = ( int ) ( rect . y / yZoom ) ; rect . width = ( int ) Math . ceil ( rect . right ( ) / xZoom ) - x ; rect . height = ( int ) Math . ceil ( rect . bottom ( ) / yZoom ) - y ; rect . x = x ; rect . y = y ; return rect ; } public int getFillRule ( ) { return graphics . getFillRule ( ) ; } public Font getFont ( ) { return getLocalFont ( ) ; } public FontMetrics getFontMetrics ( ) { return FigureUtilities . getFontMetrics ( localFont ) ; } public Color getForegroundColor ( ) { return graphics . getForegroundColor ( ) ; } public int getInterpolation ( ) { return graphics . getInterpolation ( ) ; } public int getLineCap ( ) { return graphics . getLineCap ( ) ; } public int getLineJoin ( ) { return graphics . getLineJoin ( ) ; } public int getLineStyle ( ) { return graphics . getLineStyle ( ) ; } public int getLineWidth ( ) { return getLocalLineWidth ( ) ; } private Font getLocalFont ( ) { return localFont ; } private int getLocalLineWidth ( ) { return localLineWidth ; } public int getTextAntialias ( ) { return graphics . getTextAntialias ( ) ; } public boolean getXORMode ( ) { return graphics . getXORMode ( ) ; } public void popState ( ) { graphics . popState ( ) ; stackPointer -- ; restoreLocalState ( ( State ) stack . get ( stackPointer ) ) ; } public void pushState ( ) { State s ; if ( stack . size ( ) > stackPointer ) { s = ( State ) stack . get ( stackPointer ) ; s . setValues ( xZoom , yZoom , fractionalX , fractionalY , getLocalFont ( ) , localLineWidth ) ; } else { stack . add ( new State ( xZoom , yZoom , fractionalX , fractionalY , getLocalFont ( ) , localLineWidth ) ) ; } stackPointer ++ ; graphics . pushState ( ) ; } private void restoreLocalState ( State state ) { this . fractionalX = state . appliedX ; this . fractionalY = state . appliedY ; setScale ( state . xZoom , state . yZoom ) ; setLocalFont ( state . font ) ; setLocalLineWidth ( state . lineWidth ) ; } public void restoreState ( ) { graphics . restoreState ( ) ; restoreLocalState ( ( State ) stack . get ( stackPointer - <NUM_LIT:1> ) ) ; } public void scale ( double xAmount , double yAmount ) { setScale ( xZoom * xAmount , yZoom * yAmount ) ; } public void scale ( double amount ) { throw new RuntimeException ( "<STR_LIT>" ) ; } public void setAlpha ( int alpha ) { graphics . setAlpha ( alpha ) ; } public void setAntialias ( int value ) { graphics . setAntialias ( value ) ; } public void setBackgroundColor ( Color rgb ) { graphics . setBackgroundColor ( rgb ) ; } public void setClip ( Rectangle r ) { graphics . setClip ( zoomClipRect ( r ) ) ; } public void setFillRule ( int rule ) { graphics . setFillRule ( rule ) ; } public void setFont ( Font f ) { setLocalFont ( f ) ; } public void setForegroundColor ( Color rgb ) { graphics . setForegroundColor ( rgb ) ; } public void setInterpolation ( int interpolation ) { graphics . setInterpolation ( interpolation ) ; } public void setLineCap ( int cap ) { graphics . setLineCap ( cap ) ; } public void setLineDash ( int [ ] dash ) { graphics . setLineDash ( dash ) ; } public void setLineJoin ( int join ) { graphics . setLineJoin ( join ) ; } public void setLineStyle ( int style ) { graphics . setLineStyle ( style ) ; } public void setLineWidth ( int width ) { setLocalLineWidth ( width ) ; } private void setLocalFont ( Font f ) { localFont = f ; graphics . setFont ( zoomFont ( f ) ) ; } private void setLocalLineWidth ( int width ) { localLineWidth = width ; graphics . setLineWidth ( zoomLineWidth ( width ) ) ; } public void setScale ( double xValue , double yValue ) { if ( xValue == xZoom && yValue == yZoom ) { return ; } this . xZoom = xValue ; this . yZoom = yValue ; graphics . setFont ( zoomFont ( getLocalFont ( ) ) ) ; graphics . setLineWidth ( zoomLineWidth ( localLineWidth ) ) ; } void setScale ( double value ) { throw new RuntimeException ( "<STR_LIT>" ) ; } public void setTextAntialias ( int value ) { graphics . setTextAntialias ( value ) ; } public void setXORMode ( boolean b ) { graphics . setXORMode ( b ) ; } public void translate ( int dx , int dy ) { double dxFloat = dx * xZoom + fractionalX ; double dyFloat = dy * yZoom + fractionalY ; fractionalX = dxFloat - Math . floor ( dxFloat ) ; fractionalY = dyFloat - Math . floor ( dyFloat ) ; graphics . translate ( ( int ) Math . floor ( dxFloat ) , ( int ) Math . floor ( dyFloat ) ) ; } private Rectangle zoomClipRect ( Rectangle r ) { tempRECT . x = ( int ) ( Math . floor ( r . x * xZoom + fractionalX ) ) ; tempRECT . y = ( int ) ( Math . floor ( r . y * yZoom + fractionalY ) ) ; tempRECT . width = ( int ) ( Math . ceil ( ( ( r . x + r . width ) * xZoom + fractionalX ) ) ) - tempRECT . x ; tempRECT . height = ( int ) ( Math . ceil ( ( ( r . y + r . height ) * yZoom + fractionalY ) ) ) - tempRECT . y ; return tempRECT ; } private Rectangle zoomFillRect ( int x , int y , int w , int h ) { tempRECT . x = ( int ) ( Math . floor ( ( x * xZoom + fractionalX ) ) ) ; tempRECT . y = ( int ) ( Math . floor ( ( y * yZoom + fractionalY ) ) ) ; tempRECT . width = ( int ) ( Math . floor ( ( ( x + w - <NUM_LIT:1> ) * xZoom + fractionalX ) ) ) - tempRECT . x + <NUM_LIT:1> ; tempRECT . height = ( int ) ( Math . floor ( ( ( y + h - <NUM_LIT:1> ) * yZoom + fractionalY ) ) ) - tempRECT . y + <NUM_LIT:1> ; return tempRECT ; } Font zoomFont ( Font f ) { if ( f == null ) { f = Display . getCurrent ( ) . getSystemFont ( ) ; } FontData data = getCachedFontData ( f ) ; int zoomedFontHeight = zoomFontHeight ( data . getHeight ( ) ) ; allowText = zoomedFontHeight > <NUM_LIT:0> ; fontKey . setValues ( f , zoomedFontHeight ) ; return getCachedFont ( fontKey ) ; } int zoomFontHeight ( int height ) { double tmp = Math . min ( yZoom , xZoom ) ; if ( tmp < MAX_TEXT_SIZE ) { return ( int ) ( tmp * height ) ; } else { return ( int ) ( height * tmp ) ; } } int zoomLineWidth ( int w ) { return w ; } private int [ ] zoomPointList ( int [ ] points ) { int [ ] scaled = null ; for ( int i = <NUM_LIT:0> ; i < intArrayCache . length ; i ++ ) { if ( intArrayCache [ i ] . length == points . length ) { scaled = intArrayCache [ i ] ; if ( i != <NUM_LIT:0> ) { int [ ] temp = intArrayCache [ i - <NUM_LIT:1> ] ; intArrayCache [ i - <NUM_LIT:1> ] = scaled ; intArrayCache [ i ] = temp ; } } } if ( scaled == null ) { intArrayCache [ intArrayCache . length - <NUM_LIT:1> ] = new int [ points . length ] ; scaled = intArrayCache [ intArrayCache . length - <NUM_LIT:1> ] ; } for ( int i = <NUM_LIT:0> ; ( i + <NUM_LIT:1> ) < points . length ; i += <NUM_LIT:2> ) { scaled [ i ] = ( int ) ( Math . floor ( ( points [ i ] * xZoom + fractionalX ) ) ) ; scaled [ i + <NUM_LIT:1> ] = ( int ) ( Math . floor ( ( points [ i + <NUM_LIT:1> ] * yZoom + fractionalY ) ) ) ; } return scaled ; } private Rectangle zoomRect ( int x , int y , int w , int h ) { tempRECT . x = ( int ) ( Math . floor ( x * xZoom + fractionalX ) ) ; tempRECT . y = ( int ) ( Math . floor ( y * yZoom + fractionalY ) ) ; tempRECT . width = ( int ) ( Math . floor ( ( ( x + w ) * xZoom + fractionalX ) ) ) - tempRECT . x ; tempRECT . height = ( int ) ( Math . floor ( ( ( y + h ) * yZoom + fractionalY ) ) ) - tempRECT . y ; return tempRECT ; } private TextLayout zoomTextLayout ( TextLayout layout ) { TextLayout zoomed = new TextLayout ( Display . getCurrent ( ) ) ; zoomed . setText ( layout . getText ( ) ) ; int zoomWidth = - <NUM_LIT:1> ; if ( layout . getWidth ( ) != - <NUM_LIT:1> ) { zoomWidth = ( ( int ) ( layout . getWidth ( ) * xZoom ) ) ; } if ( zoomWidth < - <NUM_LIT:1> || zoomWidth == <NUM_LIT:0> ) { return null ; } zoomed . setFont ( zoomFont ( layout . getFont ( ) ) ) ; zoomed . setAlignment ( layout . getAlignment ( ) ) ; zoomed . setAscent ( layout . getAscent ( ) ) ; zoomed . setDescent ( layout . getDescent ( ) ) ; zoomed . setOrientation ( layout . getOrientation ( ) ) ; zoomed . setSegments ( layout . getSegments ( ) ) ; zoomed . setSpacing ( layout . getSpacing ( ) ) ; zoomed . setTabs ( layout . getTabs ( ) ) ; zoomed . setWidth ( zoomWidth ) ; int length = layout . getText ( ) . length ( ) ; if ( length > <NUM_LIT:0> ) { int start = <NUM_LIT:0> , offset = <NUM_LIT:1> ; TextStyle style = null , lastStyle = layout . getStyle ( <NUM_LIT:0> ) ; for ( ; offset <= length ; offset ++ ) { if ( offset != length && ( style = layout . getStyle ( offset ) ) == lastStyle ) { continue ; } int end = offset - <NUM_LIT:1> ; if ( lastStyle != null ) { TextStyle zoomedStyle = new TextStyle ( zoomFont ( lastStyle . font ) , lastStyle . foreground , lastStyle . background ) ; zoomed . setStyle ( zoomedStyle , start , end ) ; } lastStyle = style ; start = offset ; } } return zoomed ; } private Point zoomTextPoint ( int x , int y ) { if ( localCache . font != localFont ) { FontMetrics metric = FigureUtilities . getFontMetrics ( localFont ) ; localCache . height = metric . getHeight ( ) - metric . getDescent ( ) ; localCache . font = localFont ; } if ( targetCache . font != graphics . getFont ( ) ) { FontMetrics metric = graphics . getFontMetrics ( ) ; targetCache . font = graphics . getFont ( ) ; targetCache . height = metric . getHeight ( ) - metric . getDescent ( ) ; } return new Point ( ( ( int ) ( Math . floor ( ( x * xZoom ) + fractionalX ) ) ) , ( int ) ( Math . floor ( ( y + localCache . height - <NUM_LIT:1> ) * yZoom - targetCache . height + <NUM_LIT:1> + fractionalY ) ) ) ; } } </s>
|
<s> package org . eclipse . zest . core . widgets . internal ; public class SharedMessages { public static String FitAllAction_Label = "<STR_LIT>" ; public static String FitWidthAction_Label = "<STR_LIT>" ; public static String FitHeightAction_Label = "<STR_LIT>" ; } </s>
|
<s> package org . eclipse . zest . core . widgets . internal ; import org . eclipse . draw2d . ChopboxAnchor ; import org . eclipse . draw2d . IFigure ; import org . eclipse . draw2d . geometry . Point ; public class LoopAnchor extends ChopboxAnchor { public LoopAnchor ( IFigure owner ) { super ( owner ) ; } public Point getReferencePoint ( ) { if ( getOwner ( ) == null ) { return null ; } else { Point ref = getOwner ( ) . getBounds ( ) . getCenter ( ) ; ref . y = getOwner ( ) . getBounds ( ) . y ; getOwner ( ) . translateToAbsolute ( ref ) ; return ref ; } } } </s>
|
<s> package org . eclipse . zest . core . widgets . gestures ; import java . util . ArrayList ; import java . util . Iterator ; import java . util . List ; import org . eclipse . draw2d . geometry . Point ; import org . eclipse . draw2d . geometry . Transform ; import org . eclipse . swt . SWT ; import org . eclipse . swt . events . GestureEvent ; import org . eclipse . swt . events . GestureListener ; import org . eclipse . zest . core . widgets . Graph ; import org . eclipse . zest . core . widgets . GraphNode ; public class RotateGestureListener implements GestureListener { Graph graph ; double rotate ; List nodes ; List originalLocations ; double xCenter , yCenter ; void storePosition ( List nodes ) { originalLocations = new ArrayList ( ) ; Iterator it = nodes . iterator ( ) ; Transform t = new Transform ( ) ; t . setTranslation ( - xCenter , - yCenter ) ; while ( it . hasNext ( ) ) { GraphNode node = ( GraphNode ) it . next ( ) ; originalLocations . add ( t . getTransformed ( node . getLocation ( ) ) ) ; } } void updatePositions ( double rotation ) { Transform t = new Transform ( ) ; t . setRotation ( rotation ) ; t . setTranslation ( xCenter , yCenter ) ; for ( int i = <NUM_LIT:0> ; i < nodes . size ( ) ; i ++ ) { GraphNode node = ( GraphNode ) nodes . get ( i ) ; Point p = ( Point ) originalLocations . get ( i ) ; Point rot = t . getTransformed ( p ) ; node . setLocation ( rot . preciseX ( ) , rot . preciseY ( ) ) ; } } public void gesture ( GestureEvent e ) { if ( ! ( e . widget instanceof Graph ) ) { return ; } switch ( e . detail ) { case SWT . GESTURE_BEGIN : graph = ( Graph ) e . widget ; rotate = <NUM_LIT:0.0> ; nodes = graph . getSelection ( ) ; if ( nodes . isEmpty ( ) ) { nodes = graph . getNodes ( ) ; } xCenter = <NUM_LIT:0> ; yCenter = <NUM_LIT:0> ; Iterator it = nodes . iterator ( ) ; while ( it . hasNext ( ) ) { GraphNode node = ( GraphNode ) it . next ( ) ; Point location = node . getLocation ( ) ; xCenter += location . preciseX ( ) ; yCenter += location . preciseY ( ) ; } xCenter = xCenter / nodes . size ( ) ; yCenter = yCenter / nodes . size ( ) ; storePosition ( nodes ) ; break ; case SWT . GESTURE_END : break ; case SWT . GESTURE_ROTATE : updatePositions ( e . rotation / <NUM_LIT:2> / Math . PI ) ; break ; default : } } } </s>
|
<s> package org . eclipse . zest . core . widgets . gestures ; import org . eclipse . swt . SWT ; import org . eclipse . swt . events . GestureEvent ; import org . eclipse . swt . events . GestureListener ; import org . eclipse . zest . core . widgets . Graph ; import org . eclipse . zest . core . widgets . zooming . ZoomManager ; public class ZoomGestureListener implements GestureListener { ZoomManager manager ; double zoom = <NUM_LIT:1.0> ; public void gesture ( GestureEvent e ) { if ( ! ( e . widget instanceof Graph ) ) { return ; } switch ( e . detail ) { case SWT . GESTURE_BEGIN : manager = ( ( Graph ) e . widget ) . getZoomManager ( ) ; zoom = manager . getZoom ( ) ; break ; case SWT . GESTURE_END : break ; case SWT . GESTURE_MAGNIFY : double newValue = zoom * e . magnification ; manager . setZoom ( newValue ) ; break ; default : } } } </s>
|
<s> package org . eclipse . zest . core . widgets ; import org . eclipse . draw2d . IFigure ; import org . eclipse . swt . SWT ; import org . eclipse . swt . widgets . Item ; import org . eclipse . swt . widgets . Widget ; public abstract class GraphItem extends Item { public static final int GRAPH = <NUM_LIT:0> ; public static final int NODE = <NUM_LIT:1> ; public static final int CONNECTION = <NUM_LIT:2> ; public static final int CONTAINER = <NUM_LIT:3> ; public GraphItem ( Widget parent , int style ) { super ( parent , style | SWT . NO_BACKGROUND ) ; } public GraphItem ( Widget parent , int style , Object data ) { this ( parent , style | SWT . NO_BACKGROUND ) ; setDataChecked ( data ) ; } protected GraphItem ( IContainer parent , int style , Object data ) { this ( parent . getGraph ( ) , style | SWT . NO_BACKGROUND ) ; setDataChecked ( data ) ; } private void setDataChecked ( Object data ) { if ( data != null ) { this . setData ( data ) ; } } public void dispose ( ) { super . dispose ( ) ; } public abstract int getItemType ( ) ; public abstract void setVisible ( boolean visible ) ; public abstract boolean isVisible ( ) ; public abstract Graph getGraphModel ( ) ; public abstract void highlight ( ) ; public abstract void unhighlight ( ) ; abstract IFigure getFigure ( ) ; protected boolean checkStyle ( int styleToCheck ) { return ( ( getStyle ( ) & styleToCheck ) > <NUM_LIT:0> ) ; } } </s>
|
<s> package org . eclipse . zest . core . widgets ; import org . eclipse . draw2d . ChopboxAnchor ; import org . eclipse . draw2d . ColorConstants ; import org . eclipse . draw2d . Connection ; import org . eclipse . draw2d . ConnectionRouter ; import org . eclipse . draw2d . Graphics ; import org . eclipse . draw2d . IFigure ; import org . eclipse . draw2d . Label ; import org . eclipse . draw2d . Locator ; import org . eclipse . draw2d . MidpointLocator ; import org . eclipse . draw2d . PolygonDecoration ; import org . eclipse . draw2d . PolylineConnection ; import org . eclipse . draw2d . Shape ; import org . eclipse . draw2d . geometry . Point ; import org . eclipse . swt . graphics . Color ; import org . eclipse . swt . graphics . Font ; import org . eclipse . swt . widgets . Display ; import org . eclipse . zest . core . widgets . internal . LoopAnchor ; import org . eclipse . zest . core . widgets . internal . PolylineArcConnection ; import org . eclipse . zest . core . widgets . internal . RoundedChopboxAnchor ; import org . eclipse . zest . core . widgets . internal . ZestRootLayer ; import org . eclipse . zest . layouts . interfaces . ConnectionLayout ; import org . eclipse . zest . layouts . interfaces . NodeLayout ; public class GraphConnection extends GraphItem { private Font font ; private GraphNode sourceNode ; private GraphNode destinationNode ; private double weight ; private Color color ; private Color highlightColor ; private Color foreground ; private int lineWidth ; private int lineStyle ; private final Graph graph ; private int connectionStyle ; private int curveDepth ; private boolean isDisposed = false ; private Label connectionLabel = null ; private PolylineArcConnection connectionFigure = null ; private PolylineArcConnection cachedConnectionFigure = null ; private Connection sourceContainerConnectionFigure = null ; private Connection targetContainerConnectionFigure = null ; private boolean visible ; private IFigure tooltip ; private boolean highlighted ; private boolean hasCustomTooltip ; private ConnectionRouter router = null ; public GraphConnection ( Graph graphModel , int style , GraphNode source , GraphNode destination ) { super ( graphModel , style ) ; this . connectionStyle |= graphModel . getConnectionStyle ( ) ; this . connectionStyle |= style ; this . sourceNode = source ; this . destinationNode = destination ; this . visible = true ; this . color = ColorConstants . lightGray ; this . foreground = ColorConstants . lightGray ; this . highlightColor = graphModel . DARK_BLUE ; this . lineWidth = <NUM_LIT:1> ; this . lineStyle = Graphics . LINE_SOLID ; setWeight ( <NUM_LIT:1.0> ) ; this . graph = graphModel ; this . curveDepth = <NUM_LIT:0> ; this . font = Display . getDefault ( ) . getSystemFont ( ) ; registerConnection ( source , destination ) ; } private void registerConnection ( GraphNode source , GraphNode destination ) { if ( source . getSourceConnections ( ) . contains ( this ) ) { source . removeSourceConnection ( this ) ; } if ( destination . getTargetConnections ( ) . contains ( this ) ) { destination . removeTargetConnection ( this ) ; } ( source ) . addSourceConnection ( this ) ; ( destination ) . addTargetConnection ( this ) ; if ( source . getParent ( ) . getItemType ( ) == GraphItem . CONTAINER && destination . getParent ( ) . getItemType ( ) == GraphItem . CONTAINER && ( source . getParent ( ) == destination . getParent ( ) ) ) { graph . addConnection ( this , false ) ; } else { graph . addConnection ( this , true ) ; } if ( ( source . getParent ( ) ) . getItemType ( ) == GraphItem . CONTAINER ) { sourceContainerConnectionFigure = doCreateFigure ( ) ; ( ( GraphContainer ) source . getParent ( ) ) . addConnectionFigure ( sourceContainerConnectionFigure ) ; this . setVisible ( false ) ; } if ( ( destination . getParent ( ) ) . getItemType ( ) == GraphItem . CONTAINER ) { targetContainerConnectionFigure = doCreateFigure ( ) ; ( ( GraphContainer ) destination . getParent ( ) ) . addConnectionFigure ( targetContainerConnectionFigure ) ; this . setVisible ( false ) ; } graph . registerItem ( this ) ; } void removeFigure ( ) { if ( connectionFigure . getParent ( ) != null ) { connectionFigure . getParent ( ) . remove ( connectionFigure ) ; } connectionFigure = null ; if ( sourceContainerConnectionFigure != null ) { sourceContainerConnectionFigure . getParent ( ) . remove ( sourceContainerConnectionFigure ) ; sourceContainerConnectionFigure = null ; } if ( targetContainerConnectionFigure != null ) { targetContainerConnectionFigure . getParent ( ) . remove ( targetContainerConnectionFigure ) ; targetContainerConnectionFigure = null ; } } public void dispose ( ) { super . dispose ( ) ; this . isDisposed = true ; ( getSource ( ) ) . removeSourceConnection ( this ) ; ( getDestination ( ) ) . removeTargetConnection ( this ) ; graph . removeConnection ( this ) ; if ( sourceContainerConnectionFigure != null ) { sourceContainerConnectionFigure . getParent ( ) . remove ( sourceContainerConnectionFigure ) ; } if ( targetContainerConnectionFigure != null ) { targetContainerConnectionFigure . getParent ( ) . remove ( targetContainerConnectionFigure ) ; } } public boolean isDisposed ( ) { return isDisposed ; } public Connection getConnectionFigure ( ) { if ( connectionFigure == null ) { connectionFigure = doCreateFigure ( ) ; } return connectionFigure ; } public Object getExternalConnection ( ) { return this . getData ( ) ; } public String toString ( ) { StringBuffer buffer = new StringBuffer ( "<STR_LIT>" ) ; buffer . append ( sourceNode != null ? sourceNode . getText ( ) : "<STR_LIT:null>" ) ; buffer . append ( isDirected ( ) ? "<STR_LIT>" : "<STR_LIT>" ) ; buffer . append ( destinationNode != null ? destinationNode . getText ( ) : "<STR_LIT:null>" ) ; buffer . append ( "<STR_LIT>" ) . append ( getWeightInLayout ( ) ) . append ( "<STR_LIT:)>" ) ; return buffer . toString ( ) ; } public int getConnectionStyle ( ) { return connectionStyle ; } public void setConnectionStyle ( int style ) { this . connectionStyle = style ; updateFigure ( this . connectionFigure ) ; } public double getWeightInLayout ( ) { return weight ; } public Font getFont ( ) { return this . font ; } public void setFont ( Font f ) { this . font = f ; } public void setWeight ( double weight ) { if ( weight < <NUM_LIT:0> ) { this . weight = - <NUM_LIT:1> ; } else if ( weight > <NUM_LIT:1> ) { this . weight = <NUM_LIT:1> ; } else { this . weight = weight ; } } public Color getLineColor ( ) { return color ; } public void setHighlightColor ( Color color ) { this . highlightColor = color ; } public Color getHighlightColor ( ) { return highlightColor ; } public void setLineColor ( Color color ) { this . foreground = color ; changeLineColor ( foreground ) ; } public void changeLineColor ( Color color ) { this . color = color ; updateFigure ( connectionFigure ) ; } public void setTooltip ( IFigure tooltip ) { hasCustomTooltip = true ; this . tooltip = tooltip ; updateFigure ( connectionFigure ) ; } public IFigure getTooltip ( ) { return this . tooltip ; } public int getLineWidth ( ) { return lineWidth ; } public void setLineWidth ( int lineWidth ) { this . lineWidth = lineWidth ; updateFigure ( connectionFigure ) ; } public int getLineStyle ( ) { return lineStyle ; } public void setLineStyle ( int lineStyle ) { this . lineStyle = lineStyle ; updateFigure ( connectionFigure ) ; } public GraphNode getSource ( ) { return this . sourceNode ; } public GraphNode getDestination ( ) { return this . destinationNode ; } public void highlight ( ) { if ( highlighted ) { return ; } IFigure parentFigure = connectionFigure . getParent ( ) ; if ( parentFigure instanceof ZestRootLayer ) { ( ( ZestRootLayer ) parentFigure ) . highlightConnection ( connectionFigure ) ; } highlighted = true ; updateFigure ( connectionFigure ) ; } public void unhighlight ( ) { if ( ! highlighted ) { return ; } IFigure parentFigure = connectionFigure . getParent ( ) ; if ( parentFigure instanceof ZestRootLayer ) { ( ( ZestRootLayer ) parentFigure ) . unHighlightConnection ( connectionFigure ) ; } highlighted = false ; updateFigure ( connectionFigure ) ; } public boolean isHighlighted ( ) { return highlighted ; } public Graph getGraphModel ( ) { return this . graph ; } public void setCurveDepth ( int depth ) { if ( this . curveDepth == <NUM_LIT:0> && depth != <NUM_LIT:0> || this . curveDepth != <NUM_LIT:0> && depth == <NUM_LIT:0> ) { this . cachedConnectionFigure = connectionFigure ; graph . removeConnection ( this ) ; this . curveDepth = depth ; this . connectionFigure = doCreateFigure ( ) ; registerConnection ( sourceNode , destinationNode ) ; updateFigure ( this . connectionFigure ) ; } else { this . curveDepth = depth ; updateFigure ( this . connectionFigure ) ; } } public int getItemType ( ) { return CONNECTION ; } public void setVisible ( boolean visible ) { if ( getSource ( ) . isVisible ( ) && getDestination ( ) . isVisible ( ) && visible ) { this . getFigure ( ) . setVisible ( visible ) ; if ( sourceContainerConnectionFigure != null ) { sourceContainerConnectionFigure . setVisible ( visible ) ; } if ( targetContainerConnectionFigure != null ) { targetContainerConnectionFigure . setVisible ( visible ) ; } this . visible = visible ; } else { this . getFigure ( ) . setVisible ( false ) ; if ( sourceContainerConnectionFigure != null ) { sourceContainerConnectionFigure . setVisible ( false ) ; } if ( targetContainerConnectionFigure != null ) { targetContainerConnectionFigure . setVisible ( false ) ; } this . visible = false ; } } public boolean isVisible ( ) { return visible ; } public void setText ( String string ) { super . setText ( string ) ; if ( this . connectionFigure != null ) { updateFigure ( this . connectionFigure ) ; } } public boolean isDirected ( ) { return ZestStyles . checkStyle ( connectionStyle , ZestStyles . CONNECTIONS_DIRECTED ) ; } public void setDirected ( boolean directed ) { if ( directed ) { setConnectionStyle ( connectionStyle | ZestStyles . CONNECTIONS_DIRECTED ) ; } else { setConnectionStyle ( connectionStyle & ( - <NUM_LIT:1> - ZestStyles . CONNECTIONS_DIRECTED ) ) ; } } PolylineConnection getSourceContainerConnectionFigure ( ) { return ( PolylineConnection ) sourceContainerConnectionFigure ; } PolylineConnection getTargetContainerConnectionFigure ( ) { return ( PolylineConnection ) targetContainerConnectionFigure ; } private void updateFigure ( PolylineArcConnection connection ) { if ( sourceContainerConnectionFigure != null ) { doUpdateFigure ( sourceContainerConnectionFigure ) ; } if ( targetContainerConnectionFigure != null ) { doUpdateFigure ( targetContainerConnectionFigure ) ; } doUpdateFigure ( connection ) ; } private void doUpdateFigure ( Connection connection ) { if ( connection == null || this . isDisposed ( ) ) { return ; } Shape connectionShape = ( Shape ) connection ; connectionShape . setLineStyle ( getLineStyle ( ) ) ; if ( this . getText ( ) != null || this . getImage ( ) != null ) { if ( this . getImage ( ) != null ) { this . connectionLabel . setIcon ( this . getImage ( ) ) ; } if ( this . getText ( ) != null ) { this . connectionLabel . setText ( this . getText ( ) ) ; } this . connectionLabel . setFont ( this . getFont ( ) ) ; } if ( highlighted ) { connectionShape . setForegroundColor ( getHighlightColor ( ) ) ; connectionShape . setLineWidth ( getLineWidth ( ) * <NUM_LIT:2> ) ; } else { connectionShape . setForegroundColor ( getLineColor ( ) ) ; connectionShape . setLineWidth ( getLineWidth ( ) ) ; } if ( connection instanceof PolylineArcConnection ) { PolylineArcConnection arcConnection = ( PolylineArcConnection ) connection ; arcConnection . setDepth ( curveDepth ) ; } if ( connectionFigure != null ) { applyConnectionRouter ( connectionFigure ) ; } if ( ( connectionStyle & ZestStyles . CONNECTIONS_DIRECTED ) > <NUM_LIT:0> ) { PolygonDecoration decoration = new PolygonDecoration ( ) ; if ( getLineWidth ( ) < <NUM_LIT:3> ) { decoration . setScale ( <NUM_LIT:9> , <NUM_LIT:3> ) ; } else { double logLineWith = getLineWidth ( ) / <NUM_LIT> ; decoration . setScale ( <NUM_LIT:7> * logLineWith , <NUM_LIT:3> * logLineWith ) ; } if ( connection instanceof PolylineConnection ) { ( ( PolylineArcConnection ) connection ) . setTargetDecoration ( decoration ) ; } } IFigure toolTip ; if ( this . getTooltip ( ) == null && getText ( ) != null && getText ( ) . length ( ) > <NUM_LIT:0> && hasCustomTooltip == false ) { toolTip = new Label ( ) ; ( ( Label ) toolTip ) . setText ( getText ( ) ) ; } else { toolTip = this . getTooltip ( ) ; } connection . setToolTip ( toolTip ) ; } private PolylineArcConnection doCreateFigure ( ) { PolylineArcConnection connectionFigure = cachedOrNewConnectionFigure ( ) ; ChopboxAnchor sourceAnchor = null ; ChopboxAnchor targetAnchor = null ; this . connectionLabel = new Label ( ) ; Locator labelLocator = null ; if ( getSource ( ) == getDestination ( ) ) { sourceAnchor = new LoopAnchor ( getSource ( ) . getNodeFigure ( ) ) ; targetAnchor = new LoopAnchor ( getDestination ( ) . getNodeFigure ( ) ) ; labelLocator = new MidpointLocator ( connectionFigure , <NUM_LIT:0> ) { protected Point getReferencePoint ( ) { Point p = Point . SINGLETON ; p . x = getConnection ( ) . getPoints ( ) . getPoint ( getIndex ( ) ) . x ; p . y = ( int ) ( getConnection ( ) . getPoints ( ) . getPoint ( getIndex ( ) ) . y - ( curveDepth * <NUM_LIT> ) ) ; getConnection ( ) . translateToAbsolute ( p ) ; return p ; } } ; } else { if ( curveDepth != <NUM_LIT:0> ) { connectionFigure . setDepth ( this . curveDepth ) ; } applyConnectionRouter ( connectionFigure ) ; sourceAnchor = new RoundedChopboxAnchor ( getSource ( ) . getNodeFigure ( ) , <NUM_LIT:8> ) ; targetAnchor = new RoundedChopboxAnchor ( getDestination ( ) . getNodeFigure ( ) , <NUM_LIT:8> ) ; labelLocator = new MidpointLocator ( connectionFigure , <NUM_LIT:0> ) ; } connectionFigure . setSourceAnchor ( sourceAnchor ) ; connectionFigure . setTargetAnchor ( targetAnchor ) ; connectionFigure . add ( this . connectionLabel , labelLocator ) ; doUpdateFigure ( connectionFigure ) ; return connectionFigure ; } private PolylineArcConnection cachedOrNewConnectionFigure ( ) { return cachedConnectionFigure == null ? new PolylineArcConnection ( ) : cachedConnectionFigure ; } IFigure getFigure ( ) { return this . getConnectionFigure ( ) ; } private InternalConnectionLayout layout ; InternalConnectionLayout getLayout ( ) { if ( layout == null ) { layout = new InternalConnectionLayout ( ) ; } return layout ; } class InternalConnectionLayout implements ConnectionLayout { private boolean visible = GraphConnection . this . isVisible ( ) ; public NodeLayout getSource ( ) { return sourceNode . getLayout ( ) ; } public NodeLayout getTarget ( ) { return destinationNode . getLayout ( ) ; } public double getWeight ( ) { return GraphConnection . this . getWeightInLayout ( ) ; } public boolean isDirected ( ) { return ! ZestStyles . checkStyle ( getConnectionStyle ( ) , ZestStyles . CONNECTIONS_DIRECTED ) ; } public boolean isVisible ( ) { return visible ; } public void setVisible ( boolean visible ) { graph . getLayoutContext ( ) . checkChangesAllowed ( ) ; this . visible = visible ; } void applyLayout ( ) { if ( GraphConnection . this . isVisible ( ) != this . visible ) { GraphConnection . this . setVisible ( this . visible ) ; } } } void applyLayoutChanges ( ) { if ( layout != null ) { layout . applyLayout ( ) ; } } void applyConnectionRouter ( Connection conn ) { if ( router != null ) { conn . setConnectionRouter ( router ) ; } else if ( graph . getDefaultConnectionRouter ( ) != null ) { conn . setConnectionRouter ( graph . getDefaultConnectionRouter ( ) ) ; } } public void setRouter ( ConnectionRouter router ) { this . router = router ; } } </s>
|
<s> package org . eclipse . zest . core . widgets . zooming ; import java . util . ArrayList ; import java . util . Collections ; import java . util . Iterator ; import java . util . List ; import org . eclipse . draw2d . FreeformFigure ; import org . eclipse . draw2d . IFigure ; import org . eclipse . draw2d . ScalableFigure ; import org . eclipse . draw2d . ScalableFreeformLayeredPane ; import org . eclipse . draw2d . Viewport ; import org . eclipse . draw2d . geometry . Dimension ; import org . eclipse . draw2d . geometry . Point ; import org . eclipse . draw2d . geometry . Rectangle ; import org . eclipse . swt . widgets . Display ; import org . eclipse . zest . core . widgets . internal . SharedMessages ; public class ZoomManager { public static final int ANIMATE_NEVER = <NUM_LIT:0> ; public static final int ANIMATE_ZOOM_IN_OUT = <NUM_LIT:1> ; private List listeners = new ArrayList ( ) ; private double multiplier = <NUM_LIT:1.0> ; private ScalableFigure pane ; private Viewport viewport ; private double zoom = <NUM_LIT:1.0> ; private String currentZoomContant = null ; private double [ ] zoomLevels = { <NUM_LIT> , <NUM_LIT> , <NUM_LIT:1.0> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT:4> } ; public static final String FIT_HEIGHT = SharedMessages . FitHeightAction_Label ; public static final String FIT_WIDTH = SharedMessages . FitWidthAction_Label ; public static final String FIT_ALL = SharedMessages . FitAllAction_Label ; private List zoomLevelContributions = Collections . emptyList ( ) ; public ZoomManager ( ScalableFigure pane , Viewport viewport ) { this . pane = pane ; this . viewport = viewport ; zoomLevelContributions = new ArrayList ( ) ; zoomLevelContributions . add ( FIT_ALL ) ; } public ZoomManager ( ScalableFreeformLayeredPane pane , Viewport viewport ) { this . pane = pane ; this . viewport = viewport ; } public void addZoomListener ( ZoomListener listener ) { listeners . add ( listener ) ; } public boolean canZoomIn ( ) { return getZoom ( ) < getMaxZoom ( ) ; } public boolean canZoomOut ( ) { return getZoom ( ) > getMinZoom ( ) ; } protected void fireZoomChanged ( ) { Iterator iter = listeners . iterator ( ) ; while ( iter . hasNext ( ) ) { ( ( ZoomListener ) iter . next ( ) ) . zoomChanged ( zoom ) ; } } private double getFitXZoomLevel ( int which ) { IFigure fig = getScalableFigure ( ) ; Dimension available = getViewport ( ) . getClientArea ( ) . getSize ( ) ; Dimension desired ; if ( fig instanceof FreeformFigure ) { desired = ( ( FreeformFigure ) fig ) . getFreeformExtent ( ) . getCopy ( ) . union ( <NUM_LIT:0> , <NUM_LIT:0> ) . getSize ( ) ; } else { desired = fig . getPreferredSize ( ) . getCopy ( ) ; } desired . width -= fig . getInsets ( ) . getWidth ( ) ; desired . height -= fig . getInsets ( ) . getHeight ( ) ; while ( fig != getViewport ( ) ) { available . width -= fig . getInsets ( ) . getWidth ( ) ; available . height -= fig . getInsets ( ) . getHeight ( ) ; fig = fig . getParent ( ) ; } double scaleX = Math . min ( available . width * zoom / desired . width , getMaxZoom ( ) ) ; double scaleY = Math . min ( available . height * zoom / desired . height , getMaxZoom ( ) ) ; if ( which == <NUM_LIT:0> ) { return scaleX ; } if ( which == <NUM_LIT:1> ) { return scaleY ; } return Math . min ( scaleX , scaleY ) ; } protected double getFitHeightZoomLevel ( ) { return getFitXZoomLevel ( <NUM_LIT:1> ) ; } protected double getFitPageZoomLevel ( ) { return getFitXZoomLevel ( <NUM_LIT:2> ) ; } protected double getFitWidthZoomLevel ( ) { return getFitXZoomLevel ( <NUM_LIT:0> ) ; } public double getMaxZoom ( ) { return getZoomLevels ( ) [ getZoomLevels ( ) . length - <NUM_LIT:1> ] ; } public double getMinZoom ( ) { return getZoomLevels ( ) [ <NUM_LIT:0> ] ; } public double getUIMultiplier ( ) { return multiplier ; } public double getNextZoomLevel ( ) { for ( int i = <NUM_LIT:0> ; i < zoomLevels . length ; i ++ ) { if ( zoomLevels [ i ] > zoom ) { return zoomLevels [ i ] ; } } return getMaxZoom ( ) ; } public double getPreviousZoomLevel ( ) { for ( int i = <NUM_LIT:1> ; i < zoomLevels . length ; i ++ ) { if ( zoomLevels [ i ] >= zoom ) { return zoomLevels [ i - <NUM_LIT:1> ] ; } } return getMinZoom ( ) ; } public ScalableFigure getScalableFigure ( ) { return pane ; } public Viewport getViewport ( ) { return viewport ; } public double getZoom ( ) { return zoom ; } private String format ( double d ) { return "<STR_LIT>" + ( ( int ) ( d * <NUM_LIT:100> ) ) + "<STR_LIT:%>" ; } public String getZoomAsText ( ) { if ( currentZoomContant != null ) { return currentZoomContant ; } String newItem = format ( zoom * multiplier ) ; return newItem ; } public List getZoomLevelContributions ( ) { return zoomLevelContributions ; } public double [ ] getZoomLevels ( ) { return zoomLevels ; } public String [ ] getZoomLevelsAsText ( ) { String [ ] zoomLevelStrings = new String [ zoomLevels . length + zoomLevelContributions . size ( ) ] ; if ( zoomLevelContributions != null ) { for ( int i = <NUM_LIT:0> ; i < zoomLevelContributions . size ( ) ; i ++ ) { zoomLevelStrings [ i ] = ( String ) zoomLevelContributions . get ( i ) ; } } for ( int i = <NUM_LIT:0> ; i < zoomLevels . length ; i ++ ) { zoomLevelStrings [ i + zoomLevelContributions . size ( ) ] = format ( zoomLevels [ i ] * multiplier ) ; } return zoomLevelStrings ; } protected void primSetZoom ( double zoom ) { Point p1 = getViewport ( ) . getClientArea ( ) . getCenter ( ) ; Point p2 = p1 . getCopy ( ) ; Point p = getViewport ( ) . getViewLocation ( ) ; double prevZoom = this . zoom ; this . zoom = zoom ; pane . setScale ( zoom ) ; fireZoomChanged ( ) ; getViewport ( ) . validate ( ) ; p2 . scale ( zoom / prevZoom ) ; Dimension dif = p2 . getDifference ( p1 ) ; p . x += dif . width ; p . y += dif . height ; setViewLocation ( p ) ; } public void removeZoomListener ( ZoomListener listener ) { listeners . remove ( listener ) ; } public void setUIMultiplier ( double multiplier ) { this . multiplier = multiplier ; } public void setViewLocation ( Point p ) { viewport . setViewLocation ( p . x , p . y ) ; } public void setZoom ( double zoom ) { currentZoomContant = null ; zoom = Math . min ( getMaxZoom ( ) , zoom ) ; zoom = Math . max ( getMinZoom ( ) , zoom ) ; if ( this . zoom != zoom ) { primSetZoom ( zoom ) ; } } public void setZoomAnimationStyle ( int style ) { } public void setZoomAsText ( String zoomString ) { currentZoomContant = null ; if ( zoomString . equalsIgnoreCase ( FIT_HEIGHT ) ) { currentZoomContant = FIT_HEIGHT ; primSetZoom ( getFitHeightZoomLevel ( ) ) ; viewport . getUpdateManager ( ) . performUpdate ( ) ; viewport . setViewLocation ( viewport . getHorizontalRangeModel ( ) . getValue ( ) , viewport . getVerticalRangeModel ( ) . getMinimum ( ) ) ; } else if ( zoomString . equalsIgnoreCase ( FIT_ALL ) ) { currentZoomContant = FIT_ALL ; primSetZoom ( getFitPageZoomLevel ( ) ) ; viewport . getUpdateManager ( ) . performUpdate ( ) ; viewport . setViewLocation ( viewport . getHorizontalRangeModel ( ) . getMinimum ( ) , viewport . getVerticalRangeModel ( ) . getMinimum ( ) ) ; } else if ( zoomString . equalsIgnoreCase ( FIT_WIDTH ) ) { currentZoomContant = FIT_WIDTH ; primSetZoom ( getFitWidthZoomLevel ( ) ) ; viewport . getUpdateManager ( ) . performUpdate ( ) ; viewport . setViewLocation ( viewport . getHorizontalRangeModel ( ) . getMinimum ( ) , viewport . getVerticalRangeModel ( ) . getValue ( ) ) ; } else { try { if ( zoomString . charAt ( zoomString . length ( ) - <NUM_LIT:1> ) == '<CHAR_LIT>' ) { zoomString = zoomString . substring ( <NUM_LIT:0> , zoomString . length ( ) - <NUM_LIT:1> ) ; } double newZoom = Double . parseDouble ( zoomString ) / <NUM_LIT:100> ; setZoom ( newZoom / multiplier ) ; } catch ( Exception e ) { Display . getCurrent ( ) . beep ( ) ; } } } public void setZoomLevelContributions ( List contributions ) { zoomLevelContributions = contributions ; } public void setZoomLevels ( double [ ] zoomLevels ) { this . zoomLevels = zoomLevels ; } public void zoomIn ( ) { setZoom ( getNextZoomLevel ( ) ) ; } public void zoomTo ( Rectangle rect ) { } public void zoomOut ( ) { setZoom ( getPreviousZoomLevel ( ) ) ; } } </s>
|
<s> package org . eclipse . zest . core . widgets . zooming ; public interface ZoomListener { void zoomChanged ( double zoom ) ; } </s>
|
<s> package org . eclipse . zest . core . widgets ; import org . eclipse . zest . layouts . interfaces . LayoutContext ; import org . eclipse . zest . layouts . interfaces . NodeLayout ; import org . eclipse . zest . layouts . interfaces . SubgraphLayout ; public interface SubgraphFactory { SubgraphLayout createSubgraph ( NodeLayout [ ] nodes , LayoutContext context ) ; } </s>
|
<s> package org . eclipse . zest . core . widgets ; public final class ZestStyles { public static final int NONE = <NUM_LIT:0> ; public static final int IGNORE_INVISIBLE_LAYOUT = <NUM_LIT:1> << <NUM_LIT:1> ; public static final int NODES_CACHE_LABEL = <NUM_LIT:1> << <NUM_LIT:1> ; public static final int NODES_FISHEYE = <NUM_LIT:1> << <NUM_LIT:2> ; public static final int NODES_HIDE_TEXT = <NUM_LIT:1> << <NUM_LIT:3> ; public static final int NODES_NO_LAYOUT_RESIZE = <NUM_LIT:1> << <NUM_LIT:4> ; public static final int CONNECTIONS_DIRECTED = <NUM_LIT:1> << <NUM_LIT:1> ; public static final int CONNECTIONS_SOLID = <NUM_LIT:1> << <NUM_LIT:2> ; public static final int CONNECTIONS_DASH = <NUM_LIT:1> << <NUM_LIT:3> ; public static final int CONNECTIONS_DOT = <NUM_LIT:1> << <NUM_LIT:4> ; public static final int CONNECTIONS_DASH_DOT = <NUM_LIT:1> << <NUM_LIT:5> ; public static final int GESTURES_DISABLED = <NUM_LIT:1> << <NUM_LIT:6> ; public static boolean checkStyle ( int style , int styleToCheck ) { return ( ( style & styleToCheck ) == styleToCheck ) ; } public static boolean validateConnectionStyle ( int styleToValidate ) { int style = styleToValidate ; int illegal = CONNECTIONS_DASH_DOT | CONNECTIONS_DASH | CONNECTIONS_DOT | CONNECTIONS_SOLID ; style = styleToValidate ; style &= illegal ; int rightBit = style & ( - style ) ; boolean okay = ( style == rightBit ) ; if ( ! okay ) { return okay ; } return true ; } } </s>
|
<s> package org . eclipse . zest . core . widgets ; import java . util . ArrayList ; import java . util . HashMap ; import java . util . HashSet ; import java . util . Iterator ; import org . eclipse . draw2d . FigureListener ; import org . eclipse . draw2d . IFigure ; import org . eclipse . draw2d . geometry . Dimension ; import org . eclipse . draw2d . geometry . Point ; import org . eclipse . swt . widgets . Item ; import org . eclipse . zest . layouts . dataStructures . DisplayIndependentDimension ; import org . eclipse . zest . layouts . dataStructures . DisplayIndependentPoint ; import org . eclipse . zest . layouts . interfaces . ConnectionLayout ; import org . eclipse . zest . layouts . interfaces . EntityLayout ; import org . eclipse . zest . layouts . interfaces . NodeLayout ; import org . eclipse . zest . layouts . interfaces . SubgraphLayout ; class InternalNodeLayout implements NodeLayout { private final static FigureListener figureListener = new FigureListener ( ) { public void figureMoved ( IFigure source ) { GraphNode node = ( GraphNode ) figureToNode . get ( source ) ; if ( node . getLayout ( ) . isMinimized ( ) && source . getSize ( ) . equals ( <NUM_LIT:0> , <NUM_LIT:0> ) ) { source . setVisible ( false ) ; } else { source . setVisible ( node . isVisible ( ) ) ; } } } ; private final static HashMap figureToNode = new HashMap ( ) ; private DisplayIndependentPoint location ; private DisplayIndependentDimension size ; private boolean minimized = false ; private final GraphNode node ; private final InternalLayoutContext ownerLayoutContext ; private DefaultSubgraph subgraph ; private boolean isDisposed = false ; public InternalNodeLayout ( GraphNode graphNode ) { this . node = graphNode ; this . ownerLayoutContext = node . parent . getLayoutContext ( ) ; graphNode . nodeFigure . addFigureListener ( figureListener ) ; figureToNode . put ( graphNode . nodeFigure , graphNode ) ; } public DisplayIndependentPoint getLocation ( ) { if ( location == null ) { refreshLocation ( ) ; } return new DisplayIndependentPoint ( location ) ; } public DisplayIndependentDimension getSize ( ) { if ( size == null ) { refreshSize ( ) ; } return new DisplayIndependentDimension ( size ) ; } public SubgraphLayout getSubgraph ( ) { return subgraph ; } public boolean isMovable ( ) { return true ; } public boolean isPrunable ( ) { return ownerLayoutContext . isPruningEnabled ( ) ; } public boolean isPruned ( ) { return subgraph != null ; } public boolean isResizable ( ) { return ( node . parent . getItem ( ) . getStyle ( ) & ZestStyles . NODES_NO_LAYOUT_RESIZE ) == <NUM_LIT:0> ; } public void prune ( SubgraphLayout subgraph ) { if ( subgraph != null && ! ( subgraph instanceof DefaultSubgraph ) ) { throw new RuntimeException ( "<STR_LIT>" ) ; } ownerLayoutContext . checkChangesAllowed ( ) ; if ( subgraph == this . subgraph ) { return ; } if ( this . subgraph != null ) { SubgraphLayout subgraph2 = this . subgraph ; this . subgraph = null ; subgraph2 . removeNodes ( new NodeLayout [ ] { this } ) ; } if ( subgraph != null ) { this . subgraph = ( DefaultSubgraph ) subgraph ; subgraph . addNodes ( new NodeLayout [ ] { this } ) ; } } public void setLocation ( double x , double y ) { if ( ! ownerLayoutContext . isLayoutItemFiltered ( this . getNode ( ) ) ) { ownerLayoutContext . checkChangesAllowed ( ) ; internalSetLocation ( x , y ) ; } } private void internalSetLocation ( double x , double y ) { if ( location != null ) { location . x = x ; location . y = y ; } else { location = new DisplayIndependentPoint ( x , y ) ; } } public void setSize ( double width , double height ) { ownerLayoutContext . checkChangesAllowed ( ) ; internalSetSize ( width , height ) ; } private void internalSetSize ( double width , double height ) { if ( size != null ) { size . width = width ; size . height = height ; } else { size = new DisplayIndependentDimension ( width , height ) ; } } public void setMinimized ( boolean minimized ) { ownerLayoutContext . checkChangesAllowed ( ) ; getSize ( ) ; this . minimized = minimized ; } public boolean isMinimized ( ) { return minimized ; } public NodeLayout [ ] getPredecessingNodes ( ) { ConnectionLayout [ ] connections = getIncomingConnections ( ) ; NodeLayout [ ] result = new NodeLayout [ connections . length ] ; for ( int i = <NUM_LIT:0> ; i < connections . length ; i ++ ) { result [ i ] = connections [ i ] . getSource ( ) ; if ( result [ i ] == this ) { result [ i ] = connections [ i ] . getTarget ( ) ; } } return result ; } public NodeLayout [ ] getSuccessingNodes ( ) { ConnectionLayout [ ] connections = getOutgoingConnections ( ) ; NodeLayout [ ] result = new NodeLayout [ connections . length ] ; for ( int i = <NUM_LIT:0> ; i < connections . length ; i ++ ) { result [ i ] = connections [ i ] . getTarget ( ) ; if ( result [ i ] == this ) { result [ i ] = connections [ i ] . getSource ( ) ; } } return result ; } public EntityLayout [ ] getSuccessingEntities ( ) { if ( isPruned ( ) ) { return new NodeLayout [ <NUM_LIT:0> ] ; } ArrayList result = new ArrayList ( ) ; HashSet addedSubgraphs = new HashSet ( ) ; NodeLayout [ ] successingNodes = getSuccessingNodes ( ) ; for ( int i = <NUM_LIT:0> ; i < successingNodes . length ; i ++ ) { if ( ! successingNodes [ i ] . isPruned ( ) ) { result . add ( successingNodes [ i ] ) ; } else { SubgraphLayout successingSubgraph = successingNodes [ i ] . getSubgraph ( ) ; if ( successingSubgraph . isGraphEntity ( ) && ! addedSubgraphs . contains ( successingSubgraph ) ) { result . add ( successingSubgraph ) ; addedSubgraphs . add ( successingSubgraph ) ; } } } return ( EntityLayout [ ] ) result . toArray ( new EntityLayout [ result . size ( ) ] ) ; } public EntityLayout [ ] getPredecessingEntities ( ) { if ( isPruned ( ) ) { return new NodeLayout [ <NUM_LIT:0> ] ; } ArrayList result = new ArrayList ( ) ; HashSet addedSubgraphs = new HashSet ( ) ; NodeLayout [ ] predecessingNodes = getPredecessingNodes ( ) ; for ( int i = <NUM_LIT:0> ; i < predecessingNodes . length ; i ++ ) { if ( ! predecessingNodes [ i ] . isPruned ( ) ) { result . add ( predecessingNodes [ i ] ) ; } else { SubgraphLayout predecessingSubgraph = predecessingNodes [ i ] . getSubgraph ( ) ; if ( predecessingSubgraph . isGraphEntity ( ) && ! addedSubgraphs . contains ( predecessingSubgraph ) ) { result . add ( predecessingSubgraph ) ; addedSubgraphs . add ( predecessingSubgraph ) ; } } } return ( EntityLayout [ ] ) result . toArray ( new EntityLayout [ result . size ( ) ] ) ; } public ConnectionLayout [ ] getIncomingConnections ( ) { ArrayList result = new ArrayList ( ) ; for ( Iterator iterator = node . getTargetConnections ( ) . iterator ( ) ; iterator . hasNext ( ) ; ) { GraphConnection connection = ( GraphConnection ) iterator . next ( ) ; if ( ! ownerLayoutContext . isLayoutItemFiltered ( connection ) ) { result . add ( connection . getLayout ( ) ) ; } } for ( Iterator iterator = node . getSourceConnections ( ) . iterator ( ) ; iterator . hasNext ( ) ; ) { GraphConnection connection = ( GraphConnection ) iterator . next ( ) ; if ( ! connection . isDirected ( ) && ! ownerLayoutContext . isLayoutItemFiltered ( connection ) ) { result . add ( connection . getLayout ( ) ) ; } } return ( ConnectionLayout [ ] ) result . toArray ( new ConnectionLayout [ result . size ( ) ] ) ; } public ConnectionLayout [ ] getOutgoingConnections ( ) { ArrayList result = new ArrayList ( ) ; for ( Iterator iterator = node . getSourceConnections ( ) . iterator ( ) ; iterator . hasNext ( ) ; ) { GraphConnection connection = ( GraphConnection ) iterator . next ( ) ; if ( ! ownerLayoutContext . isLayoutItemFiltered ( connection ) ) { result . add ( connection . getLayout ( ) ) ; } } for ( Iterator iterator = node . getTargetConnections ( ) . iterator ( ) ; iterator . hasNext ( ) ; ) { GraphConnection connection = ( GraphConnection ) iterator . next ( ) ; if ( ! connection . isDirected ( ) && ! ownerLayoutContext . isLayoutItemFiltered ( connection ) ) { result . add ( connection . getLayout ( ) ) ; } } return ( ConnectionLayout [ ] ) result . toArray ( new ConnectionLayout [ result . size ( ) ] ) ; } public double getPreferredAspectRatio ( ) { return <NUM_LIT:0> ; } GraphNode getNode ( ) { return node ; } public Item [ ] getItems ( ) { return new GraphNode [ ] { node } ; } void applyLayout ( ) { if ( minimized ) { node . setSize ( <NUM_LIT:0> , <NUM_LIT:0> ) ; if ( location != null ) { node . setLocation ( location . x , location . y ) ; } } else { node . setSize ( - <NUM_LIT:1> , - <NUM_LIT:1> ) ; if ( location != null ) { node . setLocation ( location . x - getSize ( ) . width / <NUM_LIT:2> , location . y - size . height / <NUM_LIT:2> ) ; } if ( size != null ) { Dimension currentSize = node . getSize ( ) ; if ( size . width != currentSize . width || size . height != currentSize . height ) { node . setSize ( size . width , size . height ) ; } } } } InternalLayoutContext getOwnerLayoutContext ( ) { return ownerLayoutContext ; } void refreshSize ( ) { Dimension size2 = node . getSize ( ) ; internalSetSize ( size2 . width , size2 . height ) ; } void refreshLocation ( ) { Point location2 = node . getLocation ( ) ; internalSetLocation ( location2 . x + getSize ( ) . width / <NUM_LIT:2> , location2 . y + size . height / <NUM_LIT:2> ) ; } public String toString ( ) { return node . toString ( ) + "<STR_LIT>" ; } void dispose ( ) { isDisposed = true ; if ( subgraph != null ) { subgraph . removeDisposedNodes ( ) ; } ownerLayoutContext . fireNodeRemovedEvent ( node . getLayout ( ) ) ; figureToNode . remove ( node . nodeFigure ) ; } boolean isDisposed ( ) { return isDisposed ; } } </s>
|
<s> package org . eclipse . zest . core . widgets ; import java . util . ArrayList ; import java . util . Iterator ; import java . util . LinkedList ; import java . util . List ; import org . eclipse . draw2d . ActionEvent ; import org . eclipse . draw2d . ActionListener ; import org . eclipse . draw2d . Animation ; import org . eclipse . draw2d . Clickable ; import org . eclipse . draw2d . ColorConstants ; import org . eclipse . draw2d . Figure ; import org . eclipse . draw2d . FreeformLayout ; import org . eclipse . draw2d . FreeformViewport ; import org . eclipse . draw2d . Graphics ; import org . eclipse . draw2d . IFigure ; import org . eclipse . draw2d . Label ; import org . eclipse . draw2d . LayoutAnimator ; import org . eclipse . draw2d . LineBorder ; import org . eclipse . draw2d . ScrollPane ; import org . eclipse . draw2d . ToolbarLayout ; import org . eclipse . draw2d . Triangle ; import org . eclipse . draw2d . Viewport ; import org . eclipse . draw2d . geometry . Dimension ; import org . eclipse . draw2d . geometry . Point ; import org . eclipse . draw2d . geometry . Rectangle ; import org . eclipse . swt . events . SelectionEvent ; import org . eclipse . swt . events . SelectionListener ; import org . eclipse . swt . graphics . Color ; import org . eclipse . swt . graphics . Image ; import org . eclipse . swt . graphics . RGB ; import org . eclipse . swt . widgets . Display ; import org . eclipse . swt . widgets . Widget ; import org . eclipse . zest . core . widgets . internal . AspectRatioFreeformLayer ; import org . eclipse . zest . core . widgets . internal . ContainerFigure ; import org . eclipse . zest . core . widgets . internal . ZestRootLayer ; import org . eclipse . zest . layouts . LayoutAlgorithm ; import org . eclipse . zest . layouts . algorithms . TreeLayoutAlgorithm ; import org . eclipse . zest . layouts . dataStructures . DisplayIndependentRectangle ; public class GraphContainer extends GraphNode implements IContainer { static class ExpandGraphLabel extends Figure implements ActionListener { private boolean isExpanded ; private Expander expander = new Expander ( ) ; private Color darkerBackground ; class Expander extends Clickable { private Triangle triangle ; public Expander ( ) { setStyle ( Clickable . STYLE_TOGGLE ) ; triangle = new Triangle ( ) ; triangle . setSize ( <NUM_LIT:10> , <NUM_LIT:10> ) ; triangle . setBackgroundColor ( ColorConstants . black ) ; triangle . setForegroundColor ( ColorConstants . black ) ; triangle . setFill ( true ) ; triangle . setDirection ( Triangle . EAST ) ; triangle . setLocation ( new Point ( <NUM_LIT:5> , <NUM_LIT:3> ) ) ; this . setLayoutManager ( new FreeformLayout ( ) ) ; this . add ( triangle ) ; this . setPreferredSize ( <NUM_LIT:15> , <NUM_LIT:15> ) ; this . addActionListener ( ExpandGraphLabel . this ) ; } public void open ( ) { triangle . setDirection ( Triangle . SOUTH ) ; } public void close ( ) { triangle . setDirection ( Triangle . EAST ) ; } } public void setExpandedState ( boolean expanded ) { if ( expanded ) { expander . open ( ) ; } else { expander . close ( ) ; } this . isExpanded = expanded ; } public void actionPerformed ( ActionEvent event ) { if ( isExpanded ) { container . close ( true ) ; } else { container . open ( true ) ; } } private final int arcWidth = <NUM_LIT:8> ; private final Label label ; private final GraphContainer container ; private final ToolbarLayout layout ; public ExpandGraphLabel ( GraphContainer container , String text , Image image , boolean cacheLabel ) { this . label = new Label ( text ) { protected void paintFigure ( Graphics graphics ) { if ( isOpaque ( ) ) { super . paintFigure ( graphics ) ; } Rectangle bounds = getBounds ( ) ; graphics . translate ( bounds . x , bounds . y ) ; if ( getIcon ( ) != null ) { graphics . drawImage ( getIcon ( ) , getIconLocation ( ) ) ; } if ( ! isEnabled ( ) ) { graphics . translate ( <NUM_LIT:1> , <NUM_LIT:1> ) ; graphics . setForegroundColor ( ColorConstants . buttonLightest ) ; graphics . drawText ( getSubStringText ( ) , getTextLocation ( ) ) ; graphics . translate ( - <NUM_LIT:1> , - <NUM_LIT:1> ) ; graphics . setForegroundColor ( ColorConstants . buttonDarker ) ; } graphics . drawText ( getText ( ) , getTextLocation ( ) ) ; graphics . translate ( - bounds . x , - bounds . y ) ; } } ; this . setText ( text ) ; this . setImage ( image ) ; this . container = container ; this . setFont ( Display . getDefault ( ) . getSystemFont ( ) ) ; layout = new ToolbarLayout ( true ) ; layout . setSpacing ( <NUM_LIT:5> ) ; layout . setMinorAlignment ( ToolbarLayout . ALIGN_CENTER ) ; this . setLayoutManager ( layout ) ; this . add ( this . expander ) ; this . add ( this . label ) ; } private Color getDarkerBackgroundColor ( ) { if ( darkerBackground == null ) { Color baseColor = getBackgroundColor ( ) ; int blue = ( int ) ( baseColor . getBlue ( ) * <NUM_LIT> + <NUM_LIT> ) ; int red = ( int ) ( baseColor . getRed ( ) * <NUM_LIT> + <NUM_LIT> ) ; int green = ( int ) ( baseColor . getGreen ( ) * <NUM_LIT> + <NUM_LIT> ) ; darkerBackground = new Color ( Display . getCurrent ( ) , new RGB ( red , green , blue ) ) ; } return darkerBackground ; } public void paint ( Graphics graphics ) { graphics . setForegroundColor ( getDarkerBackgroundColor ( ) ) ; graphics . setBackgroundColor ( getBackgroundColor ( ) ) ; graphics . pushState ( ) ; Rectangle bounds = getBounds ( ) . getCopy ( ) ; Rectangle r = bounds . getCopy ( ) ; r . y += arcWidth / <NUM_LIT:2> ; r . height -= arcWidth ; Rectangle top = bounds . getCopy ( ) ; top . height /= <NUM_LIT:2> ; graphics . setForegroundColor ( getBackgroundColor ( ) ) ; graphics . setBackgroundColor ( getBackgroundColor ( ) ) ; graphics . fillRoundRectangle ( top , arcWidth , arcWidth ) ; top . y = top . y + top . height ; graphics . setForegroundColor ( darkerBackground ) ; graphics . setBackgroundColor ( darkerBackground ) ; graphics . fillRoundRectangle ( top , arcWidth , arcWidth ) ; graphics . setBackgroundColor ( darkerBackground ) ; graphics . setForegroundColor ( getBackgroundColor ( ) ) ; graphics . fillGradient ( r , true ) ; super . paint ( graphics ) ; graphics . popState ( ) ; graphics . setForegroundColor ( darkerBackground ) ; graphics . setBackgroundColor ( darkerBackground ) ; bounds . setSize ( bounds . width - <NUM_LIT:1> , bounds . height - <NUM_LIT:1> ) ; graphics . drawRoundRectangle ( bounds , arcWidth , arcWidth ) ; } public void setBackgroundColor ( Color bg ) { super . setBackgroundColor ( bg ) ; if ( darkerBackground != null ) { darkerBackground . dispose ( ) ; } darkerBackground = null ; } public void setTextT ( String string ) { this . setPreferredSize ( null ) ; this . label . setText ( string ) ; this . add ( label ) ; this . layout . layout ( this ) ; this . invalidate ( ) ; this . revalidate ( ) ; this . validate ( ) ; } public void setText ( String string ) { this . label . setText ( string ) ; } public void setImage ( Image image ) { this . label . setIcon ( image ) ; } public void setFocus ( ) { expander . requestFocus ( ) ; } } static final double SCALED_WIDTH = <NUM_LIT> ; static final double SCALED_HEIGHT = <NUM_LIT> ; private static final int CONTAINER_HEIGHT = <NUM_LIT> ; private static final int MIN_WIDTH = <NUM_LIT> ; private static final int MIN_HEIGHT = <NUM_LIT:30> ; private static final int ANIMATION_TIME = <NUM_LIT:100> ; private static final int SUBLAYER_OFFSET = <NUM_LIT:2> ; private static SelectionListener selectionListener ; private ExpandGraphLabel expandGraphLabel ; private List childNodes = null ; private int childAreaHeight = CONTAINER_HEIGHT ; private ZestRootLayer zestLayer ; private ScrollPane scrollPane ; private LayoutAlgorithm layoutAlgorithm ; private boolean isExpanded = false ; private AspectRatioFreeformLayer scalledLayer ; private InternalLayoutContext layoutContext ; public GraphContainer ( Graph graph , int style ) { super ( graph , style ) ; initModel ( graph , "<STR_LIT>" , null ) ; close ( false ) ; childNodes = new ArrayList ( ) ; registerToParent ( graph ) ; } public GraphContainer ( Graph graph , int style , String text , Image image ) { this ( graph , style ) ; setText ( text ) ; setImage ( image ) ; } public GraphContainer ( GraphContainer container , int style ) { this ( container . getGraph ( ) , style ) ; } public void setCustomFigure ( IFigure nodeFigure ) { throw new RuntimeException ( "<STR_LIT>" ) ; } public void close ( boolean animate ) { if ( animate ) { Animation . markBegin ( ) ; } isExpanded = false ; expandGraphLabel . setExpandedState ( false ) ; Rectangle newBounds = scrollPane . getBounds ( ) . getCopy ( ) ; newBounds . height = <NUM_LIT:0> ; scrollPane . setSize ( scrollPane . getSize ( ) . width , <NUM_LIT:0> ) ; updateFigureForModel ( this . zestLayer ) ; scrollPane . setVisible ( false ) ; List children = this . zestLayer . getChildren ( ) ; for ( Iterator iterator = children . iterator ( ) ; iterator . hasNext ( ) ; ) { IFigure child = ( IFigure ) iterator . next ( ) ; GraphItem item = getGraph ( ) . getGraphItem ( child ) ; item . setVisible ( false ) ; } Rectangle containerBounds = new Rectangle ( this . getLocation ( ) , new Dimension ( this . getSize ( ) . width , CONTAINER_HEIGHT + this . expandGraphLabel . getSize ( ) . height ) ) ; moveNodesUp ( containerBounds , this ) ; if ( animate ) { Animation . run ( ANIMATION_TIME ) ; } updateFigureForModel ( nodeFigure ) ; } private static void addNodeToOrderedList ( List orderedNodeList , GraphNode node ) { Iterator orderedNodeIterator = orderedNodeList . iterator ( ) ; int counter = <NUM_LIT:0> ; while ( orderedNodeIterator . hasNext ( ) ) { GraphNode nextOrderedNode = ( GraphNode ) orderedNodeIterator . next ( ) ; if ( nextOrderedNode . getLocation ( ) . y + nextOrderedNode . getBounds ( ) . height > node . getLocation ( ) . y + node . getBounds ( ) . height ) { break ; } counter ++ ; } orderedNodeList . add ( counter , node ) ; } private static List getOrderedNodesBelowY ( List nodes , int yValue , GraphNode yValueNode ) { Iterator iterator = nodes . iterator ( ) ; LinkedList orderedNode = new LinkedList ( ) ; while ( iterator . hasNext ( ) ) { GraphNode node = ( GraphNode ) iterator . next ( ) ; if ( node == yValueNode ) { continue ; } if ( node . getLocation ( ) . y + node . getBounds ( ) . height > yValue ) { addNodeToOrderedList ( orderedNode , node ) ; } } List arrayList = new ArrayList ( ) ; iterator = orderedNode . iterator ( ) ; while ( iterator . hasNext ( ) ) { arrayList . add ( iterator . next ( ) ) ; } return arrayList ; } private static boolean nodeInStripe ( int left , int right , GraphNode node ) { return ( node . getBounds ( ) . x < right && node . getBounds ( ) . x + node . getBounds ( ) . width > left ) ; } void pack ( Graph g ) { GraphNode highestNode = getHighestNode ( g ) ; moveNodesUp ( highestNode . getBounds ( ) , highestNode ) ; } static GraphNode getHighestNode ( Graph g ) { Iterator iterator = g . getNodes ( ) . iterator ( ) ; GraphNode lowest = null ; while ( iterator . hasNext ( ) ) { GraphNode node = ( GraphNode ) iterator . next ( ) ; if ( lowest == null || lowest . getBounds ( ) . y > node . getBounds ( ) . y ) { lowest = node ; } } return lowest ; } private void moveNodesUp ( Rectangle containerBounds , GraphNode graphContainer ) { List orderedNodesBelowY = getOrderedNodesBelowY ( parent . getGraph ( ) . getNodes ( ) , containerBounds . y , graphContainer ) ; int leftSide = containerBounds . x ; int rightSide = containerBounds . x + containerBounds . width ; List nodesToConsider = new LinkedList ( ) ; for ( int i = <NUM_LIT:0> ; i < orderedNodesBelowY . size ( ) ; i ++ ) { nodesToConsider . add ( orderedNodesBelowY . get ( i ) ) ; } addNodeToOrderedList ( orderedNodesBelowY , graphContainer ) ; while ( nodesToConsider . size ( ) > <NUM_LIT:0> ) { GraphNode node = ( GraphNode ) nodesToConsider . get ( <NUM_LIT:0> ) ; if ( nodeInStripe ( leftSide , rightSide , node ) ) { leftSide = Math . min ( leftSide , node . getBounds ( ) . x ) ; rightSide = Math . max ( rightSide , node . getBounds ( ) . x + node . getBounds ( ) . width ) ; GraphNode previousNode = null ; int i = <NUM_LIT:0> ; for ( ; i < orderedNodesBelowY . size ( ) ; i ++ ) { if ( orderedNodesBelowY . get ( i ) == node ) { break ; } } int j = i - <NUM_LIT:1> ; while ( j >= <NUM_LIT:0> ) { GraphNode pastNode = ( GraphNode ) orderedNodesBelowY . get ( j ) ; if ( nodeInStripe ( node . getBounds ( ) . x , node . getBounds ( ) . x + node . getBounds ( ) . width , pastNode ) ) { previousNode = pastNode ; break ; } j -- ; } if ( previousNode == null ) { previousNode = graphContainer ; } int previousLocation = previousNode . getBounds ( ) . y + previousNode . getBounds ( ) . height + <NUM_LIT:2> ; orderedNodesBelowY . remove ( i ) ; node . setLocation ( node . getLocation ( ) . x , previousLocation ) ; addNodeToOrderedList ( orderedNodesBelowY , node ) ; } nodesToConsider . remove ( node ) ; } } public void open ( boolean animate ) { if ( animate ) { Animation . markBegin ( ) ; } isExpanded = true ; expandGraphLabel . setExpandedState ( true ) ; scrollPane . setSize ( computeChildArea ( ) ) ; scrollPane . setVisible ( true ) ; List children = this . zestLayer . getChildren ( ) ; for ( Iterator iterator = children . iterator ( ) ; iterator . hasNext ( ) ; ) { IFigure child = ( IFigure ) iterator . next ( ) ; GraphItem item = getGraph ( ) . getGraphItem ( child ) ; item . setVisible ( true ) ; } updateFigureForModel ( nodeFigure ) ; Rectangle containerBounds = new Rectangle ( this . getLocation ( ) , new Dimension ( this . getSize ( ) . width , CONTAINER_HEIGHT + this . expandGraphLabel . getSize ( ) . height ) ) ; moveNodesDown ( containerBounds , this ) ; moveNodesUp ( containerBounds , this ) ; if ( animate ) { Animation . run ( ANIMATION_TIME ) ; } this . getFigure ( ) . getUpdateManager ( ) . performValidation ( ) ; } private void moveNodesDown ( Rectangle containerBounds , GraphContainer graphContainer ) { List nodesBelowHere = getOrderedNodesBelowY ( parent . getGraph ( ) . getNodes ( ) , containerBounds . y , graphContainer ) ; Iterator nodesBelowHereIterator = nodesBelowHere . iterator ( ) ; List nodesToMove = new LinkedList ( ) ; int left = containerBounds . x ; int right = containerBounds . x + containerBounds . width ; while ( nodesBelowHereIterator . hasNext ( ) ) { GraphNode node = ( GraphNode ) nodesBelowHereIterator . next ( ) ; if ( nodeInStripe ( left , right , node ) ) { nodesToMove . add ( node ) ; left = Math . min ( left , node . getBounds ( ) . x ) ; right = Math . max ( right , node . getBounds ( ) . x + node . getBounds ( ) . width ) ; } } List intersectingNodes = intersectingNodes ( containerBounds , nodesToMove , graphContainer ) ; int delta = getMaxMovement ( containerBounds , intersectingNodes ) ; if ( delta > <NUM_LIT:0> ) { shiftNodesDown ( nodesToMove , delta ) ; } } private List intersectingNodes ( Rectangle bounds , List nodesToCheck , GraphNode node ) { List result = new LinkedList ( ) ; Iterator nodes = nodesToCheck . iterator ( ) ; while ( nodes . hasNext ( ) ) { GraphNode nodeToCheck = ( GraphNode ) nodes . next ( ) ; if ( node == nodeToCheck ) { continue ; } if ( bounds . intersects ( nodeToCheck . getBounds ( ) ) ) { result . add ( nodeToCheck ) ; } } return result ; } private int getMaxMovement ( Rectangle bounds , List nodesToMove ) { Iterator iterator = nodesToMove . iterator ( ) ; int maxMovement = <NUM_LIT:0> ; while ( iterator . hasNext ( ) ) { GraphNode node = ( GraphNode ) iterator . next ( ) ; int yValue = node . getLocation ( ) . y ; int distanceFromBottom = ( bounds . y + bounds . height ) - yValue ; maxMovement = Math . max ( maxMovement , distanceFromBottom ) ; } return maxMovement + <NUM_LIT:3> ; } private void shiftNodesDown ( List nodesToShift , int amount ) { Iterator iterator = nodesToShift . iterator ( ) ; while ( iterator . hasNext ( ) ) { GraphNode node = ( GraphNode ) iterator . next ( ) ; node . setLocation ( node . getLocation ( ) . x , node . getLocation ( ) . y + amount ) ; } } public Graph getGraph ( ) { return this . graph ; } public Widget getItem ( ) { return this ; } public int getItemType ( ) { return CONTAINER ; } public void setLayoutAlgorithm ( LayoutAlgorithm algorithm , boolean applyLayout ) { this . layoutAlgorithm = algorithm ; this . layoutAlgorithm . setLayoutContext ( getLayoutContext ( ) ) ; if ( applyLayout ) { applyLayout ( ) ; } } public InternalLayoutContext getLayoutContext ( ) { if ( layoutContext == null ) { layoutContext = new InternalLayoutContext ( this ) ; } return layoutContext ; } public DisplayIndependentRectangle getLayoutBounds ( ) { double width = GraphContainer . SCALED_WIDTH - <NUM_LIT:10> ; double height = GraphContainer . SCALED_HEIGHT - <NUM_LIT:10> ; return new DisplayIndependentRectangle ( <NUM_LIT> , <NUM_LIT> , width - <NUM_LIT> , height - <NUM_LIT> ) ; } public void applyLayout ( ) { if ( layoutAlgorithm == null ) { setLayoutAlgorithm ( new TreeLayoutAlgorithm ( ) , false ) ; } Animation . markBegin ( ) ; layoutAlgorithm . applyLayout ( true ) ; layoutContext . flushChanges ( false ) ; Animation . run ( ANIMATION_TIME ) ; getFigure ( ) . getUpdateManager ( ) . performUpdate ( ) ; } public double getScale ( ) { return this . scalledLayer . getScale ( ) ; } public void setScale ( double scale ) { this . scalledLayer . setScale ( scale ) ; } protected void initFigure ( ) { nodeFigure = createContainerFigure ( ) ; } class ContainerDimension { int width ; int labelHeight ; int expandedHeight ; } private Dimension computeChildArea ( ) { ContainerDimension containerDimension = computeContainerSize ( ) ; Dimension dimension = new Dimension ( ) ; dimension . width = containerDimension . width ; dimension . height = containerDimension . expandedHeight - containerDimension . labelHeight + SUBLAYER_OFFSET ; return dimension ; } private ContainerDimension computeContainerSize ( ) { ContainerDimension dimension = new ContainerDimension ( ) ; int labelHeight = expandGraphLabel . getPreferredSize ( ) . height ; int labelWidth = expandGraphLabel . getPreferredSize ( ) . width ; if ( labelWidth < MIN_WIDTH ) { labelWidth = MIN_WIDTH ; expandGraphLabel . setPreferredSize ( labelWidth , labelHeight ) ; } dimension . labelHeight = Math . max ( labelHeight , MIN_HEIGHT ) ; dimension . width = Math . max ( labelWidth , this . size . width ) ; dimension . expandedHeight = Math . max ( dimension . labelHeight + childAreaHeight - SUBLAYER_OFFSET , this . size . height ) ; return dimension ; } private double computeHeightScale ( ) { Dimension childArea = computeChildArea ( ) ; double heightScale = childArea . height / SCALED_HEIGHT ; return heightScale ; } private double computeWidthScale ( ) { Dimension childArea = computeChildArea ( ) ; double widthScale = childArea . width / SCALED_WIDTH ; return widthScale ; } private IFigure createContainerFigure ( ) { GraphContainer node = this ; IFigure containerFigure = new ContainerFigure ( ) ; containerFigure . setOpaque ( true ) ; containerFigure . addLayoutListener ( LayoutAnimator . getDefault ( ) ) ; containerFigure . setLayoutManager ( new FreeformLayout ( ) ) ; expandGraphLabel = new ExpandGraphLabel ( this , node . getText ( ) , node . getImage ( ) , false ) ; expandGraphLabel . setText ( getText ( ) ) ; expandGraphLabel . setImage ( getImage ( ) ) ; ContainerDimension containerDimension = computeContainerSize ( ) ; scrollPane = new ScrollPane ( ) ; scrollPane . addLayoutListener ( LayoutAnimator . getDefault ( ) ) ; Viewport viewport = new FreeformViewport ( ) ; scrollPane . setViewport ( viewport ) ; viewport . addLayoutListener ( LayoutAnimator . getDefault ( ) ) ; scrollPane . setScrollBarVisibility ( ScrollPane . AUTOMATIC ) ; scalledLayer = new AspectRatioFreeformLayer ( "<STR_LIT>" ) ; scalledLayer . addLayoutListener ( LayoutAnimator . getDefault ( ) ) ; scalledLayer . setScale ( computeWidthScale ( ) , computeHeightScale ( ) ) ; zestLayer = new ZestRootLayer ( ) ; zestLayer . addLayoutListener ( LayoutAnimator . getDefault ( ) ) ; scalledLayer . add ( zestLayer ) ; zestLayer . setLayoutManager ( new FreeformLayout ( ) ) ; scrollPane . setSize ( computeChildArea ( ) ) ; scrollPane . setLocation ( new Point ( <NUM_LIT:0> , containerDimension . labelHeight - SUBLAYER_OFFSET ) ) ; scrollPane . setForegroundColor ( ColorConstants . gray ) ; expandGraphLabel . setBackgroundColor ( getBackgroundColor ( ) ) ; expandGraphLabel . setForegroundColor ( getForegroundColor ( ) ) ; expandGraphLabel . setLocation ( new Point ( <NUM_LIT:0> , <NUM_LIT:0> ) ) ; containerFigure . add ( scrollPane ) ; containerFigure . add ( expandGraphLabel ) ; scrollPane . getViewport ( ) . setContents ( scalledLayer ) ; scrollPane . setBorder ( new LineBorder ( ) ) ; return containerFigure ; } private void registerToParent ( IContainer parent ) { if ( parent . getItemType ( ) == GRAPH ) { createSelectionListener ( ) ; parent . getGraph ( ) . addSelectionListener ( selectionListener ) ; } } private void createSelectionListener ( ) { if ( selectionListener == null ) { selectionListener = new SelectionListener ( ) { public void widgetSelected ( SelectionEvent e ) { if ( e . item instanceof GraphContainer ) { ( ( GraphContainer ) e . item ) . expandGraphLabel . setFocus ( ) ; } } public void widgetDefaultSelected ( SelectionEvent e ) { } } ; } } protected void updateFigureForModel ( IFigure currentFigure ) { if ( expandGraphLabel == null ) { initFigure ( ) ; } expandGraphLabel . setTextT ( getText ( ) ) ; expandGraphLabel . setImage ( getImage ( ) ) ; expandGraphLabel . setFont ( getFont ( ) ) ; if ( highlighted == HIGHLIGHT_ON ) { expandGraphLabel . setForegroundColor ( getForegroundColor ( ) ) ; expandGraphLabel . setBackgroundColor ( getHighlightColor ( ) ) ; } else { expandGraphLabel . setForegroundColor ( getForegroundColor ( ) ) ; expandGraphLabel . setBackgroundColor ( getBackgroundColor ( ) ) ; } ContainerDimension containerDimension = computeContainerSize ( ) ; expandGraphLabel . setSize ( containerDimension . width , containerDimension . labelHeight ) ; if ( isExpanded ) { setSize ( containerDimension . width , containerDimension . expandedHeight ) ; } else { setSize ( containerDimension . width , containerDimension . labelHeight ) ; } scrollPane . setLocation ( new Point ( expandGraphLabel . getLocation ( ) . x , expandGraphLabel . getLocation ( ) . y + containerDimension . labelHeight - SUBLAYER_OFFSET ) ) ; } void refreshBounds ( ) { if ( nodeFigure == null || nodeFigure . getParent ( ) == null ) { return ; } GraphNode node = this ; Point loc = node . getLocation ( ) ; ContainerDimension containerDimension = computeContainerSize ( ) ; Dimension size = new Dimension ( ) ; expandGraphLabel . setSize ( containerDimension . width , containerDimension . labelHeight ) ; this . childAreaHeight = computeChildArea ( ) . height ; if ( isExpanded ) { size . width = containerDimension . width ; size . height = containerDimension . expandedHeight ; } else { size . width = containerDimension . width ; size . height = containerDimension . labelHeight ; } Rectangle bounds = new Rectangle ( loc , size ) ; nodeFigure . getParent ( ) . setConstraint ( nodeFigure , bounds ) ; scrollPane . setLocation ( new Point ( expandGraphLabel . getLocation ( ) . x , expandGraphLabel . getLocation ( ) . y + containerDimension . labelHeight - SUBLAYER_OFFSET ) ) ; scrollPane . setSize ( computeChildArea ( ) ) ; scalledLayer . setScale ( computeWidthScale ( ) , computeHeightScale ( ) ) ; } public void addSubgraphFigure ( IFigure figure ) { zestLayer . addSubgraph ( figure ) ; graph . subgraphFigures . add ( figure ) ; } void addConnectionFigure ( IFigure figure ) { nodeFigure . add ( figure ) ; } public void addNode ( GraphNode node ) { zestLayer . addNode ( node . getNodeFigure ( ) ) ; this . childNodes . add ( node ) ; node . setVisible ( isExpanded ) ; } public List getNodes ( ) { return this . childNodes ; } public List getConnections ( ) { return filterConnections ( getGraph ( ) . getConnections ( ) ) ; } private List filterConnections ( List connections ) { List result = new ArrayList ( ) ; for ( Iterator iterator = connections . iterator ( ) ; iterator . hasNext ( ) ; ) { GraphConnection connection = ( GraphConnection ) iterator . next ( ) ; if ( connection . getSource ( ) . getParent ( ) == this && connection . getDestination ( ) . getParent ( ) == this ) { result . add ( connection ) ; } } return result ; } public LayoutAlgorithm getLayoutAlgorithm ( ) { return layoutAlgorithm ; } } </s>
|
<s> package org . eclipse . zest . core . widgets ; import java . util . ArrayList ; import java . util . Iterator ; import java . util . List ; import org . eclipse . draw2d . Animation ; import org . eclipse . draw2d . ColorConstants ; import org . eclipse . draw2d . FigureListener ; import org . eclipse . draw2d . IFigure ; import org . eclipse . draw2d . Label ; import org . eclipse . draw2d . geometry . Dimension ; import org . eclipse . draw2d . geometry . Insets ; import org . eclipse . draw2d . geometry . Point ; import org . eclipse . draw2d . geometry . PrecisionPoint ; import org . eclipse . draw2d . geometry . Rectangle ; import org . eclipse . swt . graphics . Color ; import org . eclipse . swt . graphics . Font ; import org . eclipse . swt . graphics . Image ; import org . eclipse . swt . widgets . Display ; import org . eclipse . zest . core . widgets . internal . GraphLabel ; import org . eclipse . zest . core . widgets . internal . ZestRootLayer ; public class GraphNode extends GraphItem { public static final int HIGHLIGHT_NONE = <NUM_LIT:0> ; public static final int HIGHLIGHT_ON = <NUM_LIT:1> ; private int nodeStyle ; private List sourceConnections ; private List targetConnections ; private Color foreColor ; private Color backColor ; private Color highlightColor ; private Color borderColor ; private Color borderHighlightColor ; private int borderWidth ; private PrecisionPoint currentLocation ; protected Dimension size ; private Font font ; private boolean cacheLabel ; private boolean visible = true ; protected Graph graph ; protected IContainer parent ; protected Object internalNode ; private boolean selected ; protected int highlighted = HIGHLIGHT_NONE ; private IFigure tooltip ; protected IFigure nodeFigure ; private boolean isDisposed = false ; private boolean hasCustomTooltip ; public GraphNode ( IContainer graphModel , int style ) { this ( graphModel , style , ( IFigure ) null ) ; } public GraphNode ( IContainer graphModel , int style , String text ) { this ( graphModel , style , text , null , null ) ; } public GraphNode ( IContainer graphModel , int style , Object data ) { this ( graphModel , style , "<STR_LIT>" , null , data ) ; } public GraphNode ( IContainer graphModel , int style , String text , Image image ) { this ( graphModel , style , text , image , null ) ; } protected GraphNode ( IContainer graphModel , int style , IFigure figure ) { this ( graphModel , style , "<STR_LIT>" , null , figure ) ; } private GraphNode ( IContainer graphModel , int style , String text , Image image , Object data ) { super ( graphModel , style , data ) ; initModel ( graphModel , text , image ) ; if ( nodeFigure == null ) { initFigure ( ) ; } this . parent . addNode ( this ) ; this . parent . getGraph ( ) . registerItem ( this ) ; } protected void initFigure ( ) { nodeFigure = createFigureForModel ( ) ; } static int count = <NUM_LIT:0> ; protected void initModel ( IContainer graphModel , String text , Image image ) { this . nodeStyle |= graphModel . getGraph ( ) . getNodeStyle ( ) ; this . parent = graphModel ; this . sourceConnections = new ArrayList ( ) ; this . targetConnections = new ArrayList ( ) ; this . foreColor = graphModel . getGraph ( ) . DARK_BLUE ; this . backColor = graphModel . getGraph ( ) . LIGHT_BLUE ; this . highlightColor = graphModel . getGraph ( ) . HIGHLIGHT_COLOR ; this . borderColor = ColorConstants . lightGray ; this . borderHighlightColor = ColorConstants . blue ; this . borderWidth = <NUM_LIT:1> ; this . currentLocation = new PrecisionPoint ( <NUM_LIT:0> , <NUM_LIT:0> ) ; this . size = new Dimension ( - <NUM_LIT:1> , - <NUM_LIT:1> ) ; this . font = Display . getDefault ( ) . getSystemFont ( ) ; this . graph = graphModel . getGraph ( ) ; this . cacheLabel = false ; this . setText ( text ) ; if ( image != null ) { this . setImage ( image ) ; } if ( font == null ) { font = Display . getDefault ( ) . getSystemFont ( ) ; } } public String toString ( ) { return "<STR_LIT>" + getText ( ) ; } public void dispose ( ) { if ( isFisheyeEnabled ) { this . fishEye ( false , false ) ; } super . dispose ( ) ; this . isDisposed = true ; while ( getSourceConnections ( ) . size ( ) > <NUM_LIT:0> ) { GraphConnection connection = ( GraphConnection ) getSourceConnections ( ) . get ( <NUM_LIT:0> ) ; if ( ! connection . isDisposed ( ) ) { connection . dispose ( ) ; } else { removeSourceConnection ( connection ) ; } } while ( getTargetConnections ( ) . size ( ) > <NUM_LIT:0> ) { GraphConnection connection = ( GraphConnection ) getTargetConnections ( ) . get ( <NUM_LIT:0> ) ; if ( ! connection . isDisposed ( ) ) { connection . dispose ( ) ; } else { removeTargetConnection ( connection ) ; } } graph . removeNode ( this ) ; } public boolean isDisposed ( ) { return isDisposed ; } public boolean isSizeFixed ( ) { return ! ( this . size . width < <NUM_LIT:0> && this . size . height < <NUM_LIT:0> ) ; } public List getSourceConnections ( ) { return new ArrayList ( sourceConnections ) ; } public List getTargetConnections ( ) { return new ArrayList ( targetConnections ) ; } Rectangle getBounds ( ) { return new Rectangle ( getLocation ( ) , getSize ( ) ) ; } public Point getLocation ( ) { return currentLocation ; } public boolean isSelected ( ) { return selected ; } public void setLocation ( double x , double y ) { if ( currentLocation . preciseX ( ) != x || currentLocation . preciseY ( ) != y ) { currentLocation . setPreciseX ( x ) ; currentLocation . setPreciseY ( y ) ; refreshBounds ( ) ; if ( getGraphModel ( ) . isDynamicLayoutEnabled ( ) ) { parent . getLayoutContext ( ) . fireNodeMovedEvent ( this . getLayout ( ) ) ; } } } public Dimension getSize ( ) { if ( size . height < <NUM_LIT:0> && size . width < <NUM_LIT:0> && nodeFigure != null ) { return nodeFigure . getSize ( ) . getCopy ( ) ; } return size . getCopy ( ) ; } public Color getForegroundColor ( ) { return foreColor ; } public void setForegroundColor ( Color c ) { this . foreColor = c ; updateFigureForModel ( nodeFigure ) ; } public Color getBackgroundColor ( ) { return backColor ; } public void setBackgroundColor ( Color c ) { backColor = c ; updateFigureForModel ( nodeFigure ) ; } public void setTooltip ( IFigure tooltip ) { hasCustomTooltip = true ; this . tooltip = tooltip ; updateFigureForModel ( nodeFigure ) ; } public IFigure getTooltip ( ) { return this . tooltip ; } public void setBorderColor ( Color c ) { borderColor = c ; updateFigureForModel ( nodeFigure ) ; } public void setBorderHighlightColor ( Color c ) { this . borderHighlightColor = c ; updateFigureForModel ( nodeFigure ) ; } public Color getHighlightColor ( ) { return highlightColor ; } public void setHighlightColor ( Color c ) { this . highlightColor = c ; } public void highlight ( ) { if ( highlighted == HIGHLIGHT_ON ) { return ; } IFigure parentFigure = nodeFigure . getParent ( ) ; if ( parentFigure instanceof ZestRootLayer ) { ( ( ZestRootLayer ) parentFigure ) . highlightNode ( nodeFigure ) ; } highlighted = HIGHLIGHT_ON ; updateFigureForModel ( getNodeFigure ( ) ) ; } public void unhighlight ( ) { if ( highlighted == HIGHLIGHT_NONE ) { return ; } IFigure parentFigure = nodeFigure . getParent ( ) ; if ( parentFigure instanceof ZestRootLayer ) { ( ( ZestRootLayer ) parentFigure ) . unHighlightNode ( nodeFigure ) ; } highlighted = HIGHLIGHT_NONE ; updateFigureForModel ( nodeFigure ) ; } void refreshBounds ( ) { Point loc = this . getLocation ( ) ; Dimension size = this . getSize ( ) ; Rectangle bounds = new Rectangle ( loc , size ) ; if ( nodeFigure == null || nodeFigure . getParent ( ) == null ) { return ; } nodeFigure . getParent ( ) . setConstraint ( nodeFigure , bounds ) ; if ( isFisheyeEnabled ) { Rectangle fishEyeBounds = calculateFishEyeBounds ( ) ; if ( fishEyeBounds != null ) { fishEyeFigure . getParent ( ) . translateToRelative ( fishEyeBounds ) ; fishEyeFigure . getParent ( ) . translateFromParent ( fishEyeBounds ) ; fishEyeFigure . getParent ( ) . setConstraint ( fishEyeFigure , fishEyeBounds ) ; } } } public Color getBorderColor ( ) { return borderColor ; } public int getBorderWidth ( ) { return borderWidth ; } public void setBorderWidth ( int width ) { this . borderWidth = width ; updateFigureForModel ( nodeFigure ) ; } public Font getFont ( ) { return font ; } public void setFont ( Font font ) { this . font = font ; updateFigureForModel ( nodeFigure ) ; } public void setText ( String string ) { if ( string == null ) { string = "<STR_LIT>" ; } super . setText ( string ) ; updateFigureForModel ( this . nodeFigure ) ; } public void setImage ( Image image ) { super . setImage ( image ) ; updateFigureForModel ( nodeFigure ) ; } public Graph getGraphModel ( ) { return this . graph ; } public int getNodeStyle ( ) { return nodeStyle ; } public void setNodeStyle ( int nodeStyle ) { this . nodeStyle = nodeStyle ; this . cacheLabel = ( ( this . nodeStyle & ZestStyles . NODES_CACHE_LABEL ) > <NUM_LIT:0> ) ? true : false ; } public void setSize ( double width , double height ) { if ( ( width != size . width ) || ( height != size . height ) ) { size . width = ( int ) width ; size . height = ( int ) height ; refreshBounds ( ) ; } } public Color getBorderHighlightColor ( ) { return borderHighlightColor ; } public boolean cacheLabel ( ) { return this . cacheLabel ; } public void setCacheLabel ( boolean cacheLabel ) { this . cacheLabel = cacheLabel ; } IFigure getNodeFigure ( ) { return this . nodeFigure ; } public void setVisible ( boolean visible ) { this . visible = visible ; this . getFigure ( ) . setVisible ( visible ) ; for ( Iterator iterator2 = sourceConnections . iterator ( ) ; iterator2 . hasNext ( ) ; ) { GraphConnection connection = ( GraphConnection ) iterator2 . next ( ) ; connection . setVisible ( visible ) ; } for ( Iterator iterator2 = targetConnections . iterator ( ) ; iterator2 . hasNext ( ) ; ) { GraphConnection connection = ( GraphConnection ) iterator2 . next ( ) ; connection . setVisible ( visible ) ; } } public boolean isVisible ( ) { return visible ; } public int getStyle ( ) { return super . getStyle ( ) | this . getNodeStyle ( ) ; } private IFigure fishEyeFigure = null ; private boolean isFisheyeEnabled ; protected IFigure fishEye ( boolean enable , boolean animate ) { if ( isDisposed ) { return null ; } if ( ! checkStyle ( ZestStyles . NODES_FISHEYE ) ) { return null ; } if ( enable ) { fishEyeFigure = createFishEyeFigure ( ) ; Rectangle rectangle = calculateFishEyeBounds ( ) ; if ( rectangle == null ) { return null ; } this . getGraphModel ( ) . fishEye ( nodeFigure , fishEyeFigure , rectangle , true ) ; if ( fishEyeFigure != null ) { isFisheyeEnabled = true ; } return fishEyeFigure ; } else { isFisheyeEnabled = false ; this . getGraphModel ( ) . removeFishEye ( fishEyeFigure , nodeFigure , animate ) ; return null ; } } IContainer getParent ( ) { return parent ; } boolean isHighlighted ( ) { return highlighted > <NUM_LIT:0> ; } protected void updateFigureForModel ( IFigure currentFigure ) { if ( currentFigure == null ) { return ; } IFigure figure = currentFigure ; IFigure toolTip ; if ( figure instanceof ILabeledFigure ) { ILabeledFigure labeledFigure = ( ILabeledFigure ) figure ; if ( ! checkStyle ( ZestStyles . NODES_HIDE_TEXT ) && ! labeledFigure . getText ( ) . equals ( this . getText ( ) ) ) { labeledFigure . setText ( this . getText ( ) ) ; } if ( labeledFigure . getIcon ( ) != getImage ( ) ) { labeledFigure . setIcon ( getImage ( ) ) ; } } if ( figure instanceof IStyleableFigure ) { IStyleableFigure styleableFigure = ( IStyleableFigure ) figure ; if ( highlighted == HIGHLIGHT_ON ) { styleableFigure . setForegroundColor ( getForegroundColor ( ) ) ; styleableFigure . setBackgroundColor ( getHighlightColor ( ) ) ; styleableFigure . setBorderColor ( getBorderHighlightColor ( ) ) ; } else { styleableFigure . setForegroundColor ( getForegroundColor ( ) ) ; styleableFigure . setBackgroundColor ( getBackgroundColor ( ) ) ; styleableFigure . setBorderColor ( getBorderColor ( ) ) ; } styleableFigure . setBorderWidth ( getBorderWidth ( ) ) ; if ( figure . getFont ( ) != getFont ( ) ) { figure . setFont ( getFont ( ) ) ; } } if ( this . getTooltip ( ) == null && hasCustomTooltip == false ) { toolTip = new Label ( ) ; ( ( Label ) toolTip ) . setText ( getText ( ) ) ; } else { toolTip = this . getTooltip ( ) ; } figure . setToolTip ( toolTip ) ; if ( isFisheyeEnabled ) { IFigure newFisheyeFigure = createFishEyeFigure ( ) ; if ( graph . replaceFishFigure ( this . fishEyeFigure , newFisheyeFigure ) ) { this . fishEyeFigure = newFisheyeFigure ; } } refreshBounds ( ) ; } protected IFigure createFigureForModel ( ) { GraphNode node = this ; boolean cacheLabel = ( this ) . cacheLabel ( ) ; final GraphLabel label = new GraphLabel ( node . getText ( ) , node . getImage ( ) , cacheLabel ) ; label . setFont ( this . font ) ; if ( checkStyle ( ZestStyles . NODES_HIDE_TEXT ) ) { label . setText ( "<STR_LIT>" ) ; } updateFigureForModel ( label ) ; label . addFigureListener ( new FigureListener ( ) { private Dimension previousSize = label . getBounds ( ) . getSize ( ) ; public void figureMoved ( IFigure source ) { if ( Animation . isAnimating ( ) || getLayout ( ) . isMinimized ( ) ) { return ; } Rectangle newBounds = nodeFigure . getBounds ( ) ; if ( ! newBounds . getSize ( ) . equals ( previousSize ) ) { previousSize = newBounds . getSize ( ) ; if ( size . width >= <NUM_LIT:0> && size . height >= <NUM_LIT:0> ) { size = newBounds . getSize ( ) ; } currentLocation = new PrecisionPoint ( nodeFigure . getBounds ( ) . getTopLeft ( ) ) ; parent . getLayoutContext ( ) . fireNodeResizedEvent ( getLayout ( ) ) ; } else if ( currentLocation . x != newBounds . x || currentLocation . y != newBounds . y ) { currentLocation = new PrecisionPoint ( nodeFigure . getBounds ( ) . getTopLeft ( ) ) ; parent . getLayoutContext ( ) . fireNodeMovedEvent ( getLayout ( ) ) ; } } } ) ; return label ; } private IFigure createFishEyeFigure ( ) { GraphNode node = this ; boolean cacheLabel = this . cacheLabel ( ) ; GraphLabel label = new GraphLabel ( node . getText ( ) , node . getImage ( ) , cacheLabel ) ; if ( highlighted == HIGHLIGHT_ON ) { label . setForegroundColor ( getForegroundColor ( ) ) ; label . setBackgroundColor ( getHighlightColor ( ) ) ; label . setBorderColor ( getBorderHighlightColor ( ) ) ; } else { label . setForegroundColor ( getForegroundColor ( ) ) ; label . setBackgroundColor ( getBackgroundColor ( ) ) ; label . setBorderColor ( getBorderColor ( ) ) ; } label . setBorderWidth ( getBorderWidth ( ) ) ; label . setFont ( getFont ( ) ) ; return label ; } private Rectangle calculateFishEyeBounds ( ) { Rectangle rectangle = nodeFigure . getBounds ( ) . getCopy ( ) ; Dimension newSize = fishEyeFigure . getPreferredSize ( ) ; Rectangle currentSize = rectangle . getCopy ( ) ; nodeFigure . translateToAbsolute ( currentSize ) ; int expandedH = Math . max ( ( newSize . height - currentSize . height ) / <NUM_LIT:2> + <NUM_LIT:1> , <NUM_LIT:0> ) ; int expandedW = Math . max ( ( newSize . width - currentSize . width ) / <NUM_LIT:2> + <NUM_LIT:1> , <NUM_LIT:0> ) ; Dimension expandAmount = new Dimension ( expandedW , expandedH ) ; nodeFigure . translateToAbsolute ( rectangle ) ; rectangle . expand ( new Insets ( expandAmount . height , expandAmount . width , expandAmount . height , expandAmount . width ) ) ; if ( expandedH <= <NUM_LIT:0> && expandedW <= <NUM_LIT:0> ) { return null ; } return rectangle ; } void addSourceConnection ( GraphConnection connection ) { this . sourceConnections . add ( connection ) ; } void addTargetConnection ( GraphConnection connection ) { this . targetConnections . add ( connection ) ; } void removeSourceConnection ( GraphConnection connection ) { this . sourceConnections . remove ( connection ) ; } void removeTargetConnection ( GraphConnection connection ) { this . targetConnections . remove ( connection ) ; } void setSelected ( boolean selected ) { if ( selected == isSelected ( ) ) { return ; } if ( selected ) { highlight ( ) ; } else { unhighlight ( ) ; } this . selected = selected ; } public int getItemType ( ) { return NODE ; } public IFigure getFigure ( ) { if ( this . nodeFigure == null ) { initFigure ( ) ; } return this . getNodeFigure ( ) ; } private InternalNodeLayout layout ; public InternalNodeLayout getLayout ( ) { if ( layout == null ) { layout = new InternalNodeLayout ( this ) ; } return layout ; } void applyLayoutChanges ( ) { if ( layout != null ) { layout . applyLayout ( ) ; } } } </s>
|
<s> package org . eclipse . zest . core . widgets ; import java . util . Iterator ; import org . eclipse . draw2d . Animation ; import org . eclipse . draw2d . FigureListener ; import org . eclipse . draw2d . IFigure ; import org . eclipse . draw2d . geometry . Dimension ; import org . eclipse . draw2d . geometry . Point ; import org . eclipse . draw2d . geometry . PrecisionPoint ; import org . eclipse . draw2d . geometry . Rectangle ; import org . eclipse . zest . layouts . dataStructures . DisplayIndependentDimension ; import org . eclipse . zest . layouts . dataStructures . DisplayIndependentPoint ; import org . eclipse . zest . layouts . interfaces . EntityLayout ; import org . eclipse . zest . layouts . interfaces . LayoutContext ; import org . eclipse . zest . layouts . interfaces . NodeLayout ; public abstract class FigureSubgraph extends DefaultSubgraph { protected IFigure figure ; private DisplayIndependentPoint location ; private boolean isLayoutBeingApplied = false ; protected class SubgraphFigrueListener implements FigureListener { private Rectangle previousBounds = figure . getBounds ( ) . getCopy ( ) ; public void figureMoved ( IFigure source ) { if ( Animation . isAnimating ( ) || isLayoutBeingApplied ) { return ; } Rectangle newBounds = figure . getBounds ( ) ; if ( ! newBounds . getSize ( ) . equals ( previousBounds . getSize ( ) ) ) { ( context ) . fireSubgraphResizedEvent ( FigureSubgraph . this ) ; } else if ( ! newBounds . getLocation ( ) . equals ( previousBounds . getLocation ( ) ) ) { ( context ) . fireSubgraphMovedEvent ( FigureSubgraph . this ) ; } previousBounds = newBounds . getCopy ( ) ; } } ; protected abstract void createFigure ( ) ; protected abstract void updateFigure ( ) ; public IFigure getFigure ( ) { if ( figure == null ) { createFigure ( ) ; updateFigure ( ) ; figure . addFigureListener ( new SubgraphFigrueListener ( ) ) ; ( context ) . container . addSubgraphFigure ( figure ) ; } return figure ; } protected FigureSubgraph ( NodeLayout [ ] nodes , LayoutContext context ) { super ( context ) ; addNodes ( nodes ) ; } public void addNodes ( NodeLayout [ ] nodes ) { int initialCount = this . nodes . size ( ) ; super . addNodes ( nodes ) ; if ( this . nodes . size ( ) > initialCount && figure != null ) { updateFigure ( ) ; if ( location != null ) { for ( int i = <NUM_LIT:0> ; i < nodes . length ; i ++ ) { nodes [ i ] . setLocation ( location . x , location . y ) ; } } } } public void removeNodes ( NodeLayout [ ] nodes ) { int initialCount = this . nodes . size ( ) ; super . removeNodes ( nodes ) ; if ( this . nodes . size ( ) < initialCount && figure != null && ! disposed ) { updateFigure ( ) ; } } public EntityLayout [ ] getSuccessingEntities ( ) { return super . getSuccessingEntities ( ) ; } public EntityLayout [ ] getPredecessingEntities ( ) { return super . getPredecessingEntities ( ) ; } public DisplayIndependentDimension getSize ( ) { Dimension size = getFigure ( ) . getSize ( ) ; return new DisplayIndependentDimension ( size . width , size . height ) ; } public DisplayIndependentPoint getLocation ( ) { if ( location == null ) { Point location2 = getFigure ( ) . getBounds ( ) . getLocation ( ) ; Dimension size = getFigure ( ) . getSize ( ) ; return new DisplayIndependentPoint ( location2 . x + size . width / <NUM_LIT:2> , location2 . y + size . height / <NUM_LIT:2> ) ; } return new DisplayIndependentPoint ( location ) ; } public void setLocation ( double x , double y ) { super . setLocation ( x , y ) ; for ( Iterator iterator = nodes . iterator ( ) ; iterator . hasNext ( ) ; ) { NodeLayout node = ( NodeLayout ) iterator . next ( ) ; node . setLocation ( x , y ) ; } if ( location != null ) { location . x = x ; location . y = y ; } else { location = new DisplayIndependentPoint ( x , y ) ; applyLayoutChanges ( ) ; } } protected void refreshLocation ( ) { Rectangle bounds = figure . getBounds ( ) ; if ( location == null ) { location = new DisplayIndependentPoint ( <NUM_LIT:0> , <NUM_LIT:0> ) ; } location . x = bounds . x + bounds . width / <NUM_LIT:2> ; location . y = bounds . y + bounds . height / <NUM_LIT:2> ; } public boolean isGraphEntity ( ) { return true ; } public boolean isMovable ( ) { return true ; } protected void dispose ( ) { if ( ! disposed ) { super . dispose ( ) ; if ( figure != null ) { context . container . getGraph ( ) . removeSubgraphFigure ( figure ) ; } } } protected void applyLayoutChanges ( ) { getFigure ( ) ; if ( location != null ) { isLayoutBeingApplied = true ; Dimension size = figure . getSize ( ) ; figure . setLocation ( new PrecisionPoint ( location . x - size . width / <NUM_LIT:2> , location . y - size . height / <NUM_LIT:2> ) ) ; isLayoutBeingApplied = false ; } } } </s>
|
<s> package org . eclipse . zest . core . widgets ; public interface LayoutFilter { public boolean isObjectFiltered ( GraphItem item ) ; } </s>
|
<s> package org . eclipse . zest . core . widgets . custom ; import org . eclipse . draw2d . IFigure ; import org . eclipse . zest . core . widgets . Graph ; import org . eclipse . zest . core . widgets . GraphContainer ; import org . eclipse . zest . core . widgets . GraphNode ; public class CGraphNode extends GraphNode { IFigure figure = null ; public CGraphNode ( Graph graphModel , int style , IFigure figure ) { super ( graphModel , style , figure ) ; } public CGraphNode ( GraphContainer graphModel , int style , IFigure figure ) { super ( graphModel , style , figure ) ; } public IFigure getFigure ( ) { return super . getFigure ( ) ; } protected IFigure createFigureForModel ( ) { this . figure = ( IFigure ) this . getData ( ) ; return this . figure ; } } </s>
|
<s> package org . eclipse . zest . core . widgets . custom ; import java . util . HashMap ; import org . eclipse . draw2d . ColorConstants ; import org . eclipse . draw2d . Graphics ; import org . eclipse . draw2d . Shape ; import org . eclipse . draw2d . geometry . PointList ; import org . eclipse . draw2d . geometry . Rectangle ; import org . eclipse . swt . graphics . Color ; import org . eclipse . zest . core . widgets . FigureSubgraph ; import org . eclipse . zest . layouts . algorithms . TreeLayoutObserver ; import org . eclipse . zest . layouts . algorithms . TreeLayoutObserver . TreeListener ; import org . eclipse . zest . layouts . algorithms . TreeLayoutObserver . TreeNode ; import org . eclipse . zest . layouts . interfaces . LayoutContext ; import org . eclipse . zest . layouts . interfaces . NodeLayout ; import org . eclipse . zest . layouts . interfaces . SubgraphLayout ; public class TriangleSubgraph extends FigureSubgraph { public static class TriangleParameters implements Cloneable { public Color color = ColorConstants . black ; public int direction = TOP_DOWN ; public double referenceHeight = <NUM_LIT> ; public double referenceBase = <NUM_LIT> ; public Object clone ( ) { TriangleParameters result = new TriangleParameters ( ) ; result . color = color ; result . direction = direction ; result . referenceHeight = referenceHeight ; result . referenceBase = referenceBase ; return result ; } } private class IsoscelesTriangle extends Shape { private PointList points = new PointList ( <NUM_LIT:3> ) ; protected void fillShape ( Graphics graphics ) { graphics . fillPolygon ( points ) ; } protected void outlineShape ( Graphics graphics ) { graphics . drawPolygon ( points ) ; } protected void primTranslate ( int dx , int dy ) { super . primTranslate ( dx , dy ) ; points . translate ( dx , dy ) ; } public void validate ( ) { super . validate ( ) ; Rectangle r = new Rectangle ( ) ; r . setBounds ( getBounds ( ) ) ; r . shrink ( getInsets ( ) ) ; points . removeAllPoints ( ) ; switch ( parameters . direction ) { case TOP_DOWN : points . addPoint ( r . x + r . width / <NUM_LIT:2> , r . y ) ; points . addPoint ( r . x , r . y + r . height ) ; points . addPoint ( r . x + r . width , r . y + r . height ) ; break ; case BOTTOM_UP : points . addPoint ( r . x + r . width / <NUM_LIT:2> , r . y + r . height ) ; points . addPoint ( r . x , r . y ) ; points . addPoint ( r . x + r . width , r . y ) ; break ; case LEFT_RIGHT : points . addPoint ( r . x , r . y + r . height / <NUM_LIT:2> ) ; points . addPoint ( r . x + r . width , r . y ) ; points . addPoint ( r . x + r . width , r . y + r . height ) ; break ; case RIGHT_LEFT : points . addPoint ( r . x + r . width , r . y + r . height / <NUM_LIT:2> ) ; points . addPoint ( r . x , r . y ) ; points . addPoint ( r . x , r . y + r . height ) ; break ; } } } private static HashMap contextToTree = new HashMap ( ) ; private TriangleParameters parameters ; public TriangleSubgraph ( NodeLayout [ ] nodes , LayoutContext context , TriangleParameters triangleParameters ) { super ( nodes , context ) ; this . parameters = triangleParameters ; if ( contextToTree . get ( context ) == null ) { TreeLayoutObserver treeLayoutObserver = new TreeLayoutObserver ( context , null ) ; treeLayoutObserver . addTreeListener ( new TreeListener ( ) { protected void defaultHandle ( TreeNode changedNode ) { SubgraphLayout subgraph = changedNode . getNode ( ) . getSubgraph ( ) ; if ( subgraph instanceof TriangleSubgraph ) { ( ( TriangleSubgraph ) subgraph ) . updateFigure ( ) ; } } } ) ; contextToTree . put ( context , treeLayoutObserver ) ; } } protected void createFigure ( ) { figure = new IsoscelesTriangle ( ) ; figure . setBackgroundColor ( parameters . color ) ; figure . setForegroundColor ( parameters . color ) ; } private double log ( double value , double base ) { return Math . log ( value ) / Math . log ( base ) ; } protected void updateFigure ( ) { TreeLayoutObserver tree = ( TreeLayoutObserver ) contextToTree . get ( context ) ; TreeNode subgraphRoot = tree . getTreeNode ( ( NodeLayout ) nodes . iterator ( ) . next ( ) ) ; if ( subgraphRoot == null ) { return ; } while ( nodes . contains ( subgraphRoot . getNode ( ) ) ) { subgraphRoot = subgraphRoot . getParent ( ) ; } TreeNode superRoot = tree . getSuperRoot ( ) ; double triangleHeight = parameters . referenceHeight * subgraphRoot . getHeight ( ) / superRoot . getHeight ( ) ; int numOfNodes = superRoot . getNumOfDescendants ( ) ; int numOfNodesWithChildren = numOfNodes - superRoot . getNumOfLeaves ( ) + <NUM_LIT:1> ; double logBase = ( numOfNodesWithChildren > <NUM_LIT:0> ) ? ( double ) numOfNodes / numOfNodesWithChildren : <NUM_LIT:1> ; double triangleBaseModifier = ( parameters . referenceBase - <NUM_LIT:1> ) / log ( superRoot . getNumOfLeaves ( ) , logBase ) ; double triangleBase = parameters . referenceBase + triangleBaseModifier * log ( ( double ) subgraphRoot . getNumOfLeaves ( ) / superRoot . getNumOfLeaves ( ) , logBase ) ; if ( parameters . direction == <NUM_LIT:0> ) { parameters . direction = parameters . direction ; } if ( parameters . direction == TOP_DOWN || parameters . direction == BOTTOM_UP ) { figure . setSize ( ( int ) ( triangleBase + <NUM_LIT> ) , ( int ) ( triangleHeight + <NUM_LIT> ) ) ; } else { figure . setSize ( ( int ) ( triangleHeight + <NUM_LIT> ) , ( int ) ( triangleBase + <NUM_LIT> ) ) ; } int numOfNodesWithChildrenInSubgraph = nodes . size ( ) - subgraphRoot . getNumOfLeaves ( ) + <NUM_LIT:1> ; double avgNumOfChildrenInSugbraph = ( numOfNodesWithChildrenInSubgraph > <NUM_LIT:0> ) ? ( double ) nodes . size ( ) / numOfNodesWithChildrenInSubgraph : <NUM_LIT:1> ; int r = ( int ) ( parameters . color . getRed ( ) + ( ( double ) <NUM_LIT:255> - parameters . color . getRed ( ) ) / avgNumOfChildrenInSugbraph ) ; int g = ( int ) ( parameters . color . getGreen ( ) + ( ( double ) <NUM_LIT:255> - parameters . color . getGreen ( ) ) / avgNumOfChildrenInSugbraph ) ; int b = ( int ) ( parameters . color . getBlue ( ) + ( ( double ) <NUM_LIT:255> - parameters . color . getBlue ( ) ) / avgNumOfChildrenInSugbraph ) ; figure . setBackgroundColor ( new Color ( parameters . color . getDevice ( ) , r , g , b ) ) ; figure . setForegroundColor ( parameters . color ) ; } public boolean isDirectionDependant ( ) { return true ; } public void setDirection ( int direction ) { super . setDirection ( direction ) ; if ( parameters . direction == direction ) { return ; } if ( direction == TOP_DOWN || direction == BOTTOM_UP || direction == LEFT_RIGHT || direction == RIGHT_LEFT ) { parameters . direction = direction ; updateFigure ( ) ; } else { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } } public void setColor ( Color color ) { parameters . color = color ; updateFigure ( ) ; } } </s>
|
<s> package org . eclipse . zest . core . widgets . custom ; import org . eclipse . draw2d . Label ; import org . eclipse . swt . graphics . Color ; import org . eclipse . zest . core . widgets . FigureSubgraph ; import org . eclipse . zest . core . widgets . internal . GraphLabel ; import org . eclipse . zest . layouts . interfaces . LayoutContext ; import org . eclipse . zest . layouts . interfaces . NodeLayout ; public class LabelSubgraph extends FigureSubgraph { private Color backgroundColor ; private Color foregroundColor ; public void setForegroundColor ( Color color ) { figure . setForegroundColor ( color ) ; } public void setBackgroundColor ( Color color ) { figure . setBackgroundColor ( color ) ; } protected void createFigure ( ) { figure = new GraphLabel ( false ) ; figure . setForegroundColor ( foregroundColor ) ; figure . setBackgroundColor ( backgroundColor ) ; updateFigure ( ) ; } protected void updateFigure ( ) { ( ( Label ) figure ) . setText ( "<STR_LIT>" + nodes . size ( ) ) ; } public LabelSubgraph ( NodeLayout [ ] nodes , LayoutContext context , Color foregroundColor , Color backgroundColor ) { super ( nodes , context ) ; this . foregroundColor = foregroundColor ; this . backgroundColor = backgroundColor ; } } </s>
|
<s> package org . eclipse . zest . core . widgets ; import java . util . HashMap ; import java . util . HashSet ; import java . util . Iterator ; import java . util . Set ; import org . eclipse . draw2d . ColorConstants ; import org . eclipse . swt . graphics . Color ; import org . eclipse . swt . widgets . Item ; import org . eclipse . zest . core . widgets . custom . LabelSubgraph ; import org . eclipse . zest . core . widgets . custom . TriangleSubgraph ; import org . eclipse . zest . core . widgets . custom . TriangleSubgraph . TriangleParameters ; import org . eclipse . zest . layouts . dataStructures . DisplayIndependentDimension ; import org . eclipse . zest . layouts . dataStructures . DisplayIndependentPoint ; import org . eclipse . zest . layouts . dataStructures . DisplayIndependentRectangle ; import org . eclipse . zest . layouts . interfaces . ConnectionLayout ; import org . eclipse . zest . layouts . interfaces . EntityLayout ; import org . eclipse . zest . layouts . interfaces . LayoutContext ; import org . eclipse . zest . layouts . interfaces . NodeLayout ; import org . eclipse . zest . layouts . interfaces . SubgraphLayout ; public class DefaultSubgraph implements SubgraphLayout { public static class DefaultSubgraphFactory implements SubgraphFactory { private HashMap contextToSubgraph = new HashMap ( ) ; public SubgraphLayout createSubgraph ( NodeLayout [ ] nodes , LayoutContext context ) { DefaultSubgraph subgraph = ( DefaultSubgraph ) contextToSubgraph . get ( context ) ; if ( subgraph == null ) { subgraph = new DefaultSubgraph ( context ) ; contextToSubgraph . put ( context , subgraph ) ; } subgraph . addNodes ( nodes ) ; return subgraph ; } } ; public static class LabelSubgraphFactory implements SubgraphFactory { private Color defaultForegroundColor = ColorConstants . black ; private Color defaultBackgroundColor = ColorConstants . yellow ; public void setDefualtForegroundColor ( Color c ) { defaultForegroundColor = c ; } public void setDefaultBackgroundColor ( Color c ) { defaultBackgroundColor = c ; } public SubgraphLayout createSubgraph ( NodeLayout [ ] nodes , LayoutContext context ) { return new LabelSubgraph ( nodes , context , defaultForegroundColor , defaultBackgroundColor ) ; } } ; public static class TriangleSubgraphFactory implements SubgraphFactory { private TriangleParameters parameters = new TriangleParameters ( ) ; public SubgraphLayout createSubgraph ( NodeLayout [ ] nodes , LayoutContext context ) { return new TriangleSubgraph ( nodes , context , ( TriangleParameters ) parameters . clone ( ) ) ; } public Color getColor ( ) { return parameters . color ; } public void setColor ( Color color ) { parameters . color = color ; } public int getDirection ( ) { return parameters . direction ; } public void setDirection ( int direction ) { parameters . direction = direction ; } public double getReferenceHeight ( ) { return parameters . referenceHeight ; } public void setReferenceHeight ( double referenceHeight ) { parameters . referenceHeight = referenceHeight ; } public double getReferenceBase ( ) { return parameters . referenceBase ; } public void setReferenceBase ( double referenceBase ) { parameters . referenceBase = referenceBase ; } } ; public static class PrunedSuccessorsSubgraphFactory implements SubgraphFactory { private HashMap contextToSubgraph = new HashMap ( ) ; public SubgraphLayout createSubgraph ( NodeLayout [ ] nodes , LayoutContext context ) { PrunedSuccessorsSubgraph subgraph = ( PrunedSuccessorsSubgraph ) contextToSubgraph . get ( context ) ; if ( subgraph == null ) { subgraph = new PrunedSuccessorsSubgraph ( context ) ; contextToSubgraph . put ( context , subgraph ) ; } subgraph . addNodes ( nodes ) ; return subgraph ; } public void updateLabelForNode ( InternalNodeLayout node ) { InternalLayoutContext context = node . getOwnerLayoutContext ( ) ; PrunedSuccessorsSubgraph subgraph = ( PrunedSuccessorsSubgraph ) contextToSubgraph . get ( context ) ; if ( subgraph == null ) { subgraph = new PrunedSuccessorsSubgraph ( context ) ; contextToSubgraph . put ( context , subgraph ) ; } subgraph . updateNodeLabel ( node ) ; } } ; protected final InternalLayoutContext context ; protected final Set nodes = new HashSet ( ) ; protected boolean disposed = false ; protected DefaultSubgraph ( LayoutContext context2 ) { if ( context2 instanceof InternalLayoutContext ) { this . context = ( InternalLayoutContext ) context2 ; } else { throw new RuntimeException ( "<STR_LIT>" ) ; } } public boolean isGraphEntity ( ) { return false ; } public void setSize ( double width , double height ) { context . checkChangesAllowed ( ) ; } public void setLocation ( double x , double y ) { context . checkChangesAllowed ( ) ; } public boolean isResizable ( ) { return false ; } public boolean isMovable ( ) { return false ; } public EntityLayout [ ] getSuccessingEntities ( ) { return new EntityLayout [ <NUM_LIT:0> ] ; } public DisplayIndependentDimension getSize ( ) { DisplayIndependentRectangle bounds = context . getBounds ( ) ; return new DisplayIndependentDimension ( bounds . width , bounds . height ) ; } public double getPreferredAspectRatio ( ) { return <NUM_LIT:0> ; } public EntityLayout [ ] getPredecessingEntities ( ) { return new EntityLayout [ <NUM_LIT:0> ] ; } public DisplayIndependentPoint getLocation ( ) { DisplayIndependentRectangle bounds = context . getBounds ( ) ; return new DisplayIndependentPoint ( bounds . x + bounds . width / <NUM_LIT:2> , bounds . y + bounds . height / <NUM_LIT:2> ) ; } public boolean isDirectionDependant ( ) { return false ; } public void setDirection ( int direction ) { context . checkChangesAllowed ( ) ; } public void removeNodes ( NodeLayout [ ] nodes ) { context . checkChangesAllowed ( ) ; for ( int i = <NUM_LIT:0> ; i < nodes . length ; i ++ ) { if ( this . nodes . remove ( nodes [ i ] ) ) { nodes [ i ] . prune ( null ) ; nodes [ i ] . setMinimized ( false ) ; refreshConnectionsVisibility ( nodes [ i ] . getIncomingConnections ( ) ) ; refreshConnectionsVisibility ( nodes [ i ] . getOutgoingConnections ( ) ) ; } } if ( this . nodes . isEmpty ( ) ) { dispose ( ) ; } } public void removeDisposedNodes ( ) { for ( Iterator iterator = nodes . iterator ( ) ; iterator . hasNext ( ) ; ) { InternalNodeLayout node = ( InternalNodeLayout ) iterator . next ( ) ; if ( node . isDisposed ( ) ) { iterator . remove ( ) ; } } } public NodeLayout [ ] getNodes ( ) { InternalNodeLayout [ ] result = new InternalNodeLayout [ nodes . size ( ) ] ; int i = <NUM_LIT:0> ; for ( Iterator iterator = nodes . iterator ( ) ; iterator . hasNext ( ) ; ) { result [ i ] = ( InternalNodeLayout ) iterator . next ( ) ; if ( ! context . isLayoutItemFiltered ( result [ i ] . getNode ( ) ) ) { i ++ ; } } if ( i == nodes . size ( ) ) { return result ; } NodeLayout [ ] result2 = new NodeLayout [ i ] ; System . arraycopy ( result , <NUM_LIT:0> , result2 , <NUM_LIT:0> , i ) ; return result2 ; } public Item [ ] getItems ( ) { GraphNode [ ] result = new GraphNode [ nodes . size ( ) ] ; int i = <NUM_LIT:0> ; for ( Iterator iterator = nodes . iterator ( ) ; iterator . hasNext ( ) ; ) { InternalNodeLayout node = ( InternalNodeLayout ) iterator . next ( ) ; result [ i ] = ( GraphNode ) node . getItems ( ) [ <NUM_LIT:0> ] ; if ( ! context . isLayoutItemFiltered ( node . getNode ( ) ) ) { i ++ ; } } if ( i == nodes . size ( ) ) { return result ; } GraphNode [ ] result2 = new GraphNode [ i ] ; System . arraycopy ( result , <NUM_LIT:0> , result2 , <NUM_LIT:0> , i ) ; return result2 ; } public int countNodes ( ) { return nodes . size ( ) ; } public void addNodes ( NodeLayout [ ] nodes ) { context . checkChangesAllowed ( ) ; for ( int i = <NUM_LIT:0> ; i < nodes . length ; i ++ ) { if ( this . nodes . add ( nodes [ i ] ) ) { nodes [ i ] . prune ( this ) ; nodes [ i ] . setMinimized ( true ) ; refreshConnectionsVisibility ( nodes [ i ] . getIncomingConnections ( ) ) ; refreshConnectionsVisibility ( nodes [ i ] . getOutgoingConnections ( ) ) ; } } } protected void refreshConnectionsVisibility ( ConnectionLayout [ ] connections ) { for ( int i = <NUM_LIT:0> ; i < connections . length ; i ++ ) { connections [ i ] . setVisible ( ! connections [ i ] . getSource ( ) . isPruned ( ) && ! connections [ i ] . getTarget ( ) . isPruned ( ) ) ; } } protected void refreshLocation ( ) { } protected void refreshSize ( ) { } protected void applyLayoutChanges ( ) { } protected void dispose ( ) { if ( ! disposed ) { context . removeSubgrah ( this ) ; disposed = true ; } } } ; </s>
|
<s> package org . eclipse . zest . core . widgets ; import org . eclipse . draw2d . IFigure ; import org . eclipse . swt . graphics . Image ; public interface ILabeledFigure extends IFigure { public void setText ( String text ) ; public String getText ( ) ; public void setIcon ( Image icon ) ; public Image getIcon ( ) ; } </s>
|
<s> package org . eclipse . zest . core . widgets ; import org . eclipse . draw2d . IFigure ; import org . eclipse . swt . graphics . Color ; public interface IStyleableFigure extends IFigure { void setBorderColor ( Color borderColor ) ; void setBorderWidth ( int borderWidth ) ; } </s>
|
<s> package org . eclipse . zest . core . widgets ; import java . util . List ; import org . eclipse . draw2d . IFigure ; import org . eclipse . swt . widgets . Widget ; import org . eclipse . zest . layouts . LayoutAlgorithm ; import org . eclipse . zest . layouts . dataStructures . DisplayIndependentRectangle ; public interface IContainer { public abstract Graph getGraph ( ) ; public Widget getItem ( ) ; public abstract List getNodes ( ) ; public abstract List getConnections ( ) ; public abstract void addNode ( GraphNode graphNode ) ; public abstract void addSubgraphFigure ( IFigure figure ) ; public abstract int getItemType ( ) ; public abstract DisplayIndependentRectangle getLayoutBounds ( ) ; public abstract InternalLayoutContext getLayoutContext ( ) ; public void applyLayout ( ) ; public void setLayoutAlgorithm ( LayoutAlgorithm algorithm , boolean apply ) ; } </s>
|
<s> package org . eclipse . zest . core . widgets ; import java . util . ArrayList ; import java . util . HashMap ; import java . util . HashSet ; import java . util . Iterator ; import java . util . List ; import org . eclipse . draw2d . Animation ; import org . eclipse . draw2d . ColorConstants ; import org . eclipse . draw2d . ConnectionRouter ; import org . eclipse . draw2d . CoordinateListener ; import org . eclipse . draw2d . FigureCanvas ; import org . eclipse . draw2d . FreeformLayer ; import org . eclipse . draw2d . FreeformLayout ; import org . eclipse . draw2d . FreeformViewport ; import org . eclipse . draw2d . IFigure ; import org . eclipse . draw2d . LayoutAnimator ; import org . eclipse . draw2d . MouseMotionListener ; import org . eclipse . draw2d . PolylineConnection ; import org . eclipse . draw2d . SWTEventDispatcher ; import org . eclipse . draw2d . ScalableFigure ; import org . eclipse . draw2d . ScalableFreeformLayeredPane ; import org . eclipse . draw2d . ScrollPane ; import org . eclipse . draw2d . TreeSearch ; import org . eclipse . draw2d . geometry . Dimension ; import org . eclipse . draw2d . geometry . Point ; import org . eclipse . draw2d . geometry . Rectangle ; import org . eclipse . swt . SWT ; import org . eclipse . swt . events . ControlEvent ; import org . eclipse . swt . events . ControlListener ; import org . eclipse . swt . events . DisposeEvent ; import org . eclipse . swt . events . DisposeListener ; import org . eclipse . swt . events . PaintEvent ; import org . eclipse . swt . events . PaintListener ; import org . eclipse . swt . events . SelectionAdapter ; import org . eclipse . swt . events . SelectionEvent ; import org . eclipse . swt . events . SelectionListener ; import org . eclipse . swt . graphics . Color ; import org . eclipse . swt . widgets . Composite ; import org . eclipse . swt . widgets . Display ; import org . eclipse . swt . widgets . Event ; import org . eclipse . swt . widgets . Item ; import org . eclipse . swt . widgets . Widget ; import org . eclipse . zest . core . widgets . gestures . RotateGestureListener ; import org . eclipse . zest . core . widgets . gestures . ZoomGestureListener ; import org . eclipse . zest . core . widgets . internal . ContainerFigure ; import org . eclipse . zest . core . widgets . internal . ZestRootLayer ; import org . eclipse . zest . core . widgets . zooming . ZoomManager ; import org . eclipse . zest . layouts . LayoutAlgorithm ; import org . eclipse . zest . layouts . dataStructures . DisplayIndependentRectangle ; import org . eclipse . zest . layouts . interfaces . ExpandCollapseManager ; public class Graph extends FigureCanvas implements IContainer { public static final int ANIMATION_TIME = <NUM_LIT> ; public static final int FISHEYE_ANIMATION_TIME = <NUM_LIT:100> ; public Color LIGHT_BLUE = new Color ( null , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) ; public Color LIGHT_BLUE_CYAN = new Color ( null , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:255> ) ; public Color GREY_BLUE = new Color ( null , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) ; public Color DARK_BLUE = new Color ( null , <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT> ) ; public Color LIGHT_YELLOW = new Color ( null , <NUM_LIT:255> , <NUM_LIT:255> , <NUM_LIT> ) ; public Color HIGHLIGHT_COLOR = ColorConstants . yellow ; public Color HIGHLIGHT_ADJACENT_COLOR = ColorConstants . orange ; public Color DEFAULT_NODE_COLOR = LIGHT_BLUE ; private List nodes ; protected List connections ; HashSet subgraphFigures ; private List selectedItems = null ; private ArrayList fisheyeListeners = new ArrayList ( ) ; private List selectionListeners = null ; private HashMap figure2ItemMap = null ; private int connectionStyle ; private int nodeStyle ; private ScalableFreeformLayeredPane fishEyeLayer = null ; private InternalLayoutContext layoutContext = null ; private volatile boolean shouldSheduleLayout ; private volatile Runnable scheduledLayoutRunnable = null ; private volatile boolean scheduledLayoutClean = false ; private Dimension preferredSize = null ; int style = <NUM_LIT:0> ; private ScalableFreeformLayeredPane rootlayer ; private ZestRootLayer zestRootLayer ; private ConnectionRouter defaultConnectionRouter ; private ZoomManager zoomManager = null ; public Graph ( Composite parent , int style ) { super ( parent , style | SWT . DOUBLE_BUFFERED ) ; this . style = style ; this . setBackground ( ColorConstants . white ) ; this . setViewport ( new FreeformViewport ( ) ) ; this . getVerticalBar ( ) . addSelectionListener ( new SelectionAdapter ( ) { public void widgetSelected ( SelectionEvent e ) { Graph . this . redraw ( ) ; } } ) ; this . getHorizontalBar ( ) . addSelectionListener ( new SelectionAdapter ( ) { public void widgetSelected ( SelectionEvent e ) { Graph . this . redraw ( ) ; } } ) ; this . getLightweightSystem ( ) . setEventDispatcher ( new SWTEventDispatcher ( ) { public void dispatchMouseMoved ( org . eclipse . swt . events . MouseEvent me ) { super . dispatchMouseMoved ( me ) ; if ( getCurrentEvent ( ) == null ) { return ; } if ( getMouseTarget ( ) == null ) { setMouseTarget ( getRoot ( ) ) ; } if ( ( me . stateMask & SWT . BUTTON_MASK ) != <NUM_LIT:0> ) { getMouseTarget ( ) . handleMouseDragged ( getCurrentEvent ( ) ) ; } else { getMouseTarget ( ) . handleMouseMoved ( getCurrentEvent ( ) ) ; } } } ) ; this . setContents ( createLayers ( ) ) ; DragSupport dragSupport = new DragSupport ( ) ; this . getLightweightSystem ( ) . getRootFigure ( ) . addMouseListener ( dragSupport ) ; this . getLightweightSystem ( ) . getRootFigure ( ) . addMouseMotionListener ( dragSupport ) ; this . nodes = new ArrayList ( ) ; this . preferredSize = new Dimension ( - <NUM_LIT:1> , - <NUM_LIT:1> ) ; this . connectionStyle = ZestStyles . NONE ; this . nodeStyle = ZestStyles . NONE ; this . connections = new ArrayList ( ) ; this . subgraphFigures = new HashSet ( ) ; this . selectedItems = new ArrayList ( ) ; this . selectionListeners = new ArrayList ( ) ; this . figure2ItemMap = new HashMap ( ) ; this . addPaintListener ( new PaintListener ( ) { public void paintControl ( PaintEvent e ) { if ( shouldSheduleLayout ) { applyLayoutInternal ( true ) ; shouldSheduleLayout = false ; } } } ) ; this . addControlListener ( new ControlListener ( ) { public void controlResized ( ControlEvent e ) { if ( preferredSize . width == - <NUM_LIT:1> || preferredSize . height == - <NUM_LIT:1> ) { getLayoutContext ( ) . fireBoundsChangedEvent ( ) ; } } public void controlMoved ( ControlEvent e ) { } } ) ; if ( ( style & ( ZestStyles . GESTURES_DISABLED ) ) == <NUM_LIT:0> ) { this . addGestureListener ( new ZoomGestureListener ( ) ) ; this . addGestureListener ( new RotateGestureListener ( ) ) ; } this . addDisposeListener ( new DisposeListener ( ) { public void widgetDisposed ( DisposeEvent e ) { release ( ) ; } } ) ; } public void addSelectionListener ( SelectionListener selectionListener ) { if ( ! selectionListeners . contains ( selectionListener ) ) { selectionListeners . add ( selectionListener ) ; } } public void removeSelectionListener ( SelectionListener selectionListener ) { if ( selectionListeners . contains ( selectionListener ) ) { selectionListeners . remove ( selectionListener ) ; } } public List getNodes ( ) { return nodes ; } public ScalableFigure getRootLayer ( ) { return rootlayer ; } public void setConnectionStyle ( int connectionStyle ) { this . connectionStyle = connectionStyle ; } public int getConnectionStyle ( ) { return connectionStyle ; } public void setNodeStyle ( int nodeStyle ) { this . nodeStyle = nodeStyle ; } public int getNodeStyle ( ) { return nodeStyle ; } public List getConnections ( ) { return this . connections ; } public void setSelection ( GraphItem [ ] items ) { clearSelection ( ) ; if ( items != null ) { for ( int i = <NUM_LIT:0> ; i < items . length ; i ++ ) { if ( items [ i ] != null ) { select ( items [ i ] ) ; } } } } public void selectAll ( ) { setSelection ( ( GraphItem [ ] ) nodes . toArray ( new GraphItem [ ] { } ) ) ; } public List getSelection ( ) { return selectedItems ; } public String toString ( ) { return "<STR_LIT>" + nodes . size ( ) + "<STR_LIT>" + connections . size ( ) + "<STR_LIT>" ; } public void dispose ( ) { release ( ) ; super . dispose ( ) ; } public void applyLayout ( ) { scheduleLayoutOnReveal ( true ) ; } public void applyLayoutNow ( ) { getLayoutContext ( ) . applyLayout ( true ) ; layoutContext . flushChanges ( false ) ; } public void setDynamicLayout ( boolean enabled ) { if ( getLayoutContext ( ) . isBackgroundLayoutEnabled ( ) != enabled ) { layoutContext . setBackgroundLayoutEnabled ( enabled ) ; if ( enabled ) { scheduleLayoutOnReveal ( false ) ; } } } public boolean isDynamicLayoutEnabled ( ) { return getLayoutContext ( ) . isBackgroundLayoutEnabled ( ) ; } private void release ( ) { while ( nodes . size ( ) > <NUM_LIT:0> ) { GraphNode node = ( GraphNode ) nodes . get ( <NUM_LIT:0> ) ; if ( node != null ) { node . dispose ( ) ; } } while ( connections . size ( ) > <NUM_LIT:0> ) { GraphConnection connection = ( GraphConnection ) connections . get ( <NUM_LIT:0> ) ; if ( connection != null ) { connection . dispose ( ) ; } } LIGHT_BLUE . dispose ( ) ; LIGHT_BLUE_CYAN . dispose ( ) ; GREY_BLUE . dispose ( ) ; DARK_BLUE . dispose ( ) ; LIGHT_YELLOW . dispose ( ) ; } private void applyLayoutInternal ( boolean clean ) { if ( getLayoutContext ( ) . getLayoutAlgorithm ( ) == null ) { return ; } scheduledLayoutClean = scheduledLayoutClean || clean ; synchronized ( this ) { if ( scheduledLayoutRunnable == null ) { Display . getDefault ( ) . asyncExec ( scheduledLayoutRunnable = new Runnable ( ) { public void run ( ) { Animation . markBegin ( ) ; getLayoutContext ( ) . applyLayout ( scheduledLayoutClean ) ; layoutContext . flushChanges ( false ) ; Animation . run ( ANIMATION_TIME ) ; getLightweightSystem ( ) . getUpdateManager ( ) . performUpdate ( ) ; synchronized ( Graph . this ) { scheduledLayoutRunnable = null ; scheduledLayoutClean = false ; } } } ) ; } } } public void setPreferredSize ( int width , int height ) { this . preferredSize = new Dimension ( width , height ) ; getLayoutContext ( ) . fireBoundsChangedEvent ( ) ; } public Dimension getPreferredSize ( ) { if ( preferredSize . width < <NUM_LIT:0> || preferredSize . height < <NUM_LIT:0> ) { org . eclipse . swt . graphics . Point size = getSize ( ) ; double scale = getZoomManager ( ) . getZoom ( ) ; return new Dimension ( ( int ) ( size . x / scale + <NUM_LIT> ) , ( int ) ( size . y / scale + <NUM_LIT> ) ) ; } return preferredSize ; } public InternalLayoutContext getLayoutContext ( ) { if ( layoutContext == null ) { layoutContext = new InternalLayoutContext ( this ) ; } return layoutContext ; } public void setLayoutAlgorithm ( LayoutAlgorithm algorithm , boolean applyLayout ) { getLayoutContext ( ) . setLayoutAlgorithm ( algorithm ) ; if ( applyLayout ) { applyLayout ( ) ; } } public LayoutAlgorithm getLayoutAlgorithm ( ) { return getLayoutContext ( ) . getLayoutAlgorithm ( ) ; } public void setSubgraphFactory ( SubgraphFactory factory ) { getLayoutContext ( ) . setSubgraphFactory ( factory ) ; } public SubgraphFactory getSubgraphFactory ( ) { return getLayoutContext ( ) . getSubgraphFactory ( ) ; } public void setExpandCollapseManager ( ExpandCollapseManager expandCollapseManager ) { getLayoutContext ( ) . setExpandCollapseManager ( expandCollapseManager ) ; } public ExpandCollapseManager getExpandCollapseManager ( ) { return getLayoutContext ( ) . getExpandCollapseManager ( ) ; } public void addLayoutFilter ( LayoutFilter filter ) { getLayoutContext ( ) . addFilter ( filter ) ; } public void removeLayoutFilter ( LayoutFilter filter ) { getLayoutContext ( ) . removeFilter ( filter ) ; } public IFigure getFigureAt ( int x , int y ) { IFigure figureUnderMouse = this . getContents ( ) . findFigureAt ( x , y , new TreeSearch ( ) { public boolean accept ( IFigure figure ) { return true ; } public boolean prune ( IFigure figure ) { IFigure parent = figure . getParent ( ) ; if ( parent == fishEyeLayer ) { return true ; } if ( parent instanceof ContainerFigure && figure instanceof PolylineConnection ) { return false ; } if ( parent == zestRootLayer || parent == zestRootLayer . getParent ( ) || parent == zestRootLayer . getParent ( ) . getParent ( ) ) { return false ; } GraphItem item = ( GraphItem ) figure2ItemMap . get ( figure ) ; if ( item != null && item . getItemType ( ) == GraphItem . CONTAINER ) { return false ; } else if ( figure instanceof FreeformLayer || parent instanceof FreeformLayer || figure instanceof ScrollPane || parent instanceof ScrollPane || parent instanceof ScalableFreeformLayeredPane || figure instanceof ScalableFreeformLayeredPane || figure instanceof FreeformViewport || parent instanceof FreeformViewport ) { return false ; } return true ; } } ) ; return figureUnderMouse ; } private class DragSupport implements MouseMotionListener , org . eclipse . draw2d . MouseListener { Point dragStartLocation = null ; IFigure draggedSubgraphFigure = null ; ArrayList relativeLocations = new ArrayList ( ) ; GraphItem fisheyedItem = null ; boolean isDragging = false ; public void mouseDragged ( org . eclipse . draw2d . MouseEvent me ) { if ( ! isDragging ) { return ; } if ( selectedItems . isEmpty ( ) ) { IFigure figureUnderMouse = getFigureAt ( dragStartLocation . x , dragStartLocation . y ) ; if ( subgraphFigures . contains ( figureUnderMouse ) ) { draggedSubgraphFigure = figureUnderMouse ; } } Point mousePoint = new Point ( me . x , me . y ) ; if ( ! selectedItems . isEmpty ( ) || draggedSubgraphFigure != null ) { if ( relativeLocations . isEmpty ( ) ) { for ( Iterator iterator = selectedItems . iterator ( ) ; iterator . hasNext ( ) ; ) { GraphItem item = ( GraphItem ) iterator . next ( ) ; if ( ( item . getItemType ( ) == GraphItem . NODE ) || ( item . getItemType ( ) == GraphItem . CONTAINER ) ) { relativeLocations . add ( getRelativeLocation ( item . getFigure ( ) ) ) ; } } if ( draggedSubgraphFigure != null ) { relativeLocations . add ( getRelativeLocation ( draggedSubgraphFigure ) ) ; } } Iterator locationsIterator = relativeLocations . iterator ( ) ; for ( Iterator selectionIterator = selectedItems . iterator ( ) ; selectionIterator . hasNext ( ) ; ) { GraphItem item = ( GraphItem ) selectionIterator . next ( ) ; if ( ( item . getItemType ( ) == GraphItem . NODE ) || ( item . getItemType ( ) == GraphItem . CONTAINER ) ) { Point pointCopy = mousePoint . getCopy ( ) ; Point relativeLocation = ( Point ) locationsIterator . next ( ) ; item . getFigure ( ) . getParent ( ) . translateToRelative ( pointCopy ) ; item . getFigure ( ) . getParent ( ) . translateFromParent ( pointCopy ) ; ( ( GraphNode ) item ) . setLocation ( relativeLocation . x + pointCopy . x , relativeLocation . y + pointCopy . y ) ; } else { } } if ( draggedSubgraphFigure != null ) { Point pointCopy = mousePoint . getCopy ( ) ; draggedSubgraphFigure . getParent ( ) . translateToRelative ( pointCopy ) ; draggedSubgraphFigure . getParent ( ) . translateFromParent ( pointCopy ) ; Point relativeLocation = ( Point ) locationsIterator . next ( ) ; pointCopy . x += relativeLocation . x ; pointCopy . y += relativeLocation . y ; draggedSubgraphFigure . setLocation ( pointCopy ) ; } } } private Point getRelativeLocation ( IFigure figure ) { Point location = figure . getBounds ( ) . getTopLeft ( ) ; Point mousePointCopy = dragStartLocation . getCopy ( ) ; figure . getParent ( ) . translateToRelative ( mousePointCopy ) ; figure . getParent ( ) . translateFromParent ( mousePointCopy ) ; location . x -= mousePointCopy . x ; location . y -= mousePointCopy . y ; return location ; } public void mouseEntered ( org . eclipse . draw2d . MouseEvent me ) { } public void mouseExited ( org . eclipse . draw2d . MouseEvent me ) { } public void mouseHover ( org . eclipse . draw2d . MouseEvent me ) { } public void mouseMoved ( org . eclipse . draw2d . MouseEvent me ) { Point mousePoint = new Point ( me . x , me . y ) ; getRootLayer ( ) . translateToRelative ( mousePoint ) ; IFigure figureUnderMouse = getFigureAt ( mousePoint . x , mousePoint . y ) ; if ( figureUnderMouse != null ) { GraphItem itemUnderMouse = ( GraphItem ) figure2ItemMap . get ( figureUnderMouse ) ; if ( itemUnderMouse == fisheyedItem ) { return ; } if ( fisheyedItem != null ) { ( ( GraphNode ) fisheyedItem ) . fishEye ( false , true ) ; fisheyedItem = null ; } if ( itemUnderMouse != null && itemUnderMouse . getItemType ( ) == GraphItem . NODE ) { fisheyedItem = itemUnderMouse ; IFigure fisheyedFigure = ( ( GraphNode ) itemUnderMouse ) . fishEye ( true , true ) ; if ( fisheyedFigure == null ) { fisheyedItem = null ; } } } else { if ( fisheyedItem != null ) { ( ( GraphNode ) fisheyedItem ) . fishEye ( false , true ) ; fisheyedItem = null ; } } } public void mouseDoubleClicked ( org . eclipse . draw2d . MouseEvent me ) { } public void mousePressed ( org . eclipse . draw2d . MouseEvent me ) { isDragging = true ; Point mousePoint = new Point ( me . x , me . y ) ; dragStartLocation = mousePoint . getCopy ( ) ; getRootLayer ( ) . translateToRelative ( mousePoint ) ; if ( ( me . getState ( ) & SWT . MOD3 ) != <NUM_LIT:0> ) { if ( ( me . getState ( ) & SWT . MOD2 ) == <NUM_LIT:0> ) { double scale = getRootLayer ( ) . getScale ( ) ; scale *= <NUM_LIT> ; getRootLayer ( ) . setScale ( scale ) ; Point newMousePoint = mousePoint . getCopy ( ) . scale ( <NUM_LIT> ) ; Point delta = new Point ( newMousePoint . x - mousePoint . x , newMousePoint . y - mousePoint . y ) ; Point newViewLocation = getViewport ( ) . getViewLocation ( ) . getCopy ( ) . translate ( delta ) ; getViewport ( ) . setViewLocation ( newViewLocation ) ; clearSelection ( ) ; return ; } else { double scale = getRootLayer ( ) . getScale ( ) ; scale /= <NUM_LIT> ; getRootLayer ( ) . setScale ( scale ) ; Point newMousePoint = mousePoint . getCopy ( ) . scale ( <NUM_LIT:1> / <NUM_LIT> ) ; Point delta = new Point ( newMousePoint . x - mousePoint . x , newMousePoint . y - mousePoint . y ) ; Point newViewLocation = getViewport ( ) . getViewLocation ( ) . getCopy ( ) . translate ( delta ) ; getViewport ( ) . setViewLocation ( newViewLocation ) ; clearSelection ( ) ; return ; } } else { boolean hasSelection = selectedItems . size ( ) > <NUM_LIT:0> ; IFigure figureUnderMouse = getFigureAt ( mousePoint . x , mousePoint . y ) ; getRootLayer ( ) . translateFromParent ( mousePoint ) ; if ( figureUnderMouse != null ) { figureUnderMouse . getParent ( ) . translateFromParent ( mousePoint ) ; } if ( figureUnderMouse == null || figureUnderMouse == Graph . this ) { if ( ( me . getState ( ) & SWT . MOD1 ) == <NUM_LIT:0> ) { clearSelection ( ) ; if ( hasSelection ) { fireWidgetSelectedEvent ( null ) ; hasSelection = false ; } } return ; } GraphItem itemUnderMouse = ( GraphItem ) figure2ItemMap . get ( figureUnderMouse ) ; if ( itemUnderMouse == null ) { if ( ( me . getState ( ) & SWT . MOD1 ) != <NUM_LIT:0> ) { clearSelection ( ) ; if ( hasSelection ) { fireWidgetSelectedEvent ( null ) ; hasSelection = false ; } } return ; } if ( selectedItems . contains ( itemUnderMouse ) ) { if ( ( me . getState ( ) & SWT . MOD1 ) != <NUM_LIT:0> ) { selectedItems . remove ( itemUnderMouse ) ; ( itemUnderMouse ) . unhighlight ( ) ; fireWidgetSelectedEvent ( itemUnderMouse ) ; } return ; } if ( ( me . getState ( ) & SWT . MOD1 ) == <NUM_LIT:0> ) { clearSelection ( ) ; } if ( itemUnderMouse . getItemType ( ) == GraphItem . NODE ) { selectedItems . add ( itemUnderMouse ) ; ( ( GraphNode ) itemUnderMouse ) . highlight ( ) ; fireWidgetSelectedEvent ( itemUnderMouse ) ; } else if ( itemUnderMouse . getItemType ( ) == GraphItem . CONNECTION ) { selectedItems . add ( itemUnderMouse ) ; ( ( GraphConnection ) itemUnderMouse ) . highlight ( ) ; fireWidgetSelectedEvent ( itemUnderMouse ) ; } else if ( itemUnderMouse . getItemType ( ) == GraphItem . CONTAINER ) { selectedItems . add ( itemUnderMouse ) ; ( ( GraphContainer ) itemUnderMouse ) . highlight ( ) ; fireWidgetSelectedEvent ( itemUnderMouse ) ; } } } public void mouseReleased ( org . eclipse . draw2d . MouseEvent me ) { isDragging = false ; relativeLocations . clear ( ) ; draggedSubgraphFigure = null ; } } public void notifyListeners ( int eventType , Event event ) { super . notifyListeners ( eventType , event ) ; if ( eventType == SWT . Selection && event != null ) { notifySelectionListeners ( new SelectionEvent ( event ) ) ; } } private void clearSelection ( ) { Iterator iterator = new ArrayList ( selectedItems ) . iterator ( ) ; while ( iterator . hasNext ( ) ) { deselect ( ( GraphItem ) iterator . next ( ) ) ; } } private void fireWidgetSelectedEvent ( Item item ) { Event swtEvent = new Event ( ) ; swtEvent . item = item ; swtEvent . widget = this ; notifySelectionListeners ( new SelectionEvent ( swtEvent ) ) ; } private void notifySelectionListeners ( SelectionEvent event ) { Iterator iterator = selectionListeners . iterator ( ) ; while ( iterator . hasNext ( ) ) { ( ( SelectionListener ) iterator . next ( ) ) . widgetSelected ( event ) ; } } private void deselect ( GraphItem item ) { selectedItems . remove ( item ) ; item . unhighlight ( ) ; setNodeSelected ( item , false ) ; } private void select ( GraphItem item ) { selectedItems . add ( item ) ; item . highlight ( ) ; setNodeSelected ( item , true ) ; } private void setNodeSelected ( GraphItem item , boolean selected ) { if ( item instanceof GraphNode ) { ( ( GraphNode ) item ) . setSelected ( selected ) ; } } GraphConnection [ ] getConnectionsArray ( ) { GraphConnection [ ] connsArray = new GraphConnection [ connections . size ( ) ] ; connsArray = ( GraphConnection [ ] ) connections . toArray ( connsArray ) ; return connsArray ; } public void clear ( ) { for ( Iterator i = new ArrayList ( connections ) . iterator ( ) ; i . hasNext ( ) ; ) { removeConnection ( ( GraphConnection ) i . next ( ) ) ; } for ( Iterator i = new HashSet ( subgraphFigures ) . iterator ( ) ; i . hasNext ( ) ; ) { removeSubgraphFigure ( ( IFigure ) i . next ( ) ) ; } for ( Iterator i = new ArrayList ( nodes ) . iterator ( ) ; i . hasNext ( ) ; ) { removeNode ( ( GraphNode ) i . next ( ) ) ; } } void removeConnection ( GraphConnection connection ) { IFigure figure = connection . getConnectionFigure ( ) ; PolylineConnection sourceContainerConnectionFigure = connection . getSourceContainerConnectionFigure ( ) ; PolylineConnection targetContainerConnectionFigure = connection . getTargetContainerConnectionFigure ( ) ; connection . removeFigure ( ) ; this . getConnections ( ) . remove ( connection ) ; this . selectedItems . remove ( connection ) ; figure2ItemMap . remove ( figure ) ; if ( sourceContainerConnectionFigure != null ) { figure2ItemMap . remove ( sourceContainerConnectionFigure ) ; } if ( targetContainerConnectionFigure != null ) { figure2ItemMap . remove ( targetContainerConnectionFigure ) ; } getLayoutContext ( ) . fireConnectionRemovedEvent ( connection . getLayout ( ) ) ; } void removeNode ( GraphNode node ) { IFigure figure = node . getNodeFigure ( ) ; if ( figure . getParent ( ) != null ) { figure . getParent ( ) . remove ( figure ) ; } this . getNodes ( ) . remove ( node ) ; this . selectedItems . remove ( node ) ; figure2ItemMap . remove ( figure ) ; node . getLayout ( ) . dispose ( ) ; } void addConnection ( GraphConnection connection , boolean addToEdgeLayer ) { this . getConnections ( ) . add ( connection ) ; if ( addToEdgeLayer ) { zestRootLayer . addConnection ( connection . getFigure ( ) ) ; } getLayoutContext ( ) . fireConnectionAddedEvent ( connection . getLayout ( ) ) ; } public void addNode ( GraphNode node ) { this . getNodes ( ) . add ( node ) ; zestRootLayer . addNode ( node . getFigure ( ) ) ; getLayoutContext ( ) . fireNodeAddedEvent ( node . getLayout ( ) ) ; } public void addSubgraphFigure ( IFigure figure ) { zestRootLayer . addSubgraph ( figure ) ; subgraphFigures . add ( figure ) ; } void removeSubgraphFigure ( IFigure figure ) { subgraphFigures . remove ( figure ) ; figure . getParent ( ) . remove ( figure ) ; } void registerItem ( GraphItem item ) { if ( item . getItemType ( ) == GraphItem . NODE ) { IFigure figure = item . getFigure ( ) ; figure2ItemMap . put ( figure , item ) ; } else if ( item . getItemType ( ) == GraphItem . CONNECTION ) { IFigure figure = item . getFigure ( ) ; figure2ItemMap . put ( figure , item ) ; if ( ( ( GraphConnection ) item ) . getSourceContainerConnectionFigure ( ) != null ) { figure2ItemMap . put ( ( ( GraphConnection ) item ) . getSourceContainerConnectionFigure ( ) , item ) ; } if ( ( ( GraphConnection ) item ) . getTargetContainerConnectionFigure ( ) != null ) { figure2ItemMap . put ( ( ( GraphConnection ) item ) . getTargetContainerConnectionFigure ( ) , item ) ; } } else if ( item . getItemType ( ) == GraphItem . CONTAINER ) { IFigure figure = item . getFigure ( ) ; figure2ItemMap . put ( figure , item ) ; } else { throw new RuntimeException ( "<STR_LIT>" + item . getItemType ( ) ) ; } } private void scheduleLayoutOnReveal ( final boolean clean ) { final boolean [ ] isVisibleSync = new boolean [ <NUM_LIT:1> ] ; Display . getDefault ( ) . syncExec ( new Runnable ( ) { public void run ( ) { isVisibleSync [ <NUM_LIT:0> ] = isVisible ( ) ; } } ) ; if ( isVisibleSync [ <NUM_LIT:0> ] ) { applyLayoutInternal ( clean ) ; } else { shouldSheduleLayout = true ; } } private ScalableFigure createLayers ( ) { rootlayer = new ScalableFreeformLayeredPane ( ) ; rootlayer . setLayoutManager ( new FreeformLayout ( ) ) ; zestRootLayer = new ZestRootLayer ( ) ; zestRootLayer . setLayoutManager ( new FreeformLayout ( ) ) ; fishEyeLayer = new ScalableFreeformLayeredPane ( ) ; fishEyeLayer . setLayoutManager ( new FreeformLayout ( ) ) ; rootlayer . add ( zestRootLayer ) ; rootlayer . add ( fishEyeLayer ) ; zestRootLayer . addLayoutListener ( LayoutAnimator . getDefault ( ) ) ; fishEyeLayer . addLayoutListener ( LayoutAnimator . getDefault ( ) ) ; rootlayer . addCoordinateListener ( new CoordinateListener ( ) { public void coordinateSystemChanged ( IFigure source ) { if ( preferredSize . width == - <NUM_LIT:1> && preferredSize . height == - <NUM_LIT:1> ) { getLayoutContext ( ) . fireBoundsChangedEvent ( ) ; } } } ) ; return rootlayer ; } void removeFishEye ( final IFigure fishEyeFigure , final IFigure regularFigure , boolean animate ) { if ( ! fishEyeLayer . getChildren ( ) . contains ( fishEyeFigure ) ) { return ; } if ( animate ) { Animation . markBegin ( ) ; } Rectangle bounds = regularFigure . getBounds ( ) . getCopy ( ) ; regularFigure . translateToAbsolute ( bounds ) ; double scale = rootlayer . getScale ( ) ; fishEyeLayer . setScale ( <NUM_LIT:1> / scale ) ; fishEyeLayer . translateToRelative ( bounds ) ; fishEyeLayer . translateFromParent ( bounds ) ; fishEyeLayer . setConstraint ( fishEyeFigure , bounds ) ; for ( Iterator iterator = fisheyeListeners . iterator ( ) ; iterator . hasNext ( ) ; ) { FisheyeListener listener = ( FisheyeListener ) iterator . next ( ) ; listener . fisheyeRemoved ( this , regularFigure , fishEyeFigure ) ; } if ( animate ) { Animation . run ( FISHEYE_ANIMATION_TIME * <NUM_LIT:2> ) ; } this . getRootLayer ( ) . getUpdateManager ( ) . performUpdate ( ) ; fishEyeLayer . removeAll ( ) ; } boolean replaceFishFigure ( IFigure oldFigure , IFigure newFigure ) { if ( this . fishEyeLayer . getChildren ( ) . contains ( oldFigure ) ) { Rectangle bounds = oldFigure . getBounds ( ) ; newFigure . setBounds ( bounds ) ; this . fishEyeLayer . remove ( oldFigure ) ; this . fishEyeLayer . add ( newFigure ) ; for ( Iterator iterator = fisheyeListeners . iterator ( ) ; iterator . hasNext ( ) ; ) { FisheyeListener listener = ( FisheyeListener ) iterator . next ( ) ; listener . fisheyeReplaced ( this , oldFigure , newFigure ) ; } return true ; } return false ; } void fishEye ( IFigure startFigure , IFigure endFigure , Rectangle newBounds , boolean animate ) { fishEyeLayer . removeAll ( ) ; if ( animate ) { Animation . markBegin ( ) ; } double scale = rootlayer . getScale ( ) ; fishEyeLayer . setScale ( <NUM_LIT:1> / scale ) ; fishEyeLayer . translateToRelative ( newBounds ) ; fishEyeLayer . translateFromParent ( newBounds ) ; Rectangle bounds = startFigure . getBounds ( ) . getCopy ( ) ; startFigure . translateToAbsolute ( bounds ) ; fishEyeLayer . translateToRelative ( bounds ) ; fishEyeLayer . translateFromParent ( bounds ) ; endFigure . setLocation ( bounds . getLocation ( ) ) ; endFigure . setSize ( bounds . getSize ( ) ) ; fishEyeLayer . add ( endFigure ) ; fishEyeLayer . setConstraint ( endFigure , newBounds ) ; for ( Iterator iterator = fisheyeListeners . iterator ( ) ; iterator . hasNext ( ) ; ) { FisheyeListener listener = ( FisheyeListener ) iterator . next ( ) ; listener . fisheyeAdded ( this , startFigure , endFigure ) ; } if ( animate ) { Animation . run ( FISHEYE_ANIMATION_TIME ) ; } this . getRootLayer ( ) . getUpdateManager ( ) . performUpdate ( ) ; } public void addFisheyeListener ( FisheyeListener listener ) { fisheyeListeners . add ( listener ) ; } public void removeFisheyeListener ( FisheyeListener listener ) { fisheyeListeners . remove ( listener ) ; } public int getItemType ( ) { return GraphItem . GRAPH ; } GraphItem getGraphItem ( IFigure figure ) { return ( GraphItem ) figure2ItemMap . get ( figure ) ; } public void setExpanded ( GraphNode node , boolean expanded ) { layoutContext . setExpanded ( node . getLayout ( ) , expanded ) ; rootlayer . invalidate ( ) ; } public boolean canExpand ( GraphNode node ) { return layoutContext . canExpand ( node . getLayout ( ) ) ; } public boolean canCollapse ( GraphNode node ) { return layoutContext . canCollapse ( node . getLayout ( ) ) ; } public Graph getGraph ( ) { return this ; } public Widget getItem ( ) { return this ; } public DisplayIndependentRectangle getLayoutBounds ( ) { Dimension preferredSize = this . getPreferredSize ( ) ; return new DisplayIndependentRectangle ( <NUM_LIT:0> , <NUM_LIT:0> , preferredSize . width , preferredSize . height ) ; } void setDefaultConnectionRouter ( ConnectionRouter defaultConnectionRouter ) { this . defaultConnectionRouter = defaultConnectionRouter ; } ConnectionRouter getDefaultConnectionRouter ( ) { return defaultConnectionRouter ; } void applyConnectionRouter ( ) { Iterator iterator = getConnections ( ) . iterator ( ) ; while ( iterator . hasNext ( ) ) { GraphConnection conn = ( GraphConnection ) iterator . next ( ) ; conn . getConnectionFigure ( ) . setConnectionRouter ( defaultConnectionRouter ) ; } this . getRootLayer ( ) . getUpdateManager ( ) . performUpdate ( ) ; } public void setRouter ( ConnectionRouter connectionRouter ) { setDefaultConnectionRouter ( connectionRouter ) ; applyConnectionRouter ( ) ; } public ZoomManager getZoomManager ( ) { if ( zoomManager == null ) { zoomManager = new ZoomManager ( getRootLayer ( ) , getViewport ( ) ) ; } return zoomManager ; } } </s>
|
<s> package org . eclipse . zest . core . widgets ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . HashSet ; import java . util . Iterator ; import java . util . List ; import org . eclipse . draw2d . Animation ; import org . eclipse . zest . layouts . LayoutAlgorithm ; import org . eclipse . zest . layouts . dataStructures . DisplayIndependentRectangle ; import org . eclipse . zest . layouts . interfaces . ConnectionLayout ; import org . eclipse . zest . layouts . interfaces . ContextListener ; import org . eclipse . zest . layouts . interfaces . EntityLayout ; import org . eclipse . zest . layouts . interfaces . ExpandCollapseManager ; import org . eclipse . zest . layouts . interfaces . GraphStructureListener ; import org . eclipse . zest . layouts . interfaces . LayoutContext ; import org . eclipse . zest . layouts . interfaces . LayoutListener ; import org . eclipse . zest . layouts . interfaces . NodeLayout ; import org . eclipse . zest . layouts . interfaces . PruningListener ; import org . eclipse . zest . layouts . interfaces . SubgraphLayout ; class InternalLayoutContext implements LayoutContext { final IContainer container ; private final List filters = new ArrayList ( ) ; private final List contextListeners = new ArrayList ( ) ; private final List graphStructureListeners = new ArrayList ( ) ; private final List layoutListeners = new ArrayList ( ) ; private final List pruningListeners = new ArrayList ( ) ; private LayoutAlgorithm mainAlgorithm ; private LayoutAlgorithm layoutAlgorithm ; private ExpandCollapseManager expandCollapseManager ; private SubgraphFactory subgraphFactory = new DefaultSubgraph . DefaultSubgraphFactory ( ) ; private final HashSet subgraphs = new HashSet ( ) ; private boolean eventsOn = true ; private boolean backgorundLayoutEnabled = true ; private boolean externalLayoutInvocation = false ; InternalLayoutContext ( Graph graph ) { this . container = graph ; } InternalLayoutContext ( GraphContainer container ) { this . container = container ; } public void addContextListener ( ContextListener listener ) { contextListeners . add ( listener ) ; } public void addGraphStructureListener ( GraphStructureListener listener ) { graphStructureListeners . add ( listener ) ; } public void addLayoutListener ( LayoutListener listener ) { layoutListeners . add ( listener ) ; } public void addPruningListener ( PruningListener listener ) { pruningListeners . add ( listener ) ; } public SubgraphLayout createSubgraph ( NodeLayout [ ] nodes ) { checkChangesAllowed ( ) ; InternalNodeLayout [ ] internalNodes = new InternalNodeLayout [ nodes . length ] ; for ( int i = <NUM_LIT:0> ; i < nodes . length ; i ++ ) { internalNodes [ i ] = ( InternalNodeLayout ) nodes [ i ] ; } SubgraphLayout subgraph = subgraphFactory . createSubgraph ( internalNodes , this ) ; subgraphs . add ( subgraph ) ; return subgraph ; } void removeSubgrah ( DefaultSubgraph subgraph ) { subgraphs . remove ( subgraph ) ; } public void flushChanges ( boolean animationHint ) { if ( ! container . getGraph ( ) . isVisible ( ) && animationHint ) { return ; } eventsOn = false ; if ( animationHint ) { Animation . markBegin ( ) ; } for ( Iterator iterator = container . getNodes ( ) . iterator ( ) ; iterator . hasNext ( ) ; ) { GraphNode node = ( GraphNode ) iterator . next ( ) ; node . applyLayoutChanges ( ) ; } for ( Iterator iterator = container . getConnections ( ) . iterator ( ) ; iterator . hasNext ( ) ; ) { GraphConnection connection = ( GraphConnection ) iterator . next ( ) ; connection . applyLayoutChanges ( ) ; } for ( Iterator iterator = subgraphs . iterator ( ) ; iterator . hasNext ( ) ; ) { DefaultSubgraph subgraph = ( DefaultSubgraph ) iterator . next ( ) ; subgraph . applyLayoutChanges ( ) ; } if ( animationHint ) { Animation . run ( Graph . ANIMATION_TIME ) ; } eventsOn = true ; } public DisplayIndependentRectangle getBounds ( ) { DisplayIndependentRectangle result = new DisplayIndependentRectangle ( container . getLayoutBounds ( ) ) ; result . width -= <NUM_LIT:20> ; result . height -= <NUM_LIT:20> ; return result ; } public LayoutAlgorithm getMainLayoutAlgorithm ( ) { return mainAlgorithm ; } public ExpandCollapseManager getExpandCollapseManager ( ) { return expandCollapseManager ; } public NodeLayout [ ] getNodes ( ) { ArrayList result = new ArrayList ( ) ; for ( Iterator iterator = this . container . getNodes ( ) . iterator ( ) ; iterator . hasNext ( ) ; ) { GraphNode node = ( GraphNode ) iterator . next ( ) ; if ( ! isLayoutItemFiltered ( node ) ) { result . add ( node . getLayout ( ) ) ; } } return ( NodeLayout [ ] ) result . toArray ( new NodeLayout [ result . size ( ) ] ) ; } public EntityLayout [ ] getEntities ( ) { HashSet addedSubgraphs = new HashSet ( ) ; ArrayList result = new ArrayList ( ) ; for ( Iterator iterator = this . container . getNodes ( ) . iterator ( ) ; iterator . hasNext ( ) ; ) { GraphNode node = ( GraphNode ) iterator . next ( ) ; if ( ! isLayoutItemFiltered ( node ) ) { InternalNodeLayout nodeLayout = node . getLayout ( ) ; if ( ! nodeLayout . isPruned ( ) ) { result . add ( nodeLayout ) ; } else { SubgraphLayout subgraph = nodeLayout . getSubgraph ( ) ; if ( subgraph . isGraphEntity ( ) && ! addedSubgraphs . contains ( subgraph ) ) { result . add ( subgraph ) ; addedSubgraphs . add ( subgraph ) ; } } } } return ( EntityLayout [ ] ) result . toArray ( new EntityLayout [ result . size ( ) ] ) ; } public SubgraphLayout [ ] getSubgraphs ( ) { SubgraphLayout [ ] result = new SubgraphLayout [ subgraphs . size ( ) ] ; int subgraphCount = <NUM_LIT:0> ; for ( Iterator iterator = subgraphs . iterator ( ) ; iterator . hasNext ( ) ; ) { SubgraphLayout subgraph = ( SubgraphLayout ) iterator . next ( ) ; NodeLayout [ ] nodes = subgraph . getNodes ( ) ; for ( int i = <NUM_LIT:0> ; i < nodes . length ; i ++ ) { if ( ! isLayoutItemFiltered ( ( ( InternalNodeLayout ) nodes [ i ] ) . getNode ( ) ) ) { result [ subgraphCount ++ ] = subgraph ; break ; } } } if ( subgraphCount == subgraphs . size ( ) ) { return result ; } else { SubgraphLayout [ ] result2 = new SubgraphLayout [ subgraphCount ] ; System . arraycopy ( result , <NUM_LIT:0> , result2 , <NUM_LIT:0> , subgraphCount ) ; return result2 ; } } public boolean isBoundsExpandable ( ) { return false ; } public boolean isBackgroundLayoutEnabled ( ) { return backgorundLayoutEnabled ; } void setBackgroundLayoutEnabled ( boolean enabled ) { if ( this . backgorundLayoutEnabled != enabled ) { this . backgorundLayoutEnabled = enabled ; fireBackgroundEnableChangedEvent ( ) ; } } public boolean isPruningEnabled ( ) { return expandCollapseManager != null ; } public void removeContextListener ( ContextListener listener ) { contextListeners . remove ( listener ) ; } public void removeGraphStructureListener ( GraphStructureListener listener ) { graphStructureListeners . remove ( listener ) ; } public void removeLayoutListener ( LayoutListener listener ) { layoutListeners . remove ( listener ) ; } public void removePruningListener ( PruningListener listener ) { pruningListeners . remove ( listener ) ; } public void setMainLayoutAlgorithm ( LayoutAlgorithm algorithm ) { mainAlgorithm = algorithm ; } public void setExpandCollapseManager ( ExpandCollapseManager expandCollapseManager ) { this . expandCollapseManager = expandCollapseManager ; expandCollapseManager . initExpansion ( this ) ; } public ConnectionLayout [ ] getConnections ( ) { List connections = container . getConnections ( ) ; ConnectionLayout [ ] result = new ConnectionLayout [ connections . size ( ) ] ; int i = <NUM_LIT:0> ; for ( Iterator iterator = connections . iterator ( ) ; iterator . hasNext ( ) ; ) { GraphConnection connection = ( GraphConnection ) iterator . next ( ) ; if ( ! isLayoutItemFiltered ( connection ) ) { result [ i ++ ] = connection . getLayout ( ) ; } } if ( i == result . length ) { return result ; } ConnectionLayout [ ] result2 = new ConnectionLayout [ i ] ; System . arraycopy ( result , <NUM_LIT:0> , result2 , <NUM_LIT:0> , i ) ; return result2 ; } public ConnectionLayout [ ] getConnections ( EntityLayout source , EntityLayout target ) { ArrayList result = new ArrayList ( ) ; ArrayList sourcesList = new ArrayList ( ) ; if ( source instanceof NodeLayout ) { sourcesList . add ( source ) ; } if ( source instanceof SubgraphLayout ) { sourcesList . addAll ( Arrays . asList ( ( ( SubgraphLayout ) source ) . getNodes ( ) ) ) ; } HashSet targets = new HashSet ( ) ; if ( target instanceof NodeLayout ) { targets . add ( target ) ; } if ( target instanceof SubgraphLayout ) { targets . addAll ( Arrays . asList ( ( ( SubgraphLayout ) target ) . getNodes ( ) ) ) ; } for ( Iterator iterator = sourcesList . iterator ( ) ; iterator . hasNext ( ) ; ) { NodeLayout source2 = ( NodeLayout ) iterator . next ( ) ; ConnectionLayout [ ] outgoingConnections = source2 . getOutgoingConnections ( ) ; for ( int i = <NUM_LIT:0> ; i < outgoingConnections . length ; i ++ ) { ConnectionLayout connection = outgoingConnections [ i ] ; if ( ( connection . getSource ( ) == source2 && targets . contains ( connection . getTarget ( ) ) ) || ( connection . getTarget ( ) == source2 && targets . contains ( connection . getSource ( ) ) ) ) { result . add ( connection ) ; } } } return ( ConnectionLayout [ ] ) result . toArray ( new ConnectionLayout [ result . size ( ) ] ) ; } void addFilter ( LayoutFilter filter ) { filters . add ( filter ) ; } void removeFilter ( LayoutFilter filter ) { filters . remove ( filter ) ; } boolean isLayoutItemFiltered ( GraphItem item ) { for ( Iterator it = filters . iterator ( ) ; it . hasNext ( ) ; ) { LayoutFilter filter = ( LayoutFilter ) it . next ( ) ; if ( filter . isObjectFiltered ( item ) ) { return true ; } } return false ; } void setExpanded ( NodeLayout node , boolean expanded ) { externalLayoutInvocation = true ; if ( expandCollapseManager != null ) { expandCollapseManager . setExpanded ( this , node , expanded ) ; } externalLayoutInvocation = false ; } boolean canExpand ( NodeLayout node ) { return expandCollapseManager != null && expandCollapseManager . canExpand ( this , node ) ; } boolean canCollapse ( NodeLayout node ) { return expandCollapseManager != null && expandCollapseManager . canCollapse ( this , node ) ; } void setSubgraphFactory ( SubgraphFactory factory ) { subgraphFactory = factory ; } SubgraphFactory getSubgraphFactory ( ) { return subgraphFactory ; } void applyMainAlgorithm ( ) { if ( backgorundLayoutEnabled && mainAlgorithm != null ) { mainAlgorithm . applyLayout ( true ) ; flushChanges ( false ) ; } } void setLayoutAlgorithm ( LayoutAlgorithm algorithm ) { this . layoutAlgorithm = algorithm ; this . layoutAlgorithm . setLayoutContext ( this ) ; } LayoutAlgorithm getLayoutAlgorithm ( ) { return layoutAlgorithm ; } void applyLayout ( boolean clean ) { if ( layoutAlgorithm != null ) { externalLayoutInvocation = true ; layoutAlgorithm . applyLayout ( clean ) ; externalLayoutInvocation = false ; } } void checkChangesAllowed ( ) { if ( ! backgorundLayoutEnabled && ! externalLayoutInvocation ) { throw new RuntimeException ( "<STR_LIT>" ) ; } } void fireNodeAddedEvent ( NodeLayout node ) { boolean intercepted = ! eventsOn ; GraphStructureListener [ ] listeners = ( GraphStructureListener [ ] ) graphStructureListeners . toArray ( new GraphStructureListener [ graphStructureListeners . size ( ) ] ) ; for ( int i = <NUM_LIT:0> ; i < listeners . length && ! intercepted ; i ++ ) { intercepted = listeners [ i ] . nodeAdded ( this , node ) ; } if ( ! intercepted ) { applyMainAlgorithm ( ) ; } } void fireNodeRemovedEvent ( NodeLayout node ) { boolean intercepted = ! eventsOn ; GraphStructureListener [ ] listeners = ( GraphStructureListener [ ] ) graphStructureListeners . toArray ( new GraphStructureListener [ graphStructureListeners . size ( ) ] ) ; for ( int i = <NUM_LIT:0> ; i < listeners . length && ! intercepted ; i ++ ) { intercepted = listeners [ i ] . nodeRemoved ( this , node ) ; } if ( ! intercepted ) { applyMainAlgorithm ( ) ; } } void fireConnectionAddedEvent ( ConnectionLayout connection ) { InternalLayoutContext sourceContext = ( ( InternalNodeLayout ) connection . getSource ( ) ) . getOwnerLayoutContext ( ) ; InternalLayoutContext targetContext = ( ( InternalNodeLayout ) connection . getTarget ( ) ) . getOwnerLayoutContext ( ) ; if ( sourceContext != targetContext ) { return ; } if ( sourceContext == this ) { boolean intercepted = ! eventsOn ; GraphStructureListener [ ] listeners = ( GraphStructureListener [ ] ) graphStructureListeners . toArray ( new GraphStructureListener [ graphStructureListeners . size ( ) ] ) ; for ( int i = <NUM_LIT:0> ; i < listeners . length && ! intercepted ; i ++ ) { intercepted = listeners [ i ] . connectionAdded ( this , connection ) ; } if ( ! intercepted ) { applyMainAlgorithm ( ) ; } } else { sourceContext . fireConnectionAddedEvent ( connection ) ; } } void fireConnectionRemovedEvent ( ConnectionLayout connection ) { InternalLayoutContext sourceContext = ( ( InternalNodeLayout ) connection . getSource ( ) ) . getOwnerLayoutContext ( ) ; InternalLayoutContext targetContext = ( ( InternalNodeLayout ) connection . getTarget ( ) ) . getOwnerLayoutContext ( ) ; if ( sourceContext != targetContext ) { return ; } if ( sourceContext == this ) { boolean intercepted = ! eventsOn ; GraphStructureListener [ ] listeners = ( GraphStructureListener [ ] ) graphStructureListeners . toArray ( new GraphStructureListener [ graphStructureListeners . size ( ) ] ) ; for ( int i = <NUM_LIT:0> ; i < listeners . length && ! intercepted ; i ++ ) { intercepted = listeners [ i ] . connectionRemoved ( this , connection ) ; } if ( ! intercepted ) { applyMainAlgorithm ( ) ; } } else { sourceContext . fireConnectionAddedEvent ( connection ) ; } } void fireBoundsChangedEvent ( ) { boolean intercepted = ! eventsOn ; ContextListener [ ] listeners = ( ContextListener [ ] ) contextListeners . toArray ( new ContextListener [ contextListeners . size ( ) ] ) ; for ( int i = <NUM_LIT:0> ; i < listeners . length && ! intercepted ; i ++ ) { intercepted = listeners [ i ] . boundsChanged ( this ) ; } if ( ! intercepted ) { applyMainAlgorithm ( ) ; } } void fireBackgroundEnableChangedEvent ( ) { ContextListener [ ] listeners = ( ContextListener [ ] ) contextListeners . toArray ( new ContextListener [ contextListeners . size ( ) ] ) ; for ( int i = <NUM_LIT:0> ; i < listeners . length ; i ++ ) { listeners [ i ] . backgroundEnableChanged ( this ) ; } } void fireNodeMovedEvent ( InternalNodeLayout node ) { if ( eventsOn ) { node . refreshLocation ( ) ; } boolean intercepted = ! eventsOn ; LayoutListener [ ] listeners = ( LayoutListener [ ] ) layoutListeners . toArray ( new LayoutListener [ layoutListeners . size ( ) ] ) ; node . setLocation ( node . getNode ( ) . getLocation ( ) . x , node . getNode ( ) . getLocation ( ) . y ) ; for ( int i = <NUM_LIT:0> ; i < listeners . length && ! intercepted ; i ++ ) { intercepted = listeners [ i ] . nodeMoved ( this , node ) ; } if ( ! intercepted ) { applyMainAlgorithm ( ) ; } } void fireNodeResizedEvent ( InternalNodeLayout node ) { if ( eventsOn ) { node . refreshSize ( ) ; node . refreshLocation ( ) ; } boolean intercepted = ! eventsOn ; LayoutListener [ ] listeners = ( LayoutListener [ ] ) layoutListeners . toArray ( new LayoutListener [ layoutListeners . size ( ) ] ) ; for ( int i = <NUM_LIT:0> ; i < listeners . length && ! intercepted ; i ++ ) { intercepted = listeners [ i ] . nodeResized ( this , node ) ; } if ( ! intercepted ) { applyMainAlgorithm ( ) ; } } void fireSubgraphMovedEvent ( DefaultSubgraph subgraph ) { if ( eventsOn ) { subgraph . refreshLocation ( ) ; } boolean intercepted = ! eventsOn ; LayoutListener [ ] listeners = ( LayoutListener [ ] ) layoutListeners . toArray ( new LayoutListener [ layoutListeners . size ( ) ] ) ; for ( int i = <NUM_LIT:0> ; i < listeners . length && ! intercepted ; i ++ ) { intercepted = listeners [ i ] . subgraphMoved ( this , subgraph ) ; } if ( ! intercepted ) { applyMainAlgorithm ( ) ; } } void fireSubgraphResizedEvent ( DefaultSubgraph subgraph ) { if ( eventsOn ) { subgraph . refreshSize ( ) ; subgraph . refreshLocation ( ) ; } boolean intercepted = ! eventsOn ; LayoutListener [ ] listeners = ( LayoutListener [ ] ) layoutListeners . toArray ( new LayoutListener [ layoutListeners . size ( ) ] ) ; for ( int i = <NUM_LIT:0> ; i < listeners . length && ! intercepted ; i ++ ) { intercepted = listeners [ i ] . subgraphResized ( this , subgraph ) ; } if ( ! intercepted ) { applyMainAlgorithm ( ) ; } } } </s>
|
<s> package org . eclipse . zest . core . widgets ; import java . util . Arrays ; import java . util . HashMap ; import java . util . HashSet ; import java . util . Iterator ; import org . eclipse . draw2d . AncestorListener ; import org . eclipse . draw2d . ColorConstants ; import org . eclipse . draw2d . FigureListener ; import org . eclipse . draw2d . IFigure ; import org . eclipse . draw2d . geometry . Dimension ; import org . eclipse . draw2d . geometry . Point ; import org . eclipse . draw2d . geometry . Rectangle ; import org . eclipse . swt . graphics . Font ; import org . eclipse . swt . graphics . FontData ; import org . eclipse . swt . widgets . Display ; import org . eclipse . zest . core . widgets . internal . GraphLabel ; import org . eclipse . zest . core . widgets . internal . ZestRootLayer ; import org . eclipse . zest . layouts . interfaces . LayoutContext ; import org . eclipse . zest . layouts . interfaces . NodeLayout ; class PrunedSuccessorsSubgraph extends DefaultSubgraph { private class LabelAncestorListener extends AncestorListener . Stub { private final IFigure originalFigure ; private IFigure fisheyeFigure ; public LabelAncestorListener ( IFigure originalFigure , IFigure fisheyeFigure ) { this . originalFigure = originalFigure ; this . fisheyeFigure = fisheyeFigure ; } public void ancestorRemoved ( IFigure ancestor ) { if ( fisheyeFigure != null ) { final GraphLabel label = ( GraphLabel ) nodeFigureToLabel . get ( fisheyeFigure ) ; if ( label == null ) { return ; } nodeFigureToLabel . remove ( fisheyeFigure ) ; Display . getDefault ( ) . asyncExec ( new Runnable ( ) { public void run ( ) { label . removeAncestorListener ( LabelAncestorListener . this ) ; } } ) ; fisheyeFigure . removeFigureListener ( nodeFigureListener ) ; originalFigure . addFigureListener ( nodeFigureListener ) ; labelToAncestorListener . remove ( label ) ; fisheyeFigure = null ; addLabelForFigure ( originalFigure , label ) ; refreshLabelBounds ( originalFigure , label ) ; } } } private final FigureListener nodeFigureListener = new FigureListener ( ) { public void figureMoved ( IFigure source ) { GraphLabel label = ( GraphLabel ) nodeFigureToLabel . get ( source ) ; if ( label != null ) { refreshLabelBounds ( source , label ) ; } } } ; private final FisheyeListener fisheyeListener = new FisheyeListener ( ) { public void fisheyeReplaced ( Graph graph , IFigure oldFisheyeFigure , IFigure newFisheyeFigure ) { oldFisheyeFigure . removeFigureListener ( nodeFigureListener ) ; newFisheyeFigure . addFigureListener ( nodeFigureListener ) ; GraphLabel label = ( GraphLabel ) nodeFigureToLabel . remove ( oldFisheyeFigure ) ; nodeFigureToLabel . put ( newFisheyeFigure , label ) ; LabelAncestorListener ancestorListener = ( LabelAncestorListener ) labelToAncestorListener . get ( label ) ; ancestorListener . fisheyeFigure = null ; addLabelForFigure ( newFisheyeFigure , label ) ; ancestorListener . fisheyeFigure = newFisheyeFigure ; refreshLabelBounds ( newFisheyeFigure , label ) ; } public void fisheyeRemoved ( Graph graph , IFigure originalFigure , IFigure fisheyeFigure ) { } public void fisheyeAdded ( Graph graph , IFigure originalFigure , IFigure fisheyeFigure ) { originalFigure . removeFigureListener ( nodeFigureListener ) ; fisheyeFigure . addFigureListener ( nodeFigureListener ) ; GraphLabel label = ( GraphLabel ) nodeFigureToLabel . get ( originalFigure ) ; if ( label == null ) { return ; } nodeFigureToLabel . put ( fisheyeFigure , label ) ; refreshLabelBounds ( fisheyeFigure , label ) ; addLabelForFigure ( fisheyeFigure , label ) ; LabelAncestorListener labelAncestorListener = new LabelAncestorListener ( originalFigure , fisheyeFigure ) ; label . addAncestorListener ( labelAncestorListener ) ; labelToAncestorListener . put ( label , labelAncestorListener ) ; } } ; private HashMap nodeFigureToLabel = new HashMap ( ) ; private HashMap labelToAncestorListener = new HashMap ( ) ; protected PrunedSuccessorsSubgraph ( LayoutContext context2 ) { super ( context2 ) ; context . container . getGraph ( ) . addFisheyeListener ( fisheyeListener ) ; } public void addNodes ( NodeLayout [ ] nodes ) { super . addNodes ( nodes ) ; HashSet nodesToUpdate = new HashSet ( ) ; for ( int i = <NUM_LIT:0> ; i < nodes . length ; i ++ ) { nodesToUpdate . addAll ( Arrays . asList ( nodes [ i ] . getPredecessingNodes ( ) ) ) ; } for ( Iterator iterator = nodesToUpdate . iterator ( ) ; iterator . hasNext ( ) ; ) { InternalNodeLayout nodeToUpdate = ( InternalNodeLayout ) iterator . next ( ) ; updateNodeLabel ( nodeToUpdate ) ; } } public void removeNodes ( NodeLayout [ ] nodes ) { super . removeNodes ( nodes ) ; HashSet nodesToUpdate = new HashSet ( ) ; for ( int i = <NUM_LIT:0> ; i < nodes . length ; i ++ ) { nodesToUpdate . addAll ( Arrays . asList ( nodes [ i ] . getPredecessingNodes ( ) ) ) ; if ( ( ( InternalNodeLayout ) nodes [ i ] ) . isDisposed ( ) ) { removeFigureForNode ( ( InternalNodeLayout ) nodes [ i ] ) ; } else { nodesToUpdate . add ( nodes [ i ] ) ; } } for ( Iterator iterator = nodesToUpdate . iterator ( ) ; iterator . hasNext ( ) ; ) { InternalNodeLayout predecessor = ( InternalNodeLayout ) iterator . next ( ) ; updateNodeLabel ( predecessor ) ; } } private void addLabelForFigure ( IFigure figure , GraphLabel label ) { IFigure parent = figure . getParent ( ) ; if ( parent instanceof ZestRootLayer ) { ( ( ZestRootLayer ) parent ) . addDecoration ( figure , label ) ; } else { if ( parent . getChildren ( ) . contains ( label ) ) { parent . remove ( label ) ; } int index = parent . getChildren ( ) . indexOf ( figure ) ; parent . add ( label , index + <NUM_LIT:1> ) ; } } private void refreshLabelBounds ( IFigure figure , GraphLabel label ) { Rectangle figureBounds = figure . getBounds ( ) ; if ( figureBounds . width * figureBounds . height > <NUM_LIT:0> ) { label . setText ( label . getText ( ) ) ; Dimension labelSize = label . getSize ( ) ; labelSize . expand ( - <NUM_LIT:6> , - <NUM_LIT:4> ) ; Point anchorPoint = figure . getBounds ( ) . getBottomRight ( ) ; anchorPoint . x -= labelSize . width / <NUM_LIT:2> ; anchorPoint . y -= labelSize . height / <NUM_LIT:2> ; Rectangle bounds = new Rectangle ( anchorPoint , labelSize ) ; label . setBounds ( bounds ) ; label . getParent ( ) . setConstraint ( label , bounds ) ; } else { label . getParent ( ) . setConstraint ( label , new Rectangle ( figureBounds . x , figureBounds . y , <NUM_LIT:0> , <NUM_LIT:0> ) ) ; label . setBounds ( new Rectangle ( figureBounds . x , figureBounds . y , <NUM_LIT:0> , <NUM_LIT:0> ) ) ; } } void updateNodeLabel ( InternalNodeLayout internalNode ) { if ( internalNode . isDisposed ( ) ) { return ; } IFigure figure = internalNode . getNode ( ) . getFigure ( ) ; GraphLabel label = ( GraphLabel ) nodeFigureToLabel . get ( figure ) ; IFigure fisheye = getFisheyeFigure ( figure ) ; if ( fisheye != null ) { figure = fisheye ; } if ( label == null ) { label = new GraphLabel ( false ) ; label . setForegroundColor ( ColorConstants . white ) ; label . setBackgroundColor ( ColorConstants . red ) ; FontData fontData = Display . getDefault ( ) . getSystemFont ( ) . getFontData ( ) [ <NUM_LIT:0> ] ; fontData . setHeight ( <NUM_LIT:6> ) ; label . setFont ( new Font ( Display . getCurrent ( ) , fontData ) ) ; figure . addFigureListener ( nodeFigureListener ) ; addLabelForFigure ( figure , label ) ; nodeFigureToLabel . put ( figure , label ) ; } GraphNode graphNode = internalNode . getNode ( ) ; if ( ! graphNode . getGraphModel ( ) . canExpand ( graphNode ) || graphNode . getGraphModel ( ) . canCollapse ( graphNode ) || internalNode . isPruned ( ) ) { label . setVisible ( false ) ; } else { NodeLayout [ ] successors = internalNode . getSuccessingNodes ( ) ; int numberOfHiddenSuccessors = <NUM_LIT:0> ; for ( int i = <NUM_LIT:0> ; i < successors . length ; i ++ ) { if ( successors [ i ] . isPruned ( ) ) { numberOfHiddenSuccessors ++ ; } } String labelText = numberOfHiddenSuccessors > <NUM_LIT:0> ? "<STR_LIT>" + numberOfHiddenSuccessors : "<STR_LIT>" ; if ( ! labelText . equals ( label . getText ( ) ) ) { label . setText ( labelText ) ; } label . setVisible ( true ) ; } refreshLabelBounds ( figure , label ) ; } private IFigure getFisheyeFigure ( IFigure originalFigure ) { GraphLabel label = ( GraphLabel ) nodeFigureToLabel . get ( originalFigure ) ; LabelAncestorListener ancestorListener = ( LabelAncestorListener ) labelToAncestorListener . get ( label ) ; if ( ancestorListener != null ) { return ancestorListener . fisheyeFigure ; } return null ; } private void removeFigureForNode ( InternalNodeLayout internalNode ) { IFigure figure = internalNode . getNode ( ) . getFigure ( ) ; GraphLabel label = ( GraphLabel ) nodeFigureToLabel . get ( figure ) ; if ( label != null && label . getParent ( ) != null ) { label . getParent ( ) . remove ( label ) ; } nodeFigureToLabel . remove ( figure ) ; } } </s>
|
<s> package org . eclipse . zest . core . widgets ; import java . util . HashSet ; import java . util . Iterator ; import org . eclipse . zest . layouts . interfaces . ConnectionLayout ; import org . eclipse . zest . layouts . interfaces . ContextListener ; import org . eclipse . zest . layouts . interfaces . ExpandCollapseManager ; import org . eclipse . zest . layouts . interfaces . GraphStructureListener ; import org . eclipse . zest . layouts . interfaces . LayoutContext ; import org . eclipse . zest . layouts . interfaces . NodeLayout ; public class DAGExpandCollapseManager implements ExpandCollapseManager { private InternalLayoutContext context ; private HashSet expandedNodes = new HashSet ( ) ; private HashSet nodesToPrune = new HashSet ( ) ; private HashSet nodesToUnprune = new HashSet ( ) ; private HashSet nodesToUpdate = new HashSet ( ) ; private boolean cleanLayoutScheduled = false ; public void initExpansion ( final LayoutContext context2 ) { if ( ! ( context2 instanceof InternalLayoutContext ) ) { throw new RuntimeException ( "<STR_LIT>" ) ; } context = ( InternalLayoutContext ) context2 ; context . addGraphStructureListener ( new GraphStructureListener ( ) { public boolean nodeRemoved ( LayoutContext context , NodeLayout node ) { if ( isExpanded ( node ) ) { collapse ( node ) ; } flushChanges ( false , true ) ; return false ; } public boolean nodeAdded ( LayoutContext context , NodeLayout node ) { resetState ( node ) ; flushChanges ( false , true ) ; return false ; } public boolean connectionRemoved ( LayoutContext context , ConnectionLayout connection ) { NodeLayout target = connection . getTarget ( ) ; if ( ! isExpanded ( target ) && target . getIncomingConnections ( ) . length == <NUM_LIT:0> ) { expand ( target ) ; } flushChanges ( false , true ) ; return false ; } public boolean connectionAdded ( LayoutContext context , ConnectionLayout connection ) { resetState ( connection . getTarget ( ) ) ; updateNodeLabel ( connection . getSource ( ) ) ; flushChanges ( false , true ) ; return false ; } } ) ; context . addContextListener ( new ContextListener . Stub ( ) { public void backgroundEnableChanged ( LayoutContext context ) { flushChanges ( false , false ) ; } } ) ; } public boolean canCollapse ( LayoutContext context , NodeLayout node ) { return isExpanded ( node ) && ! node . isPruned ( ) && node . getOutgoingConnections ( ) . length > <NUM_LIT:0> ; } public boolean canExpand ( LayoutContext context , NodeLayout node ) { return ! isExpanded ( node ) && ! node . isPruned ( ) && node . getOutgoingConnections ( ) . length > <NUM_LIT:0> ; } private void collapseAllConnections ( NodeLayout node ) { ConnectionLayout [ ] outgoingConnections = node . getOutgoingConnections ( ) ; for ( int i = <NUM_LIT:0> ; i < outgoingConnections . length ; i ++ ) { outgoingConnections [ i ] . setVisible ( false ) ; } flushChanges ( true , true ) ; } private void expandAllConnections ( NodeLayout node ) { ConnectionLayout [ ] outgoingConnections = node . getOutgoingConnections ( ) ; for ( int i = <NUM_LIT:0> ; i < outgoingConnections . length ; i ++ ) { outgoingConnections [ i ] . setVisible ( true ) ; } flushChanges ( true , true ) ; } public void setExpanded ( LayoutContext context , NodeLayout node , boolean expanded ) { if ( expanded ) { if ( canExpand ( context , node ) ) { expand ( node ) ; } expandAllConnections ( node ) ; } else { if ( canCollapse ( context , node ) ) { collapse ( node ) ; } collapseAllConnections ( node ) ; } flushChanges ( true , true ) ; } private void expand ( NodeLayout node ) { setExpanded ( node , true ) ; NodeLayout [ ] successingNodes = node . getSuccessingNodes ( ) ; for ( int i = <NUM_LIT:0> ; i < successingNodes . length ; i ++ ) { unpruneNode ( successingNodes [ i ] ) ; } updateNodeLabel ( node ) ; } private void collapse ( NodeLayout node ) { if ( isExpanded ( node ) ) { setExpanded ( node , false ) ; } else { return ; } NodeLayout [ ] successors = node . getSuccessingNodes ( ) ; for ( int i = <NUM_LIT:0> ; i < successors . length ; i ++ ) { checkPruning ( successors [ i ] ) ; if ( isPruned ( successors [ i ] ) ) { collapse ( successors [ i ] ) ; } } updateNodeLabel ( node ) ; } private void checkPruning ( NodeLayout node ) { boolean prune = true ; NodeLayout [ ] predecessors = node . getPredecessingNodes ( ) ; for ( int j = <NUM_LIT:0> ; j < predecessors . length ; j ++ ) { if ( isExpanded ( predecessors [ j ] ) ) { prune = false ; break ; } } if ( prune ) { pruneNode ( node ) ; } else { unpruneNode ( node ) ; } } private void resetState ( NodeLayout node ) { NodeLayout [ ] predecessors = node . getPredecessingNodes ( ) ; if ( predecessors . length == <NUM_LIT:0> ) { expand ( node ) ; } else { collapse ( node ) ; checkPruning ( node ) ; } } private void updateNodeLabel ( NodeLayout node ) { nodesToUpdate . add ( node ) ; } private void updateNodeLabel2 ( InternalNodeLayout node ) { SubgraphFactory subgraphFactory = node . getOwnerLayoutContext ( ) . getSubgraphFactory ( ) ; if ( subgraphFactory instanceof DefaultSubgraph . PrunedSuccessorsSubgraphFactory ) { ( ( DefaultSubgraph . PrunedSuccessorsSubgraphFactory ) subgraphFactory ) . updateLabelForNode ( node ) ; } } private void pruneNode ( NodeLayout node ) { if ( isPruned ( node ) ) { return ; } nodesToUnprune . remove ( node ) ; nodesToPrune . add ( node ) ; } private void unpruneNode ( NodeLayout node ) { if ( ! isPruned ( node ) ) { return ; } nodesToPrune . remove ( node ) ; nodesToUnprune . add ( node ) ; } private boolean isPruned ( NodeLayout node ) { if ( nodesToUnprune . contains ( node ) ) { return false ; } if ( nodesToPrune . contains ( node ) ) { return true ; } return node . isPruned ( ) ; } private void flushChanges ( boolean force , boolean clean ) { cleanLayoutScheduled = cleanLayoutScheduled || clean ; if ( ! force && ! context . isBackgroundLayoutEnabled ( ) ) { return ; } for ( Iterator iterator = nodesToUnprune . iterator ( ) ; iterator . hasNext ( ) ; ) { NodeLayout node = ( NodeLayout ) iterator . next ( ) ; node . prune ( null ) ; } nodesToUnprune . clear ( ) ; if ( ! nodesToPrune . isEmpty ( ) ) { context . createSubgraph ( ( NodeLayout [ ] ) nodesToPrune . toArray ( new NodeLayout [ nodesToPrune . size ( ) ] ) ) ; nodesToPrune . clear ( ) ; } for ( Iterator iterator = nodesToUpdate . iterator ( ) ; iterator . hasNext ( ) ; ) { InternalNodeLayout node = ( InternalNodeLayout ) iterator . next ( ) ; updateNodeLabel2 ( node ) ; } nodesToUpdate . clear ( ) ; ( context ) . applyLayout ( cleanLayoutScheduled ) ; cleanLayoutScheduled = false ; context . flushChanges ( true ) ; } private boolean isExpanded ( NodeLayout node ) { return expandedNodes . contains ( node ) ; } private void setExpanded ( NodeLayout node , boolean expanded ) { if ( expanded ) { expandedNodes . add ( node ) ; } else { expandedNodes . remove ( node ) ; } } } </s>
|
<s> package org . eclipse . zest . core . widgets ; import org . eclipse . draw2d . IFigure ; public interface FisheyeListener { public void fisheyeAdded ( Graph graph , IFigure originalFigure , IFigure fisheyeFigure ) ; public void fisheyeRemoved ( Graph graph , IFigure originalFigure , IFigure fisheyeFigure ) ; public void fisheyeReplaced ( Graph graph , IFigure oldFisheyeFigure , IFigure newFisheyeFigure ) ; } </s>
|
<s> package org . eclipse . zest . layouts ; import org . eclipse . zest . layouts . algorithms . TreeLayoutAlgorithm ; public interface LayoutStyles { public final static int NONE = <NUM_LIT:0x00> ; public final static int NO_LAYOUT_NODE_RESIZING = <NUM_LIT> ; public static final int ENFORCE_BOUNDS = <NUM_LIT> ; } </s>
|
<s> package org . eclipse . zest . layouts . interfaces ; import org . eclipse . zest . layouts . LayoutAlgorithm ; public interface PruningListener { public boolean nodesPruned ( LayoutContext context , SubgraphLayout [ ] subgraph ) ; public boolean nodesUnpruned ( LayoutContext context , NodeLayout [ ] nodes ) ; } </s>
|
<s> package org . eclipse . zest . layouts . interfaces ; import org . eclipse . zest . layouts . LayoutAlgorithm ; public interface ContextListener { public class Stub implements ContextListener { public boolean boundsChanged ( LayoutContext context ) { return false ; } public void backgroundEnableChanged ( LayoutContext context ) { } public boolean pruningEnablementChanged ( LayoutContext context ) { return false ; } } public boolean boundsChanged ( LayoutContext context ) ; public boolean pruningEnablementChanged ( LayoutContext context ) ; public void backgroundEnableChanged ( LayoutContext context ) ; } </s>
|
<s> package org . eclipse . zest . layouts . interfaces ; public interface ExpandCollapseManager { public void initExpansion ( LayoutContext context ) ; public void setExpanded ( LayoutContext context , NodeLayout node , boolean expanded ) ; public boolean canExpand ( LayoutContext context , NodeLayout node ) ; public boolean canCollapse ( LayoutContext context , NodeLayout node ) ; } </s>
|
<s> package org . eclipse . zest . layouts . interfaces ; import org . eclipse . zest . layouts . LayoutAlgorithm ; import org . eclipse . zest . layouts . dataStructures . DisplayIndependentRectangle ; public interface LayoutContext { public NodeLayout [ ] getNodes ( ) ; public ConnectionLayout [ ] getConnections ( ) ; public EntityLayout [ ] getEntities ( ) ; public ConnectionLayout [ ] getConnections ( EntityLayout layoutEntity1 , EntityLayout layoutEntity2 ) ; public DisplayIndependentRectangle getBounds ( ) ; public boolean isBoundsExpandable ( ) ; public SubgraphLayout [ ] getSubgraphs ( ) ; public SubgraphLayout createSubgraph ( NodeLayout [ ] nodes ) ; public boolean isPruningEnabled ( ) ; public boolean isBackgroundLayoutEnabled ( ) ; public void setMainLayoutAlgorithm ( LayoutAlgorithm algorithm ) ; public LayoutAlgorithm getMainLayoutAlgorithm ( ) ; public void setExpandCollapseManager ( ExpandCollapseManager expandCollapseManager ) ; public ExpandCollapseManager getExpandCollapseManager ( ) ; public void addLayoutListener ( LayoutListener listener ) ; public void removeLayoutListener ( LayoutListener listener ) ; public void addGraphStructureListener ( GraphStructureListener listener ) ; public void removeGraphStructureListener ( GraphStructureListener listener ) ; public void addContextListener ( ContextListener listener ) ; public void removeContextListener ( ContextListener listener ) ; public void addPruningListener ( PruningListener listener ) ; public void removePruningListener ( PruningListener listener ) ; public void flushChanges ( boolean animationHint ) ; } </s>
|
<s> package org . eclipse . zest . layouts . interfaces ; public interface SubgraphLayout extends EntityLayout { public final int TOP_DOWN = <NUM_LIT:1> ; public final int BOTTOM_UP = <NUM_LIT:2> ; public final int LEFT_RIGHT = <NUM_LIT:3> ; public final int RIGHT_LEFT = <NUM_LIT:4> ; public NodeLayout [ ] getNodes ( ) ; public int countNodes ( ) ; public void addNodes ( NodeLayout [ ] nodes ) ; public void removeNodes ( NodeLayout [ ] nodes ) ; public boolean isGraphEntity ( ) ; public boolean isDirectionDependant ( ) ; public void setDirection ( int direction ) ; } </s>
|
<s> package org . eclipse . zest . layouts . interfaces ; import org . eclipse . swt . widgets . Item ; import org . eclipse . zest . layouts . dataStructures . DisplayIndependentDimension ; import org . eclipse . zest . layouts . dataStructures . DisplayIndependentPoint ; public interface EntityLayout { public DisplayIndependentPoint getLocation ( ) ; public void setLocation ( double x , double y ) ; public DisplayIndependentDimension getSize ( ) ; public void setSize ( double width , double height ) ; public double getPreferredAspectRatio ( ) ; public boolean isResizable ( ) ; public boolean isMovable ( ) ; public EntityLayout [ ] getSuccessingEntities ( ) ; public EntityLayout [ ] getPredecessingEntities ( ) ; public Item [ ] getItems ( ) ; } </s>
|
<s> package org . eclipse . zest . layouts . interfaces ; import org . eclipse . zest . layouts . LayoutAlgorithm ; public interface LayoutListener { public boolean nodeMoved ( LayoutContext context , NodeLayout node ) ; public boolean nodeResized ( LayoutContext context , NodeLayout node ) ; public boolean subgraphMoved ( LayoutContext context , SubgraphLayout subgraph ) ; public boolean subgraphResized ( LayoutContext context , SubgraphLayout subgraph ) ; } </s>
|
<s> package org . eclipse . zest . layouts . interfaces ; public interface ConnectionLayout { public NodeLayout getSource ( ) ; public NodeLayout getTarget ( ) ; public double getWeight ( ) ; public boolean isDirected ( ) ; public void setVisible ( boolean visible ) ; public boolean isVisible ( ) ; } </s>
|
<s> package org . eclipse . zest . layouts . interfaces ; public interface NodeLayout extends EntityLayout { public boolean isPrunable ( ) ; public boolean isPruned ( ) ; public SubgraphLayout getSubgraph ( ) ; public void prune ( SubgraphLayout subgraph ) ; public NodeLayout [ ] getSuccessingNodes ( ) ; public NodeLayout [ ] getPredecessingNodes ( ) ; public ConnectionLayout [ ] getIncomingConnections ( ) ; public ConnectionLayout [ ] getOutgoingConnections ( ) ; public void setMinimized ( boolean minimized ) ; public boolean isMinimized ( ) ; } </s>
|
<s> package org . eclipse . zest . layouts . interfaces ; import org . eclipse . zest . layouts . LayoutAlgorithm ; public interface GraphStructureListener { public class Stub implements GraphStructureListener { public boolean nodeAdded ( LayoutContext context , NodeLayout node ) { return false ; } public boolean nodeRemoved ( LayoutContext context , NodeLayout node ) { return false ; } public boolean connectionAdded ( LayoutContext context , ConnectionLayout connection ) { return false ; } public boolean connectionRemoved ( LayoutContext context , ConnectionLayout connection ) { return false ; } } public boolean nodeAdded ( LayoutContext context , NodeLayout node ) ; public boolean nodeRemoved ( LayoutContext context , NodeLayout node ) ; public boolean connectionAdded ( LayoutContext context , ConnectionLayout connection ) ; public boolean connectionRemoved ( LayoutContext context , ConnectionLayout connection ) ; } </s>
|
<s> package org . eclipse . zest . layouts . algorithms ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . Collections ; import java . util . Comparator ; import java . util . IdentityHashMap ; import java . util . LinkedList ; import java . util . List ; import java . util . Map ; import org . eclipse . draw2d . geometry . Dimension ; import org . eclipse . zest . layouts . LayoutAlgorithm ; import org . eclipse . zest . layouts . dataStructures . DisplayIndependentRectangle ; import org . eclipse . zest . layouts . interfaces . LayoutContext ; import org . eclipse . zest . layouts . interfaces . NodeLayout ; public class SugiyamaLayoutAlgorithm implements LayoutAlgorithm { public final static int HORIZONTAL = <NUM_LIT:1> ; public final static int VERTICAL = <NUM_LIT:2> ; private static final int MAX_LAYERS = <NUM_LIT:10> ; private static final int MAX_SWEEPS = <NUM_LIT> ; private static final int PADDING = - <NUM_LIT:1> ; private class NodeWrapper { int index ; final int layer ; final NodeLayout node ; final List < NodeWrapper > pred = new LinkedList < NodeWrapper > ( ) ; final List < NodeWrapper > succ = new LinkedList < NodeWrapper > ( ) ; NodeWrapper ( NodeLayout n , int l ) { node = n ; layer = l ; } NodeWrapper ( int l ) { this ( null , l ) ; } NodeWrapper ( ) { this ( null , PADDING ) ; } void addPredecessor ( NodeWrapper node ) { pred . add ( node ) ; } void addSuccessor ( NodeWrapper node ) { succ . add ( node ) ; } boolean isDummy ( ) { return ( ( node == null ) && ( layer != PADDING ) ) ; } boolean isPadding ( ) { return ( ( node == null ) && ( layer == PADDING ) ) ; } int getBaryCenter ( List < NodeWrapper > list ) { if ( list . isEmpty ( ) ) return ( this . index ) ; if ( list . size ( ) == <NUM_LIT:1> ) return ( list . get ( <NUM_LIT:0> ) . index ) ; double barycenter = <NUM_LIT:0> ; for ( NodeWrapper node : list ) barycenter += node . index ; return ( ( int ) ( barycenter / list . size ( ) ) ) ; } int getPriorityDown ( ) { if ( isPadding ( ) ) return ( <NUM_LIT:0> ) ; if ( isDummy ( ) ) { if ( succ . get ( <NUM_LIT:0> ) . isDummy ( ) ) return ( Integer . MAX_VALUE ) ; else return ( Integer . MAX_VALUE > > <NUM_LIT:1> ) ; } return ( pred . size ( ) ) ; } int getPriorityUp ( ) { if ( isPadding ( ) ) return ( <NUM_LIT:0> ) ; if ( isDummy ( ) ) { if ( pred . get ( <NUM_LIT:0> ) . isDummy ( ) ) return ( Integer . MAX_VALUE ) ; else return ( Integer . MAX_VALUE > > <NUM_LIT:1> ) ; } return ( succ . size ( ) ) ; } } private final List < ArrayList < NodeWrapper > > layers = new ArrayList < ArrayList < NodeWrapper > > ( MAX_LAYERS ) ; private final Map < NodeLayout , NodeWrapper > map = new IdentityHashMap < NodeLayout , NodeWrapper > ( ) ; private final int direction ; private final Dimension dimension ; private LayoutContext context ; private int last ; public SugiyamaLayoutAlgorithm ( int dir , Dimension dim ) { if ( dir == HORIZONTAL ) direction = HORIZONTAL ; else direction = VERTICAL ; dimension = dim ; } public SugiyamaLayoutAlgorithm ( int dir ) { this ( dir , null ) ; } public SugiyamaLayoutAlgorithm ( ) { this ( VERTICAL , null ) ; } public void setLayoutContext ( LayoutContext context ) { this . context = context ; } public void applyLayout ( boolean clean ) { if ( ! clean ) return ; layers . clear ( ) ; map . clear ( ) ; createLayers ( ) ; padLayers ( ) ; for ( int i = <NUM_LIT:0> ; i < layers . size ( ) ; i ++ ) { reduceCrossings ( ) ; refineLayers ( ) ; } reduceCrossings ( ) ; calculatePositions ( ) ; } private void createLayers ( ) { List < NodeLayout > nodes = new LinkedList < NodeLayout > ( Arrays . asList ( context . getNodes ( ) ) ) ; List < NodeLayout > predecessors = findRoots ( nodes ) ; nodes . removeAll ( predecessors ) ; addLayer ( predecessors ) ; for ( int level = <NUM_LIT:1> ; nodes . isEmpty ( ) == false ; level ++ ) { if ( level > MAX_LAYERS ) throw new RuntimeException ( "<STR_LIT>" + MAX_LAYERS + "<STR_LIT>" ) ; List < NodeLayout > layer = new ArrayList < NodeLayout > ( ) ; for ( NodeLayout item : nodes ) { if ( predecessors . containsAll ( Arrays . asList ( item . getPredecessingNodes ( ) ) ) ) layer . add ( item ) ; } nodes . removeAll ( layer ) ; predecessors . addAll ( layer ) ; addLayer ( layer ) ; } } private void addLayer ( List < NodeLayout > list ) { ArrayList < NodeWrapper > layer = new ArrayList < NodeWrapper > ( list . size ( ) ) ; for ( NodeLayout node : list ) { NodeWrapper nw = new NodeWrapper ( node , layers . size ( ) ) ; map . put ( node , nw ) ; layer . add ( nw ) ; for ( NodeLayout node_predecessor : node . getPredecessingNodes ( ) ) { NodeWrapper nw_predecessor = map . get ( node_predecessor ) ; for ( int level = nw_predecessor . layer + <NUM_LIT:1> ; level < nw . layer ; level ++ ) { NodeWrapper nw_dummy = new NodeWrapper ( level ) ; nw_dummy . addPredecessor ( nw_predecessor ) ; nw_predecessor . addSuccessor ( nw_dummy ) ; nw_predecessor = nw_dummy ; layers . get ( level ) . add ( nw_dummy ) ; } nw . addPredecessor ( nw_predecessor ) ; nw_predecessor . addSuccessor ( nw ) ; } } layers . add ( layer ) ; updateIndex ( layer ) ; } private void reduceCrossings ( ) { for ( int round = <NUM_LIT:0> ; round < MAX_SWEEPS ; round ++ ) { if ( ( round & <NUM_LIT:1> ) == <NUM_LIT:0> ) { for ( int index = <NUM_LIT:1> ; index < layers . size ( ) ; index ++ ) reduceCrossingsDown ( layers . get ( index ) ) ; } else { for ( int index = layers . size ( ) - <NUM_LIT:2> ; index >= <NUM_LIT:0> ; index -- ) reduceCrossingsUp ( layers . get ( index ) ) ; } } } private static void reduceCrossingsDown ( ArrayList < NodeWrapper > layer ) { for ( NodeWrapper node : layer ) node . index = node . getBaryCenter ( node . pred ) ; Collections . sort ( layer , new Comparator < NodeWrapper > ( ) { public int compare ( NodeWrapper node1 , NodeWrapper node2 ) { return ( node1 . index - node2 . index ) ; } } ) ; updateIndex ( layer ) ; } private static void reduceCrossingsUp ( ArrayList < NodeWrapper > layer ) { for ( NodeWrapper node : layer ) node . index = node . getBaryCenter ( node . succ ) ; Collections . sort ( layer , new Comparator < NodeWrapper > ( ) { public int compare ( NodeWrapper node1 , NodeWrapper node2 ) { return ( node1 . index - node2 . index ) ; } } ) ; updateIndex ( layer ) ; } private void padLayers ( ) { last = <NUM_LIT:0> ; for ( List < NodeWrapper > iter : layers ) if ( iter . size ( ) > last ) last = iter . size ( ) ; last -- ; for ( List < NodeWrapper > iter : layers ) { for ( int i = iter . size ( ) ; i <= last ; i ++ ) iter . add ( new NodeWrapper ( ) ) ; updateIndex ( iter ) ; } } private void refineLayers ( ) { for ( int index = <NUM_LIT:1> ; index < layers . size ( ) ; index ++ ) refineLayersDown ( layers . get ( index ) ) ; for ( int index = layers . size ( ) - <NUM_LIT:2> ; index >= <NUM_LIT:0> ; index -- ) refineLayersUp ( layers . get ( index ) ) ; for ( int index = <NUM_LIT:1> ; index < layers . size ( ) ; index ++ ) refineLayersDown ( layers . get ( index ) ) ; } private void refineLayersDown ( List < NodeWrapper > layer ) { List < NodeWrapper > list = new ArrayList < NodeWrapper > ( layer ) ; Collections . sort ( list , new Comparator < NodeWrapper > ( ) { public int compare ( NodeWrapper node1 , NodeWrapper node2 ) { return ( node2 . getPriorityDown ( ) - node1 . getPriorityDown ( ) ) ; } } ) ; for ( NodeWrapper iter : list ) { if ( iter . isPadding ( ) ) break ; int delta = iter . getBaryCenter ( iter . pred ) - iter . index ; for ( int i = <NUM_LIT:0> ; i < delta ; i ++ ) layer . add ( iter . index , layer . remove ( last ) ) ; } updateIndex ( layer ) ; } private void refineLayersUp ( List < NodeWrapper > layer ) { List < NodeWrapper > list = new ArrayList < NodeWrapper > ( layer ) ; Collections . sort ( list , new Comparator < NodeWrapper > ( ) { public int compare ( NodeWrapper node1 , NodeWrapper node2 ) { return ( node2 . getPriorityUp ( ) - node1 . getPriorityUp ( ) ) ; } } ) ; for ( NodeWrapper iter : list ) { if ( iter . isPadding ( ) ) break ; int delta = iter . getBaryCenter ( iter . succ ) - iter . index ; for ( int i = <NUM_LIT:0> ; i < delta ; i ++ ) layer . add ( iter . index , layer . remove ( last ) ) ; } updateIndex ( layer ) ; } private void calculatePositions ( ) { DisplayIndependentRectangle boundary = context . getBounds ( ) ; if ( dimension != null ) boundary = new DisplayIndependentRectangle ( <NUM_LIT:0> , <NUM_LIT:0> , dimension . preciseWidth ( ) , dimension . preciseHeight ( ) ) ; double dx = boundary . width / layers . size ( ) ; double dy = boundary . height / ( last + <NUM_LIT:1> ) ; if ( direction == HORIZONTAL ) for ( NodeLayout node : context . getNodes ( ) ) { NodeWrapper nw = map . get ( node ) ; node . setLocation ( ( nw . layer + <NUM_LIT> ) * dx , ( nw . index + <NUM_LIT> ) * dy ) ; } else for ( NodeLayout node : context . getNodes ( ) ) { NodeWrapper nw = map . get ( node ) ; node . setLocation ( ( nw . index + <NUM_LIT> ) * dx , ( nw . layer + <NUM_LIT> ) * dy ) ; } } private static List < NodeLayout > findRoots ( List < NodeLayout > list ) { List < NodeLayout > roots = new ArrayList < NodeLayout > ( ) ; for ( NodeLayout iter : list ) { if ( iter . getPredecessingNodes ( ) . length == <NUM_LIT:0> ) roots . add ( iter ) ; } return ( roots ) ; } private static void updateIndex ( List < NodeWrapper > list ) { for ( int index = <NUM_LIT:0> ; index < list . size ( ) ; index ++ ) list . get ( index ) . index = index ; } } </s>
|
<s> package org . eclipse . zest . layouts . algorithms ; import org . eclipse . zest . layouts . LayoutAlgorithm ; import org . eclipse . zest . layouts . LayoutStyles ; import org . eclipse . zest . layouts . dataStructures . DisplayIndependentPoint ; import org . eclipse . zest . layouts . dataStructures . DisplayIndependentRectangle ; import org . eclipse . zest . layouts . interfaces . EntityLayout ; import org . eclipse . zest . layouts . interfaces . LayoutContext ; public class RadialLayoutAlgorithm implements LayoutAlgorithm { private static final double MAX_DEGREES = Math . PI * <NUM_LIT:2> ; private double startDegree = <NUM_LIT:0> ; private double endDegree = MAX_DEGREES ; private LayoutContext context ; private boolean resize = false ; private TreeLayoutAlgorithm treeLayout = new TreeLayoutAlgorithm ( ) ; public RadialLayoutAlgorithm ( int style ) { this ( ) ; setResizing ( style != LayoutStyles . NO_LAYOUT_NODE_RESIZING ) ; } public RadialLayoutAlgorithm ( ) { } public void applyLayout ( boolean clean ) { if ( ! clean ) return ; treeLayout . internalApplyLayout ( ) ; EntityLayout [ ] entities = context . getEntities ( ) ; DisplayIndependentRectangle bounds = context . getBounds ( ) ; computeRadialPositions ( entities , bounds ) ; if ( resize ) AlgorithmHelper . maximizeSizes ( entities ) ; int insets = <NUM_LIT:4> ; bounds . x += insets ; bounds . y += insets ; bounds . width -= <NUM_LIT:2> * insets ; bounds . height -= <NUM_LIT:2> * insets ; AlgorithmHelper . fitWithinBounds ( entities , bounds , resize ) ; } private void computeRadialPositions ( EntityLayout [ ] entities , DisplayIndependentRectangle bounds ) { DisplayIndependentRectangle layoutBounds = AlgorithmHelper . getLayoutBounds ( entities , false ) ; layoutBounds . x = bounds . x ; layoutBounds . width = bounds . width ; for ( int i = <NUM_LIT:0> ; i < entities . length ; i ++ ) { DisplayIndependentPoint location = entities [ i ] . getLocation ( ) ; double percenttheta = ( location . x - layoutBounds . x ) / layoutBounds . width ; double distance = ( location . y - layoutBounds . y ) / layoutBounds . height ; double theta = startDegree + Math . abs ( endDegree - startDegree ) * percenttheta ; location . x = distance * Math . cos ( theta ) ; location . y = distance * Math . sin ( theta ) ; entities [ i ] . setLocation ( location . x , location . y ) ; } } public void setLayoutContext ( LayoutContext context ) { this . context = context ; treeLayout . setLayoutContext ( context ) ; } public void setRangeToLayout ( double startDegree , double endDegree ) { this . startDegree = startDegree ; this . endDegree = endDegree ; } public boolean isResizing ( ) { return resize ; } public void setResizing ( boolean resizing ) { resize = resizing ; treeLayout . setResizing ( resize ) ; } } </s>
|
<s> package org . eclipse . zest . layouts . algorithms ; import org . eclipse . zest . layouts . LayoutAlgorithm ; import org . eclipse . zest . layouts . interfaces . LayoutContext ; public class CompositeLayoutAlgorithm implements LayoutAlgorithm { private LayoutAlgorithm [ ] algorithms = null ; public CompositeLayoutAlgorithm ( LayoutAlgorithm [ ] algorithms ) { this . algorithms = algorithms ; } public CompositeLayoutAlgorithm ( int style , LayoutAlgorithm [ ] layoutAlgorithms ) { this ( layoutAlgorithms ) ; } public void applyLayout ( boolean clean ) { for ( int i = <NUM_LIT:0> ; i < algorithms . length ; i ++ ) { algorithms [ i ] . applyLayout ( clean ) ; } } public void setLayoutContext ( LayoutContext context ) { for ( int i = <NUM_LIT:0> ; i < algorithms . length ; i ++ ) { algorithms [ i ] . setLayoutContext ( context ) ; } } } </s>
|
<s> package org . eclipse . zest . layouts . algorithms ; import java . util . HashMap ; import org . eclipse . zest . layouts . LayoutAlgorithm ; import org . eclipse . zest . layouts . LayoutStyles ; import org . eclipse . zest . layouts . dataStructures . DisplayIndependentDimension ; import org . eclipse . zest . layouts . dataStructures . DisplayIndependentPoint ; import org . eclipse . zest . layouts . dataStructures . DisplayIndependentRectangle ; import org . eclipse . zest . layouts . interfaces . ConnectionLayout ; import org . eclipse . zest . layouts . interfaces . EntityLayout ; import org . eclipse . zest . layouts . interfaces . LayoutContext ; import org . eclipse . zest . layouts . interfaces . LayoutListener ; import org . eclipse . zest . layouts . interfaces . NodeLayout ; import org . eclipse . zest . layouts . interfaces . SubgraphLayout ; public class SpringLayoutAlgorithm implements LayoutAlgorithm { public static final int DEFAULT_SPRING_ITERATIONS = <NUM_LIT:1000> ; public static final long MAX_SPRING_TIME = <NUM_LIT> ; public static final boolean DEFAULT_SPRING_RANDOM = true ; public static final double DEFAULT_SPRING_MOVE = <NUM_LIT:1.0f> ; public static final double DEFAULT_SPRING_STRAIN = <NUM_LIT:1.0f> ; public static final double DEFAULT_SPRING_LENGTH = <NUM_LIT> ; public static final double DEFAULT_SPRING_GRAVITATION = <NUM_LIT> ; protected static final double MIN_DISTANCE = <NUM_LIT> ; protected static final double EPSILON = <NUM_LIT> ; private int sprIterations = DEFAULT_SPRING_ITERATIONS ; private long maxTimeMS = MAX_SPRING_TIME ; private boolean sprRandom = DEFAULT_SPRING_RANDOM ; private double sprMove = DEFAULT_SPRING_MOVE ; private double sprStrain = DEFAULT_SPRING_STRAIN ; private double sprLength = DEFAULT_SPRING_LENGTH ; private double sprGravitation = DEFAULT_SPRING_GRAVITATION ; private boolean resize = false ; private int iteration ; private double [ ] [ ] srcDestToSumOfWeights ; private EntityLayout [ ] entities ; private double [ ] forcesX , forcesY ; private double [ ] locationsX , locationsY ; private double [ ] sizeW , sizeH ; private DisplayIndependentRectangle bounds ; private double boundsScaleX = <NUM_LIT> ; private double boundsScaleY = <NUM_LIT> ; public boolean fitWithinBounds = true ; private LayoutContext context ; class SpringLayoutListener implements LayoutListener { public boolean nodeMoved ( LayoutContext context , NodeLayout node ) { for ( int i = <NUM_LIT:0> ; i < entities . length ; i ++ ) { if ( entities [ i ] == node ) { locationsX [ i ] = entities [ i ] . getLocation ( ) . x ; locationsY [ i ] = entities [ i ] . getLocation ( ) . y ; } } return false ; } public boolean nodeResized ( LayoutContext context , NodeLayout node ) { return false ; } public boolean subgraphMoved ( LayoutContext context , SubgraphLayout subgraph ) { return false ; } public boolean subgraphResized ( LayoutContext context , SubgraphLayout subgraph ) { return false ; } } public SpringLayoutAlgorithm ( int style ) { this ( ) ; setResizing ( style != LayoutStyles . NO_LAYOUT_NODE_RESIZING ) ; } public SpringLayoutAlgorithm ( ) { } public void applyLayout ( boolean clean ) { initLayout ( ) ; if ( ! clean ) return ; while ( performAnotherNonContinuousIteration ( ) ) { computeOneIteration ( ) ; } saveLocations ( ) ; if ( resize ) AlgorithmHelper . maximizeSizes ( entities ) ; if ( fitWithinBounds ) { DisplayIndependentRectangle bounds2 = new DisplayIndependentRectangle ( bounds ) ; int insets = <NUM_LIT:4> ; bounds2 . x += insets ; bounds2 . y += insets ; bounds2 . width -= <NUM_LIT:2> * insets ; bounds2 . height -= <NUM_LIT:2> * insets ; AlgorithmHelper . fitWithinBounds ( entities , bounds2 , resize ) ; } } public void setLayoutContext ( LayoutContext context ) { this . context = context ; this . context . addLayoutListener ( new SpringLayoutListener ( ) ) ; initLayout ( ) ; } public void performNIteration ( int n ) { if ( iteration == <NUM_LIT:0> ) { entities = context . getEntities ( ) ; loadLocations ( ) ; initLayout ( ) ; } bounds = context . getBounds ( ) ; for ( int i = <NUM_LIT:0> ; i < n ; i ++ ) { computeOneIteration ( ) ; saveLocations ( ) ; } context . flushChanges ( false ) ; } public void performOneIteration ( ) { if ( iteration == <NUM_LIT:0> ) { entities = context . getEntities ( ) ; loadLocations ( ) ; initLayout ( ) ; } bounds = context . getBounds ( ) ; computeOneIteration ( ) ; saveLocations ( ) ; context . flushChanges ( false ) ; } public boolean isResizing ( ) { return resize ; } public void setResizing ( boolean resizing ) { resize = resizing ; } public void setSpringMove ( double move ) { sprMove = move ; } public double getSpringMove ( ) { return sprMove ; } public void setSpringStrain ( double strain ) { sprStrain = strain ; } public double getSpringStrain ( ) { return sprStrain ; } public void setSpringLength ( double length ) { sprLength = length ; } public long getSpringTimeout ( ) { return maxTimeMS ; } public void setSpringTimeout ( long timeout ) { maxTimeMS = timeout ; } public double getSpringLength ( ) { return sprLength ; } public void setSpringGravitation ( double gravitation ) { sprGravitation = gravitation ; } public double getSpringGravitation ( ) { return sprGravitation ; } public void setIterations ( int iterations ) { sprIterations = iterations ; } public int getIterations ( ) { return sprIterations ; } public void setRandom ( boolean random ) { sprRandom = random ; } public boolean getRandom ( ) { return sprRandom ; } private long startTime = <NUM_LIT:0> ; private int [ ] counter ; private int [ ] counterX ; private int [ ] counterY ; private void initLayout ( ) { entities = context . getEntities ( ) ; bounds = context . getBounds ( ) ; loadLocations ( ) ; srcDestToSumOfWeights = new double [ entities . length ] [ entities . length ] ; HashMap entityToPosition = new HashMap ( ) ; for ( int i = <NUM_LIT:0> ; i < entities . length ; i ++ ) { entityToPosition . put ( entities [ i ] , new Integer ( i ) ) ; } ConnectionLayout [ ] connections = context . getConnections ( ) ; for ( int i = <NUM_LIT:0> ; i < connections . length ; i ++ ) { ConnectionLayout connection = connections [ i ] ; Integer source = ( Integer ) entityToPosition . get ( getEntity ( connection . getSource ( ) ) ) ; Integer target = ( Integer ) entityToPosition . get ( getEntity ( connection . getTarget ( ) ) ) ; if ( source == null || target == null ) continue ; double weight = connection . getWeight ( ) ; weight = ( weight <= <NUM_LIT:0> ? <NUM_LIT> : weight ) ; srcDestToSumOfWeights [ source . intValue ( ) ] [ target . intValue ( ) ] += weight ; srcDestToSumOfWeights [ target . intValue ( ) ] [ source . intValue ( ) ] += weight ; } if ( sprRandom ) placeRandomly ( ) ; iteration = <NUM_LIT:1> ; startTime = System . currentTimeMillis ( ) ; } private EntityLayout getEntity ( NodeLayout node ) { if ( ! node . isPruned ( ) ) return node ; SubgraphLayout subgraph = node . getSubgraph ( ) ; if ( subgraph . isGraphEntity ( ) ) return subgraph ; return null ; } private void loadLocations ( ) { if ( locationsX == null || locationsX . length != entities . length ) { int length = entities . length ; locationsX = new double [ length ] ; locationsY = new double [ length ] ; sizeW = new double [ length ] ; sizeH = new double [ length ] ; forcesX = new double [ length ] ; forcesY = new double [ length ] ; counterX = new int [ length ] ; counterY = new int [ length ] ; } for ( int i = <NUM_LIT:0> ; i < entities . length ; i ++ ) { DisplayIndependentPoint location = entities [ i ] . getLocation ( ) ; locationsX [ i ] = location . x ; locationsY [ i ] = location . y ; DisplayIndependentDimension size = entities [ i ] . getSize ( ) ; sizeW [ i ] = size . width ; sizeH [ i ] = size . height ; } } private void saveLocations ( ) { if ( entities == null ) return ; for ( int i = <NUM_LIT:0> ; i < entities . length ; i ++ ) { entities [ i ] . setLocation ( locationsX [ i ] , locationsY [ i ] ) ; } } private void setSprIterationsBasedOnTime ( ) { if ( maxTimeMS <= <NUM_LIT:0> ) return ; long currentTime = System . currentTimeMillis ( ) ; double fractionComplete = ( double ) ( ( double ) ( currentTime - startTime ) / ( ( double ) maxTimeMS ) ) ; int currentIteration = ( int ) ( fractionComplete * sprIterations ) ; if ( currentIteration > iteration ) { iteration = currentIteration ; } } protected boolean performAnotherNonContinuousIteration ( ) { setSprIterationsBasedOnTime ( ) ; return ( iteration <= sprIterations ) ; } protected int getCurrentLayoutStep ( ) { return iteration ; } protected int getTotalNumberOfLayoutSteps ( ) { return sprIterations ; } protected void computeOneIteration ( ) { computeForces ( ) ; computePositions ( ) ; DisplayIndependentRectangle currentBounds = getLayoutBounds ( ) ; improveBoundScaleX ( currentBounds ) ; improveBoundScaleY ( currentBounds ) ; moveToCenter ( currentBounds ) ; iteration ++ ; } public void placeRandomly ( ) { if ( locationsX . length == <NUM_LIT:0> ) { return ; } if ( locationsX . length == <NUM_LIT:1> ) { locationsX [ <NUM_LIT:0> ] = bounds . x + <NUM_LIT> * bounds . width ; locationsY [ <NUM_LIT:0> ] = bounds . y + <NUM_LIT> * bounds . height ; } else { locationsX [ <NUM_LIT:0> ] = bounds . x ; locationsY [ <NUM_LIT:0> ] = bounds . y ; locationsX [ <NUM_LIT:1> ] = bounds . x + bounds . width ; locationsY [ <NUM_LIT:1> ] = bounds . y + bounds . height ; for ( int i = <NUM_LIT:2> ; i < locationsX . length ; i ++ ) { locationsX [ i ] = bounds . x + Math . random ( ) * bounds . width ; locationsY [ i ] = bounds . y + Math . random ( ) * bounds . height ; } } } protected void computeForces ( ) { double forcesX [ ] [ ] = new double [ <NUM_LIT:2> ] [ this . forcesX . length ] ; double forcesY [ ] [ ] = new double [ <NUM_LIT:2> ] [ this . forcesX . length ] ; double locationsX [ ] = new double [ this . forcesX . length ] ; double locationsY [ ] = new double [ this . forcesX . length ] ; for ( int j = <NUM_LIT:0> ; j < <NUM_LIT:2> ; j ++ ) { for ( int i = <NUM_LIT:0> ; i < this . forcesX . length ; i ++ ) { forcesX [ j ] [ i ] = <NUM_LIT:0> ; forcesY [ j ] [ i ] = <NUM_LIT:0> ; locationsX [ i ] = this . locationsX [ i ] ; locationsY [ i ] = this . locationsY [ i ] ; } } for ( int k = <NUM_LIT:0> ; k < <NUM_LIT:2> ; k ++ ) { for ( int i = <NUM_LIT:0> ; i < this . locationsX . length ; i ++ ) { for ( int j = i + <NUM_LIT:1> ; j < locationsX . length ; j ++ ) { double dx = ( locationsX [ i ] - locationsX [ j ] ) / bounds . width / boundsScaleX ; double dy = ( locationsY [ i ] - locationsY [ j ] ) / bounds . height / boundsScaleY ; double distance_sq = dx * dx + dy * dy ; distance_sq = Math . max ( MIN_DISTANCE * MIN_DISTANCE , distance_sq ) ; double distance = Math . sqrt ( distance_sq ) ; double sumOfWeights = srcDestToSumOfWeights [ i ] [ j ] ; double f ; if ( sumOfWeights > <NUM_LIT:0> ) { f = - sprStrain * Math . log ( distance / sprLength ) * sumOfWeights ; } else { f = sprGravitation / ( distance_sq ) ; } double dfx = f * dx / distance ; double dfy = f * dy / distance ; forcesX [ k ] [ i ] += dfx ; forcesY [ k ] [ i ] += dfy ; forcesX [ k ] [ j ] -= dfx ; forcesY [ k ] [ j ] -= dfy ; } } for ( int i = <NUM_LIT:0> ; i < entities . length ; i ++ ) { if ( entities [ i ] . isMovable ( ) ) { double deltaX = sprMove * forcesX [ k ] [ i ] ; double deltaY = sprMove * forcesY [ k ] [ i ] ; double dist = Math . sqrt ( deltaX * deltaX + deltaY * deltaY ) ; double maxMovement = <NUM_LIT> * sprMove ; if ( dist > maxMovement ) { deltaX *= maxMovement / dist ; deltaY *= maxMovement / dist ; } locationsX [ i ] += deltaX * bounds . width * boundsScaleX ; locationsY [ i ] += deltaY * bounds . height * boundsScaleY ; } } } for ( int i = <NUM_LIT:0> ; i < this . entities . length ; i ++ ) { if ( forcesX [ <NUM_LIT:0> ] [ i ] * forcesX [ <NUM_LIT:1> ] [ i ] < <NUM_LIT:0> ) { this . forcesX [ i ] = <NUM_LIT:0> ; } else { this . forcesX [ i ] = forcesX [ <NUM_LIT:1> ] [ i ] ; } if ( forcesY [ <NUM_LIT:0> ] [ i ] * forcesY [ <NUM_LIT:1> ] [ i ] < <NUM_LIT:0> ) { this . forcesY [ i ] = <NUM_LIT:0> ; } else { this . forcesY [ i ] = forcesY [ <NUM_LIT:1> ] [ i ] ; } } } protected void computePositions ( ) { for ( int i = <NUM_LIT:0> ; i < entities . length ; i ++ ) { if ( entities [ i ] . isMovable ( ) ) { double deltaX = sprMove * forcesX [ i ] ; double deltaY = sprMove * forcesY [ i ] ; double dist = Math . sqrt ( deltaX * deltaX + deltaY * deltaY ) ; double maxMovement = <NUM_LIT> * sprMove ; if ( dist > maxMovement ) { deltaX *= maxMovement / dist ; deltaY *= maxMovement / dist ; } locationsX [ i ] += deltaX * bounds . width * boundsScaleX ; locationsY [ i ] += deltaY * bounds . height * boundsScaleY ; } } } private DisplayIndependentRectangle getLayoutBounds ( ) { double minX , maxX , minY , maxY ; minX = minY = Double . POSITIVE_INFINITY ; maxX = maxY = Double . NEGATIVE_INFINITY ; for ( int i = <NUM_LIT:0> ; i < locationsX . length ; i ++ ) { maxX = Math . max ( maxX , locationsX [ i ] + sizeW [ i ] / <NUM_LIT:2> ) ; minX = Math . min ( minX , locationsX [ i ] - sizeW [ i ] / <NUM_LIT:2> ) ; maxY = Math . max ( maxY , locationsY [ i ] + sizeH [ i ] / <NUM_LIT:2> ) ; minY = Math . min ( minY , locationsY [ i ] - sizeH [ i ] / <NUM_LIT:2> ) ; } return new DisplayIndependentRectangle ( minX , minY , maxX - minX , maxY - minY ) ; } private void improveBoundScaleX ( DisplayIndependentRectangle currentBounds ) { double boundaryProportionX = currentBounds . width / bounds . width ; if ( boundaryProportionX < <NUM_LIT> ) { boundsScaleX *= <NUM_LIT> ; } else if ( boundaryProportionX > <NUM_LIT:1> ) { if ( boundsScaleX < <NUM_LIT> ) return ; boundsScaleX /= <NUM_LIT> ; } } private void improveBoundScaleY ( DisplayIndependentRectangle currentBounds ) { double boundaryProportionY = currentBounds . height / bounds . height ; if ( boundaryProportionY < <NUM_LIT> ) { boundsScaleY *= <NUM_LIT> ; } else if ( boundaryProportionY > <NUM_LIT:1> ) { if ( boundsScaleY < <NUM_LIT> ) return ; boundsScaleY /= <NUM_LIT> ; } } private void moveToCenter ( DisplayIndependentRectangle currentBounds ) { double moveX = ( currentBounds . x + currentBounds . width / <NUM_LIT:2> ) - ( bounds . x + bounds . width / <NUM_LIT:2> ) ; double moveY = ( currentBounds . y + currentBounds . height / <NUM_LIT:2> ) - ( bounds . y + bounds . height / <NUM_LIT:2> ) ; for ( int i = <NUM_LIT:0> ; i < locationsX . length ; i ++ ) { locationsX [ i ] -= moveX ; locationsY [ i ] -= moveY ; } } } </s>
|
<s> package org . eclipse . zest . layouts . algorithms ; import java . util . Iterator ; import org . eclipse . draw2d . geometry . Dimension ; import org . eclipse . zest . layouts . LayoutAlgorithm ; import org . eclipse . zest . layouts . algorithms . TreeLayoutObserver . TreeNode ; import org . eclipse . zest . layouts . dataStructures . DisplayIndependentRectangle ; import org . eclipse . zest . layouts . interfaces . EntityLayout ; import org . eclipse . zest . layouts . interfaces . LayoutContext ; public class TreeLayoutAlgorithm implements LayoutAlgorithm { public final static int TOP_DOWN = <NUM_LIT:1> ; public final static int BOTTOM_UP = <NUM_LIT:2> ; public final static int LEFT_RIGHT = <NUM_LIT:3> ; public final static int RIGHT_LEFT = <NUM_LIT:4> ; private int direction = TOP_DOWN ; private boolean resize = false ; private LayoutContext context ; private DisplayIndependentRectangle bounds ; private double leafSize , layerSize ; private TreeLayoutObserver treeObserver ; private Dimension nodeSpace ; public TreeLayoutAlgorithm ( ) { } public TreeLayoutAlgorithm ( int direction ) { this ( direction , null ) ; } public TreeLayoutAlgorithm ( int direction , Dimension nodeSpace ) { setDirection ( direction ) ; this . nodeSpace = nodeSpace ; } public void setNodeSpace ( Dimension nodeSpace ) { this . nodeSpace = nodeSpace ; } public int getDirection ( ) { return direction ; } public void setDirection ( int direction ) { if ( direction == TOP_DOWN || direction == BOTTOM_UP || direction == LEFT_RIGHT || direction == RIGHT_LEFT ) this . direction = direction ; else throw new IllegalArgumentException ( "<STR_LIT>" + direction ) ; } public boolean isResizing ( ) { return resize ; } public void setResizing ( boolean resizing ) { resize = resizing ; } public void setLayoutContext ( LayoutContext context ) { if ( treeObserver != null ) { treeObserver . stop ( ) ; } this . context = context ; if ( context != null ) { treeObserver = new TreeLayoutObserver ( context , null ) ; } } public void applyLayout ( boolean clean ) { if ( ! clean ) return ; internalApplyLayout ( ) ; EntityLayout [ ] entities = context . getEntities ( ) ; if ( resize ) AlgorithmHelper . maximizeSizes ( entities ) ; scaleEntities ( entities ) ; } private void scaleEntities ( EntityLayout [ ] entities ) { if ( nodeSpace == null ) { DisplayIndependentRectangle bounds2 = new DisplayIndependentRectangle ( bounds ) ; int insets = <NUM_LIT:4> ; bounds2 . x += insets ; bounds2 . y += insets ; bounds2 . width -= <NUM_LIT:2> * insets ; bounds2 . height -= <NUM_LIT:2> * insets ; AlgorithmHelper . fitWithinBounds ( entities , bounds2 , resize ) ; } } void internalApplyLayout ( ) { TreeNode superRoot = treeObserver . getSuperRoot ( ) ; bounds = context . getBounds ( ) ; updateLeafAndLayerSizes ( ) ; int leafCountSoFar = <NUM_LIT:0> ; for ( Iterator iterator = superRoot . getChildren ( ) . iterator ( ) ; iterator . hasNext ( ) ; ) { TreeNode rootInfo = ( TreeNode ) iterator . next ( ) ; computePositionRecursively ( rootInfo , leafCountSoFar ) ; leafCountSoFar = leafCountSoFar + rootInfo . numOfLeaves ; } } private void updateLeafAndLayerSizes ( ) { if ( nodeSpace != null ) { if ( getDirection ( ) == TOP_DOWN || getDirection ( ) == BOTTOM_UP ) { leafSize = nodeSpace . preciseWidth ( ) ; layerSize = nodeSpace . preciseHeight ( ) ; } else { leafSize = nodeSpace . preciseHeight ( ) ; layerSize = nodeSpace . preciseWidth ( ) ; } } else { TreeNode superRoot = treeObserver . getSuperRoot ( ) ; if ( direction == TOP_DOWN || direction == BOTTOM_UP ) { leafSize = bounds . width / superRoot . numOfLeaves ; layerSize = bounds . height / superRoot . height ; } else { leafSize = bounds . height / superRoot . numOfLeaves ; layerSize = bounds . width / superRoot . height ; } } } private void computePositionRecursively ( TreeNode entityInfo , int relativePosition ) { double breadthPosition = relativePosition + entityInfo . numOfLeaves / <NUM_LIT> ; double depthPosition = ( entityInfo . depth + <NUM_LIT> ) ; switch ( direction ) { case TOP_DOWN : entityInfo . getNode ( ) . setLocation ( breadthPosition * leafSize , depthPosition * layerSize ) ; break ; case BOTTOM_UP : entityInfo . getNode ( ) . setLocation ( breadthPosition * leafSize , bounds . height - depthPosition * layerSize ) ; break ; case LEFT_RIGHT : entityInfo . getNode ( ) . setLocation ( depthPosition * layerSize , breadthPosition * leafSize ) ; break ; case RIGHT_LEFT : entityInfo . getNode ( ) . setLocation ( bounds . width - depthPosition * layerSize , breadthPosition * leafSize ) ; break ; } for ( Iterator iterator = entityInfo . children . iterator ( ) ; iterator . hasNext ( ) ; ) { TreeNode childInfo = ( TreeNode ) iterator . next ( ) ; computePositionRecursively ( childInfo , relativePosition ) ; relativePosition += childInfo . numOfLeaves ; } } } </s>
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.