idx
int64
0
41.2k
question
stringlengths
83
4.15k
target
stringlengths
5
715
11,200
public static boolean isModelDefaultValue ( CamelCatalog camelCatalog , String modelName , String key , String value ) { String json = camelCatalog . modelJSonSchema ( modelName ) ; if ( json == null ) { throw new IllegalArgumentException ( "Could not find catalog entry for model name: " + modelName ) ; } List < Map < String , String > > data = JSonSchemaHelper . parseJsonSchema ( "properties" , json , true ) ; if ( data != null ) { for ( Map < String , String > propertyMap : data ) { String name = propertyMap . get ( "name" ) ; String defaultValue = propertyMap . get ( "defaultValue" ) ; if ( key . equals ( name ) ) { return value . equalsIgnoreCase ( defaultValue ) ; } } } return false ; }
Checks whether the given value is matching the default value from the given model .
11,201
public static String getModelJavaType ( CamelCatalog camelCatalog , String modelName ) { String json = camelCatalog . modelJSonSchema ( modelName ) ; if ( json == null ) { throw new IllegalArgumentException ( "Could not find catalog entry for model name: " + modelName ) ; } List < Map < String , String > > data = JSonSchemaHelper . parseJsonSchema ( "model" , json , false ) ; if ( data != null ) { for ( Map < String , String > propertyMap : data ) { String javaType = propertyMap . get ( "javaType" ) ; if ( javaType != null ) { return javaType ; } } } return null ; }
Gets the java type of the given model
11,202
public static boolean isModelSupportOutput ( CamelCatalog camelCatalog , String modelName ) { String json = camelCatalog . modelJSonSchema ( modelName ) ; if ( json == null ) { throw new IllegalArgumentException ( "Could not find catalog entry for model name: " + modelName ) ; } List < Map < String , String > > data = JSonSchemaHelper . parseJsonSchema ( "model" , json , false ) ; if ( data != null ) { for ( Map < String , String > propertyMap : data ) { String output = propertyMap . get ( "output" ) ; if ( output != null ) { return "true" . equals ( output ) ; } } } return false ; }
Whether the EIP supports outputs
11,203
public static boolean isComponentConsumerOnly ( CamelCatalog camelCatalog , String scheme ) { String json = camelCatalog . componentJSonSchema ( scheme ) ; if ( json == null ) { return false ; } List < Map < String , String > > data = JSonSchemaHelper . parseJsonSchema ( "component" , json , false ) ; if ( data != null ) { for ( Map < String , String > propertyMap : data ) { String consumerOnly = propertyMap . get ( "consumerOnly" ) ; if ( consumerOnly != null ) { return true ; } } } return false ; }
Whether the component is consumer only
11,204
public GitContext commitMessage ( String message ) { if ( commitMessage . length ( ) == 0 ) { commitMessage . append ( message + "\n" ) ; } else { commitMessage . append ( "\n- " + message ) ; } return this ; }
Append the commit message .
11,205
public List < Certificate > getCertificates ( ) throws CertificateException , IOException { final String methodName = "getCertificates" ; logger . entry ( this , methodName ) ; final String fileData = getPemFileData ( ) ; final List < ByteBuf > certDataList = new ArrayList < ByteBuf > ( ) ; final Matcher m = CERTIFICATE_PATTERN . matcher ( fileData ) ; int start = 0 ; while ( m . find ( start ) ) { final ByteBuf base64CertData = Unpooled . copiedBuffer ( m . group ( 1 ) , Charset . forName ( "US-ASCII" ) ) ; final ByteBuf certData = Base64 . decode ( base64CertData ) ; base64CertData . release ( ) ; certDataList . add ( certData ) ; start = m . end ( ) ; } if ( certDataList . isEmpty ( ) ) { final CertificateException exception = new CertificateException ( "No certificates found in PEM file: " + pemFile ) ; logger . throwing ( this , methodName , exception ) ; throw exception ; } final CertificateFactory cf = CertificateFactory . getInstance ( "X.509" ) ; final List < Certificate > certificates = new ArrayList < Certificate > ( ) ; try { for ( ByteBuf certData : certDataList ) { certificates . add ( cf . generateCertificate ( new ByteBufInputStream ( certData ) ) ) ; } } finally { for ( ByteBuf certData : certDataList ) certData . release ( ) ; } logger . exit ( this , methodName , certificates ) ; return certificates ; }
Obtains the list of certificates stored in the PEM file .
11,206
private String getPemFileData ( ) throws IOException { final String methodName = "getPemFileData" ; logger . entry ( this , methodName ) ; if ( pemFileData != null ) { logger . exit ( this , methodName , pemFileData ) ; return pemFileData ; } final StringBuilder sb = new StringBuilder ( ) ; final InputStreamReader isr = new InputStreamReader ( new FileInputStream ( pemFile ) , "US-ASCII" ) ; try { int ch ; while ( ( ch = isr . read ( ) ) != - 1 ) { sb . append ( ( char ) ch ) ; } } finally { try { isr . close ( ) ; } catch ( IOException e ) { logger . data ( this , methodName , "Failed to close input stream reader. Reason: " , e ) ; } } pemFileData = sb . toString ( ) ; logger . exit ( this , methodName , pemFileData ) ; return pemFileData ; }
Read the PEM file data caching it locally such that the file is only read on first use .
11,207
public static < T > T newInstance ( Class < T > type ) { try { return type . newInstance ( ) ; } catch ( InstantiationException e ) { throw new RuntimeException ( e ) ; } catch ( IllegalAccessException e ) { throw new RuntimeException ( e ) ; } }
A helper method to create a new instance of a type using the default constructor arguments .
11,208
public static boolean hasMethodWithAnnotation ( Class < ? > type , Class < ? extends Annotation > annotationType , boolean checkMetaAnnotations ) { try { do { Method [ ] methods = type . getDeclaredMethods ( ) ; for ( Method method : methods ) { if ( hasAnnotation ( method , annotationType , checkMetaAnnotations ) ) { return true ; } } type = type . getSuperclass ( ) ; } while ( type != null ) ; } catch ( Throwable e ) { } return false ; }
Returns true if the given type has a method with the given annotation
11,209
public static boolean hasAnnotation ( AnnotatedElement elem , Class < ? extends Annotation > annotationType , boolean checkMetaAnnotations ) { if ( elem . isAnnotationPresent ( annotationType ) ) { return true ; } if ( checkMetaAnnotations ) { for ( Annotation a : elem . getAnnotations ( ) ) { for ( Annotation meta : a . annotationType ( ) . getAnnotations ( ) ) { if ( meta . annotationType ( ) . getName ( ) . equals ( annotationType . getName ( ) ) ) { return true ; } } } } return false ; }
Checks if a Class or Method are annotated with the given annotation
11,210
public void drawNodeWithTransforms ( final Context2D context ) { context . save ( ) ; context . transform ( m_ltog ) ; m_prim . drawWithTransforms ( context , getNodeParentsAlpha ( m_prim . asNode ( ) ) , null ) ; context . restore ( ) ; }
Draws the node during a drag operation . Used internally .
11,211
private final double getNodeParentsAlpha ( Node < ? > node ) { double alpha = 1 ; node = node . getParent ( ) ; while ( null != node ) { alpha = alpha * node . getAttributes ( ) . getAlpha ( ) ; node = node . getParent ( ) ; if ( ( null != node ) && ( node . getNodeType ( ) == NodeType . LAYER ) ) { node = null ; } } return alpha ; }
Returns global alpha value .
11,212
public void dragUpdate ( final INodeXYEvent event ) { m_evtx = event . getX ( ) ; m_evty = event . getY ( ) ; m_dstx = m_evtx - m_begx ; m_dsty = m_evty - m_begy ; final Point2D p2 = new Point2D ( 0 , 0 ) ; m_gtol . transform ( new Point2D ( m_dstx , m_dsty ) , p2 ) ; m_lclp . setX ( p2 . getX ( ) - m_pref . getX ( ) ) ; m_lclp . setY ( p2 . getY ( ) - m_pref . getY ( ) ) ; if ( m_drag != null ) { m_drag . adjust ( m_lclp ) ; } save ( ) ; }
Updates the context for the specified Drag Move event . Used internally .
11,213
protected boolean prepare ( final Context2D context , final Attributes attr , final double alpha ) { final double w = attr . getWidth ( ) ; final double h = attr . getHeight ( ) ; final double r = attr . getCornerRadius ( ) ; if ( ( w > 0 ) && ( h > 0 ) ) { context . beginPath ( ) ; if ( ( r > 0 ) && ( r < ( w / 2 ) ) && ( r < ( h / 2 ) ) ) { context . moveTo ( r , 0 ) ; context . lineTo ( w - r , 0 ) ; context . arc ( w - r , r , r , ( Math . PI * 3 ) / 2 , 0 , false ) ; context . lineTo ( w , h - r ) ; context . arc ( w - r , h - r , r , 0 , Math . PI / 2 , false ) ; context . lineTo ( r , h ) ; context . arc ( r , h - r , r , Math . PI / 2 , Math . PI , false ) ; context . lineTo ( 0 , r ) ; context . arc ( r , r , r , Math . PI , ( Math . PI * 3 ) / 2 , false ) ; } else { context . rect ( 0 , 0 , w , h ) ; } context . closePath ( ) ; return true ; } return false ; }
Draws this rectangle .
11,214
public void marshal ( File file , final List < RouteDefinition > routeDefinitionList ) throws Exception { marshal ( file , new Model2Model ( ) { public XmlModel transform ( XmlModel model ) { copyRoutesToElement ( routeDefinitionList , model . getContextElement ( ) ) ; return model ; } } ) ; }
Loads the given file then updates the route definitions from the given list then stores the file again
11,215
public void marshalToDoc ( XmlModel model ) throws JAXBException { Marshaller marshaller = jaxbContext ( ) . createMarshaller ( ) ; marshaller . setProperty ( Marshaller . JAXB_FORMATTED_OUTPUT , java . lang . Boolean . TRUE ) ; try { marshaller . setProperty ( "com.sun.xml.bind.indentString" , " " ) ; } catch ( Exception e ) { LOG . debug ( "Property not supported: {}" , e ) ; } Object value = model . marshalRootElement ( ) ; Document doc = model . getDoc ( ) ; Element docElem = doc . getRootElement ( ) ; StringWriter buffer = new StringWriter ( ) ; marshaller . marshal ( value , buffer ) ; String xml = buffer . toString ( ) ; if ( ! model . getNs ( ) . equals ( springNS ) ) { xml = xml . replaceAll ( springNS , model . getNs ( ) ) ; } Document camelDoc = parse ( new XMLStringSource ( xml ) ) ; Node camelElem = camelDoc . getRootElement ( ) ; if ( model . isRoutesContext ( ) && camelDoc . getRootElement ( ) . getName ( ) . equals ( "camelContext" ) ) { camelDoc . getRootElement ( ) . setName ( "routeContext" ) ; } if ( model . isJustRoutes ( ) ) { replaceChild ( doc , camelElem , docElem ) ; } else { if ( model . getNode ( ) != null ) { replaceCamelElement ( docElem , camelElem , model . getNode ( ) ) ; } else { docElem . addNode ( camelElem ) ; } } }
Marshals the model to XML and updates the model s doc property to contain the new marshalled model
11,216
public static boolean isSpecialColorName ( final String colorName ) { for ( final String name : SPECIAL_COLOR_NAMES ) { if ( name . equalsIgnoreCase ( colorName ) ) { return true ; } } return false ; }
The test is case - sensitive . It assumes the value was already converted to lower - case .
11,217
public C setLocation ( final Point2D p ) { setX ( p . getX ( ) ) ; setY ( p . getY ( ) ) ; return cast ( ) ; }
Sets the X and Y attributes to P . x and P . y
11,218
public C setScale ( final double x , final double y ) { getAttributes ( ) . setScale ( x , y ) ; return cast ( ) ; }
Sets this gruop s scale starting at the given x and y
11,219
public C setShear ( final double x , final double y ) { getAttributes ( ) . setShear ( x , y ) ; return cast ( ) ; }
Sets this group s shear
11,220
public C setOffset ( final double x , final double y ) { getAttributes ( ) . setOffset ( x , y ) ; return cast ( ) ; }
Sets this group s offset at the given x and y coordinates .
11,221
public void attachToLayerColorMap ( ) { final Layer layer = getLayer ( ) ; if ( null != layer ) { final NFastArrayList < T > list = getChildNodes ( ) ; if ( null != list ) { final int size = list . size ( ) ; for ( int i = 0 ; i < size ; i ++ ) { list . get ( i ) . attachToLayerColorMap ( ) ; } } } }
Attaches all primitives to the Layers Color Map
11,222
private Node insertEndpointBefore ( Node camel ) { Node endpoint = null ; for ( int i = 0 ; i < camel . getChildNodes ( ) . getLength ( ) ; i ++ ) { Node found = camel . getChildNodes ( ) . item ( i ) ; String name = found . getNodeName ( ) ; if ( "endpoint" . equals ( name ) ) { endpoint = found ; } } if ( endpoint != null ) { return endpoint ; } Node last = null ; for ( int i = 0 ; i < camel . getChildNodes ( ) . getLength ( ) ; i ++ ) { Node found = camel . getChildNodes ( ) . item ( i ) ; String name = found . getNodeName ( ) ; if ( "dataFormats" . equals ( name ) || "redeliveryPolicyProfile" . equals ( name ) || "onException" . equals ( name ) || "onCompletion" . equals ( name ) || "intercept" . equals ( name ) || "interceptFrom" . equals ( name ) || "interceptSendToEndpoint" . equals ( name ) || "restConfiguration" . equals ( name ) || "rest" . equals ( name ) || "route" . equals ( name ) ) { return found ; } if ( found . getNodeType ( ) == Node . ELEMENT_NODE ) { last = found ; } } return last ; }
To find the closet node that we need to insert the endpoints before so the Camel schema is valid .
11,223
public static InputStream documentToPrettyInputStream ( Node document ) throws Exception { ByteArrayOutputStream outputStream = new ByteArrayOutputStream ( ) ; Source xmlSource = new DOMSource ( document ) ; Result outputTarget = new StreamResult ( outputStream ) ; Transformer transformer = TransformerFactory . newInstance ( ) . newTransformer ( ) ; transformer . setOutputProperty ( OutputKeys . INDENT , "yes" ) ; transformer . setOutputProperty ( OutputKeys . METHOD , "xml" ) ; transformer . transform ( xmlSource , outputTarget ) ; InputStream is = new ByteArrayInputStream ( outputStream . toByteArray ( ) ) ; return is ; }
To output a DOM as a stream .
11,224
public static String nodeToString ( Node document ) throws Exception { ByteArrayOutputStream outputStream = new ByteArrayOutputStream ( ) ; Source xmlSource = new DOMSource ( document ) ; Result outputTarget = new StreamResult ( outputStream ) ; Transformer transformer = TransformerFactory . newInstance ( ) . newTransformer ( ) ; transformer . transform ( xmlSource , outputTarget ) ; return outputStream . toString ( ) ; }
To output a Node as a String .
11,225
protected boolean prepare ( final Context2D context , final Attributes attr , final double alpha ) { final Point2DArray list = attr . getPoints ( ) ; if ( ( null != list ) && ( list . size ( ) == 2 ) ) { if ( attr . isDefined ( Attribute . DASH_ARRAY ) ) { if ( false == LienzoCore . get ( ) . isNativeLineDashSupported ( ) ) { final DashArray dash = attr . getDashArray ( ) ; if ( dash != null ) { final double [ ] data = dash . getNormalizedArray ( ) ; if ( data . length > 0 ) { if ( setStrokeParams ( context , attr , alpha , false ) ) { final Point2D p0 = list . get ( 0 ) ; final Point2D p1 = list . get ( 1 ) ; context . beginPath ( ) ; drawDashedLine ( context , p0 . getX ( ) , p0 . getY ( ) , p1 . getX ( ) , p1 . getY ( ) , data , attr . getStrokeWidth ( ) / 2 ) ; context . restore ( ) ; } return true ; } } } } context . beginPath ( ) ; final Point2D p0 = list . get ( 0 ) ; context . moveTo ( p0 . getX ( ) , p0 . getY ( ) ) ; final Point2D p1 = list . get ( 1 ) ; context . lineTo ( p1 . getX ( ) , p1 . getY ( ) ) ; return true ; } return false ; }
Draws this line
11,226
protected void drawDashedLine ( final Context2D context , double x , double y , final double x2 , final double y2 , final double [ ] da , final double plus ) { final int dashCount = da . length ; final double dx = ( x2 - x ) ; final double dy = ( y2 - y ) ; final boolean xbig = ( Math . abs ( dx ) > Math . abs ( dy ) ) ; final double slope = ( xbig ) ? dy / dx : dx / dy ; context . moveTo ( x , y ) ; double distRemaining = Math . sqrt ( ( dx * dx ) + ( dy * dy ) ) + plus ; int dashIndex = 0 ; while ( distRemaining >= 0.1 ) { final double dashLength = Math . min ( distRemaining , da [ dashIndex % dashCount ] ) ; double step = Math . sqrt ( ( dashLength * dashLength ) / ( 1 + ( slope * slope ) ) ) ; if ( xbig ) { if ( dx < 0 ) { step = - step ; } x += step ; y += slope * step ; } else { if ( dy < 0 ) { step = - step ; } x += slope * step ; y += step ; } if ( ( dashIndex % 2 ) == 0 ) { context . lineTo ( x , y ) ; } else { context . moveTo ( x , y ) ; } distRemaining -= dashLength ; dashIndex ++ ; } }
Draws a dashed line instead of a solid one for the shape .
11,227
public static Object convertValueToSafeJson ( Converter converter , Object value ) { value = Proxies . unwrap ( value ) ; if ( isJsonObject ( value ) ) { return value ; } if ( converter != null ) { try { Object converted = converter . convert ( value ) ; if ( converted != null ) { value = converted ; } } catch ( Exception e ) { } } if ( value != null ) { return toSafeJsonValue ( value ) ; } else { return null ; } }
Uses the given converter to convert to a nicer UI value and return the JSON safe version
11,228
protected static Object toSafeJsonValue ( Object value ) { if ( value == null ) { return null ; } else { if ( value instanceof Boolean || value instanceof String || value instanceof Number ) { return value ; } if ( value instanceof Iterable ) { Iterable iterable = ( Iterable ) value ; List answer = new ArrayList < > ( ) ; for ( Object item : iterable ) { Object itemJson = toSafeJsonValue ( item ) ; if ( itemJson != null ) { answer . add ( itemJson ) ; } } return answer ; } if ( value instanceof ProjectProvider ) { ProjectProvider projectProvider = ( ProjectProvider ) value ; return projectProvider . getType ( ) ; } if ( value instanceof ProjectType ) { ProjectType projectType = ( ProjectType ) value ; return projectType . getType ( ) ; } if ( value instanceof StackFacet ) { StackFacet stackFacet = ( StackFacet ) value ; Stack stack = stackFacet . getStack ( ) ; if ( stack != null ) { return stack . getName ( ) ; } else { return null ; } } value = Proxies . unwrap ( value ) ; if ( value instanceof ProjectProvider ) { ProjectProvider projectProvider = ( ProjectProvider ) value ; return projectProvider . getType ( ) ; } if ( value instanceof ProjectType ) { ProjectType projectType = ( ProjectType ) value ; return projectType . getType ( ) ; } if ( value instanceof StackFacet ) { StackFacet stackFacet = ( StackFacet ) value ; Stack stack = stackFacet . getStack ( ) ; if ( stack != null ) { return stack . getName ( ) ; } else { return null ; } } if ( isJsonObject ( value ) ) { return value ; } return value . toString ( ) ; } }
Lets return a safe JSON value
11,229
public static String generateJavaCore ( ) throws Throwable { final String filePath ; if ( javaDumpMethod != null ) { filePath = takeJavaCore ( ) ; } else { filePath = simulateJavaCore ( ) ; } return filePath ; }
Public method that allows the caller to ask that a javacore be generated .
11,230
private static String takeJavaCore ( ) throws Throwable { logger . entry ( "takeJavaCore" ) ; String filePath ; try { javaDumpMethod . invoke ( null ) ; File javacoreFile = getLatestJavacoreFile ( ) ; filePath = javacoreFile . getAbsolutePath ( ) ; } catch ( final InvocationTargetException invocationException ) { throw ( invocationException . getTargetException ( ) == null ) ? invocationException : invocationException . getTargetException ( ) ; } logger . exit ( "takeJavaCore" , ( Object ) filePath ) ; return filePath ; }
Causes an JVM with the IBM com . ibm . jvm . Dump class present to take a java core .
11,231
public static final double distance ( final Point2D a , final Point2D b ) { return Point2DJSO . distance ( a . getJSO ( ) , b . getJSO ( ) ) ; }
Returns the distance from point A to point B .
11,232
public static final boolean collinear ( final Point2D p1 , final Point2D p2 , final Point2D p3 ) { return Geometry . collinear ( p1 , p2 , p3 ) ; }
Returns whether the 3 points are colinear i . e . whether they lie on a single straight line .
11,233
public static final Point2D polar ( final double radius , final double angle ) { return new Point2D ( radius * Math . cos ( angle ) , radius * Math . sin ( angle ) ) ; }
Construct a Point2D from polar coordinates i . e . a radius and an angle .
11,234
public static String dumpModelAsXml ( Object definition , ClassLoader classLoader , boolean includeEndTag , int indent ) throws JAXBException , XMLStreamException { JAXBContext jaxbContext = JAXBContext . newInstance ( JAXB_CONTEXT_PACKAGES , classLoader ) ; StringWriter buffer = new StringWriter ( ) ; XMLStreamWriter delegate = XMLOutputFactory . newInstance ( ) . createXMLStreamWriter ( buffer ) ; JaxbNoNamespaceWriter writer = new JaxbNoNamespaceWriter ( delegate , indent ) ; writer . setSkipAttributes ( "customId" ) ; Marshaller marshaller = jaxbContext . createMarshaller ( ) ; marshaller . setProperty ( Marshaller . JAXB_SCHEMA_LOCATION , "" ) ; marshaller . setProperty ( Marshaller . JAXB_FRAGMENT , Boolean . TRUE ) ; marshaller . setProperty ( Marshaller . JAXB_FORMATTED_OUTPUT , Boolean . TRUE ) ; marshaller . marshal ( definition , writer ) ; String answer = buffer . toString ( ) ; answer = collapseNode ( answer , "method" ) ; answer = collapseNode ( answer , "tokenize" ) ; answer = collapseNode ( answer , "xtokenize" ) ; if ( writer . getElements ( ) == 1 ) { String token = "></" + writer . getRootElementName ( ) + ">" ; answer = answer . replaceFirst ( token , "/>" ) ; } if ( ! includeEndTag ) { int pos = answer . indexOf ( "</" + writer . getRootElementName ( ) + ">" ) ; if ( pos != - 1 ) { answer = answer . substring ( 0 , pos ) ; } answer = answer . trim ( ) ; } return answer ; }
Dumps the definition as XML
11,235
private static String collapseNode ( String xml , String name ) { String answer = xml ; Pattern pattern = Pattern . compile ( "<" + name + "(.*)></" + name + ">" ) ; Matcher matcher = pattern . matcher ( answer ) ; if ( matcher . find ( ) ) { answer = matcher . replaceAll ( "<" + name + "$1/>" ) ; } return answer ; }
Collapses all the named node in the XML
11,236
public static Object xmlAsModel ( Node node , ClassLoader classLoader ) throws JAXBException { JAXBContext jaxbContext = JAXBContext . newInstance ( JAXB_CONTEXT_PACKAGES , classLoader ) ; Unmarshaller marshaller = jaxbContext . createUnmarshaller ( ) ; Object answer = marshaller . unmarshal ( node ) ; return answer ; }
Turns the xml into EIP model classes
11,237
public static void addPrivateKey ( KeyStore keyStore , File pemKeyFile , char [ ] passwordChars , List < Certificate > certChain ) throws IOException , GeneralSecurityException { final String methodName = "addPrivateKey" ; logger . entry ( methodName , pemKeyFile , certChain ) ; PrivateKey privateKey = createPrivateKey ( pemKeyFile , passwordChars ) ; keyStore . setKeyEntry ( "key" , privateKey , passwordChars , certChain . toArray ( new Certificate [ certChain . size ( ) ] ) ) ; logger . exit ( methodName ) ; }
Adds a private key to the specified key store from the passed private key file and certificate chain .
11,238
public final void fireEvent ( final GwtEvent < ? > event ) { final NFastArrayList < Layer > layers = getChildNodes ( ) ; if ( null != layers ) { final int size = layers . size ( ) ; for ( int i = size - 1 ; i >= 0 ; i -- ) { final Layer layer = layers . get ( i ) ; if ( null != layer ) { layer . fireEvent ( event ) ; } } } }
Fires the given GWT event .
11,239
public final Scene moveDown ( final Layer layer ) { if ( ( null != layer ) && ( LienzoCore . IS_CANVAS_SUPPORTED ) ) { final int size = getElement ( ) . getChildCount ( ) ; if ( size < 2 ) { return this ; } final DivElement element = layer . getElement ( ) ; for ( int i = 0 ; i < size ; i ++ ) { final DivElement look = getElement ( ) . getChild ( i ) . cast ( ) ; if ( look == element ) { if ( i == 0 ) { break ; } getElement ( ) . insertBefore ( element , getElement ( ) . getChild ( i - 1 ) ) ; break ; } } final NFastArrayList < Layer > layers = getChildNodes ( ) ; if ( null != layers ) { layers . moveDown ( layer ) ; } } return this ; }
Moves the layer one level down in this scene .
11,240
public final Scene moveUp ( final Layer layer ) { if ( ( null != layer ) && ( LienzoCore . IS_CANVAS_SUPPORTED ) ) { final int size = getElement ( ) . getChildCount ( ) ; if ( size < 2 ) { return this ; } final DivElement element = layer . getElement ( ) ; for ( int i = 0 ; i < size ; i ++ ) { final DivElement look = getElement ( ) . getChild ( i ) . cast ( ) ; if ( look == element ) { if ( ( i + 1 ) == size ) { break ; } getElement ( ) . removeChild ( element ) ; getElement ( ) . insertAfter ( element , getElement ( ) . getChild ( i + 1 ) ) ; break ; } } final NFastArrayList < Layer > layers = getChildNodes ( ) ; if ( null != layers ) { layers . moveUp ( layer ) ; } } return this ; }
Moves the layer one level up in this scene .
11,241
public final Scene moveToTop ( final Layer layer ) { if ( ( null != layer ) && ( LienzoCore . IS_CANVAS_SUPPORTED ) ) { final int size = getElement ( ) . getChildCount ( ) ; if ( size < 2 ) { return this ; } final DivElement element = layer . getElement ( ) ; getElement ( ) . removeChild ( element ) ; getElement ( ) . appendChild ( element ) ; final NFastArrayList < Layer > layers = getChildNodes ( ) ; if ( null != layers ) { layers . moveToTop ( layer ) ; } } return this ; }
Moves the layer to the top of the layers stack in this scene .
11,242
public WiresMagnet [ ] getMagnetsOnAutoConnection ( final WiresShape headS , final WiresShape tailS ) { final WiresConnection headC = getHeadConnection ( ) ; final WiresConnection tailC = getTailConnection ( ) ; if ( ! ( headC . isAutoConnection ( ) || tailC . isAutoConnection ( ) ) ) { return null ; } WiresMagnet [ ] magnets ; final BoundingBox headBox = ( headS != null ) ? headS . getGroup ( ) . getComputedBoundingPoints ( ) . getBoundingBox ( ) : null ; final BoundingBox tailBox = ( tailS != null ) ? tailS . getGroup ( ) . getComputedBoundingPoints ( ) . getBoundingBox ( ) : null ; if ( getLine ( ) . getPoint2DArray ( ) . size ( ) > 2 ) { magnets = getMagnetsWithMidPoint ( headC , tailC , headS , tailS , headBox , tailBox ) ; } else { if ( ( headBox != null ) && ( tailBox != null ) && ! headBox . intersects ( tailBox ) ) { magnets = getMagnetsNonOverlappedShapes ( headS , tailS , headBox , tailBox ) ; } else { magnets = getMagnetsOverlappedShapesOrNoShape ( headC , tailC , headS , tailS , headBox , tailBox ) ; } } return magnets ; }
This is making some assumptions that will have to be fixed for anythign other than 8 Magnets at compass ordinal points . If there is no shape overlap and one box is in the corner of the other box then use nearest corner connections else use nearest mid connection . Else there is overlap . This is now much more difficult so just pick which every has the the shortest distanceto connections not contained by the other shape .
11,243
public static < T > T first ( Iterable < T > objects ) { if ( objects != null ) { for ( T object : objects ) { return object ; } } return null ; }
Returns the first item in the given collection
11,244
public static < T > T last ( Iterable < T > objects ) { T answer = null ; if ( objects != null ) { for ( T object : objects ) { answer = object ; } } return answer ; }
Returns the last item in the given collection
11,245
public static Matrix identity ( final int N ) { final Matrix I = new Matrix ( N , N ) ; for ( int i = 0 ; i < N ; i ++ ) { I . m_data [ i ] [ i ] = 1 ; } return I ; }
Creates and returns the N - by - N identity matrix
11,246
private void swap ( final int i , final int j ) { final double [ ] temp = m_data [ i ] ; m_data [ i ] = m_data [ j ] ; m_data [ j ] = temp ; }
Swaps rows i and j
11,247
public Matrix transpose ( ) { final Matrix A = new Matrix ( m_columns , m_rows ) ; for ( int i = 0 ; i < m_rows ; i ++ ) { for ( int j = 0 ; j < m_columns ; j ++ ) { A . m_data [ j ] [ i ] = this . m_data [ i ] [ j ] ; } } return A ; }
Creates and returns the transpose of the matrix
11,248
public Matrix plus ( final Matrix B ) { final Matrix A = this ; if ( ( B . m_rows != A . m_rows ) || ( B . m_columns != A . m_columns ) ) { throw new GeometryException ( "Illegal matrix dimensions" ) ; } final Matrix C = new Matrix ( m_rows , m_columns ) ; for ( int i = 0 ; i < m_rows ; i ++ ) { for ( int j = 0 ; j < m_columns ; j ++ ) { C . m_data [ i ] [ j ] = A . m_data [ i ] [ j ] + B . m_data [ i ] [ j ] ; } } return C ; }
Returns C = A + B
11,249
public boolean eq ( final Matrix B ) { final Matrix A = this ; if ( ( B . m_rows != A . m_rows ) || ( B . m_columns != A . m_columns ) ) { return false ; } for ( int i = 0 ; i < m_rows ; i ++ ) { for ( int j = 0 ; j < m_columns ; j ++ ) { if ( A . m_data [ i ] [ j ] != B . m_data [ i ] [ j ] ) { return false ; } } } return true ; }
Returns whether the matrix is the same as this matrix .
11,250
public Matrix solve ( final Matrix rhs ) { if ( ( m_rows != m_columns ) || ( rhs . m_rows != m_columns ) || ( rhs . m_columns != 1 ) ) { throw new GeometryException ( "Illegal matrix dimensions" ) ; } final Matrix A = new Matrix ( this ) ; final Matrix b = new Matrix ( rhs ) ; for ( int i = 0 ; i < m_columns ; i ++ ) { int max = i ; for ( int j = i + 1 ; j < m_columns ; j ++ ) { if ( Math . abs ( A . m_data [ j ] [ i ] ) > Math . abs ( A . m_data [ max ] [ i ] ) ) { max = j ; } } A . swap ( i , max ) ; b . swap ( i , max ) ; if ( A . m_data [ i ] [ i ] == 0.0 ) { throw new RuntimeException ( "Matrix is singular." ) ; } for ( int j = i + 1 ; j < m_columns ; j ++ ) { b . m_data [ j ] [ 0 ] -= ( b . m_data [ i ] [ 0 ] * A . m_data [ j ] [ i ] ) / A . m_data [ i ] [ i ] ; } for ( int j = i + 1 ; j < m_columns ; j ++ ) { final double m = A . m_data [ j ] [ i ] / A . m_data [ i ] [ i ] ; for ( int k = i + 1 ; k < m_columns ; k ++ ) { A . m_data [ j ] [ k ] -= A . m_data [ i ] [ k ] * m ; } A . m_data [ j ] [ i ] = 0.0 ; } } final Matrix x = new Matrix ( m_columns , 1 ) ; for ( int j = m_columns - 1 ; j >= 0 ; j -- ) { double t = 0.0 ; for ( int k = j + 1 ; k < m_columns ; k ++ ) { t += A . m_data [ j ] [ k ] * x . m_data [ k ] [ 0 ] ; } x . m_data [ j ] [ 0 ] = ( b . m_data [ j ] [ 0 ] - t ) / A . m_data [ j ] [ j ] ; } return x ; }
Returns x = A^ - 1 b assuming A is square and has full rank
11,251
public static ArchetypeCatalog getArchetypeCatalog ( Artifact artifact ) throws Exception { File file = artifact . getFile ( ) ; if ( file != null ) { URL url = new URL ( "file" , ( String ) null , file . getAbsolutePath ( ) ) ; URLClassLoader loader = new URLClassLoader ( new URL [ ] { url } ) ; InputStream is = loader . getResourceAsStream ( "archetype-catalog.xml" ) ; if ( is != null ) { return ( new ArchetypeCatalogXpp3Reader ( ) ) . read ( is ) ; } } return null ; }
Gets the archetype - catalog from the given maven artifact
11,252
public static boolean isGE ( String base , String other ) { ComparableVersion v1 = new ComparableVersion ( base ) ; ComparableVersion v2 = new ComparableVersion ( other ) ; return v2 . compareTo ( v1 ) >= 0 ; }
Checks whether other > = base
11,253
@ SuppressWarnings ( "unchecked" ) private final Shape < ? > doCheckEnterExitShape ( final INodeXYEvent event ) { final int x = event . getX ( ) ; final int y = event . getY ( ) ; final Shape < ? > shape = findShapeAtPoint ( x , y ) ; if ( shape != null ) { final IPrimitive < ? > prim = shape . asPrimitive ( ) ; if ( null != m_over_prim ) { if ( prim != m_over_prim ) { if ( m_over_prim . isEventHandled ( NodeMouseExitEvent . getType ( ) ) ) { if ( event instanceof AbstractNodeHumanInputEvent ) { m_over_prim . fireEvent ( new NodeMouseExitEvent ( ( ( AbstractNodeHumanInputEvent < MouseEvent < ? > , ? > ) event ) . getHumanInputEvent ( ) , x , y ) ) ; } else { m_over_prim . fireEvent ( new NodeMouseExitEvent ( null , x , y ) ) ; } } } } if ( prim != m_over_prim ) { if ( ( null != prim ) && ( prim . isEventHandled ( NodeMouseEnterEvent . getType ( ) ) ) ) { if ( event instanceof AbstractNodeHumanInputEvent ) { prim . fireEvent ( new NodeMouseEnterEvent ( ( ( AbstractNodeHumanInputEvent < MouseEvent < ? > , ? > ) event ) . getHumanInputEvent ( ) , x , y ) ) ; } else { prim . fireEvent ( new NodeMouseEnterEvent ( null , x , y ) ) ; } } m_over_prim = prim ; } } else { doCancelEnterExitShape ( event ) ; } return shape ; }
This will also return the shape under the cursor for some optimization on Mouse Move
11,254
public void updateUserRepositories ( List < RepositoryDTO > repositoryDTOs ) { for ( RepositoryDTO repositoryDTO : repositoryDTOs ) { String fullName = repositoryDTO . getFullName ( ) ; userCache . put ( fullName , repositoryDTO ) ; } }
Updates the cache of all user repositories
11,255
public RepositoryDTO getOrFindUserRepository ( String user , String repositoryName , GitRepoClient repoClient ) { RepositoryDTO repository = getUserRepository ( user , repositoryName ) ; if ( repository == null ) { List < RepositoryDTO > repositoryDTOs = repoClient . listRepositories ( ) ; updateUserRepositories ( repositoryDTOs ) ; repository = getUserRepository ( user , repositoryName ) ; } return repository ; }
Attempts to use the cache or performs a query for all the users repositories if its not present
11,256
public Triangle setPoints ( final Point2D a , final Point2D b , final Point2D c ) { return setPoint2DArray ( new Point2DArray ( a , b , c ) ) ; }
Sets this triangles points .
11,257
protected boolean prepare ( final Context2D context , final Attributes attr , final double alpha ) { final Point2DArray list = getPolygon ( ) ; if ( ( null != list ) && ( list . size ( ) > 2 ) ) { Point2D point = list . get ( 0 ) ; context . beginPath ( ) ; context . moveTo ( point . getX ( ) , point . getY ( ) ) ; final int leng = list . size ( ) ; for ( int i = 1 ; i < leng ; i ++ ) { point = list . get ( i ) ; context . lineTo ( point . getX ( ) , point . getY ( ) ) ; } context . closePath ( ) ; return true ; } return false ; }
Draws this arrow .
11,258
public Movie setVolume ( final double volume ) { getAttributes ( ) . setVolume ( volume ) ; if ( null != m_video ) { m_video . setVolume ( getVolume ( ) ) ; } return this ; }
Sets the movie s volume
11,259
public Movie pause ( ) { if ( ( null != m_video ) && ( false == isPaused ( ) ) ) { m_pause = true ; m_video . pause ( ) ; } return this ; }
Pauses this movie .
11,260
public Movie setLoop ( final boolean loop ) { getAttributes ( ) . setLoop ( loop ) ; if ( null != m_video ) { m_video . setLoop ( loop ) ; } return this ; }
Sets the movie to continuously loop or not .
11,261
public int getWidth ( ) { if ( getAttributes ( ) . isDefined ( Attribute . WIDTH ) ) { final int wide = ( int ) ( getAttributes ( ) . getWidth ( ) + 0.5 ) ; if ( wide > 0 ) { return wide ; } } if ( null != m_video ) { return m_video . getVideoWidth ( ) ; } return 0 ; }
Gets the width of this movie s display area
11,262
public int getHeight ( ) { if ( getAttributes ( ) . isDefined ( Attribute . HEIGHT ) ) { final int high = ( int ) ( getAttributes ( ) . getHeight ( ) + 0.5 ) ; if ( high > 0 ) { return high ; } } if ( null != m_video ) { return m_video . getVideoHeight ( ) ; } return 0 ; }
Gets the height of this movie s display area
11,263
public Magnets createMagnets ( final WiresShape wiresShape , final Direction [ ] requestedCardinals ) { final IPrimitive < ? > primTarget = wiresShape . getGroup ( ) ; final Point2DArray points = getWiresIntersectionPoints ( wiresShape , requestedCardinals ) ; final ControlHandleList list = new ControlHandleList ( primTarget ) ; final BoundingBox box = wiresShape . getPath ( ) . getBoundingBox ( ) ; final Point2D primLoc = primTarget . getComputedLocation ( ) ; final Magnets magnets = new Magnets ( this , list , wiresShape ) ; int i = 0 ; for ( final Point2D p : points ) { final double mx = primLoc . getX ( ) + p . getX ( ) ; final double my = primLoc . getY ( ) + p . getY ( ) ; final WiresMagnet m = new WiresMagnet ( magnets , null , i ++ , p . getX ( ) , p . getY ( ) , getControlPrimitive ( mx , my ) , true ) ; final Direction d = getDirection ( p , box ) ; m . setDirection ( d ) ; list . add ( m ) ; } final String uuid = primTarget . uuid ( ) ; m_magnetRegistry . put ( uuid , magnets ) ; wiresShape . setMagnets ( magnets ) ; return magnets ; }
Right now it only works with provided FOUR or EIGHT cardinals anything else will break WiresConnector autoconnection
11,264
public boolean matches ( Request req ) { if ( ! method . equals ( req . getMethod ( ) ) ) return false ; if ( useRegexForPath ) { if ( ! req . getPath ( ) . getPath ( ) . matches ( basePath ) ) return false ; } else { if ( ! basePath . equals ( req . getPath ( ) . getPath ( ) ) ) return false ; } if ( ! queries . keySet ( ) . containsAll ( req . getQuery ( ) . keySet ( ) ) ) return false ; if ( ! req . getNames ( ) . containsAll ( headers . keySet ( ) ) ) return false ; try { if ( ! isEmpty ( bodyMustContain ) && ! req . getContent ( ) . contains ( bodyMustContain ) ) return false ; } catch ( IOException e ) { return false ; } for ( Map . Entry < String , String > reqQuery : req . getQuery ( ) . entrySet ( ) ) { String respRegex = queries . get ( reqQuery . getKey ( ) ) ; if ( ! reqQuery . getValue ( ) . matches ( respRegex ) ) return false ; } for ( Map . Entry < String , String > header : headers . entrySet ( ) ) { String headerValueRegex = header . getValue ( ) ; if ( ! req . getValue ( header . getKey ( ) ) . matches ( headerValueRegex ) ) return false ; } return true ; }
Checks if HTTP request matches all fields specified in config . Fails on first mismatch . Both headers and query params can be configured as regex .
11,265
public final RadialGradient addColorStop ( final double stop , final IColor color ) { m_jso . addColorStop ( stop , color . getColorString ( ) ) ; return this ; }
Add color stop
11,266
private static String getThreadInfo ( Thread thread ) { final StringBuilder sb = new StringBuilder ( ) ; sb . append ( "Thread: " ) ; sb . append ( thread . getId ( ) ) ; sb . append ( " (" ) ; sb . append ( thread . getName ( ) ) ; sb . append ( ")" ) ; sb . append ( lineSeparator ) ; final StackTraceElement [ ] stack = thread . getStackTrace ( ) ; if ( stack . length == 0 ) { sb . append ( " No Java callstack associated with this thread" ) ; sb . append ( lineSeparator ) ; } else { for ( StackTraceElement element : stack ) { sb . append ( " at " ) ; sb . append ( element . getClassName ( ) ) ; sb . append ( "." ) ; sb . append ( element . getMethodName ( ) ) ; sb . append ( "(" ) ; final int lineNumber = element . getLineNumber ( ) ; if ( lineNumber == - 2 ) { sb . append ( "Native Method" ) ; } else if ( lineNumber >= 0 ) { sb . append ( element . getFileName ( ) ) ; sb . append ( ":" ) ; sb . append ( element . getLineNumber ( ) ) ; } else { sb . append ( element . getFileName ( ) ) ; } sb . append ( ")" ) ; sb . append ( lineSeparator ) ; } } sb . append ( lineSeparator ) ; return sb . toString ( ) ; }
Gets and formats the specified thread s information .
11,267
@ Path ( "commitTree/{commitId}" ) public List < CommitTreeInfo > getCommitTree ( final @ PathParam ( "commitId" ) String commitId ) throws Exception { return gitReadOperation ( new GitOperation < List < CommitTreeInfo > > ( ) { public List < CommitTreeInfo > call ( Git git , GitContext context ) throws Exception { return doGetCommitTree ( git , commitId ) ; } } ) ; }
Returns the file changes in a commit
11,268
public static TailResults tailLog ( String uri , TailResults previousResults , Function < String , Void > lineProcessor ) throws IOException { URL logURL = new URL ( uri ) ; try ( InputStream inputStream = logURL . openStream ( ) ) { BufferedReader reader = new BufferedReader ( new InputStreamReader ( inputStream ) ) ; int count = 0 ; String lastLine = null ; while ( true ) { String line = reader . readLine ( ) ; if ( line == null ) break ; lastLine = line ; if ( previousResults . isNewLine ( line , count ) ) { lineProcessor . apply ( line ) ; } count ++ ; } return new TailResults ( count , lastLine ) ; } }
Tails the log of the given URL such as a build log processing all new lines since the last results
11,269
public static String getPatternName ( OptionalIdentifiedDefinition camelNode ) { XmlRootElement root = camelNode . getClass ( ) . getAnnotation ( XmlRootElement . class ) ; if ( root != null ) { return root . name ( ) ; } String simpleName = Strings . stripSuffix ( camelNode . getClass ( ) . getSimpleName ( ) , "Definition" ) ; return Introspector . decapitalize ( simpleName ) ; }
Returns the pattern name
11,270
public static final IEventFilter not ( final IEventFilter filter ) { return new AbstractEventFilter ( ) { public final boolean test ( final GwtEvent < ? > event ) { return ( false == filter . test ( event ) ) ; } } ; }
The resulting filter will return false if the specified filter returns true .
11,271
public static String fabric8ArchetypesVersion ( ) { String version = System . getenv ( ENV_FABRIC8_ARCHETYPES_VERSION ) ; if ( Strings . isNotBlank ( version ) ) { return version ; } return MavenHelpers . getVersion ( "io.fabric8.archetypes" , "archetypes-catalog" ) ; }
Returns the version to use for the fabric8 archetypes
11,272
protected boolean prepare ( final Context2D context , final Attributes attr , final double alpha ) { context . save ( ) ; if ( false == context . isSelection ( ) ) { context . setGlobalAlpha ( alpha ) ; if ( attr . hasShadow ( ) ) { doApplyShadow ( context , attr ) ; } } getImageProxy ( ) . drawImage ( context ) ; context . restore ( ) ; return false ; }
Draws the image on the canvas .
11,273
public final SelectionLayer getSelectionLayer ( ) { if ( isListening ( ) ) { if ( null == m_select ) { m_select = new SelectionLayer ( ) ; m_select . setPixelSize ( getWidth ( ) , getHeight ( ) ) ; } return m_select ; } return null ; }
Returns the Selection Layer .
11,274
final void attachShapeToColorMap ( final Shape < ? > shape ) { if ( null != shape ) { String color = shape . getColorKey ( ) ; if ( null != color ) { m_shape_color_map . remove ( color ) ; shape . setColorKey ( null ) ; } int count = 0 ; do { count ++ ; color = m_c_rotor . next ( ) ; } while ( ( m_shape_color_map . get ( color ) != null ) && ( count <= ColorKeyRotor . COLOR_SPACE_MAXIMUM ) ) ; if ( count > ColorKeyRotor . COLOR_SPACE_MAXIMUM ) { throw new IllegalArgumentException ( "Exhausted color space " + count ) ; } m_shape_color_map . put ( color , shape ) ; shape . setColorKey ( color ) ; } }
Internal method . Attach a Shape to the Layers Color Map
11,275
void setPixelSize ( final int wide , final int high ) { m_wide = wide ; m_high = high ; if ( LienzoCore . IS_CANVAS_SUPPORTED ) { if ( false == isSelection ( ) ) { getElement ( ) . getStyle ( ) . setWidth ( wide , Unit . PX ) ; getElement ( ) . getStyle ( ) . setHeight ( high , Unit . PX ) ; } final CanvasElement element = getCanvasElement ( ) ; element . setWidth ( wide ) ; element . setHeight ( high ) ; if ( false == isSelection ( ) ) { getContext ( ) . getNativeContext ( ) . initDeviceRatio ( ) ; } if ( ( false == isSelection ( ) ) && ( null != m_select ) ) { m_select . setPixelSize ( wide , high ) ; } } }
Sets this layer s pixel size .
11,276
public Layer setListening ( final boolean listening ) { super . setListening ( listening ) ; if ( listening ) { if ( isShowSelectionLayer ( ) ) { if ( null != getSelectionLayer ( ) ) { doShowSelectionLayer ( true ) ; } } } else { if ( isShowSelectionLayer ( ) ) { doShowSelectionLayer ( false ) ; } m_select = null ; } return this ; }
Enables event handling on this object .
11,277
public Layer setVisible ( final boolean visible ) { super . setVisible ( visible ) ; getElement ( ) . getStyle ( ) . setVisibility ( visible ? Visibility . VISIBLE : Visibility . HIDDEN ) ; return this ; }
Sets whether this object is visible .
11,278
public void clear ( ) { if ( LienzoCore . get ( ) . getLayerClearMode ( ) == LayerClearMode . CLEAR ) { final Context2D context = getContext ( ) ; if ( null != context ) { context . clearRect ( 0 , 0 , getWidth ( ) , getHeight ( ) ) ; } } else { setPixelSize ( getWidth ( ) , getHeight ( ) ) ; } }
Clears the layer .
11,279
@ SuppressWarnings ( "unchecked" ) public Layer moveUp ( ) { final Node < ? > parent = getParent ( ) ; if ( null != parent ) { final IContainer < ? , Layer > container = ( IContainer < ? , Layer > ) parent . asContainer ( ) ; if ( null != container ) { container . moveUp ( this ) ; } } return this ; }
Moves this layer one level up .
11,280
public void setFillColor ( final IColor color ) { m_jso . setFillColor ( ( null != color ) ? color . getColorString ( ) : null ) ; }
Sets the fill color
11,281
public void setStrokeColor ( final IColor color ) { m_jso . setStrokeColor ( ( null != color ) ? color . getColorString ( ) : null ) ; }
Sets the stroke color
11,282
public static void sortSpecial ( final double [ ] d ) { boolean flip ; double temp ; do { flip = false ; for ( int i = 0 ; i < ( d . length - 1 ) ; i ++ ) { if ( ( ( d [ i + 1 ] >= 0 ) && ( d [ i ] > d [ i + 1 ] ) ) || ( ( d [ i ] < 0 ) && ( d [ i + 1 ] >= 0 ) ) ) { flip = true ; temp = d [ i ] ; d [ i ] = d [ i + 1 ] ; d [ i + 1 ] = temp ; } } } while ( flip ) ; }
sort but place - 1 at the end
11,283
public static final double getAngleBetweenTwoLines ( final Point2D p0 , final Point2D p1 , final Point2D p2 ) { return getAngleFromSSS ( p0 . distance ( p1 ) , p1 . distance ( p2 ) , p0 . distance ( p2 ) ) ; }
Returns the angle between p2 - > p0 and p2 - > p2
11,284
public static double getClockwiseAngleBetweenThreePoints ( final Point2D p0 , final Point2D c , final Point2D p1 ) { final Point2D a = c . sub ( p1 ) ; final Point2D b = c . sub ( p0 ) ; return Math . atan2 ( a . getY ( ) , a . getX ( ) ) - Math . atan2 ( b . getY ( ) , b . getX ( ) ) ; }
Returns the clockwise angle between three points . It starts at p0 that goes clock - wise around c until it reaches p1
11,285
private static final double getCappedOffset ( final Point2D p0 , final Point2D p2 , final Point2D p4 , final double offset ) { final double radius = Math . min ( p2 . sub ( p0 ) . getLength ( ) , p2 . sub ( p4 ) . getLength ( ) ) / 2 ; return ( ( offset > radius ) ? radius : offset ) ; }
this will check if the radius needs capping and return a smaller value if it does
11,286
public static final Point2DArray intersectLineArcTo ( final Point2D a0 , final Point2D a1 , final Point2D p0 , final Point2D p1 , final Point2D p2 , final double r ) { final Point2DArray arcPoints = getCanvasArcToPoints ( p0 , p1 , p2 , r ) ; final Point2DArray circleIntersectPoints = intersectLineCircle ( a0 , a1 , arcPoints . get ( 1 ) , r ) ; final Point2DArray arcIntersectPoints = new Point2DArray ( ) ; Point2D ps = arcPoints . get ( 0 ) ; final Point2D pc = arcPoints . get ( 1 ) ; Point2D pe = arcPoints . get ( 2 ) ; if ( ! ps . equals ( p0 ) ) { final Point2D t = intersectLineLine ( p0 , ps , a0 , a1 ) ; if ( t != null ) { arcIntersectPoints . push ( t ) ; } } if ( ( pe . sub ( pc ) ) . crossScalar ( ( ps . sub ( pc ) ) ) < 0 ) { final Point2D t = pe ; pe = ps ; ps = t ; } if ( circleIntersectPoints . size ( ) > 0 ) { final Point2D t = circleIntersectPoints . get ( 0 ) ; final boolean within = intersectPointWithinBounding ( t , a0 , a1 ) ; if ( within && ( t . sub ( ps ) . dot ( pe . sub ( ps ) . perpendicular ( ) ) >= 0 ) ) { arcIntersectPoints . push ( t ) ; } } if ( circleIntersectPoints . size ( ) == 2 ) { final Point2D t = circleIntersectPoints . get ( 1 ) ; final boolean within = intersectPointWithinBounding ( t , a0 , a1 ) ; if ( within && ( t . sub ( ps ) . dot ( pe . sub ( ps ) . perpendicular ( ) ) >= 0 ) ) { arcIntersectPoints . push ( t ) ; } } return arcIntersectPoints ; }
Returns the points the line intersects the arcTo path . Note that as arcTo s points are actually two lines form p1 at a tangent to the arc s circle it can draw a line from p0 to the start of the arc which forms another potential intersect point .
11,287
public static final Point2DArray getCanvasArcToPoints ( final Point2D p0 , final Point2D p1 , final Point2D p2 , final double r ) { final double a0 = getAngleBetweenTwoLines ( p0 , p1 , p2 ) / 2 ; final double ln = getLengthFromASA ( RADIANS_90 - a0 , r , a0 ) ; Point2D dv = p1 . sub ( p0 ) ; Point2D dx = dv . unit ( ) ; Point2D dl = dx . mul ( ln ) ; final Point2D ps = p1 . sub ( dl ) ; dv = p1 . sub ( p2 ) ; dx = dv . unit ( ) ; dl = dx . mul ( ln ) ; final Point2D pe = p1 . sub ( dl ) ; final Point2D midPoint = new Point2D ( ( ps . getX ( ) + pe . getX ( ) ) / 2 , ( ps . getY ( ) + pe . getY ( ) ) / 2 ) ; dx = midPoint . sub ( p1 ) . unit ( ) ; final Point2D pc = p1 . add ( dx . mul ( distance ( r , ln ) ) ) ; return new Point2DArray ( ps , pc , pe ) ; }
Canvas arcTo s have a variable center as points a b and c form two lines from the same point at a tangent to the arc s cirlce . This returns the arcTo arc start center and end points .
11,288
public static Point2D getPathIntersect ( final WiresConnection connection , final MultiPath path , final Point2D c , final int pointIndex ) { final Point2DArray plist = connection . getConnector ( ) . getLine ( ) . getPoint2DArray ( ) ; Point2D p = plist . get ( pointIndex ) . copy ( ) ; final Point2D offsetP = path . getComputedLocation ( ) ; p . offset ( - offsetP . getX ( ) , - offsetP . getY ( ) ) ; final double width = path . getBoundingBox ( ) . getWidth ( ) ; if ( c . equals ( p ) ) { p . offset ( offsetP . getX ( ) , offsetP . getY ( ) ) ; } try { p = getProjection ( c , p , width ) ; final Set < Point2D > [ ] set = Geometry . getCardinalIntersects ( path , new Point2DArray ( c , p ) ) ; final Point2DArray points = Geometry . removeInnerPoints ( c , set ) ; return ( points . size ( ) > 1 ) ? points . get ( 1 ) : null ; } catch ( final Exception e ) { return null ; } }
Finds the intersection of the connector s end segment on a path .
11,289
public static final Point2DArray getCardinals ( final BoundingBox box , final Direction [ ] requestedCardinals ) { final Set < Direction > set = new HashSet < > ( Arrays . asList ( requestedCardinals ) ) ; final Point2DArray points = new Point2DArray ( ) ; final Point2D c = findCenter ( box ) ; final Point2D n = new Point2D ( c . getX ( ) , box . getY ( ) ) ; final Point2D e = new Point2D ( box . getX ( ) + box . getWidth ( ) , c . getY ( ) ) ; final Point2D s = new Point2D ( c . getX ( ) , box . getY ( ) + box . getHeight ( ) ) ; final Point2D w = new Point2D ( box . getX ( ) , c . getY ( ) ) ; final Point2D sw = new Point2D ( w . getX ( ) , s . getY ( ) ) ; final Point2D se = new Point2D ( e . getX ( ) , s . getY ( ) ) ; final Point2D ne = new Point2D ( e . getX ( ) , n . getY ( ) ) ; final Point2D nw = new Point2D ( w . getX ( ) , n . getY ( ) ) ; points . push ( c ) ; if ( set . contains ( Direction . NORTH ) ) { points . push ( n ) ; } if ( set . contains ( Direction . NORTH_EAST ) ) { points . push ( ne ) ; } if ( set . contains ( Direction . EAST ) ) { points . push ( e ) ; } if ( set . contains ( Direction . SOUTH_EAST ) ) { points . push ( se ) ; } if ( set . contains ( Direction . SOUTH ) ) { points . push ( s ) ; } if ( set . contains ( Direction . SOUTH_WEST ) ) { points . push ( sw ) ; } if ( set . contains ( Direction . WEST ) ) { points . push ( w ) ; } if ( set . contains ( Direction . NORTH_WEST ) ) { points . push ( nw ) ; } return points ; }
Returns cardinal points for a given bounding box
11,290
public static Point2D findIntersection ( final int x , final int y , final MultiPath path ) { final Point2D pointerPosition = new Point2D ( x , y ) ; final BoundingBox box = path . getBoundingBox ( ) ; final Point2D center = findCenter ( box ) ; final double length = box . getWidth ( ) + box . getHeight ( ) ; final Point2D projectionPoint = getProjection ( center , pointerPosition , length ) ; final Point2DArray points = new Point2DArray ( ) ; points . push ( center ) ; points . push ( projectionPoint ) ; final Set < Point2D > [ ] intersects = Geometry . getCardinalIntersects ( path , points ) ; Point2D nearest = null ; for ( final Set < Point2D > set : intersects ) { double nearesstDistance = length ; if ( ( set != null ) && ! set . isEmpty ( ) ) { for ( final Point2D p : set ) { final double currentDistance = p . distance ( pointerPosition ) ; if ( currentDistance < nearesstDistance ) { nearesstDistance = currentDistance ; nearest = p ; } } } } return nearest ; }
Finds intersecting point from the center of a path
11,291
public static final String toBrowserRGB ( final int r , final int g , final int b ) { return "rgb(" + fixRGB ( r ) + "," + fixRGB ( g ) + "," + fixRGB ( b ) + ")" ; }
Converts RGB integer values to a browser - compliance rgb format .
11,292
public static final String toBrowserRGBA ( final int r , final int g , final int b , final double a ) { return "rgba(" + fixRGB ( r ) + "," + fixRGB ( g ) + "," + fixRGB ( g ) + "," + fixAlpha ( a ) + ")" ; }
Converts RGBA values to a browser - compliance rgba format .
11,293
public static final Color hex2RGB ( final String hex ) { String r , g , b ; final int len = hex . length ( ) ; if ( len == 7 ) { r = hex . substring ( 1 , 3 ) ; g = hex . substring ( 3 , 5 ) ; b = hex . substring ( 5 , 7 ) ; } else if ( len == 4 ) { r = hex . substring ( 1 , 2 ) ; g = hex . substring ( 2 , 3 ) ; b = hex . substring ( 3 , 4 ) ; r = r + r ; g = g + g ; b = b + b ; } else { return null ; } try { return new Color ( Integer . valueOf ( r , 16 ) , Integer . valueOf ( g , 16 ) , Integer . valueOf ( b , 16 ) ) ; } catch ( final NumberFormatException ignored ) { return null ; } }
Converts Hex string to RGB . Assumes
11,294
private static final Direction drawOrthogonalLineSegment ( final NFastDoubleArrayJSO buffer , final Direction direction , Direction nextDirection , final double p1x , final double p1y , final double p2x , final double p2y , final double p3x , final double p3y , final boolean write ) { if ( nextDirection == null ) { nextDirection = getNextDirection ( direction , p1x , p1y , p2x , p2y ) ; } if ( ( nextDirection == SOUTH ) || ( nextDirection == NORTH ) ) { if ( p1x == p2x ) { addPoint ( buffer , p2x , p2y , write ) ; } else { addPoint ( buffer , p1x , p2y , p2x , p2y , write ) ; } if ( p1x < p2x ) { return EAST ; } else if ( p1x > p2x ) { return WEST ; } else { return nextDirection ; } } else { if ( p1y != p2y ) { addPoint ( buffer , p2x , p1y , p2x , p2y , write ) ; } else { addPoint ( buffer , p2x , p2y , write ) ; } if ( p1y > p2y ) { return NORTH ; } else if ( p1y < p2y ) { return SOUTH ; } else { return nextDirection ; } } }
Draws an orthogonal line between two points it uses the previous direction to determine the new direction . It will always attempt to continue the line in the same direction if it can do so without requiring a corner . If the line goes back on itself it ll go 50% of the way and then go perpendicular so that it no longer goes back on itself .
11,295
private static Direction getNextDirection ( final Direction direction , final double p1x , final double p1y , final double p2x , final double p2y ) { Direction next_direction ; switch ( direction ) { case NORTH : if ( p2y < p1y ) { next_direction = NORTH ; } else if ( p2x > p1x ) { next_direction = EAST ; } else { next_direction = WEST ; } break ; case SOUTH : if ( p2y > p1y ) { next_direction = SOUTH ; } else if ( p2x > p1x ) { next_direction = EAST ; } else { next_direction = WEST ; } break ; case EAST : if ( p2x > p1x ) { next_direction = EAST ; } else if ( p2y < p1y ) { next_direction = NORTH ; } else { next_direction = SOUTH ; } break ; case WEST : if ( p2x < p1x ) { next_direction = WEST ; } else if ( p2y < p1y ) { next_direction = NORTH ; } else { next_direction = SOUTH ; } break ; default : throw new IllegalStateException ( "This should not be reached (Defensive Code)" ) ; } return next_direction ; }
looks at the current and target points and based on the current direction returns the next direction . This drives the orthogonal line drawing .
11,296
private static Direction getTailDirection ( final Point2DArray points , final NFastDoubleArrayJSO buffer , final Direction lastDirection , Direction tailDirection , final double correction , final OrthogonalPolyLine pline , final double p0x , final double p0y , final double p1x , final double p1y ) { final double offset = pline . getHeadOffset ( ) + correction ; switch ( tailDirection ) { case NONE : { final double dx = ( p1x - p0x ) ; final double dy = ( p1y - p0y ) ; int bestPoints = 0 ; if ( dx > offset ) { tailDirection = WEST ; bestPoints = drawTail ( points , buffer , lastDirection , WEST , correction , pline , p0x , p0y , p1x , p1y , false ) ; } else { tailDirection = EAST ; bestPoints = drawTail ( points , buffer , lastDirection , EAST , correction , pline , p0x , p0y , p1x , p1y , false ) ; } if ( dy > 0 ) { final int points3 = drawTail ( points , buffer , lastDirection , NORTH , correction , pline , p0x , p0y , p1x , p1y , false ) ; if ( points3 < bestPoints ) { tailDirection = NORTH ; bestPoints = points3 ; } } else { final int points4 = drawTail ( points , buffer , lastDirection , SOUTH , correction , pline , p0x , p0y , p1x , p1y , false ) ; if ( points4 < bestPoints ) { tailDirection = SOUTH ; bestPoints = points4 ; } } break ; } default : break ; } return tailDirection ; }
When tail is NONE it needs to try multiple directions to determine which gives the least number of corners and then selects that as the final direction .
11,297
public LienzoPanel setCursor ( final Cursor cursor ) { if ( ( cursor != null ) && ( cursor != m_active_cursor ) ) { m_active_cursor = cursor ; Scheduler . get ( ) . scheduleDeferred ( new ScheduledCommand ( ) { public void execute ( ) { getElement ( ) . getStyle ( ) . setCursor ( m_active_cursor ) ; } } ) ; } return this ; }
Sets the type of cursor to be used when hovering above the element .
11,298
public LienzoPanel setBackgroundColor ( final String color ) { if ( null != color ) { getElement ( ) . getStyle ( ) . setBackgroundColor ( color ) ; } return this ; }
Sets the background color of the LienzoPanel .
11,299
public static void copyOutput ( Logger target , String name , Process process ) { new StreamReader ( target , name + " stdout" , process . getInputStream ( ) ) . start ( ) ; new StreamReader ( target , name + " stderr" , process . getErrorStream ( ) ) . start ( ) ; }
Starts threads that copy the output of the supplied process s stdout and stderr streams to the supplied target logger . When the streams reach EOF the threads will exit . The threads will be set to daemon so that they do not prevent the VM from exiting .