Ejemplo n.º 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;
   }
 }
Ejemplo n.º 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);
  }
Ejemplo n.º 3
0
  @Override
  public Component prepareRenderer(
      final TableCellRenderer renderer, final int row, final int column) {
    Component component = super.prepareRenderer(renderer, row, column);
    boolean isSelected = isCellSelected(row, column);
    Value value = tableModel.getElementAt(row);
    String columnName =
        (String) this.getTableHeader().getColumnModel().getColumn(column).getHeaderValue();
    Object object = getValueAt(row, column);
    boolean string;
    if (object instanceof String) {
      string = true;
    } else {
      string = false;
    }

    // UGrand Total
    if (value.isGrandTotal()) {
      if (!isSelected) {
        component.setBackground(new Color(230, 230, 230));
      } else {
        component.setBackground(this.getSelectionBackground().darker());
      }
      return component;
    }
    // Best Asset: none
    if (string
        && TabsValues.get().none().equals(value.getBestAssetName())
        && columnName.equals(ValueTableFormat.BEST_ASSET_NAME.getColumnName())) {
      Font font = component.getFont();
      component.setFont(new Font(font.getName(), Font.ITALIC, font.getSize()));
    }
    // Best Module: none
    if (string
        && TabsValues.get().none().equals(value.getBestModuleName())
        && columnName.equals(ValueTableFormat.BEST_MODULE_NAME.getColumnName())) {
      Font font = component.getFont();
      component.setFont(new Font(font.getName(), Font.ITALIC, font.getSize()));
    }
    // Best Ship (Fitted): none
    if (string
        && TabsValues.get().none().equals(value.getBestShipFittedName())
        && columnName.equals(ValueTableFormat.BEST_SHIP_FITTED_NAME.getColumnName())) {
      Font font = component.getFont();
      component.setFont(new Font(font.getName(), Font.ITALIC, font.getSize()));
    }
    // Best Ship: none
    if (string
        && TabsValues.get().none().equals(value.getBestShipName())
        && columnName.equals(ValueTableFormat.BEST_SHIP_NAME.getColumnName())) {
      Font font = component.getFont();
      component.setFont(new Font(font.getName(), Font.ITALIC, font.getSize()));
    }
    return component;
  }
Ejemplo n.º 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;
 } // }}}
Ejemplo n.º 5
0
  /**
   * Sets the font used for HTML displays to the specified font. Components that display HTML do not
   * necessarily honor font properties, since the HTML document can override these values. Calling
   * {@code setHtmlFont} after the data is set will force the HTML display to use the font specified
   * to this method.
   *
   * @param doc the HTML document to update
   * @param font the font to use
   * @throws NullPointerException if any parameter is {@code null}
   */
  public static void setHtmlFont(HTMLDocument doc, Font font) {
    String stylesheet =
        String.format(STYLESHEET, font.getName(), font.getSize(), font.getName(), font.getSize());

    try {
      doc.getStyleSheet().loadRules(new StringReader(stylesheet), null);
    } catch (IOException e) {
      // this should never happen with our sheet
      throw new IllegalStateException(e);
    }
  }
Ejemplo n.º 6
0
  /**
   * 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;
  }
Ejemplo n.º 7
0
 /** @param font to use in this textPane */
 public void setFont(Font font) {
   super.setFont(font);
   descent = getDescent(font);
   if (font.getSize() != fontSize && expression != null) {
     try {
       // If we have an icon, it is considered as one char
       getDocument().remove(0, 1);
     } catch (BadLocationException e) {
     }
     ScilabSpecialTextUtilities.setText(this, expression);
     fontSize = font.getSize();
   }
 }
  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);
  }
Ejemplo n.º 9
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);
  }
Ejemplo n.º 10
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;
 }
Ejemplo n.º 11
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");
  }
Ejemplo n.º 12
0
 /**
  * Set Font to Bold
  *
  * @param bold true bold false normal
  */
 public void setFontBold(boolean bold) {
   Font font = getFont();
   if (bold != font.isBold()) {
     font = new Font(font.getName(), bold ? Font.BOLD : Font.PLAIN, font.getSize());
     setFont(font);
   }
 } //	setFontBold
Ejemplo n.º 13
0
 public void fitSize() {
   BufferedImage bi = new BufferedImage(5, 5, BufferedImage.TYPE_INT_RGB);
   FontMetrics fm = bi.getGraphics().getFontMetrics(font);
   java.awt.geom.Rectangle2D rect = fm.getStringBounds(text, bi.getGraphics());
   w = rect.getWidth() + font.getSize();
   h = rect.getHeight();
 }
Ejemplo n.º 14
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));
   }
 }
Ejemplo n.º 15
0
  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();
  }
Ejemplo n.º 16
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();
  }
