示例#1
1
 public static boolean pngCaptcha(String randomStr, int width, int height, String file) {
   char[] strs = randomStr.toCharArray();
   try (OutputStream out = new FileOutputStream(file)) {
     BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
     Graphics2D g = (Graphics2D) bi.getGraphics();
     AlphaComposite ac3;
     Color color;
     int len = strs.length;
     g.setColor(Color.WHITE);
     g.fillRect(0, 0, width, height);
     for (int i = 0; i < 15; i++) {
       color = color(150, 250);
       g.setColor(color);
       g.drawOval(num(width), num(height), 5 + num(10), 5 + num(10));
     }
     g.setFont(font);
     int h = height - ((height - font.getSize()) >> 1),
         w = width / len,
         size = w - font.getSize() + 1;
     for (int i = 0; i < len; i++) {
       // 指定透明度
       ac3 = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f);
       g.setComposite(ac3);
       // 对每个字符都用随机颜色
       color = new Color(20 + num(110), 30 + num(110), 30 + num(110));
       g.setColor(color);
       g.drawString(strs[i] + "", (width - (len - i) * w) + size, h - 4);
     }
     ImageIO.write(bi, "png", out);
     out.flush();
     return true;
   } catch (IOException e) {
     return false;
   }
 }
示例#2
0
  public void drawString(String str, int x, int y) {
    if (str == null || str.equals("")) return;

    Font excelFont = font;
    if (font.getName().equals("SansSerif")) {
      excelFont =
          new Font("Arial", font.getStyle(), (int) (font.getSize() / verticalPixelsPerPoint));
    } else {
      excelFont =
          new Font(
              font.getName(), font.getStyle(), (int) (font.getSize() / verticalPixelsPerPoint));
    }
    FontDetails d = StaticFontMetrics.getFontDetails(excelFont);
    int width = (int) ((d.getStringWidth(str) * 8) + 12);
    int height = (int) ((font.getSize() / verticalPixelsPerPoint) + 6) * 2;
    y -=
        (font.getSize() / verticalPixelsPerPoint)
            + 2 * verticalPixelsPerPoint; // we want to draw the shape from the top-left
    HSSFTextbox textbox =
        escherGroup.createTextbox(new HSSFChildAnchor(x, y, x + width, y + height));
    textbox.setNoFill(true);
    textbox.setLineStyle(HSSFShape.LINESTYLE_NONE);
    HSSFRichTextString s = new HSSFRichTextString(str);
    HSSFFont hssfFont = matchFont(excelFont);
    s.applyFont(hssfFont);
    textbox.setString(s);
  }
  /**
   * Used to create the top panel describing the current feedback question
   *
   * @param fb Feedback question to describe
   * @return Panel with title and description
   */
  public JPanel createQuestionDataPanel(AbstractFeedbackType fb) {
    JPanel questionPanel = new JPanel();
    questionPanel.setLayout(new GridBagLayout());
    questionPanel.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY));

    GridBagConstraints leftBoxConst = new GridBagConstraints();
    leftBoxConst.anchor = GridBagConstraints.LINE_START;
    leftBoxConst.gridx = 0;
    leftBoxConst.gridy = 0;
    leftBoxConst.gridheight = 2;

    JLabel titleLabel = new JLabel(fb.getTitle());
    GridBagConstraints titleLabelConst = new GridBagConstraints();
    titleLabelConst.anchor = GridBagConstraints.CENTER;
    titleLabelConst.gridx = 1;
    titleLabelConst.gridy = 0;
    titleLabelConst.weightx = 1.0;
    Font titleLabelFont = titleLabel.getFont();
    titleLabel.setFont(
        new Font(
            titleLabelFont.getName(),
            Font.BOLD,
            titleLabelFont.getSize() + 4)); // increase label font size by 2

    JLabel descLabel = new JLabel(fb.getDescription());
    GridBagConstraints descLabelConst = new GridBagConstraints();
    descLabelConst.anchor = GridBagConstraints.CENTER;
    descLabelConst.gridx = 1;
    descLabelConst.gridy = 1;
    descLabelConst.weightx = 1.0;

    JLabel exclLabel = new JLabel("!");
    exclLabel.setAlignmentX(RIGHT_ALIGNMENT);
    exclLabel.setToolTipText("Response is mandatory");
    try {
      exclLabel.setFont(loadGlyphFont(titleLabelFont.getSize() + 4));
      exclLabel.setText("\ue101");
    } catch (FontFormatException | IOException e) {
      e.printStackTrace();
    }
    GridBagConstraints rightBoxConst = new GridBagConstraints();
    rightBoxConst.anchor = GridBagConstraints.LINE_END;
    rightBoxConst.gridx = 2;
    rightBoxConst.gridy = 0;
    rightBoxConst.gridheight = 2;
    rightBoxConst.ipadx = 4;

    questionPanel.add(new JPanel(), leftBoxConst);
    questionPanel.add(titleLabel, titleLabelConst);
    questionPanel.add(descLabel, descLabelConst);
    questionPanel.add(fb.isMandatory() ? exclLabel : new JPanel(), rightBoxConst);

    return questionPanel;
  }
