/[classpath]/classpath/javax/swing/border/TitledBorder.java
ViewVC logotype

Diff of /classpath/javax/swing/border/TitledBorder.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.10 by rabbit78, Mon Sep 19 09:59:59 2005 UTC revision 1.11 by trebligd, Mon Oct 10 08:28:48 2005 UTC
# Line 1  Line 1 
1  /* TitledBorder.java --  /* TitledBorder.java --
2     Copyright (C) 2003, 2004  Free Software Foundation, Inc.     Copyright (C) 2003, 2004, 2005  Free Software Foundation, Inc.
3    
4  This file is part of GNU Classpath.  This file is part of GNU Classpath.
5    
# Line 304  public class TitledBorder Line 304  public class TitledBorder
304    public TitledBorder(String title)    public TitledBorder(String title)
305    {    {
306      this(/* border */ null,      this(/* border */ null,
307           title, DEFAULT_JUSTIFICATION, DEFAULT_POSITION,           title, LEADING, TOP,
308           /* titleFont */ null, /* titleColor */ null);           /* titleFont */ null, /* titleColor */ null);
309    }    }
310    
# Line 317  public class TitledBorder Line 317  public class TitledBorder
317     */     */
318    public TitledBorder(Border border)    public TitledBorder(Border border)
319    {    {
320      this(border, /* title */ "", DEFAULT_JUSTIFICATION, DEFAULT_POSITION,      this(border, /* title */ "", LEADING, TOP,
321           /* titleFont */ null, /* titleColor */ null);           /* titleFont */ null, /* titleColor */ null);
322    }    }
323        
# Line 333  public class TitledBorder Line 333  public class TitledBorder
333     */     */
334    public TitledBorder(Border border, String title)    public TitledBorder(Border border, String title)
335    {    {
336      this(border, title, DEFAULT_JUSTIFICATION, DEFAULT_POSITION,      this(border, title, LEADING, TOP,
337           /* titleFont */ null, /* titleColor */ null);           /* titleFont */ null, /* titleColor */ null);
338    }    }
339        
# Line 507  public class TitledBorder Line 507  public class TitledBorder
507        public void paint(Graphics g)        public void paint(Graphics g)
508        {        {
509          if (b != null)          if (b != null)
510            b.paintBorder(c, g, x, y, width - 1, height - 1);            b.paintBorder(c, g, x, y, width, height);
511        }        }
512    
513    
# Line 565  public class TitledBorder Line 565  public class TitledBorder
565          if (stripeHeight > 0)          if (stripeHeight > 0)
566          {          {
567            paint(g, x, holeY, holeX - x, stripeHeight);  // patches #2 and #3            paint(g, x, holeY, holeX - x, stripeHeight);  // patches #2 and #3
568            paint(g, holeX + holeWidth, holeY, width - (holeX + holeWidth), stripeHeight);            paint(g, holeX + holeWidth, holeY, x + width - (holeX + holeWidth), stripeHeight);
569          }          }
570    
571          stripeHeight = height - (holeY - y + holeHeight);          stripeHeight = height - (holeY - y + holeHeight);
# Line 577  public class TitledBorder Line 577  public class TitledBorder
577      BorderPainter bp;      BorderPainter bp;
578      int textX, textY, borderWidth, borderHeight;      int textX, textY, borderWidth, borderHeight;
579    
580      borderWidth = width - (mes.borderSpacing.left + mes.borderSpacing.right);      borderWidth = width - (mes.outerSpacing.left + mes.outerSpacing.right);
581      borderHeight = height - (mes.borderSpacing.top + mes.borderSpacing.bottom);      borderHeight = height - (mes.outerSpacing.top + mes.outerSpacing.bottom);
582      bp = new BorderPainter(c, getBorder(),      bp = new BorderPainter(c, getBorder(),
583                             x + mes.borderSpacing.left, y + mes.borderSpacing.top,                             x + mes.outerSpacing.left, y + mes.outerSpacing.top,
584                             borderWidth, borderHeight);                             borderWidth, borderHeight);
585    
586      switch (getRealTitleJustification(c))      switch (getRealTitleJustification(c))
587      {      {
588      case LEFT:      case LEFT:
589        textX = x + TEXT_INSET_H;        textX = x + EDGE_SPACING + TEXT_INSET_H;
590        break;        break;
591    
592      case CENTER:      case CENTER:
# Line 604  public class TitledBorder Line 604  public class TitledBorder
604      switch (titlePosition)      switch (titlePosition)
605      {      {
606      case ABOVE_TOP:      case ABOVE_TOP:
607        textY = y;        textY = y + EDGE_SPACING;
608        break;        break;
609    
610      case TOP:      case TOP:
611      case DEFAULT_POSITION:      case DEFAULT_POSITION:
612      default:      default:
613        textY = y + mes.borderSpacing.top + mes.borderInsets.top - mes.textAscent        textY = y + mes.outerSpacing.top + mes.borderInsets.top - mes.textAscent
614                + mes.lineHeight;                + mes.lineHeight;
615        break;        break;
616    
617      case BELOW_TOP:      case BELOW_TOP:
618        textY = y + mes.borderSpacing.top + mes.borderInsets.top + TEXT_SPACING;        textY = y + mes.outerSpacing.top + mes.borderInsets.top + TEXT_SPACING;
619        break;        break;
620    
621      case ABOVE_BOTTOM:      case ABOVE_BOTTOM:
622        textY = y + height - mes.borderSpacing.bottom - mes.borderInsets.bottom        textY = y + height - mes.outerSpacing.bottom - mes.borderInsets.bottom
623          - TEXT_SPACING - (mes.textAscent + mes.textDescent);          - TEXT_SPACING - (mes.textAscent + mes.textDescent);
624        break;        break;
625    
# Line 644  public class TitledBorder Line 644  public class TitledBorder
644          g.setFont(oldFont);          g.setFont(oldFont);
645          g.setColor(oldColor);          g.setColor(oldColor);
646        }        }
647        bp.paintExcept(g, textX - 2, textY,        bp.paintExcept(g, textX, textY,
648                       mes.textWidth + 2, mes.textAscent + mes.textDescent);                       mes.textWidth, mes.textAscent + mes.textDescent);
649      }      }
650    }    }
651        
# Line 1002  public class TitledBorder Line 1002  public class TitledBorder
1002          m.trimmedText = null;          m.trimmedText = null;
1003      }      }
1004            
     m.textAscent = fmet.getAscent();  
     m.textDescent = fmet.getDescent();  
   
     FontRenderContext frc = new FontRenderContext(new AffineTransform(), false,  
                                                   false);  
     LineMetrics lmet = m.font.getLineMetrics(m.trimmedText, 0,  
                                              m.trimmedText.length(), frc);  
     m.lineHeight = (int) lmet.getStrikethroughOffset();  
     // Fallback in case that LineMetrics is not available/working.  
     if (m.lineHeight == 0)  
       m.lineHeight = (int) (0.3333 * (double) m.textAscent);  
   
