private int adjustFont(Graphics2D g2, Dimension size, DiagramColors diagramColors) {
   g2.setFont(diagramColors.initialFont);
   if (fontHasAppropriateSize(g2, size, diagramColors.initialFont)) {
     return diagramColors.fontSize;
   } else {
     Font currentFont = diagramColors.initialFont;
     int currentFontSize = diagramColors.fontSize;
     for (int n = 0; n < boxes.length; n++) {
       if (currentFontSize <= diagramColors.minimalFontSize) {
         break;
       }
       ;
       DiagramBox currentBox = boxes[n];
       if (currentBox.fontSizeIsSuitable(currentFont, g2, size)) {
         continue;
       } else {
         if (currentBox.fontSizeIsSuitable(diagramColors.minimalFont, g2, size)) {
           Font lowerFont = diagramColors.minimalFont;
           int lowerFontSize = diagramColors.minimalFontSize;
           int upperFontSize = currentFontSize;
           int iterationNumber = 0;
           while (true) {
             iterationNumber = iterationNumber + 1;
             if (iterationNumber > 100) {
               break;
             }
             ;
             if (upperFontSize > lowerFontSize + 1) {
               int newFontSize = PrologInteger.toInteger((upperFontSize + lowerFontSize) / 2);
               Font newFont = DiagramUtils.computeFont(diagramColors, newFontSize);
               if (currentBox.fontSizeIsSuitable(newFont, g2, size)) {
                 lowerFont = newFont;
                 lowerFontSize = newFontSize;
               } else {
                 upperFontSize = newFontSize;
               }
             } else {
               currentFont = lowerFont;
               currentFontSize = lowerFontSize;
               break;
             }
           }
         } else {
           currentFont = diagramColors.minimalFont;
           currentFontSize = diagramColors.minimalFontSize;
         }
       }
     }
     ;
     g2.setFont(currentFont);
     return currentFontSize;
   }
 }
 public boolean boxContextIsOK(Map<String, ComponentState> componentSuccess) {
   String mother = motherIdentifier;
   int boxNumber = localNumber;
   while (true) {
     if (boxNumber > 0) {
       try {
         DiagramContent graph = DiagramTable.getDiagramContent(mother);
         DiagramBox box = graph.boxes[boxNumber - 1];
         if (!box.isOK(componentSuccess)) {
           return false;
         }
         ;
         mother = graph.motherIdentifier;
         boxNumber = graph.localNumber;
       } catch (DiagramTableEntryDoesNotExist e) {
         return false;
       }
     } else {
       return true;
     }
   }
 }