Example usage for java.awt.font TextAttribute UNDERLINE

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

Introduction

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

Prototype

TextAttribute UNDERLINE

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

Click Source Link

Document

Attribute key for 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.  ja va2  s.  c  o 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

/**
 *
 *///from   w ww .ja v  a  2 s. c  om
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:com.pronoiahealth.olhie.server.services.BookCoverImageService.java

/**
 * Initialize the various maps, fonts, etc..
 *///from  w  w w  .  jav  a2 s  .  c  o  m
@PostConstruct
protected void postActivate() {
    try {
        // Init the coverMap and load the images
        coverMap = new HashMap<String, byte[]>();
        List<BookCover> covers = coverDisplayData.getCovers();
        for (BookCover cover : covers) {
            coverMap.put(cover.getCoverName(),
                    readResourceToByteArray("/" + cover.getImgUrl(), servletContext));
        }

        // Load needed fonts
        medulaOneRegularFont = Font.createFont(Font.TRUETYPE_FONT,
                servletContext.getResourceAsStream("/Olhie/font/MedulaOne-Regular.ttf"));
        medulaOneRegularFont48 = medulaOneRegularFont.deriveFont(new Float(48.0));
        arialBoldFont13 = new Font("Arial Bold", Font.BOLD, 13);
        arialBoldFont16 = new Font("Arial Bold", Font.ITALIC, 16);

        // Init font maps
        // author
        authorFontMap = new Hashtable<TextAttribute, Object>();
        authorFontMap.put(TextAttribute.FONT, arialBoldFont16);
        authorFontMap.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD);

        // Title
        titleFontMap = new Hashtable<TextAttribute, Object>();
        titleFontMap.put(TextAttribute.FONT, medulaOneRegularFont48);
        titleFontMap.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD);

        // Back cover title
        backTitleFontMap = new Hashtable<TextAttribute, Object>();
        backTitleFontMap.put(TextAttribute.FONT, arialBoldFont13);
        backTitleFontMap.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD);
        backTitleFontMap.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_LOW_ONE_PIXEL);

        // Build palette factory
        palFac = new PaletteFactory();

    } catch (Exception e) {
        log.log(Level.SEVERE, "Error occured during BookCoverImageService initialization.", e);
    }
}

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

/**
 *
 *//*from   w  w  w  .j a va 2s .c  o  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 ww  w  .  j  av a2  s  .c  om*/
        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.  j av  a  2s .c  o 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));
    }// w  w  w.  j a  v a  2s. c  om
}