@@ -257,28 +257,43 @@ private void drawPath(Graphics2D g2d, MapDefinition mapDefinition) {
257257
258258 // Fourth pass: Draw costs
259259 if (graph == null ) {
260- // Fifth pass: Draw cell borders
261- drawCellBorders (g2d , mapDefinition );
262- return ;
260+ // Draw costs of the path
261+ drawCost (g2d , path );
262+ } else {
263+ // Draw costs of the entire graph
264+ drawCost (g2d , graph .getNodes ());
263265 }
264- for (Node [] row : graph .getNodes ()) {
265- for (Node node : row ) {
266- String cost = String .format ("%.2f" , node .getCost ());
267- if (node .getCost () == Double .MAX_VALUE ) {
268- cost = "∞" ;
269- }
270266
271- g2d .setColor (Color .BLACK );
272- g2d .drawString (
273- cost ,
274- node .getX () * CELL_SIZE + 5 ,
275- node .getY () * CELL_SIZE + 15
276- );
267+ // Fifth pass: Draw cell borders
268+ drawCellBorders (g2d , mapDefinition );
269+ }
270+
271+ private void drawCost (Graphics2D g2d , Node [][] nodes ) {
272+ for (Node [] row : nodes ) {
273+ for (Node node : row ) {
274+ drawCost (g2d , node );
277275 }
278276 }
277+ }
279278
280- // Fifth pass: Draw cell borders
281- drawCellBorders (g2d , mapDefinition );
279+ private void drawCost (Graphics2D g2d , LinkedList <Node > nodes ) {
280+ for (Node node : nodes ) {
281+ drawCost (g2d , node );
282+ }
283+ }
284+
285+ private void drawCost (Graphics2D g2d , Node node ) {
286+ String cost = String .format ("%.2f" , node .getCost ());
287+ if (node .getCost () == Double .MAX_VALUE ) {
288+ cost = "∞" ;
289+ }
290+
291+ g2d .setColor (Color .BLACK );
292+ g2d .drawString (
293+ cost ,
294+ node .getX () * CELL_SIZE + 5 ,
295+ node .getY () * CELL_SIZE + 15
296+ );
282297 }
283298
284299 private void drawCellBorders (Graphics2D g2d , MapDefinition mapDefinition ) {
0 commit comments