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 FontFamily = CharacterConstants.Family;
  58:   public static final Object FontSize = CharacterConstants.Size;
  59:   public static final Object Foreground = CharacterConstants.Foreground;
  60:   public static final Object IconAttribute = CharacterConstants.IconAttribute;
  61:   public static final Object Italic = CharacterConstants.Italic;
  62:   public static final Object StrikeThrough = CharacterConstants.StrikeThrough;
  63:   public static final Object Subscript = CharacterConstants.Subscript;
  64:   public static final Object Superscript = CharacterConstants.Superscript;
  65:   public static final Object Underline = CharacterConstants.Underline;
  66: 
  67:   public static final Object Alignment = ParagraphConstants.Alignment;
  68:   public static final Object FirstLineIndent = ParagraphConstants.FirstLineIndent;
  69:   public static final Object LeftIndent = ParagraphConstants.LeftIndent;
  70:   public static final Object LineSpacing = ParagraphConstants.LineSpacing;
  71:   public static final Object Orientation = ParagraphConstants.Orientation;
  72:   public static final Object RightIndent = ParagraphConstants.RightIndent;
  73:   public static final Object SpaceAbove = ParagraphConstants.SpaceAbove;
  74:   public static final Object SpaceBelow = ParagraphConstants.SpaceBelow;
  75:   public static final Object TabSet = ParagraphConstants.TabSet;
  76: 
  77:   public static final String ComponentElementName = "component";
  78:   public static final String IconElementName = "icon";
  79: 
  80:   public static final Object ComposedTextAttribute = new StyleConstants("composed text");
  81:   public static final Object ModelAttribute = new StyleConstants("model");
  82:   public static final Object NameAttribute = new StyleConstants("name");
  83:   public static final Object ResolveAttribute = new StyleConstants("resolver");
  84: 
  85:   String keyname;
  86: 
  87:   // Package-private to avoid accessor constructor for use by
  88:   // subclasses.
  89:   StyleConstants(String k) 
  90:   {
  91:     keyname = k;
  92:   }
  93: 
  94:   public String toString()
  95:   {
  96:     return keyname;
  97:   }
  98: 
  99:   public static int getAlignment(AttributeSet a)
 100:   {
 101:     if (a.isDefined(Alignment))
 102:       return ((Integer)a.getAttribute(Alignment)).intValue();
 103:     else
 104:       return ALIGN_LEFT;      
 105:   } 
 106: 
 107:   public static Color getBackground(AttributeSet a)
 108:   {
 109:     if (a.isDefined(Background))
 110:       return (Color) a.getAttribute(Background);
 111:     else
 112:       return Color.WHITE;
 113:   } 
 114:   
 115:   public static int getBidiLevel(AttributeSet a)
 116:   {
 117:     if (a.isDefined(BidiLevel))
 118:       return ((Integer)a.getAttribute(BidiLevel)).intValue();
 119:     else
 120:       return 0;
 121:   } 
 122: 
 123:   public static Component getComponent(AttributeSet a)
 124:   {
 125:     if (a.isDefined(ComponentAttribute))
 126:       return (Component) a.getAttribute(ComponentAttribute);
 127:     else
 128:       return (Component) null;
 129:   } 
 130: 
 131:   public static float getFirstLineIndent(AttributeSet a)
 132:   {
 133:     if (a.isDefined(FirstLineIndent))
 134:       return ((Float)a.getAttribute(FirstLineIndent)).floatValue();
 135:     else
 136:       return 0.f;
 137:   } 
 138: 
 139:   public static String getFontFamily(AttributeSet a)
 140:   {
 141:     if (a.isDefined(FontFamily))
 142:       return (String) a.getAttribute(FontFamily);
 143:     else
 144:       return "Monospaced";
 145:   } 
 146: 
 147:   public static int getFontSize(AttributeSet a)
 148:   {
 149:     if (a.isDefined(FontSize))
 150:       return ((Integer)a.getAttribute(FontSize)).intValue();
 151:     else
 152:       return 12;
 153:   } 
 154: 
 155:   public static Color getForeground(AttributeSet a)
 156:   {
 157:     if (a.isDefined(Foreground))
 158:       return (Color) a.getAttribute(Foreground);
 159:     else
 160:       return Color.BLACK;
 161:   } 
 162: 
 163:   public static Icon getIcon(AttributeSet a)
 164:   {
 165:     if (a.isDefined(IconAttribute))
 166:       return (Icon) a.getAttribute(IconAttribute);
 167:     else
 168:       return (Icon) null;
 169:   } 
 170: 
 171:   public static float getLeftIndent(AttributeSet a)
 172:   {
 173:     if (a.isDefined(LeftIndent))
 174:       return ((Float)a.getAttribute(LeftIndent)).floatValue();
 175:     else
 176:       return 0.f;  
 177:   } 
 178: 
 179:   public static float getLineSpacing(AttributeSet a)
 180:   {
 181:     if (a.isDefined(LineSpacing))
 182:       return ((Float)a.getAttribute(LineSpacing)).floatValue();
 183:     else
 184:       return 0.f;  
 185:   } 
 186: 
 187:   public static float getRightIndent(AttributeSet a)
 188:   {
 189:     if (a.isDefined(RightIndent))
 190:       return ((Float)a.getAttribute(RightIndent)).floatValue();
 191:     else
 192:       return 0.f;  
 193:   } 
 194: 
 195:   public static float getSpaceAbove(AttributeSet a)
 196:   {
 197:     if (a.isDefined(SpaceAbove))
 198:       return ((Float)a.getAttribute(SpaceAbove)).floatValue();
 199:     else
 200:       return 0.f;  
 201:   } 
 202: 
 203:   public static float getSpaceBelow(AttributeSet a)
 204:   {
 205:     if (a.isDefined(SpaceBelow))
 206:       return ((Float)a.getAttribute(SpaceBelow)).floatValue();
 207:     else
 208:       return 0.f;  
 209:   } 
 210: 
 211:   public static javax.swing.text.TabSet getTabSet(AttributeSet a)
 212:   {
 213:     if (a.isDefined(StyleConstants.TabSet))
 214:       return (javax.swing.text.TabSet) a.getAttribute(StyleConstants.TabSet);
 215:     else
 216:       return (javax.swing.text.TabSet) null;
 217:   } 
 218: 
 219:   public static boolean isBold(AttributeSet a)
 220:   {
 221:     if (a.isDefined(Bold))
 222:       return ((Boolean) a.getAttribute(Bold)).booleanValue();
 223:     else
 224:       return false;    
 225:   } 
 226: 
 227:   public static boolean isItalic(AttributeSet a)
 228:   {
 229:     if (a.isDefined(Italic))
 230:       return ((Boolean) a.getAttribute(Italic)).booleanValue();
 231:     else
 232:       return false;    
 233:   } 
 234: 
 235:   public static boolean isStrikeThrough(AttributeSet a)
 236:   {
 237:     if (a.isDefined(StrikeThrough))
 238:       return ((Boolean) a.getAttribute(StrikeThrough)).booleanValue();
 239:     else
 240:       return false;    
 241:   } 
 242: 
 243:   public static boolean isSubscript(AttributeSet a)
 244:   {
 245:     if (a.isDefined(Subscript))
 246:       return ((Boolean) a.getAttribute(Subscript)).booleanValue();
 247:     else
 248:       return false;    
 249:   } 
 250: 
 251:   public static boolean isSuperscript(AttributeSet a)
 252:   {
 253:     if (a.isDefined(Superscript))
 254:       return ((Boolean) a.getAttribute(Superscript)).booleanValue();
 255:     else
 256:       return false;    
 257:   } 
 258: 
 259:   public static boolean isUnderline(AttributeSet a)
 260:   {
 261:     if (a.isDefined(Underline))
 262:       return ((Boolean) a.getAttribute(Underline)).booleanValue();
 263:     else
 264:       return false;    
 265:   } 
 266: 
 267:   public static void setAlignment(MutableAttributeSet a, int align)
 268:   {
 269:     a.addAttribute(Alignment, new Integer(align));
 270:   } 
 271: 
 272:   public static void setBackground(MutableAttributeSet a, Color fg)
 273:   {
 274:     a.addAttribute(Background, fg);
 275:   } 
 276: 
 277:   public static void setBidiLevel(MutableAttributeSet a, int lev)
 278:   {
 279:     a.addAttribute(BidiLevel, new Integer(lev));
 280:   } 
 281: 
 282:   public static void setBold(MutableAttributeSet a, boolean b)
 283:   {
 284:     a.addAttribute(Bold, Boolean.valueOf(b));
 285:   } 
 286:   
 287:   public static void setComponent(MutableAttributeSet a, Component c)
 288:   {
 289:     a.addAttribute(ComponentAttribute, c);
 290:   } 
 291: 
 292:   public static void setFirstLineIndent(MutableAttributeSet a, float i)
 293:   {
 294:     a.addAttribute(FirstLineIndent, new Float(i));
 295:   } 
 296: 
 297:   public static void setFontFamily(MutableAttributeSet a, String fam)
 298:   {
 299:     a.addAttribute(FontFamily, fam);
 300:   } 
 301: 
 302:   public static void setFontSize(MutableAttributeSet a, int s)
 303:   {
 304:     a.addAttribute(FontSize, new Integer(s));
 305:   } 
 306: 
 307:   public static void setForeground(MutableAttributeSet a, Color fg)
 308:   {
 309:     a.addAttribute(Foreground, fg);
 310:   }
 311: 
 312:   public static void setIcon(MutableAttributeSet a, Icon c)
 313:   {
 314:     a.addAttribute(IconAttribute, c);
 315:   }
 316:  
 317:   public static void setItalic(MutableAttributeSet a, boolean b)
 318:   {
 319:     a.addAttribute(Italic, Boolean.valueOf(b));
 320:   }
 321:  
 322:   public static void setLeftIndent(MutableAttributeSet a, float i)
 323:   {
 324:     a.addAttribute(LeftIndent, new Float(i));
 325:   } 
 326: 
 327:   public static void setLineSpacing(MutableAttributeSet a, float i)
 328:   {
 329:     a.addAttribute(LineSpacing, new Float(i));
 330:   } 
 331: 
 332:   public static void setRightIndent(MutableAttributeSet a, float i)
 333:   {
 334:     a.addAttribute(RightIndent, new Float(i));
 335:   } 
 336: 
 337:   public static void setSpaceAbove(MutableAttributeSet a, float i)
 338:   {
 339:     a.addAttribute(SpaceAbove, new Float(i));
 340:   } 
 341: 
 342:   public static void setSpaceBelow(MutableAttributeSet a, float i)
 343:   {
 344:     a.addAttribute(SpaceBelow, new Float(i));
 345:   } 
 346: 
 347:   public static void setStrikeThrough(MutableAttributeSet a, boolean b)
 348:   {
 349:     a.addAttribute(StrikeThrough, Boolean.valueOf(b));
 350:   } 
 351: 
 352:   public static void setSubscript(MutableAttributeSet a, boolean b)
 353:   {
 354:     a.addAttribute(Subscript, Boolean.valueOf(b));
 355:   } 
 356: 
 357:   public static void setSuperscript(MutableAttributeSet a, boolean b)
 358:   {
 359:     a.addAttribute(Superscript, Boolean.valueOf(b));
 360:   } 
 361: 
 362:   public static void setTabSet(MutableAttributeSet a, javax.swing.text.TabSet tabs)
 363:   {
 364:     a.addAttribute(StyleConstants.TabSet, tabs);
 365:   } 
 366: 
 367:   public static void setUnderline(MutableAttributeSet a, boolean b)
 368:   {
 369:     a.addAttribute(Underline, Boolean.valueOf(b));
 370:   } 
 371: 
 372:   // The remainder are so-called "typesafe enumerations" which 
 373:   // alias subsets of the above constants.
 374:   public static class CharacterConstants
 375:     extends StyleConstants
 376:     implements AttributeSet.CharacterAttribute
 377:   {
 378:     private CharacterConstants(String k) 
 379:     {
 380:       super(k);
 381:     }
 382:     
 383:     public static Object Background = ColorConstants.Background;
 384:     public static Object BidiLevel = new CharacterConstants("bidiLevel");
 385:     public static Object Bold = FontConstants.Bold;
 386:     public static Object ComponentAttribute = new CharacterConstants("component");
 387:     public static Object Family = FontConstants.Family;
 388:     public static Object Size = FontConstants.Size;
 389:     public static Object Foreground = ColorConstants.Foreground;
 390:     public static Object IconAttribute = new CharacterConstants("icon");
 391:     public static Object Italic = FontConstants.Italic;
 392:     public static Object StrikeThrough = new CharacterConstants("strikethrough");
 393:     public static Object Subscript = new CharacterConstants("subscript");
 394:     public static Object Superscript = new CharacterConstants("superscript");
 395:     public static Object Underline = new CharacterConstants("underline");
 396:   }
 397: 
 398:   public static class ColorConstants
 399:     extends StyleConstants
 400:     implements AttributeSet.ColorAttribute, AttributeSet.CharacterAttribute
 401:   {
 402:     private ColorConstants(String k) 
 403:     {
 404:       super(k);
 405:     }
 406:     public static Object Foreground = new ColorConstants("foreground");
 407:     public static Object Background = new ColorConstants("background");
 408:   }
 409: 
 410:   public static class FontConstants
 411:     extends StyleConstants
 412:     implements AttributeSet.FontAttribute, AttributeSet.CharacterAttribute
 413:   {
 414:     private FontConstants(String k) 
 415:     {
 416:       super(k);
 417:     }
 418:     public static Object Bold = new FontConstants("bold");
 419:     public static Object Family = new FontConstants("family");
 420:     public static Object Italic = new FontConstants("italic");
 421:     public static Object Size = new FontConstants("size");
 422:   }
 423: 
 424:   public static class ParagraphConstants
 425:     extends StyleConstants
 426:     implements AttributeSet.ParagraphAttribute
 427:   {
 428:     private ParagraphConstants(String k) 
 429:     {
 430:       super(k);
 431:     }
 432:     public static Object Alignment = new ParagraphConstants("Alignment");
 433:     public static Object FirstLineIndent = new ParagraphConstants("FirstLineIndent");
 434:     public static Object LeftIndent = new ParagraphConstants("LeftIndent");
 435:     public static Object LineSpacing = new ParagraphConstants("LineSpacing");
 436:     public static Object Orientation = new ParagraphConstants("Orientation");
 437:     public static Object RightIndent = new ParagraphConstants("RightIndent");
 438:     public static Object SpaceAbove = new ParagraphConstants("SpaceAbove");
 439:     public static Object SpaceBelow = new ParagraphConstants("SpaceBelow");
 440:     public static Object TabSet = new ParagraphConstants("TabSet");
 441:   }
 442: 
 443: }