示例#4
0
 // {{{ parseHighlightStyle()
 SyntaxStyle parseHighlightStyle(String style) {
   Font f = (resultTree != null) ? resultTree.getFont() : UIManager.getFont("Tree.font");
   SyntaxStyle s;
   try {
     s = SyntaxUtilities.parseStyle(style, f.getFamily(), f.getSize(), true, null);
   } catch (Exception e) {
     style = "color:#000000";
     s = SyntaxUtilities.parseStyle(style, f.getFamily(), f.getSize(), true);
   }
   return s;
 } // }}}
示例#5
0
  /**
   * @param f Font
   * @return The script font version of the parsed font using the script_fraction variable.
   */
  public Font getScriptFont(Font f) {
    int size;

    if (f == null) return f;

    size = f.getSize();

    if (size <= MINIMUM_SIZE) return f;

    size = (int) ((double) (f.getSize()) * script_fraction + 0.5);

    if (size <= MINIMUM_SIZE) return f;

    return new Font(f.getName(), f.getStyle(), size);
  }
  public void setGameLabellingSize(int sizeShift) {

    Font font = currentHometeamL.getFont();
    Font newFont = new Font(font.getName(), font.getStyle(), font.getSize() + sizeShift);
    currentHometeamL.setFont(newFont);
    currentAwayteamL.setFont(newFont);

    Font tableHeaderFont = showTableP.getTable().getTableHeader().getFont();
    Font newTableHeaderFont =
        new Font(
            tableHeaderFont.getName(),
            tableHeaderFont.getStyle(),
            tableHeaderFont.getSize() + sizeShift);
    showTableP.getTable().getTableHeader().setFont(newTableHeaderFont);
  }
示例#7
0
 void drawRoiLabel(Graphics g, int index, Roi roi) {
   Rectangle r = roi.getBounds();
   int x = screenX(r.x);
   int y = screenY(r.y);
   double mag = getMagnification();
   int width = (int) (r.width * mag);
   int height = (int) (r.height * mag);
   int size = width > 40 && height > 40 ? 12 : 9;
   if (font != null) {
     g.setFont(font);
     size = font.getSize();
   } else if (size == 12) g.setFont(largeFont);
   else g.setFont(smallFont);
   boolean drawingList = index >= LIST_OFFSET;
   if (drawingList) index -= LIST_OFFSET;
   String label = "" + (index + 1);
   if (drawNames && roi.getName() != null) label = roi.getName();
   FontMetrics metrics = g.getFontMetrics();
   int w = metrics.stringWidth(label);
   x = x + width / 2 - w / 2;
   y = y + height / 2 + Math.max(size / 2, 6);
   int h = metrics.getAscent() + metrics.getDescent();
   if (bgColor != null) {
     g.setColor(bgColor);
     g.fillRoundRect(x - 1, y - h + 2, w + 1, h - 3, 5, 5);
   }
   if (!drawingList && labelRects != null && index < labelRects.length)
     labelRects[index] = new Rectangle(x - 1, y - h + 2, w + 1, h);
   g.setColor(labelColor);
   g.drawString(label, x, y - 2);
   g.setColor(defaultColor);
 }
  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;
  }
示例#9
0
    @Override
    public void actionPerformed(ActionEvent e) {
      // TODO Auto-generated method stub

      Object source = e.getSource();
      if (source == ok) {
        response = APPLY_OPTION;
        this.setVisible(false);
      } else if (source == cancel) {
        response = CANCEL_OPTION;
        this.setVisible(false);
      } else if (source == sizeCombo) {
        // get the number from the source
        JComboBox number = (JComboBox) source;
        String numberItem = (String) number.getSelectedItem();
        Font temp = example.getFont();
        // then set the font
        int newSize = Integer.parseInt(numberItem);
        example.setFont(new Font(temp.getFamily(), temp.getStyle(), newSize));
      } else if (source == fontCombo) {
        JComboBox font = (JComboBox) source;
        String s = (String) font.getSelectedItem();
        Font tmp = example.getFont();
        example.setFont(new Font(s, tmp.getStyle(), tmp.getSize()));
      } else if (source == foreground) {
        Color tmp = JColorChooser.showDialog(this, "Choose text color", example.getForeground());
        MenuBar.shapeLBG.setBackground(tmp);
        if (tmp != null) example.setForeground(tmp);
      }
    }
