Beispiel #1
0
  private static final void drawShadowedStringCentered(
      final Graphics2D g2d,
      final String str,
      final double x,
      final double y,
      final Font font,
      final Paint paint,
      final double shadowOffset,
      final Paint shadowPaint) {

    g2d.setFont(font);

    final FontRenderContext frc = g2d.getFontRenderContext();
    final Rectangle2D bounds = font.getStringBounds(str, frc);
    final LineMetrics metrics = font.getLineMetrics(str, frc);
    final double width = bounds.getWidth(); // The width of our text
    final float lineHeight = metrics.getHeight(); // Total line height
    final float ascent = metrics.getAscent(); // Top of text to baseline

    final double cx = (x + (0 - width) / 2);
    final double cy = (y + (0 - lineHeight) / 2 + ascent);

    if (shadowOffset > 0) {
      drawString(g2d, str, cx + shadowOffset, cy - shadowOffset, shadowPaint);
      drawString(g2d, str, cx + shadowOffset, cy + shadowOffset, shadowPaint);
      drawString(g2d, str, cx - shadowOffset, cy - shadowOffset, shadowPaint);
      drawString(g2d, str, cx - shadowOffset, cy + shadowOffset, shadowPaint);
    }
    drawString(g2d, str, cx, cy, paint);
  }
  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);
    }
  }
Beispiel #3
0
  public void workOutMinsAndMaxs() {
    StringTokenizer tokens = new StringTokenizer(getRenderString(), "\n");

    int noLines = tokens.countTokens();

    double height = (theFont.getSize2D() * noLines) + 5;
    double width = 0;

    while (tokens.hasMoreTokens()) {
      double l = theFont.getSize2D() * tokens.nextToken().length() * (5.0 / 8.0);
      if (l > width) width = l;
    }

    double parX;
    double parY;
    if (parent instanceof State) {
      parX = ((State) parent).getX();
      parY = ((State) parent).getY();
    } else if (parent instanceof Transition) {
      parX = ((Transition) parent).getMiddle().getX(); // dummy
      parY = ((Transition) parent).getMiddle().getY(); // dummy
    } else {
      parX = 0;
      parY = 0;
    }

    minX = parX + offsetX - 5;
    minY = parY + offsetY - 25;

    maxX = parX + width + offsetX + 5;
    maxY = parY + height + offsetY - 5;
  }
Beispiel #4
0
 public static void bumpUpFontSize(Component widget, int bumps) {
   if (!UserPreferences.readLocalePref()
       .equals("ko")) { // HACK!!!  refector with variable localeSupportsBold
     Font f = widget.getFont();
     widget.setFont(new Font(f.getFamily(), f.getStyle(), f.getSize() + bumps));
   }
 }
  /**
   * 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;
  }
  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));
  }
Beispiel #7
0
  /**
   * Paints the graphic component
   *
   * @param g Graphic component
   */
  public void paint(Graphics g) {
    if (environment != null) {
      Sudoku env = (Sudoku) environment;
      Board board = env.getBoard();

      int n = SudokuLanguage.DIGITS;
      int sqrt_n = (int) (Math.sqrt(n) + 0.1);

      g.setColor(Color.lightGray);
      Font font = g.getFont();
      g.setFont(new Font(font.getName(), font.getStyle(), 20));
      for (int i = 0; i < n; i++) {
        int ci = getCanvasValue(i);
        if (i % sqrt_n == 0) {
          g.drawLine(ci, DRAW_AREA_SIZE + MARGIN, ci, MARGIN);
          g.drawLine(DRAW_AREA_SIZE + MARGIN, ci, MARGIN, ci);
        }

        for (int j = 0; j < n; j++) {
          int cj = getCanvasValue(j);
          int value = board.get(i, j);
          if (value > 0) {
            g.setColor(Color.black);
            g.drawString("" + value, cj + CELL_SIZE / 5, ci + CELL_SIZE);
            g.setColor(Color.lightGray);
          }
        }
      }
      g.drawLine(DRAW_AREA_SIZE + MARGIN, DRAW_AREA_SIZE + MARGIN, DRAW_AREA_SIZE + MARGIN, MARGIN);
      g.drawLine(DRAW_AREA_SIZE + MARGIN, DRAW_AREA_SIZE + MARGIN, MARGIN, DRAW_AREA_SIZE + MARGIN);
    }
  }
  /**
   * 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();
  }
Beispiel #9
0
  /**
   * @param message Message to show in dialog.
   * @param severity
   *     <p>HTML tag can be used to format and add links into message. &lt;html&gt; and &lt;body&gt;
   *     are automatic added
   */
  public static void showClickableMessage(String message, int severity) {
    JLabel l = new JLabel();
    Font font = l.getFont();
    StringBuilder html = new StringBuilder("");
    Logger.logDebug(message);
    html.append("<html><body style=\"" + "font-family:")
        .append(font.getFamily())
        .append(";")
        .append("font-weight:")
        .append(font.isBold() ? "bold" : "normal")
        .append(";")
        .append("font-size:")
        .append(font.getSize())
        .append("pt;")
        .append("\">");

    html.append(message).append(" ").append("</html>");

    JEditorPane ep = new JEditorPane("text/html", html.toString());
    ep.addHyperlinkListener(
        new HyperlinkListener() {
          @Override
          public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) {
              OSUtils.browse(
                  e.getURL().toString()); // roll your own link launcher or use Desktop if J6+
            }
          }
        });
    ep.setEditable(false);
    Logger.logDebug("Displaying dialog");
    JOptionPane.showMessageDialog(LaunchFrame.getInstance(), ep, null, severity);
    Logger.logDebug("Returned from dialog");
  }
