/**
   * Description of the Method
   *
   * @param ctx
   * @param root_font PARAM
   * @param size PARAM
   * @param weight PARAM
   * @param style PARAM
   * @param variant PARAM
   * @return Returns
   */
  protected static Font createFont(
      final SharedContext ctx,
      final Font root_font,
      float size,
      final IdentValue weight,
      final IdentValue style,
      final IdentValue variant) {
    // Uu.p("creating font: " + root_font + " size = " + size +
    //    " weight = " + weight + " style = " + style + " variant = " + variant);
    int font_const = Font.PLAIN;
    if (weight != null
        && (weight == IdentValue.BOLD
            || weight == IdentValue.FONT_WEIGHT_700
            || weight == IdentValue.FONT_WEIGHT_800
            || weight == IdentValue.FONT_WEIGHT_900)) {

      font_const = font_const | Font.BOLD;
    }
    if (style != null && (style == IdentValue.ITALIC || style == IdentValue.OBLIQUE)) {
      font_const = font_const | Font.ITALIC;
    }

    // scale vs font scale value too
    size *= ctx.getTextRenderer().getFontScale();

    Font fnt = root_font.deriveFont(font_const, size);
    if (variant != null) {
      if (variant == IdentValue.SMALL_CAPS) {
        fnt = fnt.deriveFont((float) (((float) fnt.getSize()) * 0.6));
      }
    }

    return fnt;
  }
Exemple #2
0
  public void paint(Graphics2D g) {
    Font origFont = g.getFont();

    g.setRenderingHint(
        java.awt.RenderingHints.KEY_ANTIALIASING, java.awt.RenderingHints.VALUE_ANTIALIAS_ON);

    // 1) create scaled font
    Font font = origFont.deriveFont(AffineTransform.getScaleInstance(1.5, 3));
    g.setFont(font);
    g.drawString("Scaled Font", 20, 40);

    // 2) create translated font
    font = origFont.deriveFont(AffineTransform.getTranslateInstance(50, 20));
    g.setFont(font);
    g.drawString("Translated Font", 20, 80);
    g.drawLine(20, 80, 120, 80);

    // 3) create sheared font
    font = origFont.deriveFont(AffineTransform.getShearInstance(.5, .5));
    g.setFont(font);
    g.drawString("Sheared Font", 20, 120);

    // 4) create rotated font
    font = origFont.deriveFont(AffineTransform.getRotateInstance(Math.PI / 4));
    g.setFont(font);
    g.drawString("Rotated Font", 220, 120);
  }