Ejemplo n.º 17
0
 public void setSelectedFont(Font font) {
   selectedFont = font;
   family = font.getFamily();
   style = font.getStyle();
   size = font.getSize();
   preview.setFont(font);
 }
Ejemplo n.º 18
0
 /**
  * Returns a string representation of the specified font.
  *
  * @param font the font.
  * @return a string describing the font.
  */
 private String fontToString(final Font font) {
   if (font != null) {
     return font.getFontName() + ", " + font.getSize();
   } else {
     return localizationResources.getString("No_Font_Selected");
   }
 }
Ejemplo n.º 19
0
  public void paintBorder(final Component c, Graphics g, int x, int y, int width, int height) {
    Graphics2D g2d = (Graphics2D) g;
    GradientPaint paint;
    Paint oldPaint = g2d.getPaint();
    int textX;
    Font f = c.getFont();
    g2d.setFont(f);
    x += 2;
    width -= 1;
    if (c.getComponentOrientation() == ComponentOrientation.RIGHT_TO_LEFT) {
      textX = x + width - 4 - g2d.getFontMetrics().stringWidth(title);
      paint = new GradientPaint(x, y, destinationColor, width, height, sourceColor);
    } else {
      y += 2;
      textX = x + 4;
      paint = new GradientPaint(x, y, sourceColor, width, height, destinationColor);
    }

    height = f.getSize() + 6;
    g2d.setPaint(paint);
    g2d.fillRect(x, y, width, height);
    g2d.setPaint(oldPaint);

    g2d.setColor(textColor);
    g2d.drawString(title, textX, y + height - 5);
  }
Ejemplo n.º 20
0
  public void print(final String line) {
    if (!SwingUtilities.isEventDispatchThread()) {
      SwingUtilities.invokeLater(
          new Runnable() {
            public void run() {
              ConsoleTab.this.print(line);
            }
          });
      return;
    }

    Document document = this.console.getDocument();
    JScrollBar scrollBar = getVerticalScrollBar();
    boolean shouldScroll = false;

    if (getViewport().getView() == this.console) {
      shouldScroll =
          scrollBar.getValue() + scrollBar.getSize().getHeight() + MONOSPACED.getSize() * 4
              > scrollBar.getMaximum();
    }
    try {
      document.insertString(document.getLength(), line, null);
    } catch (BadLocationException localBadLocationException) {
    }
    if (shouldScroll) scrollBar.setValue(2147483647);
  }
Ejemplo n.º 21
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));
 }
Ejemplo n.º 22
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);
 }
Ejemplo n.º 23
0
  /**
   * 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;
      }
    }
  }
  @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;
    }
  }
  @Override
  public void actionPerformed(ActionEvent e) {
    // TODO Auto-generated method stub
    Object source = e.getSource();

    if (source == ok) {
      userResponse = APPLY_OPTION;
      this.setVisible(false);
    } else if (source == cancel) {
      userResponse = CANCEL_OPTION;
      this.setVisible(false);
    } else if (source == fontCombo) {
      @SuppressWarnings("unchecked")
      JComboBox<String> cb = (JComboBox<String>) source;
      String s = (String) cb.getSelectedItem();
      Font tmp = example.getFont();
      example.setFont(new Font(s, tmp.getStyle(), tmp.getSize()));
    } else if (source == sizeCombo) {
      @SuppressWarnings("unchecked")
      JComboBox<String> cb = (JComboBox<String>) source;
      String s = (String) cb.getSelectedItem();
      int newSize = Integer.parseInt(s);
      Font tmp = example.getFont();
      example.setFont(new Font(tmp.getFamily(), tmp.getStyle(), newSize));
    } else if (source == foreground) {
      Color tmp = JColorChooser.showDialog(this, "Choose text color", example.getForeground());
      if (tmp != null) example.setForeground(tmp);
    }
  }
Ejemplo n.º 26
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();
  }
  /**
   * 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;
  }
Ejemplo n.º 28
0
  /**
   * 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();
  }
  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;
  }
Ejemplo n.º 30
0
 static void printFont(PrintWriter html, Font font) {
   String style = "";
   if (font.isBold() && font.isItalic()) {
     style = "Bold & Italic";
   } else if (font.isBold()) {
     style = "Bold";
   } else if (font.isItalic()) {
     style = "Italic";
   }
   html.println("<td>Font: " + font.getFamily() + " " + font.getSize() + " " + style + "</td>");
   int w = 300, h = 30;
   BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
   Graphics2D g2 = img.createGraphics();
   Composite old = g2.getComposite();
   g2.setComposite(AlphaComposite.Clear);
   g2.fillRect(0, 0, w, h);
   g2.setComposite(old);
   g2.setColor(Color.BLACK);
   g2.setFont(font);
   g2.setRenderingHint(
       RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
   g2.drawString("The quick brown fox jumps over the lazy dog.", 5, 20);
   g2.dispose();
   html.println("<td>" + saveImage(img) + "</td>");
 }