Beispiel #10
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);
    }
  }
    /**
     * @see org.jfree.chart.axis.Axis#refreshTicks(java.awt.Graphics2D, java.awt.geom.Rectangle2D,
     *     java.awt.geom.Rectangle2D, int)
     */
    public void refreshTicks(
        Graphics2D g2, Rectangle2D plotArea, Rectangle2D dataArea, int location) {

      // getTicks().clear();

      Font tickLabelFont = getTickLabelFont();
      g2.setFont(tickLabelFont);

      double size = getTickUnit().getSize();
      int count = calculateVisibleTickCount();
      double lowestTickValue = calculateLowestVisibleTickValue();

      if (count <= ValueAxis.MAXIMUM_TICK_COUNT) {
        for (int i = 0; i < count; i++) {
          double currentTickValue = lowestTickValue + (i * size);
          double yy = translateValueToJava2D(currentTickValue, dataArea, RectangleEdge.BOTTOM);
          String tickLabel;
          NumberFormat formatter = getNumberFormatOverride();
          if (formatter != null) {
            tickLabel = formatter.format(currentTickValue);
          } else {
            tickLabel = valueToString(currentTickValue);
          }
          FontRenderContext frc = g2.getFontRenderContext();
          Rectangle2D tickLabelBounds = tickLabelFont.getStringBounds(longestStr, frc);
          LineMetrics lm = tickLabelFont.getLineMetrics(tickLabel, frc);
          float x =
              (float) (dataArea.getX() - tickLabelBounds.getWidth() - getTickLabelInsets().right);
          float y = (float) (yy + (lm.getAscent() / 2));
          // Tick tick = new Tick(new Double(currentTickValue), tickLabel, x, y);
          // getTicks().add(tick);
        }
      }
    }
  @Override
  public void drawGui(Graphics g) {

    Graphics2D page = (Graphics2D) g;

    int height = -4;
    int spacing = -2;

    final Font font = new Font("Consolas", Font.BOLD, 13);

    for (String str : debug) {
      g.setFont(font);
      page.setRenderingHint(
          RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

      Rectangle2D rect = g.getFontMetrics().getStringBounds(str, g);

      if (font.getSize() <= 20) height += rect.getHeight() + 1;
      else height += rect.getHeight() + 2;

      g.setColor(new Color(85, 85, 85, 190));

      this.drawString(
          str, font, Color.WHITE, this.panel.getWidth() - (int) rect.getWidth() - 3, height, g);

      height += spacing;
    }
  }
  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;
  }