示例#10
0
  @NotNull
  public static String getHtmlWithFonts(@NotNull String input, int style, @NotNull Font baseFont) {
    int start = baseFont.canDisplayUpTo(input);
    if (start == -1) return input;

    Font font = null;
    StringBuilder result = new StringBuilder();
    for (int i = start; i < input.length(); i++) {
      char c = input.charAt(i);
      if (baseFont.canDisplay(c)) {
        if (font != null) result.append("</font>");
        result.append(c);
        font = null;
      } else if (font != null && font.canDisplay(c)) {
        result.append(c);
      } else {
        if (font != null) result.append("</font>");
        font = getFontAbleToDisplay(c, baseFont.getSize(), style, baseFont.getFamily());
        if (font != baseFont) result.append("<font face=\"").append(font.getFamily()).append("\">");
        result.append(c);
      }
    }
    if (font != null) result.append("</font>");

    return result.toString();
  }
示例#11
0
 public void setSelectedFont(Font font) {
   selectedFont = font;
   family = font.getFamily();
   style = font.getStyle();
   size = font.getSize();
   preview.setFont(font);
 }
示例#12
0
 /**
  * Gets a special kind of Phrase that changes some characters into corresponding symbols.
  *
  * @param leading
  * @param string
  * @param font
  * @return a newly constructed Phrase
  */
 public static final Phrase getInstance(int leading, String string, Font font) {
   Phrase p = new Phrase(true);
   p.setLeading(leading);
   p.font = font;
   if (font.getFamily() != Font.SYMBOL
       && font.getFamily() != Font.ZAPFDINGBATS
       && font.getBaseFont() == null) {
     int index;
     while ((index = SpecialSymbol.index(string)) > -1) {
       if (index > 0) {
         String firstPart = string.substring(0, index);
         ((ArrayList) p).add(new Chunk(firstPart, font));
         string = string.substring(index);
       }
       Font symbol = new Font(Font.SYMBOL, font.getSize(), font.getStyle(), font.getColor());
       StringBuffer buf = new StringBuffer();
       buf.append(SpecialSymbol.getCorrespondingSymbol(string.charAt(0)));
       string = string.substring(1);
       while (SpecialSymbol.index(string) == 0) {
         buf.append(SpecialSymbol.getCorrespondingSymbol(string.charAt(0)));
         string = string.substring(1);
       }
       ((ArrayList) p).add(new Chunk(buf.toString(), symbol));
     }
   }
   if (string != null && string.length() != 0) {
     ((ArrayList) p).add(new Chunk(string, font));
   }
   return p;
 }
示例#13
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));
   }
 }
示例#14
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;
 }
示例#15
0
 public static void makeEmphasized(Component widget) {
   // Set to bold amd add color
   Font font = widget.getFont();
   if (!UserPreferences.readLocalePref()
       .equals("ko")) // HACK!!!  refector with variable localeSupportsBold
   widget.setFont(new Font(font.getFamily(), Font.BOLD, font.getSize()));
   widget.setForeground(UIProperties.emphasisColor);
 }
示例#16
0
 /**
  * Instantiate the class
  *
  * @param s String to parse.
  * @param f Font to use.
  */
 public TextLine(String s, Font f) {
   this(s);
   font = f;
   if (font == null) return;
   fontname = f.getName();
   fontstyle = f.getStyle();
   fontsize = f.getSize();
 }
