idx
int64
0
41.2k
question
stringlengths
73
5.81k
target
stringlengths
5
918
3,600
public static double clamp ( double value , double min , double max ) { final double fixed ; if ( value < min ) { fixed = min ; } else if ( value > max ) { fixed = max ; } else { fixed = value ; } return fixed ; }
Fix a value between an interval .
3,601
public static double curveValue ( double value , double dest , double speed ) { Check . different ( speed , 0.0 ) ; final double reciprocal = 1.0 / speed ; final double invReciprocal = 1.0 - reciprocal ; return value * invReciprocal + dest * reciprocal ; }
Apply progressive modifications to a value .
3,602
public static double getDistance ( double x1 , double y1 , double x2 , double y2 , int w2 , int h2 ) { final double maxX = x2 + w2 ; final double maxY = y2 + h2 ; double min = getDistance ( x1 , y1 , x2 , y2 ) ; for ( double x = x2 ; Double . compare ( x , maxX ) <= 0 ; x ++ ) { for ( double y = y2 ; Double . compare ( y , maxY ) <= 0 ; y ++ ) { final double dist = getDistance ( x1 , y1 , x , y ) ; if ( dist < min ) { min = dist ; } } } return min ; }
Get distance from point to area .
3,603
public static int getRounded ( double value , int round ) { Check . different ( round , 0 ) ; return ( int ) Math . floor ( value / round ) * round ; }
Get the rounded value .
3,604
public static int getRoundedC ( double value , int round ) { Check . different ( round , 0 ) ; return ( int ) Math . ceil ( value / round ) * round ; }
Get the rounded value with ceil .
3,605
public static Map < Transition , Collection < TileRef > > imports ( Media config ) { final Xml root = new Xml ( config ) ; final Collection < Xml > nodesTransition = root . getChildren ( NODE_TRANSITION ) ; final Map < Transition , Collection < TileRef > > transitions = new HashMap < > ( nodesTransition . size ( ) ) ; for ( final Xml nodeTransition : nodesTransition ) { final String groupIn = nodeTransition . readString ( ATTRIBUTE_GROUP_IN ) ; final String groupOut = nodeTransition . readString ( ATTRIBUTE_GROUP_OUT ) ; final String transitionType = nodeTransition . readString ( ATTRIBUTE_TRANSITION_TYPE ) ; final TransitionType type = TransitionType . from ( transitionType ) ; final Transition transition = new Transition ( type , groupIn , groupOut ) ; final Collection < Xml > nodesTileRef = nodeTransition . getChildren ( TileConfig . NODE_TILE ) ; final Collection < TileRef > tilesRef = importTiles ( nodesTileRef ) ; transitions . put ( transition , tilesRef ) ; } return transitions ; }
Import all transitions from configuration .
3,606
private static Collection < TileRef > importTiles ( Collection < Xml > nodesTileRef ) { final Collection < TileRef > tilesRef = new HashSet < > ( nodesTileRef . size ( ) ) ; for ( final Xml nodeTileRef : nodesTileRef ) { final TileRef tileRef = TileConfig . imports ( nodeTileRef ) ; tilesRef . add ( tileRef ) ; } return tilesRef ; }
Import all tiles from their nodes .
3,607
private static void exportTiles ( Xml nodeTransition , Collection < TileRef > tilesRef ) { for ( final TileRef tileRef : tilesRef ) { final Xml nodeTileRef = TileConfig . exports ( tileRef ) ; nodeTransition . add ( nodeTileRef ) ; } }
Export all tiles for the transition .
3,608
private void updateTile ( Tile tile , Tile neighbor , Circuit circuit ) { final Iterator < TileRef > iterator = getTiles ( circuit ) . iterator ( ) ; while ( iterator . hasNext ( ) ) { final TileRef newTile = iterator . next ( ) ; if ( mapGroup . getGroup ( newTile ) . equals ( mapGroup . getGroup ( tile ) ) ) { map . setTile ( map . createTile ( newTile . getSheet ( ) , newTile . getNumber ( ) , neighbor . getX ( ) , neighbor . getY ( ) ) ) ; break ; } } }
Update tile with new representation .
3,609
private Circuit getCircuitOverTransition ( Circuit circuit , Tile neighbor ) { final String group = getTransitiveGroup ( circuit , neighbor ) ; final Circuit newCircuit ; if ( TileGroupType . TRANSITION == mapGroup . getType ( circuit . getIn ( ) ) ) { newCircuit = new Circuit ( circuit . getType ( ) , group , circuit . getOut ( ) ) ; } else if ( TileGroupType . TRANSITION == mapGroup . getType ( circuit . getOut ( ) ) ) { newCircuit = new Circuit ( circuit . getType ( ) , circuit . getIn ( ) , group ) ; } else { newCircuit = circuit ; } return newCircuit ; }
Get the circuit supporting over existing transition .
3,610
private String getTransitiveGroup ( Circuit initialCircuit , Tile tile ) { final Set < Circuit > circuitSet = circuits . keySet ( ) ; final Collection < String > groups = new HashSet < > ( circuitSet . size ( ) ) ; final String groupIn = mapGroup . getGroup ( tile ) ; for ( final Circuit circuit : circuitSet ) { final String groupOut = circuit . getOut ( ) ; for ( final Tile neighbor : map . getNeighbors ( tile ) ) { final String groupNeighbor = mapGroup . getGroup ( neighbor ) ; if ( groupNeighbor . equals ( groupOut ) && ! groupNeighbor . equals ( groupIn ) ) { return groupOut ; } } groups . add ( groupOut ) ; } return getShortestTransitiveGroup ( groups , initialCircuit ) ; }
Get the transitive group by replacing the transition group name with the plain one .
3,611
private void computeRenderingPoint ( int width , int height ) { rx = ( int ) Math . floor ( origin . getX ( x , width ) ) ; ry = ( int ) Math . floor ( origin . getY ( y , height ) ) ; }
Compute the rendering point .
3,612
public void changeState ( Class < ? extends State > next ) { Check . notNull ( next ) ; final State from = current ; if ( current != null ) { last = current . getClass ( ) ; current . exit ( ) ; } if ( ! states . containsKey ( next ) ) { final State state = create ( next ) ; states . put ( next , state ) ; } current = states . get ( next ) ; current . enter ( ) ; listeners . forEach ( l -> l . notifyStateTransition ( from != null ? from . getClass ( ) : null , next ) ) ; }
Change the current state .
3,613
public boolean isState ( Class < ? extends State > state ) { if ( current != null ) { return current . getClass ( ) . equals ( state ) ; } return false ; }
Check the current state .
3,614
@ SuppressWarnings ( "unchecked" ) private State create ( Class < ? extends State > state ) { try { if ( configurer . isPresent ( ) ) { final AnimationConfig configAnimations = AnimationConfig . imports ( configurer . get ( ) ) ; final String name = converter . apply ( state ) ; final Animation animation = configAnimations . getAnimation ( name ) ; final Class < ? extends Feature > feature ; feature = ( Class < ? extends Feature > ) UtilReflection . getCompatibleConstructor ( state , FeatureProvider . class , Animation . class ) . getParameters ( ) [ PARAM_FEATURE_INDEX ] . getType ( ) ; return UtilReflection . create ( state , UtilReflection . getParamTypes ( feature , animation ) , getFeature ( feature ) , animation ) ; } return UtilReflection . createReduce ( state ) ; } catch ( final NoSuchMethodException exception ) { throw new LionEngineException ( exception ) ; } }
Create state from its type .
3,615
public void postUpdate ( ) { if ( current != null ) { final Class < ? extends State > next = current . checkTransitions ( last ) ; if ( next != null ) { changeState ( next ) ; } } }
Post update checking next transition if has .
3,616
private void clearMenus ( ) { for ( final Featurable menu : menus ) { menu . getFeature ( Identifiable . class ) . destroy ( ) ; handler . remove ( menu ) ; } menus . clear ( ) ; }
Clear current menus .
3,617
private void createMenus ( Collection < ActionRef > parents , Collection < ActionRef > actions ) { for ( final ActionRef action : actions ) { final Featurable menu = createMenu ( action ) ; if ( ! action . getRefs ( ) . isEmpty ( ) ) { generateSubMenu ( actions , action , menu ) ; } else if ( action . hasCancel ( ) ) { previous . put ( action , parents ) ; generateCancel ( action , menu ) ; } } for ( final Featurable current : menus ) { handler . add ( current ) ; } }
Create menus from actions .
3,618
private Featurable createMenu ( ActionRef action ) { final Featurable menu = factory . create ( Medias . create ( PATH . split ( action . getPath ( ) ) ) ) ; menus . add ( menu ) ; return menu ; }
Create menu from action and add to active menus .
3,619
private void generateSubMenu ( final Collection < ActionRef > parents , final ActionRef action , Featurable menu ) { menu . getFeature ( Actionable . class ) . setAction ( ( ) -> { clearMenus ( ) ; createMenus ( parents , action . getRefs ( ) ) ; } ) ; }
Generate sub menu creation if menu contains sub menu .
3,620
private void generateCancel ( final ActionRef action , Featurable menu ) { menu . getFeature ( Actionable . class ) . setAction ( ( ) -> { clearMenus ( ) ; final Collection < ActionRef > parents = previous . get ( action ) ; createMenus ( parents , parents ) ; } ) ; }
Generate cancel to go back .
3,621
private static void addFeatures ( Featurable featurable , Services services , Setup setup ) { final List < Feature > rawFeatures = FeaturableConfig . getFeatures ( services , setup ) ; final int length = rawFeatures . size ( ) ; for ( int i = 0 ; i < length ; i ++ ) { final Feature feature = rawFeatures . get ( i ) ; featurable . addFeature ( feature ) ; } featurable . addAfter ( services , setup ) ; }
Add all features declared in configuration .
3,622
public Setup getSetup ( Media media ) { Check . notNull ( media ) ; if ( ! setups . containsKey ( media ) ) { setups . put ( media , createSetup ( media ) ) ; } return setups . get ( media ) ; }
Get a setup reference from its media .
3,623
@ SuppressWarnings ( "unchecked" ) private Setup createSetup ( Media media ) { final Configurer configurer = new Configurer ( media ) ; try { final FeaturableConfig config = FeaturableConfig . imports ( configurer ) ; final String setup = config . getSetupName ( ) ; final Class < ? extends Setup > setupClass ; if ( setup . isEmpty ( ) ) { final Class < ? > clazz = classLoader . loadClass ( config . getClassName ( ) ) ; final Constructor < ? > constructor = UtilReflection . getCompatibleConstructorParent ( clazz , new Class < ? > [ ] { Services . class , Setup . class } ) ; setupClass = ( Class < ? extends Setup > ) constructor . getParameterTypes ( ) [ SETUP_INDEX ] ; } else { setupClass = ( Class < ? extends Setup > ) classLoader . loadClass ( config . getSetupName ( ) ) ; } return UtilReflection . create ( setupClass , new Class < ? > [ ] { Media . class } , media ) ; } catch ( final ClassNotFoundException exception ) { throw new LionEngineException ( exception , ERROR_SETUP_CLASS ) ; } catch ( final NoSuchMethodException exception ) { throw new LionEngineException ( exception , ERROR_CONSTRUCTOR_MISSING + media . getPath ( ) ) ; } }
Create a setup from its media .
3,624
private < O extends Featurable > O createFeaturable ( Class < O > type , Setup setup ) throws NoSuchMethodException { final O featurable = UtilReflection . createReduce ( type , services , setup ) ; addFeatures ( featurable , services , setup ) ; for ( final Feature feature : featurable . getFeatures ( ) ) { featurable . checkListener ( feature ) ; for ( final Feature other : featurable . getFeatures ( ) ) { if ( feature != other ) { other . checkListener ( feature ) ; } } } return featurable ; }
Create the featurable .
3,625
public static ImageHeader get ( Media media ) { Check . notNull ( media ) ; for ( final ImageHeaderReader reader : FORMATS ) { if ( reader . is ( media ) ) { return read ( media , reader ) ; } } throw new LionEngineException ( media , ERROR_READ ) ; }
Get the image info of the specified image media .
3,626
private static ImageHeader read ( Media media , ImageHeaderReader reader ) { Check . notNull ( media ) ; Check . notNull ( reader ) ; try ( InputStream input = media . getInputStream ( ) ) { return reader . readHeader ( input ) ; } catch ( final IOException exception ) { throw new LionEngineException ( exception , media , ERROR_READ ) ; } }
Read image header .
3,627
public static CollisionGroupConfig imports ( Xml root , MapTileCollision map ) { Check . notNull ( root ) ; Check . notNull ( map ) ; final Collection < Xml > childrenCollision = root . getChildren ( NODE_COLLISION ) ; final Map < String , CollisionGroup > groups = new HashMap < > ( childrenCollision . size ( ) ) ; for ( final Xml node : childrenCollision ) { final Collection < Xml > childrenFormula = node . getChildren ( CollisionFormulaConfig . NODE_FORMULA ) ; final Collection < CollisionFormula > formulas = new ArrayList < > ( childrenFormula . size ( ) ) ; for ( final Xml formula : childrenFormula ) { final String formulaName = formula . getText ( ) ; formulas . add ( map . getCollisionFormula ( formulaName ) ) ; } final String groupName = node . readString ( ATT_GROUP ) ; final CollisionGroup collision = new CollisionGroup ( groupName , formulas ) ; groups . put ( groupName , collision ) ; } return new CollisionGroupConfig ( groups ) ; }
Create the collision group data from node .
3,628
public static void exports ( Xml root , CollisionGroup group ) { Check . notNull ( root ) ; Check . notNull ( group ) ; final Xml node = root . createChild ( NODE_COLLISION ) ; node . writeString ( ATT_GROUP , group . getName ( ) ) ; for ( final CollisionFormula formula : group . getFormulas ( ) ) { final Xml nodeFormula = node . createChild ( CollisionFormulaConfig . NODE_FORMULA ) ; nodeFormula . setText ( formula . getName ( ) ) ; } }
Export the collision group data as a node .
3,629
public static void remove ( Xml root , String group ) { Check . notNull ( root ) ; Check . notNull ( group ) ; for ( final Xml node : root . getChildren ( NODE_COLLISION ) ) { if ( node . readString ( ATT_GROUP ) . equals ( group ) ) { root . removeChild ( node ) ; } } }
Remove the group node .
3,630
public static boolean has ( Xml root , String group ) { Check . notNull ( root ) ; Check . notNull ( group ) ; for ( final Xml node : root . getChildren ( NODE_COLLISION ) ) { if ( node . readString ( ATT_GROUP ) . equals ( group ) ) { return true ; } } return false ; }
Check if node has group node .
3,631
public static TileSheetsConfig imports ( Media configSheets ) { final Xml nodeSheets = new Xml ( configSheets ) ; final Xml nodeTileSize = nodeSheets . getChild ( NODE_TILE_SIZE ) ; final int tileWidth = nodeTileSize . readInteger ( ATT_TILE_WIDTH ) ; final int tileHeight = nodeTileSize . readInteger ( ATT_TILE_HEIGHT ) ; final Collection < String > sheets = importSheets ( nodeSheets ) ; return new TileSheetsConfig ( tileWidth , tileHeight , sheets ) ; }
Import the sheets data from configuration .
3,632
public static void exports ( Media configSheets , int tileWidth , int tileHeight , Collection < String > sheets ) { Check . notNull ( configSheets ) ; Check . notNull ( sheets ) ; final Xml nodeSheets = new Xml ( NODE_TILE_SHEETS ) ; nodeSheets . writeString ( Constant . XML_HEADER , Constant . ENGINE_WEBSITE ) ; final Xml tileSize = nodeSheets . createChild ( NODE_TILE_SIZE ) ; tileSize . writeString ( ATT_TILE_WIDTH , String . valueOf ( tileWidth ) ) ; tileSize . writeString ( ATT_TILE_HEIGHT , String . valueOf ( tileHeight ) ) ; exportSheets ( nodeSheets , sheets ) ; nodeSheets . save ( configSheets ) ; }
Export the sheets configuration .
3,633
private static Collection < String > importSheets ( Xml nodeSheets ) { final Collection < Xml > children = nodeSheets . getChildren ( NODE_TILE_SHEET ) ; final Collection < String > sheets = new ArrayList < > ( children . size ( ) ) ; for ( final Xml nodeSheet : children ) { final String sheetFilename = nodeSheet . getText ( ) ; sheets . add ( sheetFilename ) ; } return sheets ; }
Import the defined sheets .
3,634
private static void exportSheets ( Xml nodeSheets , Collection < String > sheets ) { for ( final String sheet : sheets ) { final Xml nodeSheet = nodeSheets . createChild ( NODE_TILE_SHEET ) ; nodeSheet . setText ( sheet ) ; } }
Export the defined sheets .
3,635
public static Force fromVector ( double ox , double oy , double x , double y ) { final double dh = x - ox ; final double dv = y - oy ; final double norm ; if ( dh > dv ) { norm = Math . abs ( dh ) ; } else { norm = Math . abs ( dv ) ; } final double sx ; final double sy ; if ( Double . compare ( norm , 0.0 ) == 0 ) { sx = 0 ; sy = 0 ; } else { sx = dh / norm ; sy = dv / norm ; } final Force force = new Force ( sx , sy ) ; force . setVelocity ( norm ) ; return force ; }
Create a force from a vector movement .
3,636
public void addDirection ( double extrp , Direction direction ) { addDirection ( extrp , direction . getDirectionHorizontal ( ) , direction . getDirectionVertical ( ) ) ; }
Increase direction with input value .
3,637
public void addDirection ( double extrp , double fh , double fv ) { fhLast = fh ; fvLast = fv ; this . fh += fh * extrp ; this . fv += fv * extrp ; fixForce ( ) ; }
Increase forces with input value .
3,638
public void setDirection ( double fh , double fv ) { fhLast = fh ; fvLast = fv ; this . fh = fh ; this . fv = fv ; fixForce ( ) ; }
Set directions .
3,639
private void updateLastForce ( ) { if ( Double . compare ( fhLast , fhDest ) != 0 ) { fhLast = fhDest ; arrivedH = false ; } if ( Double . compare ( fvLast , fvDest ) != 0 ) { fvLast = fvDest ; arrivedV = false ; } }
Update the last direction .
3,640
private void updateNotArrivedH ( double extrp ) { if ( fh < fhDest ) { fh += velocity * extrp ; if ( fh > fhDest - sensibility ) { fh = fhDest ; arrivedH = true ; } } else if ( fh > fhDest ) { fh -= velocity * extrp ; if ( fh < fhDest + sensibility ) { fh = fhDest ; arrivedH = true ; } } }
Update the force if still not reached on horizontal axis .
3,641
private void updateNotArrivedV ( double extrp ) { if ( fv < fvDest ) { fv += velocity * extrp ; if ( fv > fvDest - sensibility ) { fv = fvDest ; arrivedV = true ; } } else if ( fv > fvDest ) { fv -= velocity * extrp ; if ( fv < fvDest + sensibility ) { fv = fvDest ; arrivedV = true ; } } }
Update the force if still not reached on vertical axis .
3,642
private void fixForce ( ) { final double minH ; final double minV ; final double maxH ; final double maxV ; if ( directionMin == null ) { minH = fh ; minV = fv ; } else { minH = directionMin . getDirectionHorizontal ( ) ; minV = directionMin . getDirectionVertical ( ) ; } if ( directionMax == null ) { maxH = fh ; maxV = fv ; } else { maxH = directionMax . getDirectionHorizontal ( ) ; maxV = directionMax . getDirectionVertical ( ) ; } fh = UtilMath . clamp ( fh , minH , maxH ) ; fv = UtilMath . clamp ( fv , minV , maxV ) ; }
Fix the force to its limited range .
3,643
public void loadCollisions ( MapTileCollision mapCollision , Media collisionFormulas , Media collisionGroups ) { if ( collisionFormulas . exists ( ) ) { loadCollisionFormulas ( collisionFormulas ) ; } if ( collisionGroups . exists ( ) ) { loadCollisionGroups ( mapCollision , collisionGroups ) ; } loadTilesCollisions ( mapCollision ) ; applyConstraints ( ) ; }
Load map collision from an external file .
3,644
public void loadCollisions ( MapTileCollision mapCollision , CollisionFormulaConfig formulasConfig , CollisionGroupConfig groupsConfig ) { loadCollisionFormulas ( formulasConfig ) ; loadCollisionGroups ( groupsConfig ) ; loadTilesCollisions ( mapCollision ) ; applyConstraints ( ) ; }
Load map collision with default files .
3,645
public CollisionFormula getCollisionFormula ( String name ) { if ( formulas . containsKey ( name ) ) { return formulas . get ( name ) ; } throw new LionEngineException ( ERROR_FORMULA + name ) ; }
Get the collision formula from its name .
3,646
public CollisionGroup getCollisionGroup ( String name ) { if ( groups . containsKey ( name ) ) { return groups . get ( name ) ; } throw new LionEngineException ( ERROR_FORMULA + name ) ; }
Get the collision group from its name .
3,647
private void loadCollisionFormulas ( Media formulasConfig ) { Verbose . info ( INFO_LOAD_FORMULAS , formulasConfig . getFile ( ) . getPath ( ) ) ; this . formulasConfig = formulasConfig ; final CollisionFormulaConfig config = CollisionFormulaConfig . imports ( formulasConfig ) ; loadCollisionFormulas ( config ) ; }
Load the collision formula . All previous collisions will be cleared .
3,648
private void loadCollisionGroups ( MapTileCollision mapCollision , Media groupsConfig ) { Verbose . info ( INFO_LOAD_GROUPS , groupsConfig . getFile ( ) . getPath ( ) ) ; this . groupsConfig = groupsConfig ; final Xml nodeGroups = new Xml ( groupsConfig ) ; final CollisionGroupConfig config = CollisionGroupConfig . imports ( nodeGroups , mapCollision ) ; loadCollisionGroups ( config ) ; }
Load the collision groups . All previous groups will be cleared .
3,649
private void loadTilesCollisions ( MapTileCollision mapCollision ) { for ( int v = 0 ; v < map . getInTileHeight ( ) ; v ++ ) { for ( int h = 0 ; h < map . getInTileWidth ( ) ; h ++ ) { final Tile tile = map . getTile ( h , v ) ; if ( tile != null ) { loadTileCollisions ( mapCollision , tile ) ; } } } }
Load collisions for each tile . Previous collisions will be removed .
3,650
private void loadTileCollisions ( MapTileCollision mapCollision , Tile tile ) { final TileCollision tileCollision ; if ( ! tile . hasFeature ( TileCollision . class ) ) { tileCollision = new TileCollisionModel ( tile ) ; tile . addFeature ( tileCollision ) ; } else { tileCollision = tile . getFeature ( TileCollision . class ) ; } tileCollision . removeCollisionFormulas ( ) ; addTileCollisions ( mapCollision , tileCollision , tile ) ; }
Load the tile collisions .
3,651
private void addTileCollisions ( MapTileCollision mapCollision , TileCollision tileCollision , Tile tile ) { final TileRef ref = new TileRef ( tile ) ; for ( final CollisionGroup collision : mapCollision . getCollisionGroups ( ) ) { final Collection < TileRef > group = mapGroup . getGroup ( collision . getName ( ) ) ; if ( group . contains ( ref ) ) { for ( final CollisionFormula formula : collision . getFormulas ( ) ) { tileCollision . addCollisionFormula ( formula ) ; } } } }
Add the tile collisions from loaded configuration .
3,652
private void applyConstraints ( ) { final Map < Tile , Collection < CollisionFormula > > toRemove = new HashMap < > ( ) ; for ( int v = 0 ; v < map . getInTileHeight ( ) ; v ++ ) { for ( int h = 0 ; h < map . getInTileWidth ( ) ; h ++ ) { final Tile tile = map . getTile ( h , v ) ; if ( tile != null ) { final TileCollision tileCollision = tile . getFeature ( TileCollision . class ) ; toRemove . put ( tile , checkConstraints ( tileCollision , h , v ) ) ; } } } for ( final Entry < Tile , Collection < CollisionFormula > > current : toRemove . entrySet ( ) ) { final Tile tile = current . getKey ( ) ; final TileCollision tileCollision = tile . getFeature ( TileCollision . class ) ; for ( final CollisionFormula formula : current . getValue ( ) ) { tileCollision . removeCollisionFormula ( formula ) ; } } }
Apply tile constraints depending of their adjacent collisions .
3,653
private Collection < CollisionFormula > checkConstraints ( TileCollision tile , int h , int v ) { final Tile top = map . getTile ( h , v + 1 ) ; final Tile bottom = map . getTile ( h , v - 1 ) ; final Tile left = map . getTile ( h - 1 , v ) ; final Tile right = map . getTile ( h + 1 , v ) ; final Collection < CollisionFormula > toRemove = new ArrayList < > ( ) ; for ( final CollisionFormula formula : tile . getCollisionFormulas ( ) ) { final CollisionConstraint constraint = formula . getConstraint ( ) ; if ( checkConstraint ( constraint . getConstraints ( Orientation . NORTH ) , top ) || checkConstraint ( constraint . getConstraints ( Orientation . SOUTH ) , bottom ) || checkConstraint ( constraint . getConstraints ( Orientation . WEST ) , left ) || checkConstraint ( constraint . getConstraints ( Orientation . EAST ) , right ) ) { toRemove . add ( formula ) ; } } return toRemove ; }
Check the tile constraints and get the removable formulas .
3,654
private boolean checkConstraint ( Collection < String > constraints , Tile tile ) { return tile != null && constraints . contains ( mapGroup . getGroup ( tile ) ) && ! tile . getFeature ( TileCollision . class ) . getCollisionFormulas ( ) . isEmpty ( ) ; }
Check the constraint with the specified tile .
3,655
public void addPoint ( double x , double y ) { if ( npoints >= xpoints . length ) { final int newLength = npoints * 2 ; xpoints = Arrays . copyOf ( xpoints , newLength ) ; ypoints = Arrays . copyOf ( ypoints , newLength ) ; } xpoints [ npoints ] = x ; ypoints [ npoints ] = y ; npoints ++ ; updateBounds ( ) ; }
Add a point to the polygon .
3,656
public Collection < Line > getPoints ( ) { final Collection < Line > list = new ArrayList < > ( npoints ) ; for ( int i = 0 ; i < npoints / 2 ; i ++ ) { list . add ( new Line ( xpoints [ i ] , ypoints [ i ] , xpoints [ i + npoints / 2 ] , ypoints [ i + npoints / 2 ] ) ) ; } return list ; }
Get the points .
3,657
private void updateBounds ( ) { if ( npoints >= MIN_POINTS ) { double boundsMinX = Double . MAX_VALUE ; double boundsMinY = Double . MAX_VALUE ; double boundsMaxX = - Double . MAX_VALUE ; double boundsMaxY = - Double . MAX_VALUE ; for ( int i = 0 ; i < npoints ; i ++ ) { final double x = xpoints [ i ] ; boundsMinX = Math . min ( boundsMinX , x ) ; boundsMaxX = Math . max ( boundsMaxX , x ) ; final double y = ypoints [ i ] ; boundsMinY = Math . min ( boundsMinY , y ) ; boundsMaxY = Math . max ( boundsMaxY , y ) ; } bounds . set ( boundsMinX , boundsMinY , boundsMaxX - boundsMinX , boundsMaxY - boundsMinY ) ; } }
Update the bounds .
3,658
public Resolution getScaled ( double factorX , double factorY ) { Check . superiorStrict ( factorX , 0 ) ; Check . superiorStrict ( factorY , 0 ) ; return new Resolution ( ( int ) ( width * factorX ) , ( int ) ( height * factorY ) , rate ) ; }
Get scaled resolution .
3,659
public static TileRef imports ( Xml nodeTile ) { Check . notNull ( nodeTile ) ; final int sheet = nodeTile . readInteger ( ATT_TILE_SHEET ) ; final int number = nodeTile . readInteger ( ATT_TILE_NUMBER ) ; return new TileRef ( sheet , number ) ; }
Create the tile data from node .
3,660
public static Xml exports ( TileRef tileRef ) { Check . notNull ( tileRef ) ; final Xml node = new Xml ( NODE_TILE ) ; node . writeInteger ( ATT_TILE_SHEET , tileRef . getSheet ( ) . intValue ( ) ) ; node . writeInteger ( ATT_TILE_NUMBER , tileRef . getNumber ( ) ) ; return node ; }
Export the tile as a node .
3,661
public static SurfaceConfig imports ( Configurer configurer ) { Check . notNull ( configurer ) ; return imports ( configurer . getRoot ( ) ) ; }
Create the surface data from configurer .
3,662
private static boolean checkPixel ( MapTile map , ImageBuffer tileRef , int progressTileX , int progressTileY ) { final int x = progressTileX * map . getTileWidth ( ) ; final int y = progressTileY * map . getTileHeight ( ) ; final int pixel = tileRef . getRgb ( x , y ) ; if ( TilesExtractor . IGNORED_COLOR_VALUE != pixel ) { final Tile tile = searchForTile ( map , tileRef , progressTileX , progressTileY ) ; if ( tile == null ) { return false ; } map . setTile ( tile ) ; } return true ; }
Check the pixel by searching tile on sheet .
3,663
private static Tile searchForTile ( MapTile map , ImageBuffer tileSprite , int x , int y ) { for ( final Integer sheet : map . getSheets ( ) ) { final Tile tile = checkTile ( map , tileSprite , sheet , x , y ) ; if ( tile != null ) { return tile ; } } return null ; }
Search current tile of image map by checking all surfaces .
3,664
private static Tile checkTile ( MapTile map , ImageBuffer tileSprite , Integer sheet , int x , int y ) { final int tw = map . getTileWidth ( ) ; final int th = map . getTileHeight ( ) ; final SpriteTiled tileSheet = map . getSheet ( sheet ) ; final ImageBuffer sheetImage = tileSheet . getSurface ( ) ; final int tilesInX = tileSheet . getWidth ( ) / tw ; final int tilesInY = tileSheet . getHeight ( ) / th ; for ( int surfaceCurrentTileY = 0 ; surfaceCurrentTileY < tilesInY ; surfaceCurrentTileY ++ ) { for ( int surfaceCurrentTileX = 0 ; surfaceCurrentTileX < tilesInX ; surfaceCurrentTileX ++ ) { final int number = surfaceCurrentTileX + surfaceCurrentTileY * tilesInX ; final int xa = x * tw ; final int ya = y * th ; final int xb = surfaceCurrentTileX * tw ; final int yb = surfaceCurrentTileY * th ; if ( TilesExtractor . compareTile ( tw , th , tileSprite , xa , ya , sheetImage , xb , yb ) ) { return map . createTile ( sheet , number , xa , ( map . getInTileHeight ( ) - 1.0 - y ) * th ) ; } } } return null ; }
Check tile of sheet .
3,665
private static StateUpdater createCheck ( Cursor cursor , SelectorModel model , AtomicReference < StateUpdater > start ) { return ( extrp , current ) -> { if ( model . isEnabled ( ) && cursor . getClick ( ) == 0 ) { return start . get ( ) ; } return current ; } ; }
Create check action .
3,666
private StateUpdater createStart ( Cursor cursor , SelectorModel model , StateUpdater check , StateUpdater select ) { return ( extrp , current ) -> { StateUpdater next = current ; if ( ! model . isEnabled ( ) ) { next = check ; } else if ( model . getSelectionClick ( ) == cursor . getClick ( ) ) { checkBeginSelection ( cursor , model ) ; if ( model . isSelecting ( ) ) { next = select ; } } return next ; } ; }
Create start action .
3,667
private void checkBeginSelection ( Cursor cursor , SelectorModel model ) { final boolean canClick = ! model . getClickableArea ( ) . contains ( cursor . getScreenX ( ) , cursor . getScreenY ( ) ) ; if ( ! model . isSelecting ( ) && ! canClick ) { model . setSelecting ( true ) ; startX = cursor . getX ( ) ; startY = cursor . getY ( ) ; for ( final SelectorListener listener : listeners ) { listener . notifySelectionStarted ( Geom . createArea ( startX , startY , 0 , 0 ) ) ; } } }
Check if can begin selection . Notify listeners if started .
3,668
private void computeSelection ( Viewer viewer , Cursor cursor , SelectorModel model ) { final double viewX = viewer . getX ( ) + viewer . getViewX ( ) ; final double viewY = viewer . getY ( ) - viewer . getViewY ( ) ; final double currentX = UtilMath . clamp ( cursor . getX ( ) , viewX , viewX + viewer . getWidth ( ) ) ; final double currentY = UtilMath . clamp ( cursor . getY ( ) , viewY , viewY + viewer . getHeight ( ) ) ; double selectX = startX ; double selectY = startY ; model . setSelectRawY ( selectY ) ; model . setSelectRawH ( startY - currentY ) ; double selectW = currentX - startX ; if ( selectW < 0 ) { selectX += selectW ; selectW = - selectW ; } double selectH = currentY - startY ; if ( selectH < 0 ) { selectY += selectH ; selectH = - selectH ; } model . getSelectionArea ( ) . set ( selectX , selectY , selectW , selectH ) ; }
Compute the selection from cursor location .
3,669
public static Map < Circuit , Collection < TileRef > > imports ( Media circuitsConfig ) { Check . notNull ( circuitsConfig ) ; final Xml root = new Xml ( circuitsConfig ) ; final Collection < Xml > nodesCircuit = root . getChildren ( NODE_CIRCUIT ) ; final Map < Circuit , Collection < TileRef > > circuits = new HashMap < > ( nodesCircuit . size ( ) ) ; for ( final Xml nodeCircuit : nodesCircuit ) { final String groupIn = nodeCircuit . readString ( ATT_GROUP_IN ) ; final String groupOut = nodeCircuit . readString ( ATT_GROUP_OUT ) ; final String circuitType = nodeCircuit . readString ( ATT_CIRCUIT_TYPE ) ; final CircuitType type = CircuitType . from ( circuitType ) ; final Circuit circuit = new Circuit ( type , groupIn , groupOut ) ; final Collection < Xml > nodesTileRef = nodeCircuit . getChildren ( TileConfig . NODE_TILE ) ; final Collection < TileRef > tilesRef = importTiles ( nodesTileRef ) ; circuits . put ( circuit , tilesRef ) ; } return circuits ; }
Import all circuits from configuration .
3,670
private List < SpriteTiled > getRasters ( Integer sheet ) { return rasterSheets . computeIfAbsent ( sheet , s -> { final List < SpriteTiled > rasters = new ArrayList < > ( RasterImage . MAX_RASTERS ) ; rasterSheets . put ( s , rasters ) ; return rasters ; } ) ; }
Get the associated raster sheets for a sheet number . Create it if needed .
3,671
public void terminate ( ) { try { in . close ( ) ; } catch ( final IOException exception ) { Verbose . exception ( exception ) ; } try { out . close ( ) ; } catch ( final IOException exception ) { Verbose . exception ( exception ) ; } try { socket . close ( ) ; } catch ( final IOException exception ) { Verbose . exception ( exception ) ; } state = StateConnection . DISCONNECTED ; }
Terminate client .
3,672
public byte [ ] receiveMessages ( ) { try { final byte [ ] data ; final int size = in . available ( ) ; if ( size <= 0 ) { data = null ; } else { data = new byte [ size ] ; in . readFully ( data ) ; } return data ; } catch ( final IOException exception ) { Verbose . exception ( exception ) ; return new byte [ 0 ] ; } }
Receive messages data from the client .
3,673
private static Integer getLayer ( Featurable featurable ) { if ( featurable . hasFeature ( Layerable . class ) ) { final Layerable layerable = featurable . getFeature ( Layerable . class ) ; return layerable . getLayerDisplay ( ) ; } return LAYER_DEFAULT ; }
Get the featurable layer .
3,674
private void remove ( Integer layer , Displayable displayable ) { final Collection < Displayable > displayables = getLayer ( layer ) ; displayables . remove ( displayable ) ; if ( displayables . isEmpty ( ) ) { indexs . remove ( layer ) ; } }
Remove displayable and its layer .
3,675
public void reset ( ) { for ( final Tile tile : revealed ) { final Tile reset = new TileGame ( tile . getSheet ( ) , FOG , tile . getX ( ) , tile . getY ( ) , tile . getWidth ( ) , tile . getHeight ( ) ) ; map . setTile ( reset ) ; } revealed . clear ( ) ; }
Reset the revealed tiles to fogged .
3,676
private void actionWillProduce ( ) { if ( checker . checkProduction ( current ) ) { startProduction ( current ) ; state = ProducerState . PRODUCING ; } else { for ( final ProducerListener listener : listeners ) { listener . notifyCanNotProduce ( current ) ; } } }
Action called from update production in will produce state .
3,677
private void actionProducing ( double extrp ) { for ( final ProducerListener listener : listeners ) { listener . notifyProducing ( currentObject ) ; } for ( final ProducibleListener listener : current . getFeature ( Producible . class ) . getListeners ( ) ) { listener . notifyProductionProgress ( this ) ; } progress += speed * extrp ; if ( progress >= steps ) { progress = steps ; state = ProducerState . PRODUCED ; } }
Action called from update production in producing state .
3,678
private void actionProduced ( ) { for ( final ProducerListener listener : listeners ) { listener . notifyProduced ( currentObject ) ; } for ( final ProducibleListener listener : current . getFeature ( Producible . class ) . getListeners ( ) ) { listener . notifyProductionEnded ( this ) ; } currentObject = null ; progress = - 1 ; if ( ! productions . isEmpty ( ) ) { state = ProducerState . CHECK ; } else { state = ProducerState . NONE ; } }
Action called from update production in produced state .
3,679
private void startProduction ( Featurable featurable ) { final Transformable transformable = featurable . getFeature ( Transformable . class ) ; final Producible producible = featurable . getFeature ( Producible . class ) ; transformable . setLocation ( producible . getX ( ) , producible . getY ( ) ) ; handler . add ( featurable ) ; currentObject = featurable ; speed = stepsPerSecond / rate . getAsInt ( ) ; steps = current . getFeature ( Producible . class ) . getSteps ( ) ; progress = 0.0 ; for ( final ProducerListener listener : listeners ) { listener . notifyStartProduction ( featurable ) ; } for ( final ProducibleListener listener : featurable . getFeature ( Producible . class ) . getListeners ( ) ) { listener . notifyProductionStarted ( this ) ; } }
Start production of this element . Get its corresponding instance and add it to the handler . Featurable will be removed from handler if production is cancelled .
3,680
public static FramesConfig imports ( Configurer configurer ) { Check . notNull ( configurer ) ; return imports ( configurer . getRoot ( ) ) ; }
Imports the frames config from configurer .
3,681
public static FramesConfig imports ( Xml root ) { Check . notNull ( root ) ; final Xml node = root . getChild ( NODE_FRAMES ) ; final int horizontals = node . readInteger ( ATT_HORIZONTAL ) ; final int verticals = node . readInteger ( ATT_VERTICAL ) ; final int offsetX = node . readInteger ( 0 , ATT_OFFSET_X ) ; final int offsetY = node . readInteger ( 0 , ATT_OFFSET_Y ) ; return new FramesConfig ( horizontals , verticals , offsetX , offsetY ) ; }
Imports the frames config from node .
3,682
public static Xml exports ( FramesConfig config ) { Check . notNull ( config ) ; final Xml node = new Xml ( NODE_FRAMES ) ; node . writeInteger ( ATT_HORIZONTAL , config . getHorizontal ( ) ) ; node . writeInteger ( ATT_VERTICAL , config . getVertical ( ) ) ; node . writeInteger ( ATT_OFFSET_X , config . getOffsetX ( ) ) ; node . writeInteger ( ATT_OFFSET_Y , config . getOffsetY ( ) ) ; return node ; }
Exports the frames node from config .
3,683
public static Integer imports ( Configurer configurer ) { Check . notNull ( configurer ) ; if ( configurer . hasNode ( NODE_GROUP ) ) { final String group = configurer . getText ( NODE_GROUP ) ; try { return Integer . valueOf ( group ) ; } catch ( final NumberFormatException exception ) { throw new LionEngineException ( exception , ERROR_INVALID_GROUP + group ) ; } } return DEFAULT_GROUP ; }
Create the collidable data from node .
3,684
public static void exports ( Xml root , Collidable collidable ) { Check . notNull ( root ) ; Check . notNull ( collidable ) ; final Xml node = root . createChild ( NODE_GROUP ) ; node . setText ( collidable . getGroup ( ) . toString ( ) ) ; }
Create an XML node from a collidable .
3,685
public static boolean compareTile ( int tw , int th , ImageBuffer a , int xa , int ya , ImageBuffer b , int xb , int yb ) { for ( int x = 0 ; x < tw ; x ++ ) { for ( int y = 0 ; y < th ; y ++ ) { final int colorA = a . getRgb ( x + xa , y + ya ) ; final int colorB = b . getRgb ( x + xb , y + yb ) ; if ( colorA != colorB ) { return false ; } } } return true ; }
Compare two tiles by checking all pixels .
3,686
private static boolean isExtracted ( SpriteTiled level , int x , int y , Collection < ImageBuffer > tiles ) { final int tw = level . getTileWidth ( ) ; final int th = level . getTileHeight ( ) ; final ImageBuffer surface = level . getSurface ( ) ; for ( final ImageBuffer tile : tiles ) { if ( compareTile ( tw , th , surface , x , y , tile , 0 , 0 ) ) { return true ; } } return false ; }
Check if tile has already been extracted regarding the current tile on level rip .
3,687
private static ImageBuffer extract ( SpriteTiled level , int number ) { final ColorRgba transparency = level . getSurface ( ) . getTransparentColor ( ) ; final ImageBuffer tile = Graphics . createImageBuffer ( level . getTileWidth ( ) , level . getTileHeight ( ) , transparency ) ; final Graphic g = tile . createGraphic ( ) ; level . setTile ( number ) ; level . render ( g ) ; g . dispose ( ) ; final ImageBuffer copy = Graphics . getImageBuffer ( tile ) ; tile . dispose ( ) ; return copy ; }
Extract the tile from level .
3,688
private static int getTilesNumber ( int tileWidth , int tileHeight , Collection < Media > levelRips ) { int tiles = 0 ; for ( final Media levelRip : levelRips ) { final ImageHeader info = ImageInfo . get ( levelRip ) ; final int horizontalTiles = info . getWidth ( ) / tileWidth ; final int verticalTiles = info . getHeight ( ) / tileHeight ; tiles += horizontalTiles * verticalTiles ; } return tiles ; }
Get the total number of tiles .
3,689
private int extract ( Canceler canceler , SpriteTiled level , int tilesNumber , Collection < ImageBuffer > tiles , int checkedTiles ) { final int horizontalTiles = level . getTilesHorizontal ( ) ; final int verticalTiles = level . getTilesVertical ( ) ; final ImageBuffer surface = level . getSurface ( ) ; final int tw = level . getTileWidth ( ) ; final int th = level . getTileHeight ( ) ; int checked = checkedTiles ; int oldPercent = 0 ; for ( int v = 0 ; v < verticalTiles ; v ++ ) { for ( int h = 0 ; h < horizontalTiles ; h ++ ) { final int x = h * tw ; final int y = v * th ; if ( IGNORED_COLOR_VALUE != surface . getRgb ( x , y ) && ! isExtracted ( level , x , y , tiles ) ) { final ImageBuffer tile = extract ( level , h + v * horizontalTiles ) ; tiles . add ( tile ) ; } checked ++ ; oldPercent = updateProgress ( checked , tilesNumber , oldPercent , tiles ) ; if ( canceler != null && canceler . isCanceled ( ) ) { return - 1 ; } } } return checked ; }
Proceed the specified level rip .
3,690
private int updateProgress ( int checkedTiles , int tilesNumber , int oldPercent , Collection < ImageBuffer > tiles ) { final int percent = getProgressPercent ( checkedTiles , tilesNumber ) ; if ( percent != oldPercent ) { for ( final ProgressListener listener : listeners ) { listener . notifyProgress ( percent , tiles ) ; } } return percent ; }
Update progress and notify if needed .
3,691
public void rotate ( double angle ) { final double x2 = x + width ; final double y2 = y ; final double x3 = x2 ; final double y3 = y + height ; final double x4 = x ; final double y4 = y3 ; final double cx = x + width / 2.0 ; final double cy = y + height / 2.0 ; final double a = UtilMath . wrapDouble ( angle , 0 , 360 ) ; final double cos = UtilMath . cos ( a ) ; final double sin = UtilMath . sin ( a ) ; final double rx1 = cos * ( x - cx ) - sin * ( y - cy ) + cx ; final double ry1 = sin * ( x - cx ) + cos * ( y - cy ) + cy ; final double rx2 = cos * ( x2 - cx ) - sin * ( y2 - cy ) + cx ; final double ry2 = sin * ( x2 - cx ) + cos * ( y2 - cy ) + cy ; final double rx3 = cos * ( x3 - cx ) - sin * ( y3 - cy ) + cx ; final double ry3 = sin * ( x3 - cx ) + cos * ( y3 - cy ) + cy ; final double rx4 = cos * ( x4 - cx ) - sin * ( y4 - cy ) + cx ; final double ry4 = sin * ( x4 - cx ) + cos * ( y4 - cy ) + cy ; final double nx1 = Math . min ( Math . min ( Math . min ( rx1 , rx2 ) , rx3 ) , rx4 ) ; final double ny1 = Math . max ( Math . max ( Math . max ( ry1 , ry2 ) , ry3 ) , ry4 ) ; final double nx2 = Math . max ( Math . max ( Math . max ( rx1 , rx2 ) , rx3 ) , rx4 ) ; final double ny3 = Math . min ( Math . min ( Math . min ( ry1 , ry2 ) , ry3 ) , ry4 ) ; x = nx1 ; y = ny3 ; width = nx2 - nx1 ; height = ny1 - ny3 ; }
Rotate rectangle with specific angle .
3,692
public void set ( double x , double y , double w , double h ) { this . x = x ; this . y = y ; width = w ; height = h ; }
Sets the location and size .
3,693
public static Raster load ( Media media ) { Check . notNull ( media ) ; final Xml root = new Xml ( media ) ; final RasterData dataRed = RasterData . load ( root , CHANNEL_RED ) ; final RasterData dataGreen = RasterData . load ( root , CHANNEL_GREEN ) ; final RasterData dataBlue = RasterData . load ( root , CHANNEL_BLUE ) ; return new Raster ( dataRed , dataGreen , dataBlue ) ; }
Load raster from media .
3,694
public static Collection < PathCategory > imports ( Media configPathfinding ) { Check . notNull ( configPathfinding ) ; final Xml nodeCategories = new Xml ( configPathfinding ) ; final Collection < Xml > childrenTile = nodeCategories . getChildren ( TILE_PATH ) ; final Collection < PathCategory > categories = new HashSet < > ( childrenTile . size ( ) ) ; for ( final Xml node : childrenTile ) { final String name = node . readString ( CATEGORY ) ; final Collection < Xml > childrenGroup = node . getChildren ( TileGroupsConfig . NODE_GROUP ) ; final Collection < String > groups = new HashSet < > ( childrenGroup . size ( ) ) ; for ( final Xml groupNode : childrenGroup ) { groups . add ( groupNode . getText ( ) ) ; } final PathCategory category = new PathCategory ( name , groups ) ; categories . add ( category ) ; } return categories ; }
Import the category data from configuration .
3,695
private void addBorderLabels ( ) { borderLabels = new JLabel [ 6 ] [ 6 ] ; int [ ] labelLocations_X_forColumn = new int [ ] { 0 , 1 , 2 , 3 , 4 , 11 } ; int [ ] labelLocations_Y_forRow = new int [ ] { 0 , 1 , 2 , 5 , 6 , 12 } ; int [ ] labelWidthsInCells_forColumn = new int [ ] { 0 , 1 , 1 , 1 , 7 , 1 } ; int [ ] labelHeightsInCells_forRow = new int [ ] { 0 , 1 , 3 , 1 , 6 , 1 } ; Point [ ] allBorderLabelIndexes = new Point [ ] { new Point ( 1 , 1 ) , new Point ( 2 , 1 ) , new Point ( 3 , 1 ) , new Point ( 4 , 1 ) , new Point ( 5 , 1 ) , new Point ( 1 , 2 ) , new Point ( 3 , 2 ) , new Point ( 5 , 2 ) , new Point ( 1 , 3 ) , new Point ( 2 , 3 ) , new Point ( 3 , 3 ) , new Point ( 4 , 3 ) , new Point ( 5 , 3 ) , new Point ( 1 , 4 ) , new Point ( 3 , 4 ) , new Point ( 5 , 4 ) , new Point ( 1 , 5 ) , new Point ( 2 , 5 ) , new Point ( 3 , 5 ) , new Point ( 4 , 5 ) , new Point ( 5 , 5 ) } ; for ( Point index : allBorderLabelIndexes ) { Point labelLocationCell = new Point ( labelLocations_X_forColumn [ index . x ] , labelLocations_Y_forRow [ index . y ] ) ; Dimension labelSizeInCells = new Dimension ( labelWidthsInCells_forColumn [ index . x ] , labelHeightsInCells_forRow [ index . y ] ) ; JLabel label = new JLabel ( ) ; label . setOpaque ( true ) ; label . setVisible ( false ) ; borderLabels [ index . x ] [ index . y ] = label ; centerPanel . add ( label , CC . xywh ( labelLocationCell . x , labelLocationCell . y , labelSizeInCells . width , labelSizeInCells . height ) ) ; } }
addBorderLabels This adds the border labels to the calendar panel and to the two dimensional border labels array .
3,696
private void addDateLabels ( ) { dateLabels = new ArrayList < JLabel > ( ) ; for ( int i = 0 ; i < 42 ; ++ i ) { int dateLabelColumnX = ( ( i % 7 ) ) + constantFirstDateLabelCell . x ; int dateLabelRowY = ( ( i / 7 ) + constantFirstDateLabelCell . y ) ; JLabel dateLabel = new JLabel ( ) ; dateLabel . setHorizontalAlignment ( SwingConstants . CENTER ) ; dateLabel . setVerticalAlignment ( SwingConstants . CENTER ) ; dateLabel . setBackground ( Color . white ) ; dateLabel . setForeground ( Color . black ) ; dateLabel . setBorder ( null ) ; dateLabel . setOpaque ( true ) ; dateLabel . setText ( "" + i ) ; CellConstraints constraints = CC . xy ( dateLabelColumnX , dateLabelRowY ) ; centerPanel . add ( dateLabel , constraints ) ; dateLabels . add ( dateLabel ) ; dateLabel . addMouseListener ( new MouseLiberalAdapter ( ) { public void mouseLiberalClick ( MouseEvent e ) { dateLabelMousePressed ( e ) ; } } ) ; } }
addDateLabels This adds a set of 42 date labels to the calendar and ties each of those labels to a mouse click event handler . The date labels are reused any time that the calendar is redrawn .
3,697
private void addWeekNumberLabels ( ) { weekNumberLabels = new ArrayList < JLabel > ( ) ; int weekNumberLabelColumnX = constantFirstWeekNumberLabelCell . x ; int weekNumberLabelWidthInCells = 1 ; int weekNumberLabelHeightInCells = 1 ; for ( int i = 0 ; i < 6 ; ++ i ) { int weekNumberLabelRowY = ( i + constantFirstWeekNumberLabelCell . y ) ; JLabel weekNumberLabel = new JLabel ( ) ; weekNumberLabel . setHorizontalAlignment ( SwingConstants . CENTER ) ; weekNumberLabel . setVerticalAlignment ( SwingConstants . CENTER ) ; weekNumberLabel . setBorder ( new EmptyBorder ( constantWeekNumberLabelInsets ) ) ; weekNumberLabel . setOpaque ( true ) ; weekNumberLabel . setText ( "3" + i ) ; weekNumberLabel . setVisible ( false ) ; CellConstraints constraints = CC . xywh ( weekNumberLabelColumnX , weekNumberLabelRowY , weekNumberLabelWidthInCells , weekNumberLabelHeightInCells ) ; centerPanel . add ( weekNumberLabel , constraints ) ; weekNumberLabels . add ( weekNumberLabel ) ; } setSizeOfWeekNumberLabels ( ) ; }
addWeekNumberLabels This adds a set of 6 week number labels to the calendar panel . The text of these labels is set with locale sensitive week numbers each time that the calendar is redrawn .
3,698
private void addWeekdayLabels ( ) { weekdayLabels = new ArrayList < JLabel > ( ) ; int weekdayLabelRowY = constantFirstWeekdayLabelCell . y ; int weekdayLabelWidthInCells = 1 ; int weekdayLabelHeightInCells = 3 ; for ( int i = 0 ; i < 7 ; ++ i ) { int weekdayLabelColumnX = ( i + constantFirstWeekdayLabelCell . x ) ; JLabel weekdayLabel = new JLabel ( ) ; weekdayLabel . setHorizontalAlignment ( SwingConstants . CENTER ) ; weekdayLabel . setVerticalAlignment ( SwingConstants . CENTER ) ; weekdayLabel . setBorder ( new EmptyBorder ( 0 , 2 , 0 , 2 ) ) ; weekdayLabel . setOpaque ( true ) ; weekdayLabel . setText ( "wd" + i ) ; CellConstraints constraints = CC . xywh ( weekdayLabelColumnX , weekdayLabelRowY , weekdayLabelWidthInCells , weekdayLabelHeightInCells ) ; centerPanel . add ( weekdayLabel , constraints ) ; weekdayLabels . add ( weekdayLabel ) ; } }
addWeekdayLabels This adds a set of 7 weekday labels to the calendar panel . The text of these labels is set with locale sensitive weekday names each time that the calendar is redrawn .
3,699
private void addTopLeftLabel ( ) { topLeftLabel = new JLabel ( ) ; topLeftLabel . setOpaque ( true ) ; topLeftLabel . setVisible ( false ) ; centerPanel . add ( topLeftLabel , CC . xywh ( constantTopLeftLabelCell . x , constantTopLeftLabelCell . y , 1 , 3 ) ) ; }
addTopLeftLabel This adds the top left label to the center panel .