Beispiel #14
0
  /**
   * format a given Font to a string, following "Font.decode()" format, ie fontname-style-pointsize,
   * fontname-pointsize, fontname-style or fontname, where style is one of "BOLD", "ITALIC",
   * "BOLDITALIC" (default being PLAIN)
   */
  public static String formatFontAsProperties(Font font) {
    // jpicedt.Log.debug(new MiscUtilities(),"formatFontAsProperties","font="+font);
    String family = font.getFamily();
    /*
    System.out.println("family="+family);
    String faceName = font.getFontName();
    System.out.println("faceName="+faceName);
    String logicalName = font.getName();
    System.out.println("logicalName"+logicalName);
    String psName = font.getPSName();
    System.out.println("PSName="+psName);
    */

    StringBuffer buf = new StringBuffer(20);
    buf.append(family);
    buf.append("-");
    switch (font.getStyle()) {
      case Font.ITALIC:
        buf.append("ITALIC-");
        break;
      case Font.BOLD:
        buf.append("BOLD-");
        break;
      case Font.BOLD | Font.ITALIC:
        buf.append("BOLDITALIC-");
        break;
      default: // PLAIN -> nothing
    }
    buf.append(Integer.toString(font.getSize()));
    return buf.toString();
  }
 private static File findFileForFont(Font font, final boolean matchStyle) {
   final String normalizedFamilyName =
       font.getFamily().toLowerCase(Locale.getDefault()).replace(" ", "");
   final int fontStyle = font.getStyle();
   File[] files =
       new File(System.getProperty("user.home"), "Library/Fonts")
           .listFiles(
               new FilenameFilter() {
                 @Override
                 public boolean accept(File file, String name) {
                   String normalizedName = name.toLowerCase(Locale.getDefault());
                   return normalizedName.startsWith(normalizedFamilyName)
                       && (normalizedName.endsWith(".otf") || normalizedName.endsWith(".ttf"))
                       && (!matchStyle
                           || fontStyle == ComplementaryFontsRegistry.getFontStyle(name));
                 }
               });
   if (files == null || files.length == 0) return null;
   // to make sure results are predictable we return first file in alphabetical order
   return Collections.min(
       Arrays.asList(files),
       new Comparator<File>() {
         @Override
         public int compare(File file1, File file2) {
           return file1.getName().compareTo(file2.getName());
         }
       });
 }
  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);
  }
Beispiel #17
0
  /** Creates new form MainPagePanel */
  public MainPagePanel() {
    initComponents();

    pnlButtons = new javax.swing.JPanel();
    pnlButtons.setLayout(null);

    int w = 150, h = 50;
    btnRun = new ConstomButton();
    btnRun.setBounds(0, 0, w, h);
    Font font = btnRun.getFont();
    Font newFont = new Font(font.getName(), font.getStyle(), 15);
    pnlButtons.add(btnRun);

    btnRun.setText(C.i18n("ui.button.run"));
    btnRun.setFont(newFont);
    btnRun.addActionListener(e -> btnRunActionPerformed());

    this.add(pnlButtons);
    pnlButtons.setBounds(0, 0, w, h);

    this.setSize(new Dimension(deWidth, deHeight));
    this.pnlButtons.setLocation(
        deWidth - pnlButtons.getWidth() - 25, deHeight - pnlButtons.getHeight() - 25);
    pnlMore.setBounds(0, 0, pnlMore.getWidth(), deHeight);
    pnlMore.setBackground(GraphicsUtils.getWebColorWithAlpha("FFFFFF7F"));
    pnlMore.setOpaque(true);

    prepareAuths();
  }
  @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);
    }
  }
  /**
   * Initializes the contents of the dialog from the given font object.
   *
   * @param font the font from which to read the properties.
   */
  public void setSelectedFont(final Font font) {
    if (font == null) {
      throw new NullPointerException();
    }
    this.boldCheck.setSelected(font.isBold());
    this.italicCheck.setSelected(font.isItalic());

    final String fontName = font.getName();
    ListModel model = this.fontlist.getModel();
    for (int i = 0; i < model.getSize(); i++) {
      if (fontName.equals(model.getElementAt(i))) {
        this.fontlist.setSelectedIndex(i);
        break;
      }
    }

    final String fontSize = String.valueOf(font.getSize());
    model = this.sizelist.getModel();
    for (int i = 0; i < model.getSize(); i++) {
      if (fontSize.equals(model.getElementAt(i))) {
        this.sizelist.setSelectedIndex(i);
        break;
      }
    }
  }