示例#17
0
  public Browser(String currentHref) {
    super();

    this.currentHref = currentHref;

    try {
      if (Bither.getMainFrame() != null) {
        Bither.getMainFrame().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
      }
      addHyperlinkListener(new ActivatedHyperlinkListener(Bither.getMainFrame(), this));

      loadingMessage = LocaliserUtils.getString("browser.loadingMessage");

      setEditable(false);
      setBackground(Themes.currentTheme.detailPanelBackground());

      String fontName = null;
      if (fontName == null || "".equals(fontName)) {
        fontName = ColorAndFontConstants.BITHER_DEFAULT_FONT_NAME;
      }
      // Add in san-serif as a fallback.
      fontName = fontName + ", san-serif";

      int fontSize = ColorAndFontConstants.BITHER_DEFAULT_FONT_SIZE;
      boolean isItalic = false;
      boolean isBold = false;
      Font adjustedFont = FontSizer.INSTANCE.getAdjustedDefaultFont();
      if (adjustedFont != null) {
        setFont(adjustedFont);
        fontSize = adjustedFont.getSize();
        isItalic = adjustedFont.isItalic();
        isBold = adjustedFont.isBold();
      }

      String fontCSS = "font-size:" + fontSize + "pt; font-family:" + fontName + ";";
      if (isItalic) {
        fontCSS = fontCSS + "font-style:italic;";
      } else {
        fontCSS = fontCSS + "font-style:normal;";
      }
      if (isBold) {
        fontCSS = fontCSS + "font-weight:bold;";
      } else {
        fontCSS = fontCSS + "font-weight:normal;";
      }

      HTMLEditorKit kit = new HTMLEditorKit();
      setEditorKit(kit);
      javax.swing.text.html.StyleSheet styleSheet = kit.getStyleSheet();
      styleSheet.addRule("body {" + fontCSS + "}");
      Document doc = kit.createDefaultDocument();
      setDocument(doc);

      log.debug("Trying to load '" + currentHref + "'...");
    } catch (Exception ex) {
      showUnableToLoadMessage(ex.getClass().getCanonicalName() + " " + ex.getMessage());
    }
  }
示例#18
0
 /**
  * Gets a chunk with a symbol character.
  *
  * @param c a character that has to be changed into a symbol
  * @param font Font if there is no SYMBOL character corresponding with c
  * @return a SYMBOL version of a character
  */
 public static Chunk get(char c, Font font) {
   char greek = SpecialSymbol.getCorrespondingSymbol(c);
   if (greek == ' ') {
     return new Chunk(String.valueOf(c), font);
   }
   Font symbol = new Font(FontFamily.SYMBOL, font.getSize(), font.getStyle(), font.getColor());
   String s = String.valueOf(greek);
   return new Chunk(s, symbol);
 }
 /** @param args command line params */
 public static void main(String[] args) {
   try {
     UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
     f = UIManager.getDefaults().getFont("TabbedPane.font");
     f = new Font(f.getFamily(), Font.BOLD, f.getSize());
   } catch (Exception x) {
   }
   new TestProgram().start();
 }
  /**
   * Gets image with desired text with Font size fontSize and desired width and height. It is
   * buffered.
   *
   * @param text
   * @param fontSize
   * @param textWidth
   * @param textHeigh
   * @param ascent
   * @return
   */
  public BufferedImage getImageWithText(
      String text, Font font, int textWidth, int textHeigh, int ascent) {
    BufferedImage image;

    image = imageBuffer.getBufferedImageWithText(text, font.getSize());

    if (image == null) {
      // System.out.println("MISS");
      // load image from file
      image = createImageWithText(text, font, textWidth, textHeigh, ascent);
      // put image into buffer
      imageBuffer.putBufferedImageWithText(text, font.getSize(), image);
    } else {
      // System.out.println("HIT");
    }

    return image;
  }
示例#21
0
  /**
   * Creates a new <code>ThemeEditorPanel</code>.
   *
   * @param parent dialog in which the panel is stored.
   * @param title title of the panel.
   * @param themeData data that is being edited.
   */
  public ThemeEditorPanel(PreferencesDialog parent, String title, ThemeData themeData) {
    super(parent, title);

    this.themeData = themeData;

    // Initialises the caption label font.
    captionLabelFont = new JLabel().getFont();
    captionLabelFont = captionLabelFont.deriveFont(Font.BOLD, captionLabelFont.getSize() - 1.5f);
  }
