    001package org.vishia.gral.awt;
    002
    003import java.awt.Color;
    004import java.awt.Font;
    005import java.util.Map;
    006import java.util.TreeMap;
    007
    008import org.vishia.gral.base.GralGridProperties;
    009import org.vishia.gral.ifc.GralColor;
    010import org.vishia.gral.ifc.GralFont;
    011
    012public class AwtProperties extends GralGridProperties
    013{
    014
    015  public final Font smallPromptFont;
    016
    017  public final Font[] textFontAwt = new Font[10];
    018
    019  public final Font stdInputFont;
    020
    021  public final Font stdButtonFont;
    022
    023  Map<Integer, Color> colorsSwt = new TreeMap<Integer, Color>();
    024
    025  private final Color colorBlack;
    026
    027  public final Color colorGrid, colorGridStrong;
    028
    029  /**A common background color for all widgets which are paint at the background. */
    030  public Color colorBackground;
    031
    032
    033
    034
    035  public AwtProperties(char sizeC)
    036  {
    037    super(sizeC);
    038    this.colorBlack = new Color(0,0,0);
    039    this.colorGrid = new Color(0xe0e0e0);
    040    this.colorGridStrong = new Color(0xc0c0c0);
    041    this.colorBackground = new Color(0xffffff);
    042    this.smallPromptFont = new Font("Arial", 0, smallPromptFontSize[size]);
    043    this.stdInputFont = new Font("Arial", 0, stdInputFontSize[size]);
    044    this.stdButtonFont = new Font("Arial", 0, stdButtonFontSize[size]);
    045    this.textFontAwt[0] = new Font("Arial", 0, stdTextFontSize[0][size]);
    046    this.textFontAwt[1] = new Font("Arial", 0, stdTextFontSize[1][size]);
    047    this.textFontAwt[2] = new Font("Arial", 0, stdTextFontSize[2][size]);
    048    this.textFontAwt[3] = new Font("Arial", 0, stdTextFontSize[3][size]);
    049    this.textFontAwt[4] = new Font("Arial", 0, stdTextFontSize[4][size]);
    050    this.textFontAwt[5] = new Font("Arial", 0, stdTextFontSize[5][size]);
    051    this.textFontAwt[6] = new Font("Arial", 0, stdTextFontSize[6][size]);
    052    this.textFontAwt[7] = new Font("Arial", 0, stdTextFontSize[7][size]);
    053    this.textFontAwt[8] = new Font("Arial", 0, stdTextFontSize[8][size]);
    054    this.textFontAwt[9] = new Font("Arial", 0, stdTextFontSize[9][size]);
    055  }
    056
    057
    058  /**Returns a color with given Gui-independent color.
    059   * The SWT-Color instance is taken from a pool if the color is used already.
    060   * Elsewhere it is created newly and put into the pool.
    061   * @param color The given color in system-indpending form.
    062   * @return An instance of SWT-color
    063   */
    064  public Color colorAwt(GralColor color)
    065  {
    066    if(color.colorGuimpl == null){
    067      int colorValue = color.getColorValue();
    068      color.colorGuimpl = new Color(colorValue);
    069    } else if(!(color.colorGuimpl instanceof Color)){
    070      throw new IllegalArgumentException("unauthorized color setting");
    071    }
    072    return (Color)color.colorGuimpl;
    073  }
    074
    075
    076
    077
    078  /**Returns a implementation font with given Gui-independent font.
    079   * The SWT-Font instance is taken from a pool if the font is used already.
    080   * Elsewhere it is created newly and put into the pool.
    081   * @param forn The given Gral font in system-independent form.
    082   * @return An instance of SWT-Font
    083   */
    084  public Font fontAwt(GralFont font)
    085  {
    086    if(font.fontImpl == null){
    087      int styleSwt = 0;
    088      switch(font.style){
    089        case 'b': styleSwt |= Font.BOLD; break;
    090        case 'B': styleSwt |= Font.BOLD; break;
    091        case 'i': styleSwt |= Font.ITALIC; break;
    092        case 'I': styleSwt |= Font.BOLD | Font.ITALIC; break;
    093        default: styleSwt = Font.PLAIN;
    094      }
    095      String fontName;
    096      //NOTE: on SWT there are not Java standardfonts, there are platform-depending.
    097      if(font.fontName.equals(GralFont.fontMonospacedSansSerif)){ fontName = "Courier"; }
    098      else if(font.fontName.equals(GralFont.fontMonospacedSmall)){ fontName = "Courier"; }
    099      else if(font.fontName.equals(GralFont.fontMonospacedSerif)){ fontName = "Courier"; }
    100      else if(font.fontName.equals(GralFont.fontSansSerif)){ fontName = "Arial"; }
    101      else if(font.fontName.equals(GralFont.fontSerif)){ fontName = "Serif"; }
    102      else {fontName = font.fontName; }
    103      font.fontImpl = new Font(fontName, font.size, styleSwt);
    104    } else if(!(font.fontImpl instanceof Font)){
    105      throw new IllegalArgumentException("unauthorized font setting");
    106    }
    107    return (Font)font.fontImpl;
    108  }
    109
    110
    111
    112}