Source for javax.swing.text.StyleConstants

   1: /* StyleConstants.java --
   2:    Copyright (C) 2004, 2005 Free Software Foundation, Inc.
   3: 
   4: This file is part of GNU Classpath.
   5: 
   6: GNU Classpath is free software; you can redistribute it and/or modify
   7: it under the terms of the GNU General Public License as published by
   8: the Free Software Foundation; either version 2, or (at your option)
   9: any later version.
  10: 
  11: GNU Classpath is distributed in the hope that it will be useful, but
  12: WITHOUT ANY WARRANTY; without even the implied warranty of
  13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14: General Public License for more details.
  15: 
  16: You should have received a copy of the GNU General Public License
  17: along with GNU Classpath; see the file COPYING.  If not, write to the
  18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  19: 02110-1301 USA.
  20: 
  21: Linking this library statically or dynamically with other modules is
  22: making a combined work based on this library.  Thus, the terms and
  23: conditions of the GNU General Public License cover the whole
  24: combination.
  25: 
  26: As a special exception, the copyright holders of this library give you
  27: permission to link this library with independent modules to produce an
  28: executable, regardless of the license terms of these independent
  29: modules, and to copy and distribute the resulting executable under
  30: terms of your choice, provided that you also meet, for each linked
  31: independent module, the terms and conditions of the license of that
  32: module.  An independent module is a module which is not derived from
  33: or based on this library.  If you modify this library, you may extend
  34: this exception to your version of the library, but you are not
  35: obligated to do so.  If you do not wish to do so, delete this
  36: exception statement from your version. */
  37: 
  38: 
  39: package javax.swing.text;
  40: 
  41: import java.awt.Color;
  42: import java.awt.Component;
  43: 
  44: import javax.swing.Icon;
  45: 
  46: public class StyleConstants
  47: {
  48:   public static final int ALIGN_LEFT = 0;
  49:   public static final int ALIGN_CENTER = 1;
  50:   public static final int ALIGN_RIGHT = 2;
  51:   public static final int ALIGN_JUSTIFIED = 3;
  52: 
  53:   public static final Object Background = CharacterConstants.Background;
  54:   public static final Object BidiLevel = CharacterConstants.BidiLevel;
  55:   public static final Object Bold = CharacterConstants.Bold;
  56:   public static final Object ComponentAttribute = CharacterConstants.ComponentAttribute;
  57:   public static final Object Family = CharacterConstants.Family;
  58:   public static final Object FontFamily = CharacterConstants.Family;  
  59:   public static final Object FontSize = CharacterConstants.Size;
  60:   public static final Object Foreground = CharacterConstants.Foreground;
  61:   public static final Object IconAttribute = CharacterConstants.IconAttribute;
  62:   public static final Object Italic = CharacterConstants.Italic;
  63:   public static final Object Size = CharacterConstants.Size;
  64:   public static final Object StrikeThrough = CharacterConstants.StrikeThrough;
  65:   public static final Object Subscript = CharacterConstants.Subscript;
  66:   public static final Object Superscript = CharacterConstants.Superscript;
  67:   public static final Object Underline = CharacterConstants.Underline;
  68: 
  69:   public static final Object Alignment = ParagraphConstants.Alignment;
  70:   public static final Object FirstLineIndent = ParagraphConstants.FirstLineIndent;
  71:   public static final Object LeftIndent = ParagraphConstants.LeftIndent;
  72:   public static final Object LineSpacing = ParagraphConstants.LineSpacing;
  73:   public static final Object Orientation = ParagraphConstants.Orientation;
  74:   public static final Object RightIndent = ParagraphConstants.RightIndent;
  75:   public static final Object SpaceAbove = ParagraphConstants.SpaceAbove;
  76:   public static final Object SpaceBelow = ParagraphConstants.SpaceBelow;
  77:   public static final Object TabSet = ParagraphConstants.TabSet;
  78: 
  79:   public static final String ComponentElementName = "component";
  80:   public static final String IconElementName = "icon";
  81: 
  82:   public static final Object ComposedTextAttribute = new StyleConstants("composed text");
  83:   public static final Object ModelAttribute = new StyleConstants("model");
  84:   public static final Object NameAttribute = new StyleConstants("name");
  85:   public static final Object ResolveAttribute = new StyleConstants("resolver");
  86: 
  87:   String keyname;
  88: 
  89:   // Package-private to avoid accessor constructor for use by
  90:   // subclasses.
  91:   StyleConstants(String k) 
  92:   {
  93:     keyname = k;
  94:   }
  95: 
  96:   public String toString()
  97:   {
  98:     return keyname;
  99:   }
 100: 
 101:   public static int getAlignment(AttributeSet a)
 102:   {
 103:     if (a.isDefined(Alignment))
 104:       return ((Integer)a.getAttribute(Alignment)).intValue();
 105:     else
 106:       return ALIGN_LEFT;      
 107:   } 
 108: 
 109:   public static Color getBackground(AttributeSet a)
 110:   {
 111:     if (a.isDefined(Background))
 112:       return (Color) a.getAttribute(Background);
 113:     else
 114:       return Color.WHITE;
 115:   } 
 116:   
 117:   public static int getBidiLevel(AttributeSet a)
 118:   {
 119:     if (a.isDefined(BidiLevel))
 120:       return ((Integer)a.getAttribute(BidiLevel)).intValue();
 121:     else
 122:       return 0;
 123:   } 
 124: 
 125:   public static Component getComponent(AttributeSet a)
 126:   {
 127:     if (a.isDefined(ComponentAttribute))
 128:       return (Component) a.getAttribute(ComponentAttribute);
 129:     else
 130:       return (Component) null;
 131:   } 
 132: 
 133:   public static float getFirstLineIndent(AttributeSet a)
 134:   {
 135:     if (a.isDefined(FirstLineIndent))
 136:       return ((Float)a.getAttribute(FirstLineIndent)).floatValue();
 137:     else
 138:       return 0.f;
 139:   } 
 140: 
 141:   public static String getFontFamily(AttributeSet a)
 142:   {
 143:     if (a.isDefined(FontFamily))
 144:       return (String) a.getAttribute(FontFamily);
 145:     else
 146:       return "Monospaced";
 147:   } 
 148: 
 149:   public static int getFontSize(AttributeSet a)
 150:   {
 151:     if (a.isDefined(FontSize))
 152:       return ((Integer)a.getAttribute(FontSize)).intValue();
 153:     else
 154:       return 12;
 155:   } 
 156: 
 157:   public static Color getForeground(AttributeSet a)
 158:   {
 159:     if (a.isDefined(Foreground))
 160:       return (Color) a.getAttribute(Foreground);
 161:     else
 162:       return Color.BLACK;
 163:   } 
 164: 
 165:   public static Icon getIcon(AttributeSet a)
 166:   {
 167:     if (a.isDefined(IconAttribute))
 168:       return (Icon) a.getAttribute(IconAttribute);
 169:     else
 170:       return (Icon) null;
 171:   } 
 172: 
 173:   public static float getLeftIndent(AttributeSet a)
 174:   {
 175:     if (a.isDefined(LeftIndent))
 176:       return ((Float)a.getAttribute(LeftIndent)).floatValue();
 177:     else
 178:       return 0.f;  
 179:   } 
 180: 
 181:   public static float getLineSpacing(AttributeSet a)
 182:   {
 183:     if (a.isDefined(LineSpacing))
 184:       return ((Float)a.getAttribute(LineSpacing)).floatValue();
 185:     else
 186:       return 0.f;  
 187:   } 
 188: 
 189:   public static float getRightIndent(AttributeSet a)
 190:   {
 191:     if (a.isDefined(RightIndent))
 192:       return ((Float)a.getAttribute(RightIndent)).floatValue();
 193:     else
 194:       return 0.f;  
 195:   } 
 196: 
 197:   public static float getSpaceAbove(AttributeSet a)
 198:   {
 199:     if (a.isDefined(SpaceAbove))
 200:       return ((Float)a.getAttribute(SpaceAbove)).floatValue();
 201:     else
 202:       return 0.f;  
 203:   } 
 204: 
 205:   public static float getSpaceBelow(AttributeSet a)
 206:   {
 207:     if (a.isDefined(SpaceBelow))
 208:       return ((Float)a.getAttribute(SpaceBelow)).floatValue();
 209:     else
 210:       return 0.f;  
 211:   } 
 212: 
 213:   public static javax.swing.text.TabSet getTabSet(AttributeSet a)
 214:   {
 215:     if (a.isDefined(StyleConstants.TabSet))
 216:       return (javax.swing.text.TabSet) a.getAttribute(StyleConstants.TabSet);
 217:     else
 218:       return (javax.swing.text.TabSet) null;
 219:   } 
 220: 
 221:   public static boolean isBold(AttributeSet a)
 222:   {
 223:     if (a.isDefined(Bold))
 224:       return ((Boolean) a.getAttribute(Bold)).booleanValue();
 225:     else
 226:       return false;    
 227:   } 
 228: 
 229:   public static boolean isItalic(AttributeSet a)
 230:   {
 231:     if (a.isDefined(Italic))
 232:       return ((Boolean) a.getAttribute(Italic)).booleanValue();
 233:     else
 234:       return false;    
 235:   } 
 236: 
 237:   public static boolean isStrikeThrough(AttributeSet a)
 238:   {
 239:     if (a.isDefined(StrikeThrough))
 240:       return ((Boolean) a.getAttribute(StrikeThrough)).booleanValue();
 241:     else
 242:       return false;    
 243:   } 
 244: 
 245:   public static boolean isSubscript(AttributeSet a)
 246:   {
 247:     if (a.isDefined(Subscript))
 248:       return ((Boolean) a.getAttribute(Subscript)).booleanValue();
 249:     else
 250:       return false;    
 251:   } 
 252: 
 253:   public static boolean isSuperscript(AttributeSet a)
 254:   {
 255:     if (a.isDefined(Superscript))
 256:       return ((Boolean) a.getAttribute(Superscript)).booleanValue();
 257:     else
 258:       return false;    
 259:   } 
 260: 
 261:   public static boolean isUnderline(AttributeSet a)
 262:   {
 263:     if (a.isDefined(Underline))
 264:       return ((Boolean) a.getAttribute(Underline)).booleanValue();
 265:     else
 266:       return false;    
 267:   } 
 268: 
 269:   public static void setAlignment(MutableAttributeSet a, int align)
 270:   {
 271:     a.addAttribute(Alignment, new Integer(align));
 272:   } 
 273: 
 274:   public static void setBackground(MutableAttributeSet a, Color fg)
 275:   {
 276:     a.addAttribute(Background, fg);
 277:   } 
 278: 
 279:   public static void setBidiLevel(MutableAttributeSet a, int lev)
 280:   {
 281:     a.addAttribute(BidiLevel, new Integer(lev));
 282:   } 
 283: 
 284:   public static void setBold(MutableAttributeSet a, boolean b)
 285:   {
 286:     a.addAttribute(Bold, Boolean.valueOf(b));
 287:   } 
 288:   
 289:   public static void setComponent(MutableAttributeSet a, Component c)
 290:   {
 291:     a.addAttribute(ComponentAttribute, c);
 292:   } 
 293: 
 294:   public static void setFirstLineIndent(MutableAttributeSet a, float i)
 295:   {
 296:     a.addAttribute(FirstLineIndent, new Float(i));
 297:   } 
 298: 
 299:   public static void setFontFamily(MutableAttributeSet a, String fam)
 300:   {
 301:     a.addAttribute(FontFamily, fam);
 302:   } 
 303: 
 304:   public static void setFontSize(MutableAttributeSet a, int s)
 305:   {
 306:     a.addAttribute(FontSize, new Integer(s));
 307:   } 
 308: 
 309:   public static void setForeground(MutableAttributeSet a, Color fg)
 310:   {
 311:     a.addAttribute(Foreground, fg);
 312:   }
 313: 
 314:   public static void setIcon(MutableAttributeSet a, Icon c)
 315:   {
 316:     a.addAttribute(IconAttribute, c);
 317:   }
 318:  
 319:   public static void setItalic(MutableAttributeSet a, boolean b)
 320:   {
 321:     a.addAttribute(Italic, Boolean.valueOf(b));
 322:   }
 323:  
 324:   public static void setLeftIndent(MutableAttributeSet a, float i)
 325:   {
 326:     a.addAttribute(LeftIndent, new Float(i));
 327:   } 
 328: 
 329:   public static void setLineSpacing(MutableAttributeSet a, float i)
 330:   {
 331:     a.addAttribute(LineSpacing, new Float(i));
 332:   } 
 333: 
 334:   public static void setRightIndent(MutableAttributeSet a, float i)
 335:   {
 336:     a.addAttribute(RightIndent, new Float(i));
 337:   } 
 338: 
 339:   public static void setSpaceAbove(MutableAttributeSet a, float i)
 340:   {
 341:     a.addAttribute(SpaceAbove, new Float(i));
 342:   } 
 343: 
 344:   public static void setSpaceBelow(MutableAttributeSet a, float i)
 345:   {
 346:     a.addAttribute(SpaceBelow, new Float(i));
 347:   } 
 348: 
 349:   public static void setStrikeThrough(MutableAttributeSet a, boolean b)
 350:   {
 351:     a.addAttribute(StrikeThrough, Boolean.valueOf(b));
 352:   } 
 353: 
 354:   public static void setSubscript(MutableAttributeSet a, boolean b)
 355:   {
 356:     a.addAttribute(Subscript, Boolean.valueOf(b));
 357:   } 
 358: 
 359:   public static void setSuperscript(MutableAttributeSet a, boolean b)
 360:   {
 361:     a.addAttribute(Superscript, Boolean.valueOf(b));
 362:   } 
 363: 
 364:   public static void setTabSet(MutableAttributeSet a, javax.swing.text.TabSet tabs)
 365:   {
 366:     a.addAttribute(StyleConstants.TabSet, tabs);
 367:   } 
 368: 
 369:   public static void setUnderline(MutableAttributeSet a, boolean b)
 370:   {
 371:     a.addAttribute(Underline, Boolean.valueOf(b));
 372:   } 
 373: 
 374:   // The remainder are so-called "typesafe enumerations" which 
 375:   // alias subsets of the above constants.
 376:   public static class CharacterConstants
 377:     extends StyleConstants
 378:     implements AttributeSet.CharacterAttribute
 379:   {
 380:     private CharacterConstants(String k) 
 381:     {
 382:       super(k);
 383:     }
 384:     
 385:     public static Object Background = ColorConstants.Background;
 386:     public static Object BidiLevel = new CharacterConstants("bidiLevel");
 387:     public static Object Bold = FontConstants.Bold;
 388:     public static Object ComponentAttribute = new CharacterConstants("component");
 389:     public static Object Family = FontConstants.Family;
 390:     public static Object Size = FontConstants.Size;
 391:     public static Object Foreground = ColorConstants.Foreground;
 392:     public static Object IconAttribute = new CharacterConstants("icon");
 393:     public static Object Italic = FontConstants.Italic;
 394:     public static Object StrikeThrough = new CharacterConstants("strikethrough");
 395:     public static Object Subscript = new CharacterConstants("subscript");
 396:     public static Object Superscript = new CharacterConstants("superscript");
 397:     public static Object Underline = new CharacterConstants("underline");
 398:   }
 399: 
 400:   public static class ColorConstants
 401:     extends StyleConstants
 402:     implements AttributeSet.ColorAttribute, AttributeSet.CharacterAttribute
 403:   {
 404:     private ColorConstants(String k) 
 405:     {
 406:       super(k);
 407:     }
 408:     public static Object Foreground = new ColorConstants("foreground");
 409:     public static Object Background = new ColorConstants("background");
 410:   }
 411: 
 412:   public static class FontConstants
 413:     extends StyleConstants
 414:     implements AttributeSet.FontAttribute, AttributeSet.CharacterAttribute
 415:   {
 416:     private FontConstants(String k) 
 417:     {
 418:       super(k);
 419:     }
 420:     public static Object Bold = new FontConstants("bold");
 421:     public static Object Family = new FontConstants("family");
 422:     public static Object Italic = new FontConstants("italic");
 423:     public static Object Size = new FontConstants("size");
 424:   }
 425: 
 426:   public static class ParagraphConstants
 427:     extends StyleConstants
 428:     implements AttributeSet.ParagraphAttribute
 429:   {
 430:     private ParagraphConstants(String k) 
 431:     {
 432:       super(k);
 433:     }
 434:     public static Object Alignment = new ParagraphConstants("Alignment");
 435:     public static Object FirstLineIndent = new ParagraphConstants("FirstLineIndent");
 436:     public static Object LeftIndent = new ParagraphConstants("LeftIndent");
 437:     public static Object LineSpacing = new ParagraphConstants("LineSpacing");
 438:     public static Object Orientation = new ParagraphConstants("Orientation");
 439:     public static Object RightIndent = new ParagraphConstants("RightIndent");
 440:     public static Object SpaceAbove = new ParagraphConstants("SpaceAbove");
 441:     public static Object SpaceBelow = new ParagraphConstants("SpaceBelow");
 442:     public static Object TabSet = new ParagraphConstants("TabSet");
 443:   }
 444: 
 445: }