示例#22
0
  /**
   * A rendering method to draw this label to the given Graphics2D object, with the additional
   * option of allowing the "long" lines to be drawn. Due to the fact that the relative drawing
   * point of a state is its x and y co-ordinates and for a Transition there is a workOutMiddle()
   * method, the relative x and y values must be supplied to this method. Usually this method will
   * be called from inside a Transition render method or a State render method.
   *
   * @param g2 the Graphics2D component upon which to draw this label.
   * @param x the x position upon which to make relative co-ordinates exact.
   * @param y the y position upon which to make relative co-ordinates exact.
   * @param longLines flag to determine whether the long version of this label should be drawn.
   */
  public void render(Graphics2D g2, double x, double y, boolean longLines) {
    intersects(new Rectangle2D.Double(0, 0, 1, 1));
    StringTokenizer tokens = new StringTokenizer(getRenderString(), "\n");
    if (selected) {
      g2.setColor(Color.green);
    } else {
      g2.setColor(theColour);
    }
    g2.setFont(theFont);
    int i = 0;
    boolean doneLong = false;
    while (tokens.hasMoreTokens()) {
      if (doneLong)
        g2.drawString(
            tokens.nextToken(),
            (float) (x + offsetX),
            (float) (y + offsetY + ((i * (theFont.getSize() + 2)))));
      else {
        if (!longLines)
          g2.drawString(
              tokens.nextToken().trim(),
              (float) (x + offsetX),
              (float) (y + offsetY + ((i * (theFont.getSize()))) + 2));
        else
          g2.drawString(
              getName() + ": " + tokens.nextToken().trim(),
              (float) (x + offsetX),
              (float) (y + offsetY + ((i * (theFont.getSize()))) + 2));
      }
      i++;
      doneLong = true;
    }

    /*if(intersects != null)
    {
        g2.setColor(Color.magenta);
        for(int j = 0; j < intersects.size(); j++)
        {
            Rectangle2D rect = (Rectangle2D)intersects.get(j);
            g2.draw(rect);
        }
    }*/

  }
示例#23
0
  /**
   * Instantiate the class
   *
   * @param f Font to use.
   * @param c Color to use
   * @param j Justification
   */
  public TextLine(Font f, Color c, int j) {
    font = f;
    color = c;
    justification = j;

    if (font == null) return;
    fontname = f.getName();
    fontstyle = f.getStyle();
    fontsize = f.getSize();
  }
示例#24
0
  private HSSFFont matchFont(Font font) {
    HSSFColor hssfColor =
        workbook
            .getCustomPalette()
            .findColor(
                (byte) foreground.getRed(),
                (byte) foreground.getGreen(),
                (byte) foreground.getBlue());
    if (hssfColor == null)
      hssfColor =
          workbook
              .getCustomPalette()
              .findSimilarColor(
                  (byte) foreground.getRed(),
                  (byte) foreground.getGreen(),
                  (byte) foreground.getBlue());
    boolean bold = (font.getStyle() & Font.BOLD) != 0;
    boolean italic = (font.getStyle() & Font.ITALIC) != 0;
    HSSFFont hssfFont =
        workbook.findFont(
            bold ? HSSFFont.BOLDWEIGHT_BOLD : 0,
            hssfColor.getIndex(),
            (short) (font.getSize() * 20),
            font.getName(),
            italic,
            false,
            (short) 0,
            (byte) 0);
    if (hssfFont == null) {
      hssfFont = workbook.createFont();
      hssfFont.setBoldweight(bold ? HSSFFont.BOLDWEIGHT_BOLD : 0);
      hssfFont.setColor(hssfColor.getIndex());
      hssfFont.setFontHeight((short) (font.getSize() * 20));
      hssfFont.setFontName(font.getName());
      hssfFont.setItalic(italic);
      hssfFont.setStrikeout(false);
      hssfFont.setTypeOffset((short) 0);
      hssfFont.setUnderline((byte) 0);
    }

    return hssfFont;
  }
示例#25
0
  /**
   * Creates a font metrics for the supplied font. To get a font metrics for a font use the static
   * method getFontMetrics instead which does caching.
   */
  private BDFontMetrics(Font font, String nativeName) {
    super(font);

    ftFace = loadFontN(ftLib, nativeName, font.getSize());
    if (ftFace == 0) throw new AWTError("font face:" + nativeName + " not loaded");

    /* Cache first 256 char widths for use by the getWidths method and for faster metric
    calculation as they are commonly used (ASCII) characters. */
    widths = new int[256];
    for (int i = 0; i < 256; i++) widths[i] = charWidthN(ftFace, (char) i);
  }
