idx
int64
0
165k
question
stringlengths
73
4.15k
target
stringlengths
5
918
len_question
int64
21
890
len_target
int64
3
255
138,500
@ Override public boolean addAll ( Collection < ? extends TimeSeriesCollection > c ) { try { final rh_protoClient client = getRpcClient ( OncRpcProtocols . ONCRPC_TCP ) ; try { final list_of_timeseries_collection enc_c = encodeTSCCollection ( c ) ; return BlockingWrapper . execute ( ( ) -> client . addTSData_1 ( enc_c ) ) ; } finally { client . close ( ) ; } } catch ( OncRpcException | IOException | InterruptedException | RuntimeException ex ) { LOG . log ( Level . SEVERE , "addAll RPC call failed" , ex ) ; throw new RuntimeException ( "RPC call failed" , ex ) ; } }
Add multiple TimeSeriesCollections to the history .
168
10
138,501
@ Override public DateTime getEnd ( ) { try { final rh_protoClient client = getRpcClient ( OncRpcProtocols . ONCRPC_UDP ) ; try { return decodeTimestamp ( BlockingWrapper . execute ( ( ) -> client . getEnd_1 ( ) ) ) ; } finally { client . close ( ) ; } } catch ( OncRpcException | IOException | InterruptedException | RuntimeException ex ) { LOG . log ( Level . SEVERE , "getEnd RPC call failed" , ex ) ; throw new RuntimeException ( "RPC call failed" , ex ) ; } }
Return the highest timestamp in the stored metrics .
139
9
138,502
public MetricValue [ ] getAll ( int startInclusive , int endExclusive ) { return IntStream . range ( startInclusive , endExclusive ) . mapToObj ( this :: getOrNull ) . toArray ( MetricValue [ ] :: new ) ; }
Returns metric values at the given range .
59
8
138,503
public List < ChallengeHandler > lookup ( String location ) { List < ChallengeHandler > result = Collections . emptyList ( ) ; if ( location != null ) { Node < ChallengeHandler , UriElement > resultNode = findBestMatchingNode ( location ) ; if ( resultNode != null ) { return resultNode . getValues ( ) ; } } return result ; }
Locate all challenge handlers to serve the given location .
76
11
138,504
ChallengeHandler lookup ( ChallengeRequest challengeRequest ) { ChallengeHandler result = null ; String location = challengeRequest . getLocation ( ) ; if ( location != null ) { Node < ChallengeHandler , UriElement > resultNode = findBestMatchingNode ( location ) ; // // If we found an exact or wildcard match, try to find a handler // for the requested challenge. // if ( resultNode != null ) { List < ChallengeHandler > handlers = resultNode . getValues ( ) ; if ( handlers != null ) { for ( ChallengeHandler challengeHandler : handlers ) { if ( challengeHandler . canHandle ( challengeRequest ) ) { result = challengeHandler ; break ; } } } } } return result ; }
Locate a challenge handler factory to serve the given location and challenge type .
148
15
138,505
private void refresh ( ) { try { // Invoke underlying getTuples unsynchronized. // This way it won't block tuple access, in case it is a long // running or expensive function. final CompletableFuture < ? extends Collection < ResolverTuple > > fut = underlying . getTuples ( ) ; // Publish future, needs synchronization, so close() method can cancel properly. synchronized ( this ) { // We create the whenCompleteAsync continuation with synchronization locked, // because the update code will want to clear the currentFut member-variable. // We must ensure it is set before. currentFut = fut . whenCompleteAsync ( this :: update , SCHEDULER ) ; if ( closed ) // Close may have set close bit while we were creating future. fut . cancel ( false ) ; } } catch ( Exception ex ) { synchronized ( this ) { exception = ex ; } reschedule ( FAILURE_RESCHEDULE_DELAY ) ; } }
Attempt to refresh the resolver result .
209
8
138,506
private void update ( Collection < ResolverTuple > underlyingTuples , Throwable t ) { if ( t != null ) applyException ( t ) ; else if ( underlyingTuples != null ) applyUpdate ( underlyingTuples ) ; else applyException ( null ) ; }
Update callback called when the completable future completes .
57
10
138,507
private synchronized void applyUpdate ( Collection < ResolverTuple > underlyingTuples ) { lastRefresh = DateTime . now ( ) ; tuples = underlyingTuples ; exception = null ; reschedule ( minAge . getMillis ( ) ) ; }
Apply updated tuple collection .
55
5
138,508
private synchronized void reschedule ( long millis ) { currentFut = null ; // Remove current future. if ( ! closed ) { SCHEDULER . schedule ( this :: refresh , millis , TimeUnit . MILLISECONDS ) ; } else { try { underlying . close ( ) ; } catch ( Exception ex ) { LOG . log ( Level . WARNING , "failed to close resolver " + underlying . configString ( ) , ex ) ; } } }
Schedule next invocation of the update task .
100
9
138,509
public static Map < String , TileSet > parseActionTileSets ( File file ) throws IOException , SAXException { return parseActionTileSets ( new BufferedInputStream ( new FileInputStream ( file ) ) ) ; }
Parses the action tileset definitions in the supplied file and puts them into a hash map keyed on action name .
50
25
138,510
public static Map < String , TileSet > parseActionTileSets ( InputStream in ) throws IOException , SAXException { Digester digester = new Digester ( ) ; digester . addSetProperties ( "actions" + ActionRuleSet . ACTION_PATH ) ; addTileSetRuleSet ( digester , new SwissArmyTileSetRuleSet ( ) ) ; addTileSetRuleSet ( digester , new UniformTileSetRuleSet ( "/uniformTileset" ) ) ; Map < String , TileSet > actsets = new ActionMap ( ) ; digester . push ( actsets ) ; digester . parse ( in ) ; return actsets ; }
Parses the action tileset definitions in the supplied input stream and puts them into a hash map keyed on action name .
143
26
138,511
public static TileSetBundle extractBundle ( ResourceBundle bundle ) throws IOException , ClassNotFoundException { // unserialize the tileset bundles array InputStream tbin = null ; try { tbin = bundle . getResource ( METADATA_PATH ) ; ObjectInputStream oin = new ObjectInputStream ( new BufferedInputStream ( tbin ) ) ; TileSetBundle tsb = ( TileSetBundle ) oin . readObject ( ) ; return tsb ; } finally { StreamUtil . close ( tbin ) ; } }
Extracts but does not initialize a serialized tileset bundle instance from the supplied resource bundle .
119
20
138,512
public static TileSetBundle extractBundle ( File file ) throws IOException , ClassNotFoundException { // unserialize the tileset bundles array FileInputStream fin = new FileInputStream ( file ) ; try { ObjectInputStream oin = new ObjectInputStream ( new BufferedInputStream ( fin ) ) ; TileSetBundle tsb = ( TileSetBundle ) oin . readObject ( ) ; return tsb ; } finally { StreamUtil . close ( fin ) ; } }
Extracts but does not initialize a serialized tileset bundle instance from the supplied file .
106
19
138,513
public static FileChannel createTempFile ( Path dir , String prefix , String suffix ) throws IOException { return createNewFileImpl ( dir , prefix , suffix , new OpenOption [ ] { READ , WRITE , CREATE_NEW , DELETE_ON_CLOSE } ) . getFileChannel ( ) ; }
Create a temporary file that will be removed when it is closed .
65
13
138,514
public static FileChannel createTempFile ( String prefix , String suffix ) throws IOException { return createTempFile ( TMPDIR , prefix , suffix ) ; }
Create a temporary file that will be removed when it is closed in the tmpdir location .
33
18
138,515
public static NamedFileChannel createNewFile ( Path dir , String prefix , String suffix ) throws IOException { return createNewFileImpl ( dir , prefix , suffix , new OpenOption [ ] { READ , WRITE , CREATE_NEW } ) ; }
Creates a new file and opens it for reading and writing .
52
13
138,516
public void paint ( Graphics2D gfx ) { // if we're rendering footprints, paint that boolean footpaint = _fprintDebug . getValue ( ) ; if ( footpaint ) { gfx . setColor ( Color . black ) ; gfx . draw ( _footprint ) ; if ( _hideObjects . getValue ( ) ) { // We're in footprints but no objects mode, so let's also fill it in so we can // see things better/tell if we have overlapping ones Composite ocomp = gfx . getComposite ( ) ; gfx . setComposite ( ALPHA_WARN ) ; gfx . fill ( _footprint ) ; gfx . setComposite ( ocomp ) ; } } if ( _hideObjects . getValue ( ) ) { return ; } // if we have a warning, render an alpha'd red rectangle over our bounds if ( _warning ) { Composite ocomp = gfx . getComposite ( ) ; gfx . setComposite ( ALPHA_WARN ) ; gfx . fill ( bounds ) ; gfx . setComposite ( ocomp ) ; } // paint our tile tile . paint ( gfx , bounds . x , bounds . y ) ; // and possibly paint the object's spot if ( footpaint && _sspot != null ) { // translate the origin to center on the portal gfx . translate ( _sspot . x , _sspot . y ) ; // rotate to reflect the spot orientation double rot = ( Math . PI / 4.0f ) * tile . getSpotOrient ( ) ; gfx . rotate ( rot ) ; // draw the spot triangle gfx . setColor ( Color . green ) ; gfx . fill ( _spotTri ) ; // outline the triangle in black gfx . setColor ( Color . black ) ; gfx . draw ( _spotTri ) ; // restore the original transform gfx . rotate ( - rot ) ; gfx . translate ( - _sspot . x , - _sspot . y ) ; } }
Requests that this scene object render itself .
441
9
138,517
public void setPriority ( byte priority ) { info . priority = ( byte ) Math . max ( Byte . MIN_VALUE , Math . min ( Byte . MAX_VALUE , priority ) ) ; }
Overrides the render priority of this object .
42
10
138,518
public void relocateObject ( MisoSceneMetrics metrics , int tx , int ty ) { // Log.info("Relocating object " + this + " to " + // StringUtil.coordsToString(tx, ty)); info . x = tx ; info . y = ty ; computeInfo ( metrics ) ; }
Updates this object s origin tile coordinate . Its bounds and other cached screen coordinate information are updated .
68
20
138,519
protected void computeInfo ( MisoSceneMetrics metrics ) { // start with the screen coordinates of our origin tile Point tpos = MisoUtil . tileToScreen ( metrics , info . x , info . y , new Point ( ) ) ; // if the tile has an origin coordinate, use that, otherwise // compute it from the tile footprint int tox = tile . getOriginX ( ) , toy = tile . getOriginY ( ) ; if ( tox == Integer . MIN_VALUE ) { tox = tile . getBaseWidth ( ) * metrics . tilehwid ; } if ( toy == Integer . MIN_VALUE ) { toy = tile . getHeight ( ) ; } bounds = new Rectangle ( tpos . x + metrics . tilehwid - tox , tpos . y + metrics . tilehei - toy , tile . getWidth ( ) , tile . getHeight ( ) ) ; // compute our object footprint as well _frect = new Rectangle ( info . x - tile . getBaseWidth ( ) + 1 , info . y - tile . getBaseHeight ( ) + 1 , tile . getBaseWidth ( ) , tile . getBaseHeight ( ) ) ; _footprint = MisoUtil . getFootprintPolygon ( metrics , _frect . x , _frect . y , _frect . width , _frect . height ) ; // compute our object spot if we've got one if ( tile . hasSpot ( ) ) { _fspot = MisoUtil . tilePlusFineToFull ( metrics , info . x , info . y , tile . getSpotX ( ) , tile . getSpotY ( ) , new Point ( ) ) ; _sspot = MisoUtil . fullToScreen ( metrics , _fspot . x , _fspot . y , new Point ( ) ) ; } // Log.info("Computed object metrics " + // "[tpos=" + StringUtil.coordsToString(tx, ty) + // ", info=" + info + // ", sbounds=" + StringUtil.toString(bounds) + "]."); }
Computes our screen bounds tile footprint and other useful cached metrics .
451
13
138,520
@ Override public void run ( ) { try { Thread . sleep ( 3000 ) ; } catch ( InterruptedException e ) { e . printStackTrace ( ) ; } subjectRepository . getSubjectsCollection ( new SubjectRepository . SubjectListCallback ( ) { @ Override public void onSubjectListLoader ( final Collection < Subject > subjects ) { mainThread . post ( new Runnable ( ) { @ Override public void run ( ) { callback . onSubjectListLoaded ( subjects ) ; } } ) ; } @ Override public void onError ( final SubjectException exception ) { mainThread . post ( new Runnable ( ) { @ Override public void run ( ) { callback . onError ( exception ) ; Log . i ( getClass ( ) . toString ( ) , "Error!" ) ; } } ) ; } } ) ; }
Interactor User case
183
4
138,521
private void fixBacklog ( ) throws IOException { try { writers . values ( ) . parallelStream ( ) . forEach ( groupWriter -> { try { groupWriter . fixBacklog ( timestamps . size ( ) ) ; } catch ( IOException ex ) { throw new RuntimeIOException ( ex ) ; } } ) ; } catch ( RuntimeIOException ex ) { throw ex . getEx ( ) ; } }
Pad all groups with empty maps to ensure it s the same size as timestamps list .
89
19
138,522
public void setPaused ( boolean paused ) { // sanity check if ( ( paused && ( _pauseTime != 0 ) ) || ( ! paused && ( _pauseTime == 0 ) ) ) { log . warning ( "Requested to pause when paused or vice-versa" , "paused" , paused ) ; return ; } _paused = paused ; if ( _paused ) { // make a note of our pause time _pauseTime = _framemgr . getTimeStamp ( ) ; } else { // let the animation and sprite managers know that we just warped into the future long delta = _framemgr . getTimeStamp ( ) - _pauseTime ; _animmgr . fastForward ( delta ) ; _spritemgr . fastForward ( delta ) ; // clear out our pause time _pauseTime = 0 ; } }
Pauses the sprites and animations that are currently active on this media panel . Also stops listening to the frame tick while paused .
181
25
138,523
public void paintMedia ( Graphics2D gfx , int layer , Rectangle dirty ) { if ( layer == FRONT ) { _spritemgr . paint ( gfx , layer , dirty ) ; _animmgr . paint ( gfx , layer , dirty ) ; } else { _animmgr . paint ( gfx , layer , dirty ) ; _spritemgr . paint ( gfx , layer , dirty ) ; } }
Renders the sprites and animations that intersect the supplied dirty region in the specified layer .
94
17
138,524
public void paintPerf ( Graphics2D gfx ) { if ( _perfRect != null && FrameManager . _perfDebug . getValue ( ) ) { gfx . setClip ( null ) ; _perfLabel . render ( gfx , _perfRect . x , _perfRect . y ) ; } }
Renders our performance debugging information if enabled .
73
9
138,525
public void viewLocationDidChange ( int dx , int dy ) { if ( _perfRect != null ) { Rectangle sdirty = new Rectangle ( _perfRect ) ; sdirty . translate ( - dx , - dy ) ; _remgr . addDirtyRegion ( sdirty ) ; } // let our sprites and animations know what's up _animmgr . viewLocationDidChange ( dx , dy ) ; _spritemgr . viewLocationDidChange ( dx , dy ) ; }
If our host supports scrolling around in a virtual view it should call this method when the view origin changes .
107
21
138,526
public void setImage ( Mirage image ) { if ( _mirage != null ) { _totalTileMemory -= _mirage . getEstimatedMemoryUsage ( ) ; } _mirage = image ; if ( _mirage != null ) { _totalTileMemory += _mirage . getEstimatedMemoryUsage ( ) ; } }
Configures this tile with its tile image .
70
9
138,527
public void paint ( Graphics2D gfx , int x , int y ) { _mirage . paint ( gfx , x , y ) ; }
Render the tile image at the specified position in the given graphics context .
32
14
138,528
public InputStream getSound ( String bundle , String path ) throws IOException { InputStream rsrc ; try { rsrc = _rmgr . getResource ( bundle , path ) ; } catch ( FileNotFoundException notFound ) { // try from the classpath try { rsrc = _rmgr . getResource ( path ) ; } catch ( FileNotFoundException notFoundAgain ) { throw notFound ; } } return rsrc ; }
Attempts to load a sound stream from the given path from the given bundle and from the classpath . If nothing is found a FileNotFoundException is thrown .
93
32
138,529
protected Config getConfig ( String packagePath ) { Config c = _configs . get ( packagePath ) ; if ( c == null ) { Properties props = new Properties ( ) ; String propFilename = packagePath + Sounds . PROP_NAME + ".properties" ; try { props = ConfigUtil . loadInheritedProperties ( propFilename , _rmgr . getClassLoader ( ) ) ; } catch ( IOException ioe ) { log . warning ( "Failed to load sound properties" , "filename" , propFilename , ioe ) ; } c = new Config ( props ) ; _configs . put ( packagePath , c ) ; } return c ; }
Get the cached Config .
144
5
138,530
protected byte [ ] loadClipData ( String bundle , String path ) throws IOException { InputStream clipin = null ; try { clipin = getSound ( bundle , path ) ; } catch ( FileNotFoundException fnfe ) { // only play the default sound if we have verbose sound debugging turned on. if ( JavaSoundPlayer . _verbose . getValue ( ) ) { log . warning ( "Could not locate sound data" , "bundle" , bundle , "path" , path ) ; if ( _defaultClipPath != null ) { try { clipin = _rmgr . getResource ( _defaultClipBundle , _defaultClipPath ) ; } catch ( FileNotFoundException fnfe3 ) { try { clipin = _rmgr . getResource ( _defaultClipPath ) ; } catch ( FileNotFoundException fnfe4 ) { log . warning ( "Additionally, the default fallback sound could not be located" , "bundle" , _defaultClipBundle , "path" , _defaultClipPath ) ; } } } else { log . warning ( "No fallback default sound specified!" ) ; } } // if we couldn't load the default, rethrow if ( clipin == null ) { throw fnfe ; } } return StreamUtil . toByteArray ( clipin ) ; }
Read the data from the resource manager .
289
8
138,531
protected void init ( long milliDivider , long microDivider ) { _milliDivider = milliDivider ; _microDivider = microDivider ; reset ( ) ; log . info ( "Using " + getClass ( ) + " timer" , "mfreq" , _milliDivider , "ufreq" , _microDivider , "start" , _startStamp ) ; }
Initializes this timer . Must be called before the timer is used .
90
14
138,532
protected void calibrate ( ) { long currentTimer = current ( ) ; long currentMillis = System . currentTimeMillis ( ) ; long elapsedTimer = currentTimer - _driftTimerStamp ; float elapsedMillis = currentMillis - _driftMilliStamp ; float drift = elapsedMillis / ( elapsedTimer / _milliDivider ) ; if ( _debugCalibrate . getValue ( ) ) { log . warning ( "Calibrating" , "timer" , elapsedTimer , "millis" , elapsedMillis , "drift" , drift , "timerstamp" , _driftTimerStamp , "millistamp" , _driftMilliStamp , "current" , currentTimer ) ; } if ( elapsedTimer < 0 ) { log . warning ( "The timer has decided to live in the past, resetting drift" , "previousTimer" , _driftTimerStamp , "currentTimer" , currentTimer , "previousMillis" , _driftMilliStamp , "currentMillis" , currentMillis ) ; _driftRatio = 1.0F ; } else if ( drift > MAX_ALLOWED_DRIFT_RATIO || drift < MIN_ALLOWED_DRIFT_RATIO ) { log . warning ( "Calibrating" , "drift" , drift ) ; // Ignore the drift if it's hugely out of range. That indicates general clock insanity, // and we just want to stay out of the way. if ( drift < 100 * MAX_ALLOWED_DRIFT_RATIO && drift > MIN_ALLOWED_DRIFT_RATIO / 100 ) { _driftRatio = drift ; } else { _driftRatio = 1.0F ; } if ( Math . abs ( drift - 1.0 ) > Math . abs ( _maxDriftRatio - 1.0 ) ) { _maxDriftRatio = drift ; } } else if ( _driftRatio != 1.0 ) { log . warning ( "Calibrating" , "drift" , drift ) ; // If we're within bounds now but we weren't before, reset _driftFactor and log it _driftRatio = 1.0F ; } _driftMilliStamp = currentMillis ; _driftTimerStamp = currentTimer ; }
Calculates the drift factor from the time elapsed from the last calibrate call .
519
17
138,533
@ Override public void addRuleInstances ( Digester digester ) { // this creates the appropriate instance when we encounter a // <class> tag digester . addObjectCreate ( _prefix + CLASS_PATH , ComponentClass . class . getName ( ) ) ; // grab the attributes from the <class> tag SetPropertyFieldsRule rule = new SetPropertyFieldsRule ( ) ; rule . addFieldParser ( "shadowColor" , new FieldParser ( ) { public Object parse ( String text ) { int [ ] values = StringUtil . parseIntArray ( text ) ; return new Color ( values [ 0 ] , values [ 1 ] , values [ 2 ] , values [ 3 ] ) ; } } ) ; digester . addRule ( _prefix + CLASS_PATH , rule ) ; // parse render priority overrides String opath = _prefix + CLASS_PATH + "/override" ; digester . addObjectCreate ( opath , PriorityOverride . class . getName ( ) ) ; rule = new SetPropertyFieldsRule ( ) ; rule . addFieldParser ( "orients" , new FieldParser ( ) { public Object parse ( String text ) { String [ ] orients = StringUtil . parseStringArray ( text ) ; ArrayIntSet oset = new ArrayIntSet ( ) ; for ( String orient : orients ) { oset . add ( DirectionUtil . fromShortString ( orient ) ) ; } return oset ; } } ) ; digester . addRule ( opath , rule ) ; digester . addSetNext ( opath , "addPriorityOverride" , PriorityOverride . class . getName ( ) ) ; }
Adds the necessary rules to the digester to parse our classes .
353
13
138,534
public boolean insert ( ObjectInfo info ) { // bail if it's already in the set int ipos = indexOf ( info ) ; if ( ipos >= 0 ) { // log a warning because the caller shouldn't be doing this log . warning ( "Requested to add an object to a set that already " + "contains such an object [ninfo=" + info + ", oinfo=" + _objs [ ipos ] + "]." , new Exception ( ) ) ; return false ; } // otherwise insert it ipos = - ( ipos + 1 ) ; _objs = ListUtil . insert ( _objs , ipos , info ) ; _size ++ ; return true ; }
Inserts the supplied object into the set .
148
9
138,535
public boolean remove ( ObjectInfo info ) { int opos = indexOf ( info ) ; if ( opos >= 0 ) { remove ( opos ) ; return true ; } else { return false ; } }
Removes the specified object from the set .
44
9
138,536
public ObjectInfo [ ] toArray ( ) { ObjectInfo [ ] info = new ObjectInfo [ _size ] ; System . arraycopy ( _objs , 0 , info , 0 , _size ) ; return info ; }
Converts the contents of this object set to an array .
47
12
138,537
public BaseTile getBaseTile ( int tx , int ty ) { BaseTile tile = _base [ index ( tx , ty ) ] ; if ( tile == null && _defset != null ) { tile = ( BaseTile ) _defset . getTile ( TileUtil . getTileHash ( tx , ty ) % _defset . getTileCount ( ) ) ; } return tile ; }
Returns the base tile at the specified coordinates or null if there s no tile at said coordinates .
84
19
138,538
public void updateBaseTile ( int fqTileId , int tx , int ty ) { String errmsg = null ; int tidx = index ( tx , ty ) ; // this is a bit magical: we pass the fully qualified tile id to // the tile manager which loads up from the configured tileset // repository the appropriate tileset (which should be a // BaseTileSet) and then extracts the appropriate base tile (the // index of which is also in the fqTileId) try { if ( fqTileId <= 0 ) { _base [ tidx ] = null ; } else { _base [ tidx ] = ( BaseTile ) _tileMgr . getTile ( fqTileId ) ; } // clear out the fringe (it must be recomputed by the caller) _fringe [ tidx ] = null ; } catch ( ClassCastException cce ) { errmsg = "Scene contains non-base tile in base layer" ; } catch ( NoSuchTileSetException nste ) { errmsg = "Scene contains non-existent tileset" ; } if ( errmsg != null ) { log . warning ( errmsg + " [fqtid=" + fqTileId + ", x=" + tx + ", y=" + ty + "]." ) ; } }
Informs this scene block that the specified base tile has been changed .
273
14
138,539
public void updateFringe ( int tx , int ty ) { int tidx = index ( tx , ty ) ; if ( _base [ tidx ] != null ) { _fringe [ tidx ] = computeFringeTile ( tx , ty ) ; } }
Instructs this block to recompute its fringe at the specified location .
56
14
138,540
public void computeMemoryUsage ( Map < Tile . Key , BaseTile > bases , Set < BaseTile > fringes , Map < Tile . Key , ObjectTile > objects , long [ ] usage ) { // account for our base tiles for ( int yy = 0 ; yy < _bounds . height ; yy ++ ) { for ( int xx = 0 ; xx < _bounds . width ; xx ++ ) { int x = _bounds . x + xx , y = _bounds . y + yy ; int tidx = index ( x , y ) ; BaseTile base = _base [ tidx ] ; if ( base == null ) { continue ; } BaseTile sbase = bases . get ( base . key ) ; if ( sbase == null ) { bases . put ( base . key , base ) ; usage [ 0 ] += base . getEstimatedMemoryUsage ( ) ; } else if ( base != _base [ tidx ] ) { log . warning ( "Multiple instances of same base tile " + "[base=" + base + ", x=" + xx + ", y=" + yy + "]." ) ; usage [ 0 ] += base . getEstimatedMemoryUsage ( ) ; } // now account for the fringe if ( _fringe [ tidx ] == null ) { continue ; } else if ( ! fringes . contains ( _fringe [ tidx ] ) ) { fringes . add ( _fringe [ tidx ] ) ; usage [ 1 ] += _fringe [ tidx ] . getEstimatedMemoryUsage ( ) ; } } } // now get the object tiles int ocount = ( _objects == null ) ? 0 : _objects . length ; for ( int ii = 0 ; ii < ocount ; ii ++ ) { SceneObject scobj = _objects [ ii ] ; ObjectTile tile = objects . get ( scobj . tile . key ) ; if ( tile == null ) { objects . put ( scobj . tile . key , scobj . tile ) ; usage [ 2 ] += scobj . tile . getEstimatedMemoryUsage ( ) ; } else if ( tile != scobj . tile ) { log . warning ( "Multiple instances of same object tile: " + scobj . info + "." ) ; usage [ 2 ] += scobj . tile . getEstimatedMemoryUsage ( ) ; } } }
Computes the memory usage of the base and object tiles in this scene block ; registering counted tiles in the hash map so that other blocks can be sure not to double count them . Base tile usage is placed into the zeroth array element fringe tile usage into the first and object tile usage into the second .
501
62
138,541
protected final int index ( int tx , int ty ) { // if (!_bounds.contains(tx, ty)) { // String errmsg = "Coordinates out of bounds: +" + tx + "+" + ty + // " not in " + StringUtil.toString(_bounds); // throw new IllegalArgumentException(errmsg); // } return ( ty - _bounds . y ) * _bounds . width + ( tx - _bounds . x ) ; }
Returns the index into our arrays of the specified tile .
107
11
138,542
protected void update ( Map < Integer , SceneBlock > blocks ) { boolean recover = false ; // link up to our neighbors for ( int ii = 0 ; ii < DX . length ; ii ++ ) { SceneBlock neigh = blocks . get ( neighborKey ( DX [ ii ] , DY [ ii ] ) ) ; if ( neigh != _neighbors [ ii ] ) { _neighbors [ ii ] = neigh ; // if we're linking up to a neighbor for the first time; // we need to recalculate our coverage recover = recover || ( neigh != null ) ; // Log.info(this + " was introduced to " + neigh + "."); } } // if we need to regenerate the set of tiles covered by our // objects, do so if ( recover ) { for ( SceneObject _object : _objects ) { setCovered ( blocks , _object ) ; } } }
Links this block to its neighbors ; informs neighboring blocks of object coverage .
189
14
138,543
protected final int neighborKey ( int dx , int dy ) { int nx = MathUtil . floorDiv ( _bounds . x , _bounds . width ) + dx ; int ny = MathUtil . floorDiv ( _bounds . y , _bounds . height ) + dy ; return MisoScenePanel . compose ( nx , ny ) ; }
Computes the key of our neighbor .
81
8
138,544
protected final int blockKey ( int tx , int ty ) { int bx = MathUtil . floorDiv ( tx , _bounds . width ) ; int by = MathUtil . floorDiv ( ty , _bounds . height ) ; return MisoScenePanel . compose ( bx , by ) ; }
Computes the key for the block that holds the specified tile .
67
13
138,545
protected void setCovered ( Map < Integer , SceneBlock > blocks , SceneObject scobj ) { int endx = scobj . info . x - scobj . tile . getBaseWidth ( ) + 1 ; int endy = scobj . info . y - scobj . tile . getBaseHeight ( ) + 1 ; for ( int xx = scobj . info . x ; xx >= endx ; xx -- ) { for ( int yy = scobj . info . y ; yy >= endy ; yy -- ) { SceneBlock block = blocks . get ( blockKey ( xx , yy ) ) ; if ( block != null ) { block . setCovered ( xx , yy ) ; } } } // Log.info("Updated coverage " + scobj.info + "."); }
Sets the footprint of this object tile
172
8
138,546
public static void clearEditText ( String editText ) throws Exception { Client . getInstance ( ) . map ( Constants . ROBOTIUM_SOLO , "clearEditText" , editText ) ; }
Clears edit text for the specified widget
45
8
138,547
public static int [ ] getLocationOnScreen ( String view ) throws Exception { int [ ] location = new int [ 2 ] ; JSONArray results = Client . getInstance ( ) . map ( Constants . ROBOTIUM_SOLO , "getLocationOnScreen" , view ) ; location [ 0 ] = results . getInt ( 0 ) ; location [ 1 ] = results . getInt ( 1 ) ; return location ; }
Get the location of a view on the screen
91
9
138,548
public void applyToTiles ( Rectangle region , TileOp op ) { // determine which tiles intersect this region: this is going to // be nearly incomprehensible without some sort of diagram; i'll // do what i can to comment it, but you'll want to print out a // scene diagram (docs/miso/scene.ps) and start making notes if // you want to follow along // obtain our upper left tile Point tpos = MisoUtil . screenToTile ( _metrics , region . x , region . y , new Point ( ) ) ; // determine which quadrant of the upper left tile we occupy Point spos = MisoUtil . tileToScreen ( _metrics , tpos . x , tpos . y , new Point ( ) ) ; boolean left = ( region . x - spos . x < _metrics . tilehwid ) ; boolean top = ( region . y - spos . y < _metrics . tilehhei ) ; // set up our tile position counters int dx , dy ; if ( left ) { dx = 0 ; dy = 1 ; } else { dx = 1 ; dy = 0 ; } // if we're in the top-half of the tile we need to move up a row, // either forward or back depending on whether we're in the left // or right half of the tile if ( top ) { if ( left ) { tpos . x -= 1 ; } else { tpos . y -= 1 ; } // we'll need to start zig-zagging the other way as well dx = 1 - dx ; dy = 1 - dy ; } // these will bound our loops int rightx = region . x + region . width , bottomy = region . y + region . height ; // Log.info("Preparing to apply [tpos=" + StringUtil.toString(tpos) + // ", left=" + left + ", top=" + top + // ", bounds=" + StringUtil.toString(bounds) + // ", spos=" + StringUtil.toString(spos) + // "]."); // obtain the coordinates of the tile that starts the first row // and loop through, applying to the intersecting tiles MisoUtil . tileToScreen ( _metrics , tpos . x , tpos . y , spos ) ; while ( spos . y < bottomy ) { // set up our row counters int tx = tpos . x , ty = tpos . y ; _tbounds . x = spos . x ; _tbounds . y = spos . y ; // Log.info("Applying to row [tx=" + tx + ", ty=" + ty + "]."); // apply to the tiles in this row while ( _tbounds . x < rightx ) { op . apply ( tx , ty , _tbounds ) ; // move one tile to the right tx += 1 ; ty -= 1 ; _tbounds . x += _metrics . tilewid ; } // update our tile coordinates tpos . x += dx ; dx = 1 - dx ; tpos . y += dy ; dy = 1 - dy ; // obtain the screen coordinates of the next starting tile MisoUtil . tileToScreen ( _metrics , tpos . x , tpos . y , spos ) ; } }
Applies the supplied tile operation to all tiles that intersect the supplied screen rectangle .
710
16
138,549
public static final Tag findAncestorWithClass ( Tag from , Class klass ) { boolean isInterface = false ; if ( from == null || klass == null || ( ! Tag . class . isAssignableFrom ( klass ) && ! ( isInterface = klass . isInterface ( ) ) ) ) { return null ; } for ( ; ; ) { Tag tag = from . getParent ( ) ; if ( tag == null ) { return null ; } if ( ( isInterface && klass . isInstance ( tag ) ) || klass . isAssignableFrom ( tag . getClass ( ) ) ) return tag ; else from = tag ; } }
Find the instance of a given class type that is closest to a given instance . This method uses the getParent method from the Tag interface . This method is used for coordination among cooperating tags .
142
38
138,550
public void release ( ) { parent = null ; id = null ; if ( values != null ) { values . clear ( ) ; } values = null ; }
Release state .
33
3
138,551
public void setValue ( String k , Object o ) { if ( values == null ) { values = new Hashtable < String , Object > ( ) ; } values . put ( k , o ) ; }
Associate a value with a String key .
43
9
138,552
public Object getValue ( String k ) { if ( values == null ) { return null ; } else { return values . get ( k ) ; } }
Get a the value associated with a key .
32
9
138,553
public static int getDirection ( MisoSceneMetrics metrics , int ax , int ay , int bx , int by ) { Point afpos = new Point ( ) , bfpos = new Point ( ) ; // convert screen coordinates to full coordinates to get both // tile coordinates and fine coordinates screenToFull ( metrics , ax , ay , afpos ) ; screenToFull ( metrics , bx , by , bfpos ) ; // pull out the tile coordinates for each point int tax = fullToTile ( afpos . x ) ; int tay = fullToTile ( afpos . y ) ; int tbx = fullToTile ( bfpos . x ) ; int tby = fullToTile ( bfpos . y ) ; // compare tile coordinates to determine direction int dir = getIsoDirection ( tax , tay , tbx , tby ) ; if ( dir != DirectionCodes . NONE ) { return dir ; } // destination point is in the same tile as the // origination point, so consider fine coordinates // pull out the fine coordinates for each point int fax = afpos . x - ( tax * FULL_TILE_FACTOR ) ; int fay = afpos . y - ( tay * FULL_TILE_FACTOR ) ; int fbx = bfpos . x - ( tbx * FULL_TILE_FACTOR ) ; int fby = bfpos . y - ( tby * FULL_TILE_FACTOR ) ; // compare fine coordinates to determine direction dir = getIsoDirection ( fax , fay , fbx , fby ) ; // arbitrarily return southwest if fine coords were also equivalent return ( dir == - 1 ) ? SOUTHWEST : dir ; }
Given two points in screen pixel coordinates return the compass direction that point B lies in from point A from an isometric perspective .
381
25
138,554
public static int getProjectedIsoDirection ( int ax , int ay , int bx , int by ) { return toIsoDirection ( DirectionUtil . getDirection ( ax , ay , bx , by ) ) ; }
Given two points in screen coordinates return the isometrically projected compass direction that point B lies in from point A .
52
24
138,555
public static Point screenToTile ( MisoSceneMetrics metrics , int sx , int sy , Point tpos ) { // determine the upper-left of the quadrant that contains our point int zx = ( int ) Math . floor ( ( float ) sx / metrics . tilewid ) ; int zy = ( int ) Math . floor ( ( float ) sy / metrics . tilehei ) ; // these are the screen coordinates of the tile's top int ox = ( zx * metrics . tilewid ) , oy = ( zy * metrics . tilehei ) ; // these are the tile coordinates tpos . x = zy + zx ; tpos . y = zy - zx ; // now determine which of the four tiles our point occupies int dx = sx - ox , dy = sy - oy ; if ( Math . round ( metrics . slopeY * dx + metrics . tilehei ) <= dy ) { tpos . x += 1 ; } if ( Math . round ( metrics . slopeX * dx ) > dy ) { tpos . y -= 1 ; } // Log.info("Converted [sx=" + sx + ", sy=" + sy + // ", zx=" + zx + ", zy=" + zy + // ", ox=" + ox + ", oy=" + oy + // ", dx=" + dx + ", dy=" + dy + // ", tpos.x=" + tpos.x + ", tpos.y=" + tpos.y + "]."); return tpos ; }
Convert the given screen - based pixel coordinates to their corresponding tile - based coordinates . Converted coordinates are placed in the given point object .
326
27
138,556
public static Point tileToScreen ( MisoSceneMetrics metrics , int x , int y , Point spos ) { spos . x = ( x - y - 1 ) * metrics . tilehwid ; spos . y = ( x + y ) * metrics . tilehhei ; return spos ; }
Convert the given tile - based coordinates to their corresponding screen - based pixel coordinates . The screen coordinate for a tile is the upper - left coordinate of the rectangle that bounds the tile polygon . Converted coordinates are placed in the given point object .
66
49
138,557
public static void fineToPixel ( MisoSceneMetrics metrics , int x , int y , Point ppos ) { ppos . x = metrics . tilehwid + ( ( x - y ) * metrics . finehwid ) ; ppos . y = ( x + y ) * metrics . finehhei ; }
Convert the given fine coordinates to pixel coordinates within the containing tile . Converted coordinates are placed in the given point object .
68
24
138,558
public static void pixelToFine ( MisoSceneMetrics metrics , int x , int y , Point fpos ) { // calculate line parallel to the y-axis (from the given // x/y-pos to the x-axis) float bY = y - ( metrics . fineSlopeY * x ) ; // determine intersection of x- and y-axis lines int crossx = ( int ) ( ( bY - metrics . fineBX ) / ( metrics . fineSlopeX - metrics . fineSlopeY ) ) ; int crossy = ( int ) ( ( metrics . fineSlopeY * crossx ) + bY ) ; // TODO: final position should check distance between our // position and the surrounding fine coords and return the // actual closest fine coord, rather than just dividing. // determine distance along the x-axis float xdist = MathUtil . distance ( metrics . tilehwid , 0 , crossx , crossy ) ; fpos . x = ( int ) ( xdist / metrics . finelen ) ; // determine distance along the y-axis float ydist = MathUtil . distance ( x , y , crossx , crossy ) ; fpos . y = ( int ) ( ydist / metrics . finelen ) ; // Log.info("Pixel to fine " + StringUtil.coordsToString(x, y) + // " -> " + StringUtil.toString(fpos) + "."); }
Convert the given pixel coordinates whose origin is at the top - left of a tile s containing rectangle to fine coordinates within that tile . Converted coordinates are placed in the given point object .
315
37
138,559
public static Point screenToFull ( MisoSceneMetrics metrics , int sx , int sy , Point fpos ) { // get the tile coordinates Point tpos = new Point ( ) ; screenToTile ( metrics , sx , sy , tpos ) ; // get the screen coordinates for the containing tile Point spos = tileToScreen ( metrics , tpos . x , tpos . y , new Point ( ) ) ; // Log.info("Screen to full " + // "[screen=" + StringUtil.coordsToString(sx, sy) + // ", tpos=" + StringUtil.toString(tpos) + // ", spos=" + StringUtil.toString(spos) + // ", fpix=" + StringUtil.coordsToString( // sx-spos.x, sy-spos.y) + "]."); // get the fine coordinates within the containing tile pixelToFine ( metrics , sx - spos . x , sy - spos . y , fpos ) ; // toss in the tile coordinates for good measure fpos . x += ( tpos . x * FULL_TILE_FACTOR ) ; fpos . y += ( tpos . y * FULL_TILE_FACTOR ) ; return fpos ; }
Convert the given screen - based pixel coordinates to full scene - based coordinates that include both the tile coordinates and the fine coordinates in each dimension . Converted coordinates are placed in the given point object .
280
39
138,560
public static Point fullToScreen ( MisoSceneMetrics metrics , int x , int y , Point spos ) { // get the tile screen position int tx = fullToTile ( x ) , ty = fullToTile ( y ) ; Point tspos = tileToScreen ( metrics , tx , ty , new Point ( ) ) ; // get the pixel position of the fine coords within the tile Point ppos = new Point ( ) ; int fx = x - ( tx * FULL_TILE_FACTOR ) , fy = y - ( ty * FULL_TILE_FACTOR ) ; fineToPixel ( metrics , fx , fy , ppos ) ; // final position is tile position offset by fine position spos . x = tspos . x + ppos . x ; spos . y = tspos . y + ppos . y ; return spos ; }
Convert the given full coordinates to screen - based pixel coordinates . Converted coordinates are placed in the given point object .
190
23
138,561
public static Polygon getTilePolygon ( MisoSceneMetrics metrics , int x , int y ) { return getFootprintPolygon ( metrics , x , y , 1 , 1 ) ; }
Return a polygon framing the specified tile .
42
9
138,562
public static Polygon getMultiTilePolygon ( MisoSceneMetrics metrics , Point sp1 , Point sp2 ) { int x = Math . min ( sp1 . x , sp2 . x ) , y = Math . min ( sp1 . y , sp2 . y ) ; int width = Math . abs ( sp1 . x - sp2 . x ) + 1 , height = Math . abs ( sp1 . y - sp2 . y ) + 1 ; return getFootprintPolygon ( metrics , x , y , width , height ) ; }
Return a screen - coordinates polygon framing the two specified tile - coordinate points .
119
16
138,563
public static Polygon getFootprintPolygon ( MisoSceneMetrics metrics , int x , int y , int width , int height ) { SmartPolygon footprint = new SmartPolygon ( ) ; Point tpos = MisoUtil . tileToScreen ( metrics , x , y , new Point ( ) ) ; // start with top-center point int rx = tpos . x + metrics . tilehwid , ry = tpos . y ; footprint . addPoint ( rx , ry ) ; // right point rx += width * metrics . tilehwid ; ry += width * metrics . tilehhei ; footprint . addPoint ( rx , ry ) ; // bottom-center point rx -= height * metrics . tilehwid ; ry += height * metrics . tilehhei ; footprint . addPoint ( rx , ry ) ; // left point rx -= width * metrics . tilehwid ; ry -= width * metrics . tilehhei ; footprint . addPoint ( rx , ry ) ; // end with top-center point rx += height * metrics . tilehwid ; ry -= height * metrics . tilehhei ; footprint . addPoint ( rx , ry ) ; return footprint ; }
Returns a polygon framing the specified scene footprint .
267
10
138,564
public static Point tilePlusFineToFull ( MisoSceneMetrics metrics , int tileX , int tileY , int fineX , int fineY , Point full ) { int dtx = fineX / metrics . finegran ; int dty = fineY / metrics . finegran ; int fx = fineX - dtx * metrics . finegran ; if ( fx < 0 ) { dtx -- ; fx += metrics . finegran ; } int fy = fineY - dty * metrics . finegran ; if ( fy < 0 ) { dty -- ; fy += metrics . finegran ; } full . x = toFull ( tileX + dtx , fx ) ; full . y = toFull ( tileY + dty , fy ) ; return full ; }
Adds the supplied fine coordinates to the supplied tile coordinates to compute full coordinates .
170
15
138,565
public static Client getInstance ( ) { if ( instance == null ) { instance = new Client ( ) ; } instance . API_PORT = PortSingleton . getInstance ( ) . getPort ( ) ; return instance ; }
Gets a client instance on the roboremote port
47
11
138,566
protected void clearBubbles ( boolean all ) { for ( Iterator < BubbleGlyph > iter = _bubbles . iterator ( ) ; iter . hasNext ( ) ; ) { ChatGlyph rec = iter . next ( ) ; if ( all || isPlaceOrientedType ( rec . getType ( ) ) ) { _target . abortAnimation ( rec ) ; iter . remove ( ) ; } } }
Clear chat bubbles either all of them or just the place - oriented ones .
90
15
138,567
protected String splitNear ( String text , int pos ) { if ( pos >= text . length ( ) ) { return text ; } int forward = text . indexOf ( ' ' , pos ) ; int backward = text . lastIndexOf ( ' ' , pos ) ; int newpos = ( Math . abs ( pos - forward ) < Math . abs ( pos - backward ) ) ? forward : backward ; // if we couldn't find a decent place to split, just do it wherever if ( newpos == - 1 ) { newpos = pos ; } else { // actually split the space onto the first part newpos ++ ; } return text . substring ( 0 , newpos ) ; }
Split the text at the space nearest the specified location .
144
11
138,568
protected Point adjustLabel ( int type , Point labelpos ) { switch ( ChatLogic . modeOf ( type ) ) { case ChatLogic . SHOUT : case ChatLogic . EMOTE : case ChatLogic . THINK : labelpos . translate ( PAD * 2 , PAD * 2 ) ; break ; default : labelpos . translate ( PAD , PAD ) ; break ; } return labelpos ; }
Position the label based on the type .
90
8
138,569
protected Rectangle getRectWithOlds ( Rectangle r , List < BubbleGlyph > oldbubs ) { int n = oldbubs . size ( ) ; // if no old bubs, just return the new one. if ( n == 0 ) { return r ; } // otherwise, encompass all the oldies Rectangle bigR = null ; for ( int ii = 0 ; ii < n ; ii ++ ) { BubbleGlyph bub = oldbubs . get ( ii ) ; if ( ii == 0 ) { bigR = bub . getBubbleBounds ( ) ; } else { bigR = bigR . union ( bub . getBubbleBounds ( ) ) ; } } // and add space for the new boy bigR . width = Math . max ( bigR . width , r . width ) ; bigR . height += r . height ; return bigR ; }
Get a rectangle based on the old bubbles but with room for the new one .
192
16
138,570
protected Shape getTail ( int type , Rectangle r , Point speaker ) { // emotes don't actually have tails if ( ChatLogic . modeOf ( type ) == ChatLogic . EMOTE ) { return new Area ( ) ; // empty shape } int midx = r . x + ( r . width / 2 ) ; int midy = r . y + ( r . height / 2 ) ; // we actually want to start about SPEAKER_DISTANCE away from the // speaker int xx = speaker . x - midx ; int yy = speaker . y - midy ; float dist = ( float ) Math . sqrt ( xx * xx + yy * yy ) ; float perc = ( dist - SPEAKER_DISTANCE ) / dist ; if ( ChatLogic . modeOf ( type ) == ChatLogic . THINK ) { int steps = Math . max ( ( int ) ( dist / SPEAKER_DISTANCE ) , 2 ) ; float step = perc / steps ; Area a = new Area ( ) ; for ( int ii = 0 ; ii < steps ; ii ++ , perc -= step ) { int radius = Math . min ( SPEAKER_DISTANCE / 2 - 1 , ii + 2 ) ; a . add ( new Area ( new Ellipse2D . Float ( ( int ) ( ( 1 - perc ) * midx + perc * speaker . x ) + perc * radius , ( int ) ( ( 1 - perc ) * midy + perc * speaker . y ) + perc * radius , radius * 2 , radius * 2 ) ) ) ; } return a ; } // ELSE draw a triangular tail shape Polygon p = new Polygon ( ) ; p . addPoint ( ( int ) ( ( 1 - perc ) * midx + perc * speaker . x ) , ( int ) ( ( 1 - perc ) * midy + perc * speaker . y ) ) ; if ( Math . abs ( speaker . x - midx ) > Math . abs ( speaker . y - midy ) ) { int x ; if ( midx > speaker . x ) { x = r . x + PAD ; } else { x = r . x + r . width - PAD ; } p . addPoint ( x , midy - ( TAIL_WIDTH / 2 ) ) ; p . addPoint ( x , midy + ( TAIL_WIDTH / 2 ) ) ; } else { int y ; if ( midy > speaker . y ) { y = r . y + PAD ; } else { y = r . y + r . height - PAD ; } p . addPoint ( midx - ( TAIL_WIDTH / 2 ) , y ) ; p . addPoint ( midx + ( TAIL_WIDTH / 2 ) , y ) ; } return p ; }
Create a tail to the specified rectangular area from the speaker point .
631
13
138,571
protected List < BubbleGlyph > getAndExpireBubbles ( Name speaker ) { int num = _bubbles . size ( ) ; // first, get all the old bubbles belonging to the user List < BubbleGlyph > oldbubs = Lists . newArrayList ( ) ; if ( speaker != null ) { for ( int ii = 0 ; ii < num ; ii ++ ) { BubbleGlyph bub = _bubbles . get ( ii ) ; if ( bub . isSpeaker ( speaker ) ) { oldbubs . add ( bub ) ; } } } // see if we need to expire this user's oldest bubble if ( oldbubs . size ( ) >= MAX_BUBBLES_PER_USER ) { BubbleGlyph bub = oldbubs . remove ( 0 ) ; _bubbles . remove ( bub ) ; _target . abortAnimation ( bub ) ; // or some other old bubble } else if ( num >= MAX_BUBBLES ) { _target . abortAnimation ( _bubbles . remove ( 0 ) ) ; } // return the speaker's old bubbles return oldbubs ; }
Expire a bubble if necessary and return the old bubbles for the specified speaker .
240
16
138,572
protected Label layoutText ( Graphics2D gfx , Font font , String text ) { Label label = _logic . createLabel ( text ) ; label . setFont ( font ) ; // layout in one line Rectangle vbounds = _target . getViewBounds ( ) ; label . setTargetWidth ( vbounds . width - PAD * 2 ) ; label . layout ( gfx ) ; Dimension d = label . getSize ( ) ; // if the label is wide enough, try to split the text into multiple // lines if ( d . width > MINIMUM_SPLIT_WIDTH ) { int targetheight = getGoldenLabelHeight ( d ) ; if ( targetheight > 1 ) { label . setTargetHeight ( targetheight * d . height ) ; label . layout ( gfx ) ; } } return label ; }
Get a label formatted as close to the golden ratio as possible for the specified text and given the standard padding we use on all bubbles .
180
27
138,573
protected List < Shape > getAvoidList ( Name speaker ) { List < Shape > avoid = Lists . newArrayList ( ) ; if ( _provider == null ) { return avoid ; } // for now we don't accept low-priority avoids _provider . getAvoidables ( speaker , avoid , null ) ; // add the existing chatbub non-tail areas from other speakers for ( BubbleGlyph bub : _bubbles ) { if ( ! bub . isSpeaker ( speaker ) ) { avoid . add ( bub . getBubbleTerritory ( ) ) ; } } return avoid ; }
Return a list of rectangular areas that we should avoid while laying out a bubble for the specified speaker .
128
20
138,574
public void queueFile ( File file , boolean loop ) { try { queueURL ( file . toURI ( ) . toURL ( ) , loop ) ; } catch ( MalformedURLException e ) { log . warning ( "Invalid file url." , "file" , file , e ) ; } }
Adds a file to the queue of files to play .
65
11
138,575
public ActionFrames getActionFrames ( CharacterDescriptor descrip , String action ) throws NoSuchComponentException { Tuple < CharacterDescriptor , String > key = new Tuple < CharacterDescriptor , String > ( descrip , action ) ; ActionFrames frames = _actionFrames . get ( key ) ; if ( frames == null ) { // this doesn't actually composite the images, but prepares an // object to be able to do so frames = createCompositeFrames ( descrip , action ) ; _actionFrames . put ( key , frames ) ; } // periodically report our frame image cache performance if ( ! _cacheStatThrottle . throttleOp ( ) ) { long size = getEstimatedCacheMemoryUsage ( ) ; int [ ] eff = _frameCache . getTrackedEffectiveness ( ) ; log . debug ( "CharacterManager LRU [mem=" + ( size / 1024 ) + "k" + ", size=" + _frameCache . size ( ) + ", hits=" + eff [ 0 ] + ", misses=" + eff [ 1 ] + "]." ) ; } return frames ; }
Obtains the composited animation frames for the specified action for a character with the specified descriptor . The resulting composited animation will be cached .
234
28
138,576
public void resolveActionSequence ( CharacterDescriptor desc , String action ) { try { if ( getActionFrames ( desc , action ) == null ) { log . warning ( "Failed to resolve action sequence " + "[desc=" + desc + ", action=" + action + "]." ) ; } } catch ( NoSuchComponentException nsce ) { log . warning ( "Failed to resolve action sequence " + "[nsce=" + nsce + "]." ) ; } }
Informs the character manager that the action sequence for the given character descriptor is likely to be needed in the near future and so any efforts that can be made to load it into the action sequence cache in advance should be undertaken .
101
45
138,577
protected long getEstimatedCacheMemoryUsage ( ) { long size = 0 ; Iterator < CompositedMultiFrameImage > iter = _frameCache . values ( ) . iterator ( ) ; while ( iter . hasNext ( ) ) { size += iter . next ( ) . getEstimatedMemoryUsage ( ) ; } return size ; }
Returns the estimated memory usage in bytes for all images currently cached by the cached action frames .
70
18
138,578
@ Override public void processAuthorize ( WebSocketChannel channel , String authorizeToken ) { LOG . entering ( CLASS_NAME , "processAuthorize" ) ; WebSocketNativeChannel nativeChannel = ( WebSocketNativeChannel ) channel ; Proxy proxy = nativeChannel . getProxy ( ) ; proxy . processEvent ( XoaEventKind . AUTHORIZE , new String [ ] { authorizeToken } ) ; }
Set the authorize token for future requests for Basic authentication .
84
11
138,579
public static int byteArrayToInt ( byte [ ] b , int offset ) { int value = 0 ; for ( int i = 0 ; i < 4 ; i ++ ) { int shift = ( 4 - 1 - i ) * 8 ; value += ( b [ i + offset ] & 0x000000FF ) << shift ; } return value ; }
Convert the byte array to an int starting from the given offset .
73
14
138,580
public void setZations ( byte primary , byte secondary , byte tertiary , byte quaternary ) { zations = ( primary | ( secondary << 16 ) | ( tertiary << 24 ) | ( quaternary << 8 ) ) ; }
Sets the primary and secondary colorization assignments .
51
10
138,581
public < T extends View > ArrayList < T > getFilteredViews ( Class < T > classToFilterBy ) { ArrayList < T > filteredViews = new ArrayList < T > ( ) ; List < View > allViews = this . getViews ( ) ; for ( View view : allViews ) { if ( view != null && classToFilterBy . isAssignableFrom ( view . getClass ( ) ) ) { filteredViews . add ( classToFilterBy . cast ( view ) ) ; } } return filteredViews ; }
Filters through all views in current activity and gets those that inherit from a given class to filter by
122
20
138,582
public ArrayList < String > getVisibleText ( ) { ArrayList < TextView > textViews = getFilteredViews ( TextView . class ) ; ArrayList < String > allStrings = new ArrayList < String > ( ) ; for ( TextView v : textViews ) { if ( v . getVisibility ( ) == View . VISIBLE ) { String s = v . getText ( ) . toString ( ) ; allStrings . add ( s ) ; } } return allStrings ; }
Searches through all views and gets those containing text which are visible . Stips the text form each view and returns it as an arraylist .
112
30
138,583
public View getView ( int id , int timeout ) { View v = null ; int RETRY_PERIOD = 250 ; int retryNum = timeout / RETRY_PERIOD ; for ( int i = 0 ; i < retryNum ; i ++ ) { try { v = super . getView ( id ) ; } catch ( Exception e ) { } if ( v != null ) { break ; } this . sleep ( RETRY_PERIOD ) ; } return v ; }
Extend the normal robotium getView to retry every 250ms over 10s to get the view requested
105
22
138,584
public < T > boolean waitForResource ( int res , int timeout ) { int RETRY_PERIOD = 250 ; int retryNum = timeout / RETRY_PERIOD ; for ( int i = 0 ; i < retryNum ; i ++ ) { T View = ( T ) this . getView ( res ) ; if ( View != null ) { break ; } if ( i == retryNum - 1 ) { return false ; } this . sleep ( RETRY_PERIOD ) ; } return true ; }
Wait for a resource to become active
113
7
138,585
public ArrayList < View > getCustomViews ( String viewName ) { ArrayList < View > returnViews = new ArrayList < View > ( ) ; for ( View v : this . getViews ( ) ) { if ( v . getClass ( ) . getSimpleName ( ) . equals ( viewName ) ) returnViews . add ( v ) ; } return returnViews ; }
Gets views with a custom class name
85
8
138,586
public void waitForHintText ( String hintText , int timeout ) throws Exception { int RETRY_PERIOD = 250 ; int retryNum = timeout / RETRY_PERIOD ; for ( int i = 0 ; i < retryNum ; i ++ ) { ArrayList < View > imageViews = getCustomViews ( "EditText" ) ; for ( View v : imageViews ) { if ( ( ( EditText ) v ) . getHint ( ) == null ) continue ; if ( ( ( EditText ) v ) . getHint ( ) . equals ( hintText ) && v . getVisibility ( ) == View . VISIBLE ) return ; } this . sleep ( RETRY_PERIOD ) ; } throw new Exception ( String . format ( "Splash screen didn't disappear after %d ms" , timeout ) ) ; }
Waits for hint text to appear in an EditText
186
11
138,587
public void enterTextAndWait ( int fieldResource , String value ) { EditText textBox = ( EditText ) this . getView ( fieldResource ) ; this . enterText ( textBox , value ) ; this . waitForText ( value ) ; }
Enter text into a given field resource id
54
8
138,588
public String getLocalizedResource ( String namespace , String resourceId ) throws Exception { String resourceValue = "" ; Class r = Class . forName ( namespace + "$string" ) ; Field f = r . getField ( resourceId ) ; resourceValue = getCurrentActivity ( ) . getResources ( ) . getString ( f . getInt ( f ) ) ; return resourceValue ; }
Returns a string for a resourceId in the specified namespace
81
11
138,589
public String [ ] getLocalizedResourceArray ( String namespace , String resourceId ) throws Exception { Class r = Class . forName ( namespace + "$string" ) ; Field f = r . getField ( resourceId ) ; return getCurrentActivity ( ) . getResources ( ) . getStringArray ( f . getInt ( f ) ) ; }
Returns a string array for a specified string - array resourceId in the specified namespace
73
16
138,590
public void setPosition ( float x , float y , float z ) { if ( _px != x || _py != y || _pz != z ) { AL10 . alListener3f ( AL10 . AL_POSITION , _px = x , _py = y , _pz = z ) ; } }
Sets the position of the listener .
69
8
138,591
public void setVelocity ( float x , float y , float z ) { if ( _vx != x || _vy != y || _vz != z ) { AL10 . alListener3f ( AL10 . AL_VELOCITY , _vx = x , _vy = y , _vz = z ) ; } }
Sets the velocity of the listener .
73
8
138,592
public void setGain ( float gain ) { if ( _gain != gain ) { AL10 . alListenerf ( AL10 . AL_GAIN , _gain = gain ) ; } }
Sets the gain of the listener .
41
8
138,593
public boolean matches ( float [ ] hsv , int [ ] fhsv ) { // check to see that this color is sufficiently "close" to the // root color based on the supplied distance parameters if ( distance ( fhsv [ 0 ] , _fhsv [ 0 ] , Short . MAX_VALUE ) > range [ 0 ] * Short . MAX_VALUE ) { return false ; } // saturation and value don't wrap around like hue if ( Math . abs ( _hsv [ 1 ] - hsv [ 1 ] ) > range [ 1 ] || Math . abs ( _hsv [ 2 ] - hsv [ 2 ] ) > range [ 2 ] ) { return false ; } return true ; }
Returns true if this colorization matches the supplied color false otherwise .
150
13
138,594
public static int [ ] toFixedHSV ( float [ ] hsv , int [ ] fhsv ) { if ( fhsv == null ) { fhsv = new int [ hsv . length ] ; } for ( int ii = 0 ; ii < hsv . length ; ii ++ ) { // fhsv[i] = (int)(hsv[i]*Integer.MAX_VALUE); fhsv [ ii ] = ( int ) ( hsv [ ii ] * Short . MAX_VALUE ) ; } return fhsv ; }
Converts floating point HSV values to a fixed point integer representation .
119
14
138,595
public static int distance ( int a , int b , int N ) { return ( a > b ) ? Math . min ( a - b , b + N - a ) : Math . min ( b - a , a + N - b ) ; }
Returns the distance between the supplied to numbers modulo N .
53
12
138,596
public void setSceneModel ( MisoSceneModel model ) { _model = model ; // clear out old blocks and objects clearScene ( ) ; centerOnTile ( 0 , 0 ) ; if ( isShowing ( ) ) { rethink ( ) ; _remgr . invalidateRegion ( _vbounds ) ; } }
Configures this display with a scene model which will immediately be resolved and displayed .
68
16
138,597
protected void clearScene ( ) { _blocks . clear ( ) ; _vizobjs . clear ( ) ; _fringes . clear ( ) ; _masks . clear ( ) ; if ( _dpanel != null ) { _dpanel . newScene ( ) ; } }
Clears out our old scene business .
61
8
138,598
public void centerOnTile ( int tx , int ty ) { Rectangle trect = MisoUtil . getTilePolygon ( _metrics , tx , ty ) . getBounds ( ) ; int nx = trect . x + trect . width / 2 - _vbounds . width / 2 ; int ny = trect . y + trect . height / 2 - _vbounds . height / 2 ; // Log.info("Centering on t:" + StringUtil.coordsToString(tx, ty) + // " b:" + StringUtil.toString(trect) + // " vb: " + StringUtil.toString(_vbounds) + // ", n:" + StringUtil.coordsToString(nx, ny) + "."); setViewLocation ( nx , ny ) ; }
Moves the scene such that the specified tile is in the center .
189
14
138,599
protected void showFlagsDidChange ( int oldflags ) { if ( ( oldflags & SHOW_TIPS ) != ( _showFlags & SHOW_TIPS ) ) { for ( SceneObjectIndicator indic : _indicators . values ( ) ) { dirtyIndicator ( indic ) ; } } }
Called when our show flags have changed .
63
9