Example usage for java.awt.font TextAttribute UNDERLINE_ON

List of usage examples for java.awt.font TextAttribute UNDERLINE_ON

Introduction

In this page you can find the example usage for java.awt.font TextAttribute UNDERLINE_ON.

Prototype

Integer UNDERLINE_ON

To view the source code for java.awt.font TextAttribute UNDERLINE_ON.

Click Source Link

Document

Standard underline.

Usage

From source file:Main.java

public void paint(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    AttributedString as1 = new AttributedString("1234567890");
    as1.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON, 3, 4);
    g2d.drawString(as1.getIterator(), 15, 60);
}

From source file:IteratorUnderStrike.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    String s = "\"www.java2s.com\" is great.";

    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    Font plainFont = new Font("Times New Roman", Font.PLAIN, 24);

    AttributedString as = new AttributedString(s);
    as.addAttribute(TextAttribute.FONT, plainFont);
    as.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON, 1, 15);
    as.addAttribute(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON, 18, 25);

    g2.drawString(as.getIterator(), 24, 70);
}

From source file:MainClass.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    String s = "\"www.java2s.com,\" www.java2s.com";

    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    Font plainFont = new Font("Times New Roman", Font.PLAIN, 24);

    AttributedString as = new AttributedString(s);
    as.addAttribute(TextAttribute.FONT, plainFont);
    as.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON, 1, 11);
    g2.drawString(as.getIterator(), 24, 70);

}

From source file:AttributesApp.java

public AttributesApp() {
    setBackground(Color.lightGray);
    setSize(500, 200);//from  w w  w. j  a  v  a 2  s.  co m

    attribString = new AttributedString(text);

    GeneralPath star = new GeneralPath();
    star.moveTo(0, 0);
    star.lineTo(10, 30);
    star.lineTo(-10, 10);
    star.lineTo(10, 10);
    star.lineTo(-10, 30);
    star.closePath();
    GraphicAttribute starShapeAttr = new ShapeGraphicAttribute(star, GraphicAttribute.TOP_ALIGNMENT, false);
    attribString.addAttribute(TextAttribute.CHAR_REPLACEMENT, starShapeAttr, 0, 1);
    attribString.addAttribute(TextAttribute.FOREGROUND, new Color(255, 255, 0), 0, 1);

    int index = text.indexOf("Java Source");
    attribString.addAttribute(TextAttribute.FOREGROUND, Color.blue, index, index + 7);
    Font font = new Font("sanserif", Font.ITALIC, 40);
    attribString.addAttribute(TextAttribute.FONT, font, index, index + 7);

    loadImage();
    BufferedImage bimage = new BufferedImage(image.getWidth(this), image.getHeight(this),
            BufferedImage.TYPE_INT_ARGB);
    Graphics2D big = bimage.createGraphics();
    big.drawImage(image, null, this);
    GraphicAttribute javaImageAttr = new ImageGraphicAttribute(bimage, GraphicAttribute.TOP_ALIGNMENT, 0, 0);

    index = text.indexOf("Java");
    attribString.addAttribute(TextAttribute.CHAR_REPLACEMENT, javaImageAttr, index - 1, index);

    font = new Font("serif", Font.BOLD, 60);
    attribString.addAttribute(TextAttribute.FONT, font, index, index + 4);
    attribString.addAttribute(TextAttribute.FOREGROUND, new Color(243, 63, 163), index, index + 4); // Start and end indexes.

    index = text.indexOf("source");
    attribString.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON, index, index + 2);

    index = text.indexOf("and support");
    font = new Font("sanserif", Font.ITALIC, 40);
    attribString.addAttribute(TextAttribute.FONT, font, index, index + 10);

    attribString.addAttribute(TextAttribute.FOREGROUND, Color.white, index, index + 2); // Start and end indexes.
    attribString.addAttribute(TextAttribute.FOREGROUND, Color.blue, index + 3, index + 10); // Start and end indexes.
}