示例#26
0
 public void changeFont() {
   font = DisplayOptions.getFont(fontName, fontStyle, fontSize);
   setFont(font);
   fontH = font.getSize();
   rHeight = fontH;
   if (!inEditMode) {
     if ((curDim.height > 0) && (rHeight > curDim.height)) {
       adjustFont(curDim.width, curDim.height);
     }
   }
   repaint();
 }
  @Override
  public UIDefaults getDefaults() {
    try {
      final Method superMethod = BasicLookAndFeel.class.getDeclaredMethod("getDefaults");
      superMethod.setAccessible(true);
      final UIDefaults metalDefaults = (UIDefaults) superMethod.invoke(new MetalLookAndFeel());

      final UIDefaults defaults = (UIDefaults) superMethod.invoke(base);
      if (SystemInfo.isLinux) {
        if (!Registry.is("darcula.use.native.fonts.on.linux")) {
          Font font = findFont("DejaVu Sans");
          if (font != null) {
            for (Object key : defaults.keySet()) {
              if (key instanceof String && ((String) key).endsWith(".font")) {
                defaults.put(key, new FontUIResource(font.deriveFont(13f)));
              }
            }
          }
        } else if (Arrays.asList("CN", "JP", "KR", "TW")
            .contains(Locale.getDefault().getCountry())) {
          for (Object key : defaults.keySet()) {
            if (key instanceof String && ((String) key).endsWith(".font")) {
              final Font font = defaults.getFont(key);
              if (font != null) {
                defaults.put(key, new FontUIResource("Dialog", font.getStyle(), font.getSize()));
              }
            }
          }
        }
      }

      LafManagerImpl.initInputMapDefaults(defaults);
      initIdeaDefaults(defaults);
      patchStyledEditorKit(defaults);
      patchComboBox(metalDefaults, defaults);
      defaults.remove("Spinner.arrowButtonBorder");
      defaults.put("Spinner.arrowButtonSize", JBUI.size(16, 5).asUIResource());
      MetalLookAndFeel.setCurrentTheme(createMetalTheme());
      if (SystemInfo.isWindows && Registry.is("ide.win.frame.decoration")) {
        JFrame.setDefaultLookAndFeelDecorated(true);
        JDialog.setDefaultLookAndFeelDecorated(true);
      }
      if (SystemInfo.isLinux && JBUI.isHiDPI()) {
        applySystemFonts(defaults);
      }
      defaults.put("EditorPane.font", defaults.getFont("TextField.font"));
      return defaults;
    } catch (Exception e) {
      log(e);
    }
    return super.getDefaults();
  }
示例#28
0
  private void _applyFontStyleForSelection(Font font) {
    StyledDocument doc = mTextEditor.getStyledDocument();
    MutableAttributeSet attrs = mTextEditor.getInputAttributes();
    StyleConstants.setFontFamily(attrs, font.getFamily());
    StyleConstants.setFontSize(attrs, font.getSize());
    StyleConstants.setBold(attrs, ((font.getStyle() & Font.BOLD) != 0));
    StyleConstants.setItalic(attrs, ((font.getStyle() & Font.ITALIC) != 0));
    StyleConstants.setUnderline(attrs, ((font.getStyle() & Font.CENTER_BASELINE) != 0));

    int start = mTextEditor.getSelectionStart();
    int end = mTextEditor.getSelectionEnd();
    doc.setCharacterAttributes(start, (end - start), attrs, false);
  }
示例#29
0
 /**
  * 画随机码图
  *
  * @param fontcolor 随机字体颜色
  * @param strs 字符数组
  * @param flag 透明度使用
  * @return BufferedImage
  */
 private static BufferedImage graphicsImage(
     Color[] fontcolor, char[] strs, int flag, int width, int height, int len) {
   BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
   // 或得图形上下文
   // Graphics2D g2d=image.createGraphics();
   Graphics2D g2d = (Graphics2D) image.getGraphics();
   // 利用指定颜色填充背景
   g2d.setColor(Color.WHITE);
   g2d.fillRect(0, 0, width, height);
   AlphaComposite ac3;
   int h = height - ((height - font.getSize()) >> 1);
   int w = width / len;
   g2d.setFont(font);
   for (int i = 0; i < len; i++) {
     ac3 = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getAlpha(flag, i, len));
     g2d.setComposite(ac3);
     g2d.setColor(fontcolor[i]);
     g2d.drawOval(num(width), num(height), 5 + num(10), 5 + num(10));
     g2d.drawString(strs[i] + "", (width - (len - i) * w) + (w - font.getSize()) + 1, h - 4);
   }
   g2d.dispose();
   return image;
 }
示例#30
0
  /**
   * Copy the state of the parsed Textline into the existing object.
   *
   * @param t The TextLine to get the state information from.
   */
  public void copyState(TextLine t) {
    if (t == null) return;

    font = t.getFont();
    color = t.getColor();
    justification = t.getJustification();

    if (font == null) return;
    fontname = font.getName();
    fontstyle = font.getStyle();
    fontsize = font.getSize();

    parse = true;
  }