1005      if (m.trimmedText != null)      if (m.trimmedText != null)
1006        m.textWidth = fmet.stringWidth(m.trimmedText) + 3;        {
1007            m.textAscent = fmet.getAscent();
1008            m.textDescent = fmet.getDescent() + fmet.getLeading();
1009    
1010      m.edgeSpacing = new Insets(EDGE_SPACING, EDGE_SPACING, EDGE_SPACING, EDGE_SPACING);          FontRenderContext frc = new FontRenderContext(new AffineTransform(),
1011      m.borderSpacing = new Insets(0, 0, 0, 0);              false, false);
1012            LineMetrics lmet = m.font.getLineMetrics(m.trimmedText, 0,
1013                m.trimmedText.length(), frc);
1014            m.lineHeight = (int) lmet.getStrikethroughOffset();
1015            
1016            // Fallback in case that LineMetrics is not available/working.
1017            if (m.lineHeight == 0)
1018              m.lineHeight = (int) (0.3333 * (double) m.textAscent);
1019            m.textWidth = fmet.stringWidth(m.trimmedText) + 3;
1020          }
1021        else
1022          {
1023            m.textAscent = 0;
1024            m.textDescent = 0;
1025          }
1026    
1027        m.innerSpacing = new Insets(EDGE_SPACING, EDGE_SPACING, EDGE_SPACING,
1028                EDGE_SPACING);
1029        m.outerSpacing = new Insets(EDGE_SPACING, EDGE_SPACING, EDGE_SPACING,
1030                EDGE_SPACING);
1031    
1032      switch (titlePosition)      switch (titlePosition)
1033      {      {
1034      case ABOVE_TOP:      case ABOVE_TOP:
1035        m.borderSpacing.top += m.textAscent + m.textDescent + TEXT_SPACING;        m.outerSpacing.top += m.textAscent + m.textDescent + TEXT_SPACING;
1036        break;        break;
1037    
1038        case TOP:
1039          m.outerSpacing.top += m.textDescent + m.lineHeight;
1040          m.innerSpacing.top += m.textAscent - m.lineHeight;
1041          break;
1042          
1043      case BELOW_TOP:      case BELOW_TOP:
1044        m.edgeSpacing.top += m.textAscent + m.textDescent + TEXT_SPACING;        m.innerSpacing.top += m.textAscent + m.textDescent + TEXT_SPACING;
1045        break;        break;
1046    
1047      case ABOVE_BOTTOM:      case ABOVE_BOTTOM:
1048        m.edgeSpacing.bottom += m.textAscent + m.textDescent + TEXT_SPACING;        m.innerSpacing.bottom += m.textAscent + m.textDescent + TEXT_SPACING;
1049        break;        break;
1050    
1051      case BOTTOM:      case BOTTOM:
1052        m.edgeSpacing.bottom += Math.max(m.textAscent - m.borderInsets.bottom, 0);        m.innerSpacing.bottom += Math.max(m.textAscent - m.lineHeight, 0);
1053        m.borderSpacing.bottom += m.textDescent;        m.outerSpacing.bottom += m.textDescent + m.lineHeight;
1054        break;        break;
1055    
1056      case BELOW_BOTTOM:      case BELOW_BOTTOM:
1057        m.borderSpacing.bottom += m.textAscent + m.textDescent + TEXT_SPACING;        m.outerSpacing.bottom += m.textAscent + m.textDescent;
1058        break;        break;
1059    
1060      default:      default:
1061        m.borderSpacing.top += m.textAscent;        m.outerSpacing.top += m.textAscent;
1062      }      }
1063    
1064      return m;      return m;
# Line 1067  public class TitledBorder Line 1081  public class TitledBorder
1081       * which means that the font is to be retrieved from the current       * which means that the font is to be retrieved from the current
1082       * LookAndFeel. In this case, this <code>font</code> field will       * LookAndFeel. In this case, this <code>font</code> field will
1083       * contain the result of the retrieval. Therefore, it is safe       * contain the result of the retrieval. Therefore, it is safe
1084       * to assume that his <code>font</code> field will never have       * to assume that this <code>font</code> field will never have
1085       * a <code>null</code> value.       * a <code>null</code> value.
1086       */       */
1087      Font font;      Font font;
# Line 1107  public class TitledBorder Line 1121  public class TitledBorder
1121    
1122    
1123      /**      /**
1124       * The border that constitues the interior border       * The border that constitutes the interior border
1125       * underneath the title text.       * underneath the title text.
1126       */       */
1127      Border border;      Border border;
# Line 1116  public class TitledBorder Line 1130  public class TitledBorder
1130      /**      /**
1131       * The distance between the TitledBorder and the interior border.       * The distance between the TitledBorder and the interior border.
1132       */       */
1133      Insets borderSpacing;      Insets outerSpacing;
   
