Examples of GlyphVector


Examples of java.awt.font.GlyphVector

   * @throws FontFormatException
   * @throws IOException
   */
  private int drawRow(Graphics2D g2d, int y,int leftBorder, String text) throws FontFormatException, IOException{
    y += positions.lineHeight;
    GlyphVector gv = opPainter.createGlyphVector(g2d, text, 18);
    int x = leftBorder-(int)Math.rint(gv.getVisualBounds().getWidth());
    g2d.drawGlyphVector(gv, x, y);
    return y;
  }
View Full Code Here

Examples of java.awt.font.GlyphVector

  protected BufferedImage initBackgroundImage(IImageLoader loader,Point topLeft) {
    BufferedImage bg = super.initBackgroundImage(loader,topLeft);
    Graphics2D g2d = bg.createGraphics();
    g2d.setColor(Color.BLACK);
    try {
      GlyphVector gv = opPainter.createGlyphVector(g2d, "Weapon Inventory", 24); // TODO externalize
      double titleHeight = gv.getVisualBounds().getHeight();
      int length = (int) Math.rint(gv.getVisualBounds().getWidth());
      int x = ((bg.getWidth()-getInset().left-getInset().right)-length)/2;
      int y = getInset().top+10+(int)Math.rint(titleHeight*2/3);
      g2d.drawGlyphVector(gv, x, y);
      // Dynamic row
      y += titleHeight;
      y += (int)Math.rint(titleHeight*2/3);
     
      BufferedImage waxSeal = loader.getImage("waxseal");
      int leftBorderX = topLeft.x+getInset().left;
      int firstColumn = leftBorderX+150; // right aligned
      int secondcolumn = leftBorderX+200;
      int yLineDiff = waxSeal.getHeight();
      // Initialize the position relative to the frame
      positions = new DialogPositions(titleHeight, yLineDiff, firstColumn,secondcolumn);
     
      leftBorderX = getInset().left; // Use local coordinates
      firstColumn = leftBorderX+150; // right aligned
     
      y += positions.lineHeight;
      y += positions.lineHeight;
      y += positions.lineHeight;
      y += positions.lineHeight;
      y += positions.titleHeigth;
      // table header
      y += positions.lineHeight; // more space to the title
      y += positions.lineHeight;
     
      // Table
      for (IWeapon weapon : EWeapon.values()){
        y = drawRow(g2d, y, firstColumn, weapon.getLocalDisplayName());
      }

      // Footer buttons
      y = bg.getHeight()-getInset().bottom-positions.lineHeight;
      x = getInset().left+30;
      int footerWidth = bg.getWidth()-getInset().left-getInset().right-2*30;
      x += 3*footerWidth/4;
      // close
      g2d.drawImage(waxSeal, x,y-(int)(positions.lineHeight*0.8), null);
      NamedPolygon polygon = new NamedPolygon("Close");
      polygon.addPoint(topLeft.x+x, topLeft.y+y-(int)(positions.lineHeight*0.8));
      polygon.addPoint(topLeft.x+x+waxSeal.getWidth(), topLeft.y+y-(int)(positions.lineHeight*0.8));
      polygon.addPoint(topLeft.x+x+waxSeal.getWidth(), topLeft.y+y-(int)(positions.lineHeight*0.8)+waxSeal.getHeight());
      polygon.addPoint(topLeft.x+x, topLeft.y+y-(int)(positions.lineHeight*0.8)+waxSeal.getHeight());
      footerPolygons.add(polygon, new CloseAction(this));
      g2d.setColor(new Color(0xEA,0xC1,0x17)); // Gold
      gv = opPainter.createGlyphVector(g2d, "X", 18);
      int xPadding = imageUtils.computeCenterAlignX(x, waxSeal.getWidth(), (int)gv.getVisualBounds().getWidth());
      g2d.drawGlyphVector(gv, xPadding, y); // centeralign


    } catch (FontFormatException e1) {
      e1.printStackTrace();
View Full Code Here

Examples of java.awt.font.GlyphVector

   * @throws FontFormatException
   * @throws IOException
   */
  private int drawRow(Graphics2D g2d, int y,int leftBorder, String text) throws FontFormatException, IOException{
    y += positions.lineHeight;
    GlyphVector gv = opPainter.createGlyphVector(g2d, text, 18);
    int x = leftBorder-(int)Math.rint(gv.getVisualBounds().getWidth());
    g2d.drawGlyphVector(gv, x, y);
    return y;
  }
View Full Code Here

Examples of java.awt.font.GlyphVector

  protected BufferedImage initBackgroundImage(IImageLoader loader,Point topLeft) {
    BufferedImage bg = super.initBackgroundImage(loader,topLeft);
    Graphics2D g2d = bg.createGraphics();
    g2d.setColor(Color.BLACK);
    try {
      GlyphVector gv = opPainter.createGlyphVector(g2d, "Storage", 24); // TODO externalize
      double titleHeight = gv.getVisualBounds().getHeight();
      int length = (int) Math.rint(gv.getVisualBounds().getWidth());
      int x = ((bg.getWidth()-getInset().left-getInset().right)-length)/2;
      int y = getInset().top+10+(int)Math.rint(titleHeight*2/3);
      g2d.drawGlyphVector(gv, x, y);
      // Dynamic row
      y += titleHeight;
      y += (int)Math.rint(titleHeight*2/3);
     
      BufferedImage waxSeal = loader.getImage("waxseal");
      final BufferedImage plus = loader.getImage("plusIcon");
      final BufferedImage minus = loader.getImage("minusIcon");
      final BufferedImage barrel = loader.getImage("barrel_icon");
      final BufferedImage bale = loader.getImage("bale_icon");
      BufferedImage coin = loader.getImage("coin_icon");
     
      int leftBorderX = topLeft.x+getInset().left;
      int firstColumn = leftBorderX+230; // right aligned
      int icons = leftBorderX+350;
      int xMinus = leftBorderX+300;
      int numbers = leftBorderX+335;
      int yLineDiff = waxSeal.getHeight();
      // Initialize the position relative to the frame
      positions = new DialogPositions(titleHeight, yLineDiff, numbers);
     
      leftBorderX = getInset().left; // Use local coordinates
      firstColumn = leftBorderX+230; // right aligned
      icons = leftBorderX+350;
      xMinus = leftBorderX+300;
      numbers = leftBorderX+335;
     
     
      y += 5*positions.lineHeight;
     
      // Table
      String s = "Required storage capacity";
      y = drawRow(g2d, y, firstColumn, s);
      g2d.drawImage(bale, icons,y-(int)(positions.lineHeight*0.8), null);
     
      s = "Available storage capacity";
      y = drawRow(g2d, y, firstColumn, s);
      g2d.drawImage(bale, icons,y-(int)(positions.lineHeight*0.8), null);

      s = "Additional storage capacity";
      y = drawRow(g2d, y, firstColumn, s);
      g2d.drawImage(bale, icons,y-(int)(positions.lineHeight*0.8), null);

      s = "Other goods";
      y = drawRow(g2d, y, firstColumn, s);
      g2d.drawImage(barrel, icons,y-(int)(positions.lineHeight*0.8), null);

      s = "Costs (per day)";
      y = drawRow(g2d, y, firstColumn, s);
      g2d.drawImage(coin, icons,y-(int)(positions.lineHeight*0.8), null);
     
      y += positions.lineHeight;
      y += positions.lineHeight;
      y += positions.lineHeight;

      s = "Guards";
      gv = opPainter.createGlyphVector(g2d, s, 18);
      length = (int) Math.rint(gv.getVisualBounds().getWidth());
      x = ((bg.getWidth()-getInset().left-getInset().right)-length)/2;
      g2d.drawGlyphVector(gv, x, y);
     
      s = "Number of Guards";
      y = drawRow(g2d, y, firstColumn, s);     
     
      x = xMinus;
      g2d.drawImage(minus, x,y-(int)(positions.lineHeight*0.8), null);
      NamedPolygon polygon = new NamedPolygon("MinusOneGuard");
      polygon.addPoint(topLeft.x+x, topLeft.y+y-(int)(positions.lineHeight*0.8));
      polygon.addPoint(topLeft.x+x+waxSeal.getWidth(), topLeft.y+y-(int)(positions.lineHeight*0.8));
      polygon.addPoint(topLeft.x+x+waxSeal.getWidth(), topLeft.y+y-(int)(positions.lineHeight*0.8)+minus.getHeight());
      polygon.addPoint(topLeft.x+x, topLeft.y+y-(int)(positions.lineHeight*0.8)+minus.getHeight());
      polygons.add(polygon, new GuardNumberChange(-1));

      x = icons;
      g2d.drawImage(plus, x,y-(int)(positions.lineHeight*0.8), null);
      polygon = new NamedPolygon("PlusOneGuard");
      polygon.addPoint(topLeft.x+x, topLeft.y+y-(int)(positions.lineHeight*0.8));
      polygon.addPoint(topLeft.x+x+waxSeal.getWidth(), topLeft.y+y-(int)(positions.lineHeight*0.8));
      polygon.addPoint(topLeft.x+x+waxSeal.getWidth(), topLeft.y+y-(int)(positions.lineHeight*0.8)+plus.getHeight());
      polygon.addPoint(topLeft.x+x, topLeft.y+y-(int)(positions.lineHeight*0.8)+plus.getHeight());
      polygons.add(polygon, new GuardNumberChange(1));
     
      s = "Costs (per day)";
      y = drawRow(g2d, y, firstColumn, s);
      g2d.drawImage(coin, icons,y-(int)(positions.lineHeight*0.8), null);
     
      s = "Security";
      y = drawRow(g2d, y, firstColumn, s);

      // Footer buttons
      y = bg.getHeight()-getInset().bottom-positions.lineHeight;
      x = getInset().left+30;
      int footerWidth = bg.getWidth()-getInset().left-getInset().right-2*30;
      x += 3*footerWidth/4;
      // close
      g2d.drawImage(waxSeal, x,y-(int)(positions.lineHeight*0.8), null);
      polygon = new NamedPolygon("Close");
      polygon.addPoint(topLeft.x+x, topLeft.y+y-(int)(positions.lineHeight*0.8));
      polygon.addPoint(topLeft.x+x+waxSeal.getWidth(), topLeft.y+y-(int)(positions.lineHeight*0.8));
      polygon.addPoint(topLeft.x+x+waxSeal.getWidth(), topLeft.y+y-(int)(positions.lineHeight*0.8)+waxSeal.getHeight());
      polygon.addPoint(topLeft.x+x, topLeft.y+y-(int)(positions.lineHeight*0.8)+waxSeal.getHeight());
      footerPolygons.add(polygon, new CloseAction(this));
      g2d.setColor(new Color(0xEA,0xC1,0x17)); // Gold
      gv = opPainter.createGlyphVector(g2d, "X", 18);
      int xPadding = imageUtils.computeCenterAlignX(x, waxSeal.getWidth(), (int)gv.getVisualBounds().getWidth());
      g2d.drawGlyphVector(gv, xPadding, y); // centeralign


    } catch (FontFormatException e1) {
      e1.printStackTrace();
View Full Code Here

Examples of java.awt.font.GlyphVector

//    final int y = rect.y+rect.height/2;
//    gScr.drawString("ViewStatus", x, y);
    try {
      Font font = fontLoader.createDefaultDecorativeFont();
      font = font.deriveFont(18f);
      GlyphVector gv =opPainter.createGlyphVector((Graphics2D) gScr, cityName, font);
      Rectangle2D gvBounds = gv.getVisualBounds();
      int xPadding = (int) ((rect.width-gvBounds.getWidth())/2);
      ((Graphics2D)gScr).drawGlyphVector(gv, rect.x+xPadding, (rect.y+rect.height)*3/4);
    } catch (FontFormatException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
View Full Code Here

Examples of java.awt.font.GlyphVector

      String s = text;
      if (s==null){
        s="";
      }
      Graphics2D g2d = (Graphics2D) g;
      GlyphVector gv = painter.createGlyphVector(g2d,s, font.getSize());
      int descent = metric.getDescent();
      g2d.drawGlyphVector(gv, bounds.x, bounds.y+bounds.height-descent);
    } catch (FontFormatException e) {
      e.printStackTrace();
    } catch (IOException e) {
View Full Code Here

Examples of java.awt.font.GlyphVector

    if (drawCarret && hasFocus){
      s += "|";
    }
    if (s!=null && s.length()>0){
      try {
        GlyphVector gv = painter.createGlyphVector(s, getFont().getSize());
        Insets insets = getInsets();
        int x = rect.x+insets.left;
        int y = rect.y+insets.top+rect.height-TEXT_INSET;
        int descent = metric.getDescent();
        ((Graphics2D)g).drawGlyphVector(gv, x, y-descent); // (x,y) denotes the baseline of the leftmost character
View Full Code Here

Examples of java.awt.font.GlyphVector

   * @param s String to be used
   * @return Rectangle representing the visual bounds of s
   */
  protected final Rectangle2D createVisualBounds(String s) {
    try {
      GlyphVector gv = painter.createGlyphVector(s, getFont().getSize());
      Rectangle2D view = gv.getVisualBounds();
      return view;
    } catch (FontFormatException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
View Full Code Here

Examples of java.awt.font.GlyphVector

//    gScr.fillRect(rect.x, rect.y, rect.width, rect.height);
    gScr.setColor(Color.WHITE);
    int x = 20+rect.x;
    final int y = rect.y+rect.height/2;
    try {
      GlyphVector gv = opPainter.createGlyphVector((Graphics2D) gScr, cash, 18);
      ((Graphics2D)gScr).drawGlyphVector(gv, x, y);
      gv = opPainter.createGlyphVector((Graphics2D) gScr, date, 18);
      Rectangle2D b = gv.getVisualBounds();
      x = (int) (rect.x+rect.width-20-b.getWidth());
      ((Graphics2D)gScr).drawGlyphVector(gv, x, y);
    } catch (FontFormatException e) {
      e.printStackTrace();
    } catch (IOException e) {
View Full Code Here

Examples of java.awt.font.GlyphVector

  protected BufferedImage initBackgroundImage(IImageLoader loader,Point topLeft) {
    BufferedImage bg = super.initBackgroundImage(loader,topLeft);
    Graphics2D g2d = bg.createGraphics();
    g2d.setColor(Color.BLACK);
    try {
      GlyphVector gv = opPainter.createGlyphVector(g2d, "Personal", 24); // TODO externalize
      double titleHeight = gv.getVisualBounds().getHeight();
      int length = (int) Math.rint(gv.getVisualBounds().getWidth());
      int x = ((bg.getWidth()-getInset().left-getInset().right)-length)/2;
      int y = getInset().top+10+(int)Math.rint(titleHeight*2/3);
      g2d.drawGlyphVector(gv, x, y);
      // Dynamic row
      y += titleHeight;
      y += (int)Math.rint(titleHeight*2/3);
     
      BufferedImage waxSeal = loader.getImage("waxseal");
      int yLineDiff = waxSeal.getHeight();
      int leftBorderX = topLeft.x+getInset().left;
      int firstColumn = leftBorderX+20; // right aligned
      int xPortrait = leftBorderX+200;
      int yPortrait = y+yLineDiff*10;
      // Initialize the position relative to the frame
      positions = new DialogPositions( yLineDiff, xPortrait,yPortrait);
     
      leftBorderX = getInset().left; // Use local coordinates
      firstColumn = leftBorderX+20; // right aligned
     
      // table header
      IPlayer player = city.getPlayer();
      IPersonalData data = player.getPersonalData();
      y += positions.lineHeight; // more space to the title
     
      // Name
      y = drawRow(g2d, y, firstColumn, "Name");
      StringBuilder sb = new StringBuilder();
      sb.append(data.getName()).append(" ").append(data.getLastName());
      ESocialRank rank = player.getRank();
      sb.append(" (").append(player.getCareerLevel()).append(" ").append(rank).append(")"); // TODO externalize
      y = drawRow(g2d, y, firstColumn, sb.toString());
     
      y += positions.lineHeight;
     
      // Birth
      DateObject now = new DateObject(Date.getInstance(0).getCurrentDate()); // TODO ugly
      y = drawRow(g2d, y, firstColumn, "Born");
      sb = new StringBuilder();
      ICity birthPlace = data.getBirthPlace();
      sb.append("on ").append(data.getBirthDate().toDisplayString()).append(" in ").append(birthPlace.getName()).append(", ");
      sb.append("Age ").append(data.getAge(now));
      y = drawRow(g2d, y, firstColumn, sb.toString());

      y += positions.lineHeight;

      y = drawRow(g2d, y, firstColumn, "Hometown");
      y = drawRow(g2d, y, firstColumn, player.getHometown().getName());
     
      y += positions.lineHeight;
      sb = new StringBuilder();
      sb.append("Social status in this town: ").append(city.getCity().getSocialRank());
      y = drawRow(g2d, y, firstColumn, sb.toString());
     
      IReputation rep = city.getCity().getReputation(player);
      int repDiff = rep.getReputationDifference();
      sb = new StringBuilder();
      if (repDiff<0){
        // reputation has sunk
        if (repDiff<=-10 && repDiff>-25){
          sb.append("Your reputation has sunken.");
        } else if (repDiff>-10){
          sb.append("Your reputation has sunken slightly");
        } else {
          sb.append("Your reputation has dropped");
        }
      } else if (repDiff>0){
        // reputation has risen
        if (repDiff>=10 && repDiff<25){
          sb.append("Your reputation has risen");
        } else if (repDiff<10){
          sb.append("Your reputation has risen slightly");
        } else {
          sb.append("Your reputation has risen massivly");
        }
      } else {
        sb.append("Your reputation in this city is unchanged");
      }
      y = drawRow(g2d, y, firstColumn, sb.toString());
     
      if (rank!=ESocialRank.ALDERMAN && rank!=ESocialRank.MAYOR){
        // draw string what is needed
        ESocialRank nextRank = rank.getNextRank();
        boolean needFortune = false;
        if (player.getCompany().getCompanyValue()<nextRank.getCompanyValue()){
          needFortune=true;
        }
        boolean needReputation=false;
        if (city.getCity().getReputation(player).getPopularity()<nextRank.getSocialReputation()){
          needReputation=true;
        }
        sb = new StringBuilder();
        if (needFortune && needReputation){
          sb.append("You need more fortune and respect in ").append(city.getCity().getName()).append(" to");
          y = drawRow(g2d, y, firstColumn, sb.toString());
          sb = new StringBuilder();
          sb.append("advanve to the next social rank");
          y = drawRow(g2d, y, firstColumn, sb.toString());
        } else if (needFortune){
          sb.append("You need more fortune in ").append(city.getCity().getName()).append(" to");
          y = drawRow(g2d, y, firstColumn, sb.toString());
          sb = new StringBuilder();
          sb.append("advanve to the next social rank");
          y = drawRow(g2d, y, firstColumn, sb.toString());
        } else if (needReputation){
          sb.append("You need more respect in ").append(city.getCity().getName()).append(" to");
          y = drawRow(g2d, y, firstColumn, sb.toString());
          sb = new StringBuilder();
          sb.append("advanve to the next social rank");
          y = drawRow(g2d, y, firstColumn, sb.toString());
        } else {
          y += positions.lineHeight;
          y += positions.lineHeight;
        }
      } else {
        y += positions.lineHeight;
        y += positions.lineHeight;
      }
     
      // Draw underworld string
      ICareer careerLevel = player.getCareerLevel();
      String s;
      if (careerLevel instanceof IMilitantCareer){
        if (((EMilitantCareer)careerLevel)!=EMilitantCareer.BOISTEROUS &&
          ((EMilitantCareer)careerLevel)!=EMilitantCareer.BOLD ){
          s = "The underworld fears you";
        } else {
          s = "The underworld avoids you";
        }
      } else {
        s = "The underworld avoids you";
      }
      y = drawRow(g2d, y, firstColumn, s);
      y += positions.lineHeight;
     
      if (player.getSpouseData()!=null){
        ISpouseData spouse = player.getSpouseData();
        // Name
        if (spouse.isMale()){
          s = "Name of husband"; // TODO externalize
        } else {
          s = "Name of wife";
        }
        y = drawRow(g2d, y, firstColumn, s);
        sb = new StringBuilder();
        sb.append(spouse.getName()).append(" ").append(spouse.getLastName());
        sb.append(", Age ").append(spouse.getAge(now));
        y = drawRow(g2d, y, firstColumn, sb.toString());
       
        y += positions.lineHeight;
       
        // Birth
        y = drawRow(g2d, y, firstColumn, "Born");
        sb = new StringBuilder();
        sb.append("on ").append(data.getBirthDate().toDisplayString()).append(" in ").append(birthPlace.getName());
        y = drawRow(g2d, y, firstColumn, sb.toString());

        y += positions.lineHeight;

        y = drawRow(g2d, y, firstColumn, "Children");
        y = drawRow(g2d, y, firstColumn, String.valueOf(spouse.getNumberOfChildren()));
       
        y += positions.lineHeight;

        sb = new StringBuilder();
        if (city.getCity()==birthPlace){
          // TODO consider the spouses popularity and relations
          if (spouse.isMale()){
            sb.append("Your husband is unknown to the citizens of ").append(city.getCity().getName());
          } else {
            sb.append("Your wife is unknown to the citizens of ").append(city.getCity().getName());
          }
          y = drawRow(g2d, y, firstColumn, sb.toString());
          sb = new StringBuilder();
          y = drawRow(g2d, y, firstColumn, sb.toString());
          sb.append("and has no relations with the counsilmen.");
        } else if (city.getCity()==player.getCompany().getHomeTown()){
          // TODO consider the spouses popularity and relations
          if (spouse.isMale()){
            sb.append("Your husband is unknown to the citizens of ").append(city.getCity().getName());
          } else {
            sb.append("Your wife is unknown to the citizens of ").append(city.getCity().getName());
          }
          y = drawRow(g2d, y, firstColumn, sb.toString());
          sb = new StringBuilder();
          y = drawRow(g2d, y, firstColumn, sb.toString());
          sb.append("and has no relations with the counsilmen.");
        } else {
          if (spouse.isMale()){
            sb.append("Your husband is unknown to the citizens of ").append(city.getCity().getName());
          } else {
            sb.append("Your wife is unknown to the citizens of ").append(city.getCity().getName());
          }
          y = drawRow(g2d, y, firstColumn, sb.toString());
          sb = new StringBuilder();
          y = drawRow(g2d, y, firstColumn, sb.toString());
          sb.append("and has no relations with the counsilmen.");
        }
        if (spouse.getPortrait()!=null){
          g2d.drawImage(spouse.getPortrait(), positions.xPortrait,  positions.yPortrait, null);
        }
      }

      // Footer buttons
      y = bg.getHeight()-getInset().bottom-positions.lineHeight;
      x = getInset().left+30;
      int footerWidth = bg.getWidth()-getInset().left-getInset().right-2*30;
      x += 3*footerWidth/4;
      // close
      g2d.drawImage(waxSeal, x,y-(int)(positions.lineHeight*0.8), null);
      NamedPolygon polygon = new NamedPolygon("Close");
      polygon.addPoint(topLeft.x+x, topLeft.y+y-(int)(positions.lineHeight*0.8));
      polygon.addPoint(topLeft.x+x+waxSeal.getWidth(), topLeft.y+y-(int)(positions.lineHeight*0.8));
      polygon.addPoint(topLeft.x+x+waxSeal.getWidth(), topLeft.y+y-(int)(positions.lineHeight*0.8)+waxSeal.getHeight());
      polygon.addPoint(topLeft.x+x, topLeft.y+y-(int)(positions.lineHeight*0.8)+waxSeal.getHeight());
      footerPolygons.add(polygon, new CloseAction(this));
      g2d.setColor(new Color(0xEA,0xC1,0x17)); // Gold
      gv = opPainter.createGlyphVector(g2d, "X", 18);
      int xPadding = imageUtils.computeCenterAlignX(x, waxSeal.getWidth(), (int)gv.getVisualBounds().getWidth());
      g2d.drawGlyphVector(gv, xPadding, y); // centeralign


    } catch (FontFormatException e1) {
      e1.printStackTrace();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.