Beispiel #20
0
 /**
  * Set the Font to use with the class
  *
  * @param f Font
  */
 public void setFont(Font f) {
   font = f;
   fontname = f.getName();
   fontstyle = f.getStyle();
   fontsize = f.getSize();
   parse = true;
 }
  protected void refreshGUI() {
    Object value = property.get();
    StringBuffer repr = new StringBuffer();

    if (!omitPropertyName) {
      repr.append(
          edu.cmu.cs.stage3.alice.authoringtool.AuthoringToolResources.getReprForValue(property)
              + " = ");
    }

    if (value instanceof edu.cmu.cs.stage3.alice.core.Expression) {
      repr.append(
          edu.cmu.cs.stage3.alice.authoringtool.AuthoringToolResources.getNameInContext(
              (edu.cmu.cs.stage3.alice.core.Element) value, property.getOwner()));
    } else if (value == null) {
      repr.append("<None>");
    } else if (value instanceof java.awt.Font) {
      java.awt.Font font = (java.awt.Font) value;
      repr.append(font.getFontName());
      if (!(property.getOwner() instanceof edu.cmu.cs.stage3.alice.core.Text3D)) {
        repr.append(", " + font.getSize());
      }
    } else {
      throw new RuntimeException("Bad value: " + value);
    }

    setText(repr.toString());
    revalidate();
    repaint();
  }
  /** 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;
  }
Beispiel #23
0
 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));
 }
Beispiel #24
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;
 }
Beispiel #25
0
  public static void reloadFonts() {
    String font1Path = Config.getString("font1_file");
    String font2Path = Config.getString("font2_file");

    int font1Type = font1Path.endsWith(".ttf") ? Font.TRUETYPE_FONT : Font.TYPE1_FONT;
    int font2Type = font2Path.endsWith(".ttf") ? Font.TRUETYPE_FONT : Font.TYPE1_FONT;

    File font1 = new File(font1Path);
    File font2 = new File(font2Path);

    try {
      fonts =
          new Font[] {
            Font.createFont(font1Type, font1)
                .deriveFont(Font.BOLD, Integer.parseInt(Config.getString("font1_size"))),
            Font.createFont(font2Type, font2)
                .deriveFont(Font.BOLD, Integer.parseInt(Config.getString("font2_size"))),
          };
    } catch (IOException | FontFormatException e) {
      JOptionPane.showMessageDialog(
          instance,
          "Font failed to load: " + e,
          Constants.SOFTWARE_NAME,
          JOptionPane.WARNING_MESSAGE);
      e.printStackTrace();
    }
  }
Beispiel #26
0
 private void updateWithFont(Font aFont) {
   fontNameList.setSelectedValue(aFont.getFamily(), true);
   fontStyleList.setSelectedValue(fontStyle(aFont), true);
   fontSizeList.setSelectedValue("" + aFont.getSize(), true);
   previewLabel.setFont(aFont);
   previewLabel.setText(fontDescription(aFont));
 }
Beispiel #27
0
  public Rectangle2D getBounds2D() {
    StringTokenizer tokens = new StringTokenizer(getRenderString(), "\n");

    int noLines = tokens.countTokens();

    double height = (theFont.getSize2D() * noLines) + 5;
    double width = 0;

    while (tokens.hasMoreTokens()) {
      double l = theFont.getSize2D() * tokens.nextToken().length() * (5.0 / 8.0);
      if (l > width) width = l;
    }

    double parX;
    double parY;
    if (parent instanceof State) {
      parX = ((State) parent).getX();
      parY = ((State) parent).getY();
    } else if (parent instanceof Transition) {
      parX = ((Transition) parent).getMiddle().getX(); // dummy
      parY = ((Transition) parent).getMiddle().getY(); // dummy
    } else {
      parX = 0;
      parY = 0;
    }

    double mx = parX + offsetX;
    double my = parY + offsetY - 10;

    double tx = parX + width + offsetX;
    double ty = parY + height + offsetY - 10;

    return new Rectangle2D.Double(mx, my, tx - mx, ty - my);
  }
 private boolean canDisplayImpl(char c) {
   if (USE_ALTERNATIVE_CAN_DISPLAY_PROCEDURE) {
     return myFont.createGlyphVector(DUMMY_CONTEXT, new char[] {c}).getGlyphCode(0) > 0;
   } else {
     return myFont.canDisplay(c);
   }
 }
    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;
    }
Beispiel #30
0
  public ColorMenu(JFrame frame, int players) {
    this.frame = frame;
    numPlayers = players;

    try {
      kenVector25 =
          Font.createFont(Font.TRUETYPE_FONT, new File("fonts/kenvector_future.ttf"))
              .deriveFont(25f);
      kenVector16 =
          Font.createFont(Font.TRUETYPE_FONT, new File("fonts/kenvector_future.ttf"))
              .deriveFont(16f);
      GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
      // register the font
      ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, new File("fonts/kenvector_future.ttf")));
      ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, new File("fonts/kenvector_future.ttf")));
    } catch (IOException e) {
      e.printStackTrace();
    } catch (FontFormatException e) {
      e.printStackTrace();
    }

    initializeComponents();
    createGUI();
    addEvents();
  }