From source file:net.sf.jasperreports.engine.util.JRFontUtil.java

/**
 *
 *///  w w  w  . j a  v a2s  . c o  m
public static Map<Attribute, Object> getAttributesWithoutAwtFont(Map<Attribute, Object> attributes,
        JRFont font) {
    attributes.put(TextAttribute.FAMILY, font.getFontName());

    attributes.put(TextAttribute.SIZE, new Float(font.getFontSize()));

    if (font.isBold()) {
        attributes.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD);
    }
    if (font.isItalic()) {
        attributes.put(TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE);
    }
    if (font.isUnderline()) {
        attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
    }
    if (font.isStrikeThrough()) {
        attributes.put(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON);
    }

    attributes.put(JRTextAttribute.PDF_FONT_NAME, font.getPdfFontName());
    attributes.put(JRTextAttribute.PDF_ENCODING, font.getPdfEncoding());

    if (font.isPdfEmbedded()) {
        attributes.put(JRTextAttribute.IS_PDF_EMBEDDED, Boolean.TRUE);
    }

    return attributes;
}

From source file:net.sf.jasperreports.engine.fonts.FontUtil.java

/**
 *
 *//*  www .jav  a 2  s  .  co  m*/
public Map<Attribute, Object> getAttributesWithoutAwtFont(Map<Attribute, Object> attributes, JRFont font) {
    attributes.put(TextAttribute.FAMILY, font.getFontName());

    attributes.put(TextAttribute.SIZE, font.getFontsize());

    if (font.isBold()) {
        attributes.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD);
    }
    if (font.isItalic()) {
        attributes.put(TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE);
    }
    if (font.isUnderline()) {
        attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
    }
    if (font.isStrikeThrough()) {
        attributes.put(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON);
    }

    attributes.put(JRTextAttribute.PDF_FONT_NAME, font.getPdfFontName());
    attributes.put(JRTextAttribute.PDF_ENCODING, font.getPdfEncoding());

    if (font.isPdfEmbedded()) {
        attributes.put(JRTextAttribute.IS_PDF_EMBEDDED, Boolean.TRUE);
    }

    return attributes;
}

From source file:com.github.benchdoos.weblocopener.weblocOpener.gui.EditDialog.java

private void fillTextFieldWithClipboard() {
    String data = "<empty clipboard>";
    try {//from  w  ww .j  av a 2s.c  o m
        data = (String) Toolkit.getDefaultToolkit().getSystemClipboard().getData(DataFlavor.stringFlavor);
        URL url = new URL(data);
        UrlValidator urlValidator = new UrlValidator();
        if (urlValidator.isValid(data)) {
            textField.setText(url.toString());
            setTextFieldFont(textField.getFont(), TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
            textField.setCaretPosition(textField.getText().length());
            textField.selectAll();
            log.debug("Got URL from clipboard: " + url);
        }
    } catch (UnsupportedFlavorException | IllegalStateException | HeadlessException | IOException e) {
        textField.setText("");
        log.warn("Can not read URL from clipboard: [" + data + "]", e);
    }
}

From source file:com.github.benchdoos.weblocopener.weblocOpener.gui.EditDialog.java

private void initTextField(String pathToEditingFile) {
    textField.addMouseListener(new ClickListener() {
        @Override/*from   w w  w  .  jav  a2 s .co m*/
        public void doubleClick(MouseEvent e) {
            textField.selectAll();
        }
    });

    textField.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void changedUpdate(DocumentEvent e) {
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            updateTextFont();
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            updateTextFont();
        }

        private void updateTextFont() {
            UrlValidator urlValidator = new UrlValidator();
            if (urlValidator.isValid(textField.getText())) {
                if (textField != null) {
                    setTextFieldFont(textField.getFont(), TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
                    textField.setForeground(Color.BLUE);
                }
            } else {
                if (textField != null) {
                    setTextFieldFont(textField.getFont(), TextAttribute.UNDERLINE, -1);
                    textField.setForeground(Color.BLACK);
                }
            }
        }

    });

    UndoManager undoManager = new UndoManager();
    textField.getDocument().addUndoableEditListener(new UndoableEditListener() {

        public void undoableEditHappened(UndoableEditEvent evt) {
            undoManager.addEdit(evt.getEdit());
        }

    });

    textField.getActionMap().put("Undo", new AbstractAction("Undo") {
        public void actionPerformed(ActionEvent evt) {
            try {
                if (undoManager.canUndo()) {
                    undoManager.undo();
                }
            } catch (CannotUndoException e) {
            }
        }
    });

    textField.getInputMap().put(KeyStroke.getKeyStroke("control Z"), "Undo");

    textField.getActionMap().put("Redo", new AbstractAction("Redo") {
        public void actionPerformed(ActionEvent evt) {
            try {
                if (undoManager.canRedo()) {
                    undoManager.redo();
                }
            } catch (CannotRedoException e) {
            }
        }
    });

    textField.getInputMap().put(KeyStroke.getKeyStroke("control shift Z"), "Redo");

    fillTextField(pathToEditingFile);
}