1134            
1135      /**      /**
1136       * The width of the interior border, as returned by       * The width of the interior border, as returned by
# Line 1130  public class TitledBorder Line 1143  public class TitledBorder
1143       * The distance between the interior border and the nested       * The distance between the interior border and the nested
1144       * Component for which this TitledBorder is a border.       * Component for which this TitledBorder is a border.
1145       */       */
1146      Insets edgeSpacing;      Insets innerSpacing;
1147    
1148    
1149      /**      /**
# Line 1149  public class TitledBorder Line 1162  public class TitledBorder
1162      {      {
1163        if (i == null)        if (i == null)
1164          i = new Insets(0, 0, 0, 0);          i = new Insets(0, 0, 0, 0);
1165        i.left = borderSpacing.left + borderInsets.left + edgeSpacing.left;        i.left = outerSpacing.left + borderInsets.left + innerSpacing.left;
1166        i.right = borderSpacing.right + borderInsets.right + edgeSpacing.right;        i.right = outerSpacing.right + borderInsets.right + innerSpacing.right;
1167        i.top = borderSpacing.top + borderInsets.top + edgeSpacing.top;        i.top = outerSpacing.top + borderInsets.top + innerSpacing.top;
1168        i.bottom = borderSpacing.bottom + borderInsets.bottom + edgeSpacing.bottom;        i.bottom = outerSpacing.bottom + borderInsets.bottom + innerSpacing.bottom;
1169        return i;        return i;
1170      }      }
1171    
# Line 1167  public class TitledBorder Line 1180  public class TitledBorder
1180        Insets insets;        Insets insets;
1181    
1182        insets = getContentInsets(null);        insets = getContentInsets(null);
1183        width = Math.max(insets.left + insets.right, textWidth + 2 * TEXT_INSET_H);        width = Math.max(insets.left + insets.right, textWidth + 2
1184                  * TEXT_INSET_H);
1185        return new Dimension(width, insets.top + insets.bottom);        return new Dimension(width, insets.top + insets.bottom);
1186      }      }
1187    }    }

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.11

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26