Exemple #3
0
  protected void initFont() {
    myNormalFont = createFont();
    myBoldFont = myNormalFont.deriveFont(Font.BOLD);
    myItalicFont = myNormalFont.deriveFont(Font.ITALIC);
    myBoldItalicFont = myBoldFont.deriveFont(Font.ITALIC);

    establishFontMetrics();
  }
  public void initializeComponents() {

    Font font;
    try {
      font = Font.createFont(Font.TRUETYPE_FONT, new FileInputStream("images/Riffic.ttf"));
      Font styledAndSized = font.deriveFont(42F);
      hostLabel = new JLabel("Host");
      hostLabel.setFont(styledAndSized);
      portLabel = new JLabel("Port:");
      styledAndSized = font.deriveFont(28F);
      portLabel.setFont(styledAndSized);
      portTF = new JTextField(5);
      portTF.setFont(styledAndSized);

      portTF
          .getDocument()
          .addDocumentListener(
              new DocumentListener() {
                public void changedUpdate(DocumentEvent e) {
                  changed();
                }

                public void removeUpdate(DocumentEvent e) {
                  changed();
                }

                public void insertUpdate(DocumentEvent e) {
                  changed();
                }

                public void changed() {
                  if (portTF.getText().equals("")) {
                    submitButton.setEnabled(false);
                  } else {
                    submitButton.setEnabled(true);
                  }
                }
              });

      submitButton = new JButton("Submit");
      styledAndSized = font.deriveFont(20F);
      submitButton.setFont(styledAndSized);
      submitButton.setPreferredSize(new Dimension(200, 50));
      buttonPanel = new JPanel();
      hostPanel = new JPanel();

    } catch (FileNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (FontFormatException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
 /**
  * Loads the Bootstrap font containing the glyphs
  *
  * @param size Desired font size
  * @return Font object for Bootstrap Glyph Font
  * @throws FontFormatException
  * @throws IOException
  */
 private Font loadGlyphFont(float size) throws FontFormatException, IOException {
   Font fontRaw =
       Font.createFont(
           Font.TRUETYPE_FONT,
           this.getClass()
               .getResourceAsStream("/resource/image/glyphicons-halflings-regular.ttf"));
   Font fontBase = fontRaw.deriveFont(16f);
   return fontBase.deriveFont(Font.PLAIN, size);
 }
Exemple #6
0
  public HighScorePanel() {
    super.setLayout(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.insets = new Insets(10, 0, 0, 0);

    HighScore[] hsdb = HighScore.readFromFile();
    int easyScore = hsdb[0].getScore();
    int medScore = hsdb[1].getScore();
    int hardScore = hsdb[2].getScore();

    String easy = easyScore + "";
    String med = medScore + "";
    String hard = hardScore + "";
    String easyN = hsdb[0].getUserName();
    String medN = hsdb[1].getUserName();
    String hardN = hsdb[2].getUserName();
    JLabel easyLabel = new JLabel("Easy:");
    Font f = easyLabel.getFont();
    easyLabel.setFont(f.deriveFont(f.getStyle() ^ Font.BOLD));
    JLabel easyNameLabel = new JLabel("Name: " + easyN);
    JLabel easyScoreLabel = new JLabel("Score: " + easy);
    JLabel medLabel = new JLabel("Medium:");
    medLabel.setFont(f.deriveFont(f.getStyle() ^ Font.BOLD));
    JLabel medNameLabel = new JLabel("Name: " + medN);
    JLabel medScoreLabel = new JLabel("Score: " + med);
    JLabel hardLabel = new JLabel("Hard:");
    hardLabel.setFont(f.deriveFont(f.getStyle() ^ Font.BOLD));
    JLabel hardNameLabel = new JLabel("Name: " + hardN);
    JLabel hardScoreLabel = new JLabel("Score: " + hard);
    JLabel highScores = new JLabel("High Scores");
    gbc.gridy = 0;
    super.add(highScores, gbc);
    gbc.gridy++;
    super.add(easyLabel, gbc);
    gbc.insets = new Insets(2, 0, 2, 0);
    gbc.gridy++;
    super.add(easyNameLabel, gbc);
    gbc.gridy++;
    super.add(easyScoreLabel, gbc);
    gbc.insets = new Insets(10, 0, 0, 0);
    gbc.gridy++;
    super.add(medLabel, gbc);
    gbc.insets = new Insets(2, 0, 2, 0);
    gbc.gridy++;
    super.add(medNameLabel, gbc);
    gbc.gridy++;
    super.add(medScoreLabel, gbc);
    gbc.insets = new Insets(10, 0, 0, 0);
    gbc.gridy++;
    super.add(hardLabel, gbc);
    gbc.insets = new Insets(2, 0, 2, 0);
    gbc.gridy++;
    super.add(hardNameLabel, gbc);
    gbc.gridy++;
    super.add(hardScoreLabel, gbc); // initiates all labels and adds them
  }
Exemple #7
0
  private Font derive(Font font, String value) throws Exception {
    if (value.equals("bold")) return font.deriveFont(Font.BOLD);
    if (value.equals("italic")) return font.deriveFont(Font.ITALIC);
    if (value.equals("plain")) return font.deriveFont(Font.PLAIN);

    try {
      int size = Integer.parseInt(value);
      return font.deriveFont((float) size);
    } catch (NumberFormatException e) {
    }

    throw new Exception("Unsupported font derive value: " + value);
  }
  public RollResultView() {

    this.setOpaque(true);
    this.setLayout(new BorderLayout());
    this.setBorder(BorderFactory.createLineBorder(Color.black, BORDER_WIDTH));

    // add the title label to the panel
    titleLabel = new JLabel("Roll Results");
    Font titleLabelFont = titleLabel.getFont();
    titleLabelFont = titleLabelFont.deriveFont(titleLabelFont.getStyle(), TITLE_TEXT_SIZE);
    titleLabel.setFont(titleLabelFont);
    this.add(titleLabel, BorderLayout.NORTH);

    // add the button to the panel
    okayButton = new JButton("Okay");
    okayButton.addActionListener(actionListener);
    Font okayButtonFont = okayButton.getFont();
    okayButtonFont = okayButtonFont.deriveFont(okayButtonFont.getStyle(), BUTTON_TEXT_SIZE);
    okayButton.setFont(okayButtonFont);
    this.add(okayButton, BorderLayout.SOUTH);

    // create the rollLabel
    rollLabel =
        new JLabel(
            "ERROR: YOU FORGOT TO SET THE ROLL VALUE BEFORE DISPLAYING THIS WINDOW... NAUGHTY, NAUGHTY");
    Font rollLabelFont = rollLabel.getFont();
    rollLabelFont = rollLabelFont.deriveFont(rollLabelFont.getStyle(), LABEL_TEXT_SIZE);
    rollLabel.setFont(rollLabelFont);
    rollLabel.setHorizontalAlignment(SwingConstants.CENTER);
    rollLabel.setBorder(BorderFactory.createEmptyBorder(25, 0, 25, 0));

    // create the picture
    picture =
        new ImageIcon(
            ImageUtils.loadImage("images/resources/resources.png")
                .getScaledInstance(250, 250, Image.SCALE_SMOOTH));
    pictureLabel = new JLabel();
    pictureLabel.setIcon(picture);

    // create the center label
    centerPanel = new JPanel();
    centerPanel.setLayout(new BorderLayout());
    centerPanel.add(pictureLabel, BorderLayout.NORTH);
    centerPanel.add(Box.createRigidArea(new Dimension(25, 25)));
    centerPanel.add(rollLabel, BorderLayout.SOUTH);
    this.add(centerPanel, BorderLayout.CENTER);

    // add some spacing
    this.add(Box.createRigidArea(new Dimension(50, 50)), BorderLayout.EAST);
    this.add(Box.createRigidArea(new Dimension(50, 50)), BorderLayout.WEST);
  }
Exemple #9
0
  /**
   * Create a new font data element
   *
   * @param ttf The TTF file to read
   * @param size The size of the new font
   * @throws java.io.IOException Indicates a failure to
   */
  private FontData(InputStream ttf, float size) throws IOException {
    if (ttf.available() > MAX_FILE_SIZE) {
      throw new IOException("Can't load font - too big");
    }
    byte[] data = IOUtils.toByteArray(ttf);
    if (data.length > MAX_FILE_SIZE) {
      throw new IOException("Can't load font - too big");
    }

    this.size = size;
    try {
      javaFont = Font.createFont(Font.TRUETYPE_FONT, new ByteArrayInputStream(data));
      TTFFile rawFont = new TTFFile();
      if (!rawFont.readFont(new FontFileReader(data))) {
        throw new IOException("Invalid font file");
      }
      upem = rawFont.getUPEM();
      ansiKerning = rawFont.getAnsiKerning();
      charWidth = rawFont.getAnsiWidth();
      fontName = rawFont.getPostScriptName();
      familyName = rawFont.getFamilyName();

      String name = getName();
      System.err.println("Loaded: " + name + " (" + data.length + ")");
      boolean bo = false;
      boolean it = false;
      if (name.indexOf(',') >= 0) {
        name = name.substring(name.indexOf(','));

        if (name.indexOf("Bold") >= 0) {
          bo = true;
        }
        if (name.indexOf("Italic") >= 0) {
          it = true;
        }
      }

      if ((bo & it)) {
        javaFont = javaFont.deriveFont(Font.BOLD | Font.ITALIC);
      } else if (bo) {
        javaFont = javaFont.deriveFont(Font.BOLD);
      } else if (it) {
        javaFont = javaFont.deriveFont(Font.ITALIC);
      }
    } catch (FontFormatException e) {
      IOException x = new IOException("Failed to read font");
      x.initCause(e);
      throw x;
    }
  }
Exemple #10
0
 BufferedImage drawText(boolean doGV) {
   int w = 400;
   int h = 50;
   BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
   Graphics2D g = bi.createGraphics();
   g.setColor(Color.white);
   g.fillRect(0, 0, w, h);
   g.setColor(Color.black);
   Font f = helvFont.deriveFont(Font.PLAIN, 40);
   g.setFont(f);
   int x = 5;
   int y = h - 10;
   if (doGV) {
     FontRenderContext frc = new FontRenderContext(null, true, true);
     GlyphVector gv = f.createGlyphVector(frc, codes);
     g.drawGlyphVector(gv, 5, y);
   } else {
     g.setRenderingHint(
         RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
     g.setRenderingHint(
         RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
     g.drawString(str, x, y);
   }
   return bi;
 }
  /** Builds the Network panel. */
  protected JPanel buildNetworkPanel() {
    JGridBagPanel p = new JGridBagPanel();
    p.setBorder(BorderFactory.createEmptyBorder(16, 16, 16, 16));

    JLabel proxyLabel = new JLabel(Resources.getString(PREFERENCE_KEY_LABEL_HTTP_PROXY));
    JLabel hostLabel = new JLabel(Resources.getString(PREFERENCE_KEY_LABEL_HOST));
    JLabel portLabel = new JLabel(Resources.getString(PREFERENCE_KEY_LABEL_PORT));
    JLabel colonLabel = new JLabel(Resources.getString(PREFERENCE_KEY_LABEL_COLON));
    Font f = hostLabel.getFont();
    float size = f.getSize2D() * 0.85f;
    f = f.deriveFont(size);
    hostLabel.setFont(f);
    portLabel.setFont(f);
    host = new JTextField();
    host.setPreferredSize(new Dimension(200, 20));
    port = new JTextField();
    port.setPreferredSize(new Dimension(40, 20));

    p.add(proxyLabel, 0, 0, 1, 1, EAST, NONE, 0, 0);
    p.add(host, 1, 0, 1, 1, WEST, HORIZONTAL, 0, 0);
    p.add(colonLabel, 2, 0, 1, 1, WEST, NONE, 0, 0);
    p.add(port, 3, 0, 1, 1, WEST, HORIZONTAL, 0, 0);
    p.add(hostLabel, 1, 1, 1, 1, WEST, NONE, 0, 0);
    p.add(portLabel, 3, 1, 1, 1, WEST, NONE, 0, 0);

    return p;
  }
  @Override
  public void drawString(String string, BoundingBox2d bounds, double padding) {
    FontMetrics metrics = pipe.getFontMetrics(pipe.getFont());

    final double stringWidth = metrics.stringWidth(string);
    final double stringHeight = metrics.getHeight();

    // calculate scale, so that bb fits into bounds - padding
    final double sx = bounds.getWidth() / (stringWidth + padding);
    final double sy = bounds.getHeight() / (stringHeight + padding);

    final double scale = Math.min(sx, sy);

    java.awt.Font oldFont = pipe.getFont();
    java.awt.Font scaledFont = oldFont.deriveFont((float) (oldFont.getSize2D() * scale));

    // position b inside bounds
    final double x = bounds.getLocation().getX() + (bounds.getWidth() - stringWidth * scale) / 2;
    final double y =
        bounds.getLocation().getY()
            + bounds.getHeight()
            - (bounds.getHeight() - scaledFont.getSize2D()) / 2;

    pipe.setFont(scaledFont);
    try {
      pipe.drawString(string, (float) x, (float) y);
    } finally {
      pipe.setFont(oldFont);
    }
  }
  public void render(Graphics2D g, Dimension d) {
    int n = this.problemScore.getAttempts();
    n += this.problemScore.getPendings();
    String text = "" + n;
    Color baseColor;
    if (this.problemScore.isSolved()) {
      baseColor = Color.GREEN;
      text += " / " + this.problemScore.getSolutionTime();
    } else if (this.problemScore.isPending()) {
      baseColor = Color.BLUE.brighter();
    } else if (this.problemScore.getAttempts() > 0) {
      baseColor = Color.RED;
    } else {
      baseColor = new Color(0, 0, 0, 0);
    }
    // g.fillRect(0, 0, d.width, d.height);
    ShadedRectangle.drawShadedRoundRect(g, baseColor, 0, 0, d.width, d.height, d.height / 3f);
    g.setColor(Color.BLACK);

    Font backup = g.getFont();
    double magicScale = d.height / 20f;
    Font nfont = backup.deriveFont(AffineTransform.getScaleInstance(magicScale, magicScale));
    Rectangle2D rect = new Rectangle2D.Float(0, 0, d.width, d.height);
    Utility.drawString3D(g, text, rect, nfont, Alignment.center);
  }
Exemple #14
0
  /** Overrides the paintComponent method to paint the horses images in their proper position. */
  @Override
  public synchronized void paintComponent(Graphics g) {
    // Draw the six images of the horses
    for (int i = 0; i < horsesPoint.size(); i++) {
      Image image = horsesImage.get(i);
      Interpolator<Object> interpolator = horsesPoint.get(i);
      g.drawImage(image, interpolator.getXPosition(), interpolator.getYPosition(), 25, 25, null);
    }

    // Draw the images of the bets
    for (Interpolator<BetContainer> b : betsPoint) {
      Image image = b.getObject().getBet().getBetToken().getImage();
      Interpolator<BetContainer> interpolator = b;
      g.drawImage(image, interpolator.getXPosition(), interpolator.getYPosition(), 40, 40, null);
      String danari = String.format("%d$", b.getObject().getBet().getValue());

      try {
        g.setColor(Color.BLACK);
        g.setFont(font.deriveFont(15F));
      } catch (NullPointerException e) {
        // Font not loaded
      }

      g.drawString(
          b.getObject().getPlayerName(),
          interpolator.getXPosition(),
          interpolator.getYPosition() + 51);
      g.drawString(danari, interpolator.getXPosition(), interpolator.getYPosition() + 65);
    }
    super.paintComponent(g);
  }
Exemple #15
0
  @Override
  public void renderHUD(Graphics2D g) {
    // TODO Auto-generated method stub
    super.renderHUD(g);

    g.drawImage(HUDBg, 0, 0, null);

    if (player.weapon != null) {

      g.drawImage(player.weapon.getHUDImage(), 123, 121, null);

      float wh = (player.weapon.bulletsLeft / (float) player.weapon.bulletsCapacity);
      drawHealth(g, wh, 121, 137, 36, 4);
    }

    // player health
    drawHealth(g, player.health / (float) player.maxHealth, 3, 137, 36, 4);

    Font f = g.getFont();
    g.setColor(Color.black);
    g.setFont(f.deriveFont(4));
    Text.drawText(g, String.format("%05d", score), 130, 5);

    Text.drawText(
        g, String.format("Day: %d", (int) Math.ceil(realtime / (float) secondsPerDay)), 66, 136);

    if (menu != null) {
      menu.render(g);
    }
  }
  public void cancelButton(boolean selected, Graphics2D g2, int x, int y) {

    Font f = Window.FONT;
    f = f.deriveFont(Font.PLAIN, 20);
    g2.setFont(f);

    Color color1 = new Color(115, 88, 167), color3 = NOT_SELECTED_OUT_LINE;

    if (selected) {
      color1 = SELECTED_UP;
      color3 = SELECTED_OUT_LINE;
    }

    g2.setColor(color3);
    g2.fill(new RoundRectangle2D.Double(x, y, WIDTH3, HEIGHT3, 50, 50));
    g2.setColor(color1);
    g2.fill(new RoundRectangle2D.Double(x + 5, y + 5, WIDTH3 - 10, HEIGHT3 - 10, 50, 50));
    g2.setColor(Color.WHITE);
    String str = "CANCEL";
    g2.drawString(
        str,
        (int)
            (x
                + WIDTH3 / 2
                - f.getStringBounds(str, new FontRenderContext(null, true, true)).getWidth() / 2),
        (int)
            (y
                + HEIGHT3 / 2
                + f.getStringBounds(str, new FontRenderContext(null, true, true)).getHeight() / 2
                - 8));
  }
  public Component getListCellRendererComponent(
      JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
    // Method Instances.
    String buttonTextLabel;
    Color buttonColor;
    Font buttonFont;

    // Set label, background, selection highlight, & font.

    buttonTextLabel = ((SQLQueryBucketListObject) value).getText();
    buttonColor = ((SQLQueryBucketListObject) value).getBackground();
    buttonFont = list.getFont();

    setText(buttonTextLabel);
    setBackground(buttonColor);

    if (isSelected) {
      setBorder(BorderFactory.createLineBorder(list.getSelectionForeground(), 1));
    } else {
      setBorder(((SQLQueryBucketListObject) value).getBorder());
    }

    setEnabled(list.isEnabled());
    setFont(buttonFont.deriveFont(Font.BOLD));
    setOpaque(true);
    return this;
  }
Exemple #18
0
  @Override
  public int print(Graphics g, PageFormat pf, int pageIndex) throws PrinterException {
    System.out.println("PageFormat: width=" + pf.getWidth() + ", height=" + pf.getHeight());
    Logger.getGlobal().log(Level.INFO, "PageFormat {0}", pf);
    System.out.println("pageIndex " + pageIndex);
    Logger.getGlobal().log(Level.INFO, "pageIndex {0}", pageIndex);

    if (pageIndex == 0) {
      Graphics2D g2d = (Graphics2D) g;
      Font font = g2d.getFont();
      g2d.setFont(font.deriveFont((float) fontSize));

      g2d.translate(pf.getImageableX(), pf.getImageableY());
      g2d.setColor(Color.black);
      int step = g2d.getFont().getSize();
      step += step / 4;
      double y = paddingTop + g2d.getFont().getSize();
      for (String s : printStringList) {
        Logger.getGlobal().log(Level.INFO, "printStringList: {0}", s);
        g2d.drawString(s, (float) paddingLeft, (float) y);
        y += step;
      }

      // g2d.fillRect(0, 0, 200, 200);
      return Printable.PAGE_EXISTS;

    } else {
      return Printable.NO_SUCH_PAGE;
    }
  }
Exemple #19
0
    /*
     * (non-Javadoc)
     *
     * @see
     * javax.swing.tree.DefaultTreeCellRenderer#getTreeCellRendererComponent
     * (javax.swing.JTree, java.lang.Object, boolean, boolean, boolean, int,
     * boolean)
     */
    public Component getTreeCellRendererComponent(
        JTree tree,
        Object value,
        boolean selected,
        boolean expanded,
        boolean leaf,
        int row,
        boolean hasFocus) {

      Component c =
          super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);

      Font normalFont = TrackingViewer.this.getFont();

      this.setFont(normalFont);

      if (value == null) return null;

      if (value instanceof NodeStyle) {

        NodeStyle obj = (NodeStyle) value;

        this.setIcon(obj.getIcon());
      }

      if (value instanceof ViewerTreeModel.AnnotationSource.ValuesAnnotations) {

        ViewerTreeModel.AnnotationSource.ValuesAnnotations obj =
            (ViewerTreeModel.AnnotationSource.ValuesAnnotations) value;

        if (obj.isPlotVisible()) this.setFont(normalFont.deriveFont(Font.BOLD));
      }

      return c;
    }
  /**
   * Creates a title item (i.e. bold font etc.) with the given string. Simply gets the default font
   * from the plotConfig and sets it style to bold.
   *
   * @return The created legend item.
   */
  private LegendItem createTitleLegendItem(
      String titleString, PlotConfiguration plotConfiguration) {
    LegendItem titleItem =
        new LegendItem(
            titleString,
            "",
            "",
            "",
            false,
            new Rectangle(),
            false,
            Color.WHITE,
            false,
            Color.WHITE,
            new BasicStroke(),
            false,
            new Rectangle(),
            new BasicStroke(),
            Color.WHITE);
    Font titleFont = titleItem.getLabelFont();

    if (titleFont == null) {
      titleFont = plotConfiguration.getLegendConfiguration().getLegendFont();
    }
    titleItem.setLabelFont(titleFont.deriveFont(Font.BOLD));
    return titleItem;
  }
 private void formatoLink(JLabel lbl) {
   lbl.setForeground(new Color(0, 0, 205));
   Font font = lbl.getFont();
   Map attributes = font.getAttributes();
   attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
   lbl.setFont(font.deriveFont(attributes));
 }
  private int computeTextWidth(@NotNull Font font, final boolean mainTextOnly) {
    int result = 0;
    int baseSize = font.getSize();
    boolean wasSmaller = false;
    for (int i = 0; i < myAttributes.size(); i++) {
      SimpleTextAttributes attributes = myAttributes.get(i);
      boolean isSmaller = attributes.isSmaller();
      if (font.getStyle() != attributes.getFontStyle()
          || isSmaller != wasSmaller) { // derive font only if it is necessary
        font =
            font.deriveFont(
                attributes.getFontStyle(),
                isSmaller ? UIUtil.getFontSize(UIUtil.FontSize.SMALL) : baseSize);
      }
      wasSmaller = isSmaller;

      result += computeStringWidth(i, font);

      final int fixedWidth = myFragmentPadding.get(i);
      if (fixedWidth > 0 && result < fixedWidth) {
        result = fixedWidth;
      }
      if (mainTextOnly && myMainTextLastIndex >= 0 && i == myMainTextLastIndex) break;
    }
    return result;
  }
  public ChatPane createChatPane(String userName) {
    JTextPane chatPane = new JTextPane();
    chatPane.setEditable(false);
    Font font = chatPane.getFont();
    float size = Main.pref.getInteger("geochat.fontsize", -1);
    if (size < 6) size += font.getSize2D();
    chatPane.setFont(font.deriveFont(size));
    //        DefaultCaret caret = (DefaultCaret)chatPane.getCaret(); // does not work
    //        caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
    JScrollPane scrollPane =
        new JScrollPane(
            chatPane,
            JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    chatPane.addMouseListener(new GeoChatPopupAdapter(panel));

    ChatPane entry = new ChatPane();
    entry.pane = chatPane;
    entry.component = scrollPane;
    entry.notify = 0;
    entry.userName = userName;
    entry.isPublic = userName == null;
    chatPanes.put(userName == null ? PUBLIC_PANE : userName, entry);

    tabs.addTab(null, scrollPane);
    tabs.setTabComponentAt(tabs.getTabCount() - 1, new ChatTabTitleComponent(entry));
    tabs.setSelectedComponent(scrollPane);
    return entry;
  }
    public Component getListCellRendererComponent(
        JList list, // the list
        Object value, // value to display
        int index, // cell index
        boolean isSelected, // is the cell selected
        boolean cellHasFocus) // does the cell have focus
        {
      Song song = (Song) value;

      String display = song.getTitle() + "<br>" + song.getArtist();

      setText("<html>" + display);

      if (isSelected) {
        setBackground(Const.highlightColor);
        setForeground(Const.bgColor);
      } else {
        setBackground(Const.bgColor);
        setForeground(Const.txtColor);
      }

      // The current playing song
      if (index == list.getModel().getSize() - 1) {
        Font f = list.getFont();
        setFont(f.deriveFont(Font.BOLD));
      } else {
        setFont(list.getFont());
      }

      setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, Color.LIGHT_GRAY));
      setEnabled(list.isEnabled());
      setOpaque(true);
      return this;
    }
    private JComponent createLogo() {
      NonOpaquePanel panel = new NonOpaquePanel(new BorderLayout());
      ApplicationInfoEx app = ApplicationInfoEx.getInstanceEx();
      JLabel logo = new JLabel(IconLoader.getIcon(app.getWelcomeScreenLogoUrl()));
      logo.setBorder(JBUI.Borders.empty(30, 0, 10, 0));
      logo.setHorizontalAlignment(SwingConstants.CENTER);
      panel.add(logo, BorderLayout.NORTH);
      JLabel appName = new JLabel(ApplicationNamesInfo.getInstance().getFullProductName());
      Font font = getProductFont();
      appName.setForeground(JBColor.foreground());
      appName.setFont(font.deriveFont(JBUI.scale(36f)).deriveFont(Font.PLAIN));
      appName.setHorizontalAlignment(SwingConstants.CENTER);
      String appVersion = "Version " + app.getFullVersion();

      if (app.isEAP() && app.getBuild().getBuildNumber() < Integer.MAX_VALUE) {
        appVersion += " (" + app.getBuild().asString() + ")";
      }

      JLabel version = new JLabel(appVersion);
      version.setFont(getProductFont().deriveFont(JBUI.scale(16f)));
      version.setHorizontalAlignment(SwingConstants.CENTER);
      version.setForeground(Gray._128);

      panel.add(appName);
      panel.add(version, BorderLayout.SOUTH);
      panel.setBorder(JBUI.Borders.emptyBottom(20));
      return panel;
    }
  /**
   * Adds the specified files to the list of import data.
   *
   * @param files The files to import.
   */
  private void insertFiles(Map<File, StatusLabel> files) {
    if (files == null || files.size() == 0) {
      statusLabel.setText("No files to import.");
      return;
    }
    components = new HashMap<File, FileImportComponent>();
    totalFiles = files.size();
    String text = "Importing " + totalFiles + " file";
    if (totalFiles > 1) text += "s";
    statusLabel.setText(text);

    Entry entry;
    Iterator i = files.entrySet().iterator();
    FileImportComponent c;
    JPanel p = new JPanel();
    p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
    int index = 0;
    p.setBorder(BorderFactory.createLineBorder(Color.BLACK));
    File f;
    DatasetData d = dataset;
    Object node = refNode;
    if (folderAsContainer) {
      node = null;
      d = new DatasetData();
      d.setName(file.getName());
    }
    while (i.hasNext()) {
      entry = (Entry) i.next();
      f = (File) entry.getKey();
      c = new FileImportComponent(f, folderAsContainer, browsable, group, singleGroup);
      if (f.isFile()) {
        c.setLocation(data, d, node);
        c.setParent(this);
      }
      c.showContainerLabel(showContainerLabel);
      c.setType(getType());
      attachListeners(c);
      c.setStatusLabel((StatusLabel) entry.getValue());
      if (index % 2 == 0) c.setBackground(UIUtilities.BACKGROUND_COLOUR_EVEN);
      else c.setBackground(UIUtilities.BACKGROUND_COLOUR_ODD);
      components.put((File) entry.getKey(), c);
      p.add(c);
      index++;
    }
    removeAll();
    pane = EditorUtil.createTaskPane("");
    pane.setCollapsed(false);
    setNumberOfImport();

    IconManager icons = IconManager.getInstance();
    pane.setIcon(icons.getIcon(IconManager.DIRECTORY));
    Font font = pane.getFont();
    pane.setFont(font.deriveFont(font.getStyle(), font.getSize() - 2));
    pane.add(p);
    double[][] size = {{TableLayout.FILL}, {TableLayout.PREFERRED}};
    setLayout(new TableLayout(size));
    add(pane, "0, 0");
    validate();
    repaint();
  }
  public void drawPoolOrLane(String name, int x, int y, int width, int height) {
    g.drawRect(x, y, width, height);

    // Add the name as text, vertical
    if (name != null && name.length() > 0) {
      // Include some padding
      int availableTextSpace = height - 6;

      // Create rotation for derived font
      AffineTransform transformation = new AffineTransform();
      transformation.setToIdentity();
      transformation.rotate(270 * Math.PI / 180);

      Font currentFont = g.getFont();
      Font theDerivedFont = currentFont.deriveFont(transformation);
      g.setFont(theDerivedFont);

      String truncated = fitTextToWidth(name, availableTextSpace);
      int realWidth = fontMetrics.stringWidth(truncated);

      g.drawString(
          truncated,
          x + 2 + fontMetrics.getHeight(),
          3 + y + availableTextSpace - (availableTextSpace - realWidth) / 2);
      g.setFont(currentFont);
    }
  }
Exemple #28
0
    TilePanel(Tile tile) {
      mTile = tile;
      setOpaque(false);
      // Used to keep track what component should be displayed
      components = new Stack<Component>();

      if (mTile != null) {
        if (mTile.isHome()) {
          try {
            JLabel j = new JLabel("Home");
            Font f =
                Font.createFont(
                    Font.TRUETYPE_FONT, new FileInputStream("src/fonts/kenvector_future.ttf"));
            f = f.deriveFont(7f);
            j.setFont(f);
            components.push(j);
          } catch (FontFormatException | IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
        }
        if (mTile.isStart()) {
          try {
            JLabel j = new JLabel("Start");
            Font f =
                Font.createFont(
                    Font.TRUETYPE_FONT, new FileInputStream("src/fonts/kenvector_future.ttf"));
            f = f.deriveFont(7f);
            j.setFont(f);
            components.push(j);
          } catch (FontFormatException | IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
        }
      }

      // If the tile is clicked by the user...
      addMouseListener(
          new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent me) {
              // Update this in the action manager
              mGameManager.tileClicked(mTile, mGameManager.getMainPlayer());
            }
          });
    }
  public void bigPkm(boolean selected, Graphics2D g2, Pokemon p) {

    if (p == null) return;

    Font f = Window.FONT;
    f = f.deriveFont(Font.PLAIN, 20);
    g2.setFont(f);

    Color color1 = NOT_SELECTED_UP, color2 = NOT_SELECTED_DOWN, color3 = NOT_SELECTED_OUT_LINE;

    if (selected) {
      color1 = SELECTED_UP;
      color2 = SELECTED_DOWN;
      color3 = SELECTED_OUT_LINE;
    }

    g2.setColor(color3);
    g2.fill(new RoundRectangle2D.Double(X_SHIFT - 5, Y_SHIFT - 5, WIDTH1 + 10, HEIGHT1 + 10, 5, 5));

    g2.setColor(color1);
    g2.fill(new Rectangle2D.Double(X_SHIFT, Y_SHIFT, WIDTH1, HEIGHT1));
    g2.setColor(color2);
    g2.fill(new Rectangle2D.Double(X_SHIFT, Y_SHIFT + HEIGHT1 * 2 / 3, WIDTH1, HEIGHT1 / 3));

    BattleFrontEnd.drawHpBar(
        g2,
        X_SHIFT + 40,
        Y_SHIFT + HEIGHT1 * 2 / 3,
        p.getCurrentHP(),
        p.getMaxHP(),
        p.getCurrentHP() / (double) p.getMaxHP());

    String hp = p.getCurrentHP() + "/" + p.getMaxHP();

    g2.setColor(Color.BLACK);
    g2.drawString(
        hp,
        X_SHIFT + 100,
        (int)
            (Y_SHIFT
                + HEIGHT1 * 2 / 3
                + f.getStringBounds(hp, new FontRenderContext(null, true, true)).getHeight()));
    String name = p.getName() + " Lvl: " + p.getLevel();
    g2.drawString(
        name,
        (int)
            (X_SHIFT
                + WIDTH1 / 2
                - f.getStringBounds(name, new FontRenderContext(null, true, true)).getWidth() / 2),
        (int)
            (Y_SHIFT
                + 30
                + f.getStringBounds(name, new FontRenderContext(null, true, true)).getHeight()));
    g2.drawImage(
        p.getFront().getScaledInstance(40, 40, Image.SCALE_DEFAULT),
        X_SHIFT + 5,
        Y_SHIFT + 5,
        null);
  }
Exemple #30
0
 /**
  * Returns the SourceSansPro regular font.
  *
  * @param size the size of font
  * @return the font SourceSansPro-Regualar
  * @throws FontFormatException the font format exception
  * @throws IOException Signals that an I/O exception has occurred.
  * @throws Exception the exception
  */
 private static Font getSourceSansPro(float size)
     throws FontFormatException, IOException, Exception {
   Font font =
       Font.createFont(
           Font.TRUETYPE_FONT,
           Fonts.class.getResourceAsStream("/information/fonts/SourceSansPro-Regular.otf"));
   return font.deriveFont(size);
 }