From source file:com.haulmont.cuba.desktop.gui.components.SwingXTableSettings.java

protected void saveFontPreferences(Element element) {
    if (table.getFont() != null) {
        Font font = table.getFont();
        Map<TextAttribute, ?> attributes = font.getAttributes();
        // save content font
        element.addAttribute("fontFamily", font.getFamily());
        element.addAttribute("fontSize", Integer.toString(font.getSize()));
        element.addAttribute("fontStyle", Integer.toString(font.getStyle()));
        element.addAttribute("fontUnderline",
                Boolean.toString(attributes.get(TextAttribute.UNDERLINE) == TextAttribute.UNDERLINE_ON));
    }//from www  .j  av  a2  s. co  m
}

From source file:com.haulmont.cuba.desktop.gui.components.SwingXTableSettings.java

protected void loadFontPreferences(Element element) {
    // load font preferences
    String fontFamily = element.attributeValue("fontFamily");
    String fontSize = element.attributeValue("fontSize");
    String fontStyle = element.attributeValue("fontStyle");
    String fontUnderline = element.attributeValue("fontUnderline");
    if (!StringUtils.isBlank(fontFamily) && !StringUtils.isBlank(fontSize)
            && !StringUtils.isBlank(fontUnderline) && !StringUtils.isBlank(fontStyle)) {

        try {/*from   ww w .  java 2  s  .  c om*/
            int size = Integer.parseInt(fontSize);
            int style = Integer.parseInt(fontStyle);

            String[] availableFonts = GraphicsEnvironment.getLocalGraphicsEnvironment()
                    .getAvailableFontFamilyNames();
            int fontIndex = Arrays.asList(availableFonts).indexOf(fontFamily);
            if (fontIndex < 0) {
                log.debug("Unsupported font family, font settings not loaded");
                return;
            }

            Configuration configuration = AppBeans.get(Configuration.NAME);
            DesktopConfig desktopConfig = configuration.getConfig(DesktopConfig.class);
            int sizeIndex = desktopConfig.getAvailableFontSizes().indexOf(size);

            if (sizeIndex < 0) {
                log.debug("Unsupported font size, font settings not loaded");
                return;
            }

            Boolean underline = BooleanUtils.toBooleanObject(fontUnderline);

            @SuppressWarnings("MagicConstant")
            Font font = new Font(fontFamily, style, size);
            if (underline != null && Boolean.TRUE.equals(underline)) {
                Map<TextAttribute, Integer> attributes = new HashMap<>();
                attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
                font = font.deriveFont(attributes);
            }
            table.setFont(font);
        } catch (NumberFormatException ex) {
            log.debug("Broken font definition in user setting");
        }
    }
}