List of usage examples for java.awt.font TextAttribute STRIKETHROUGH
TextAttribute STRIKETHROUGH
To view the source code for java.awt.font TextAttribute STRIKETHROUGH.
Click Source Link
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame(); final JFormattedTextField textField1 = new JFormattedTextField(new Float(10.01)); textField1.setFormatterFactory(new AbstractFormatterFactory() { @Override/*from w w w. jav a 2s. c o m*/ public AbstractFormatter getFormatter(JFormattedTextField tf) { NumberFormat format = DecimalFormat.getInstance(); format.setMinimumFractionDigits(2); format.setMaximumFractionDigits(2); format.setRoundingMode(RoundingMode.HALF_UP); InternationalFormatter formatter = new InternationalFormatter(format); formatter.setAllowsInvalid(false); formatter.setMinimum(0.0); formatter.setMaximum(1000.00); return formatter; } }); Map attributes = (new Font("Serif", Font.BOLD, 16)).getAttributes(); attributes.put(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON); final JFormattedTextField textField2 = new JFormattedTextField(new Float(10.01)); textField2.setFormatterFactory(new AbstractFormatterFactory() { @Override public AbstractFormatter getFormatter(JFormattedTextField tf) { NumberFormat format = DecimalFormat.getInstance(); format.setMinimumFractionDigits(2); format.setMaximumFractionDigits(2); format.setRoundingMode(RoundingMode.HALF_UP); InternationalFormatter formatter = new InternationalFormatter(format); formatter.setAllowsInvalid(false); formatter.setMinimum(0.0); formatter.setMaximum(1000.00); return formatter; } }); textField2.getDocument().addDocumentListener(new DocumentListener() { @Override public void changedUpdate(DocumentEvent documentEvent) { printIt(documentEvent); } @Override public void insertUpdate(DocumentEvent documentEvent) { printIt(documentEvent); } @Override public void removeUpdate(DocumentEvent documentEvent) { printIt(documentEvent); } private void printIt(DocumentEvent documentEvent) { DocumentEvent.EventType type = documentEvent.getType(); double t1a1 = (((Number) textField2.getValue()).doubleValue()); if (t1a1 > 100) { textField2.setFont(new Font(attributes)); textField2.setForeground(Color.red); } else { textField2.setFont(new Font("Serif", Font.BOLD, 16)); textField2.setForeground(Color.black); } } }); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(textField1, BorderLayout.NORTH); frame.add(textField2, BorderLayout.SOUTH); frame.setVisible(true); frame.pack(); }
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.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON, 2, 8); 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.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON, 18, 22); g2.drawString(as.getIterator(), 24, 70); }
From source file:net.sf.jasperreports.engine.util.JRFontUtil.java
/** * *//*from w w w .j a v a 2s . 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
/** * *//* w ww .j av a 2 s . 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:io.github.jeddict.jsonb.modeler.widget.JSONNodeWidget.java
private void setTransientLabel(Boolean transientProperty) { Font font = getPinNameWidget().getFont(); Map attributes = font.getAttributes(); attributes.put(TextAttribute.STRIKETHROUGH, transientProperty); getPinNameWidget().setFont(new Font(attributes)); }
From source file:com.qumasoft.guitools.compare.ContentRow.java
@Override public void paint(Graphics g) { if ((getRowType() == ROWTYPE_REPLACE) && rowHadAnnotations) { Graphics2D g2 = (Graphics2D) g; String s = getText();// w ww. j ava 2 s. c o m g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); if (s.length() > 0) { int index = 0; AttributedString attributedString = new AttributedString(s, getFont().getAttributes()); try { for (byte rType : fileACharacterTypeArray) { switch (rType) { case ContentRow.ROWTYPE_DELETE: attributedString.addAttribute(TextAttribute.STRIKETHROUGH, null, index, index + 1); break; case ContentRow.ROWTYPE_REPLACE: attributedString.addAttribute(TextAttribute.BACKGROUND, ColorManager.getReplaceCompareHiliteBackgroundColor(), index, index + 1); break; default: break; } index++; } g2.drawString(attributedString.getIterator(), 0, getFont().getSize()); } catch (java.lang.IllegalArgumentException e) { LOGGER.log(Level.WARNING, "bad replace indexes. begin index: [" + index + "] end index: [" + index + "]. String length: [" + s.length() + "]"); } } else { super.paint(g); } } else { super.paint(g); } }
From source file:net.sf.jasperreports.engine.util.JRFontUtil.java
/** * Returns a java.awt.Font instance by converting a JRFont instance. * Mostly used in combination with third-party visualization packages such as JFreeChart (for chart themes). * Unless the font parameter is null, this method always returns a non-null AWT font, regardless whether it was * found in the font extensions or not. This is because we do need a font to draw with and there is no point * in raising a font missing exception here, as it is not JasperReports who does the drawing. *//* www .j a v a 2 s . c o m*/ public static Font getAwtFont(JRFont font, Locale locale) { if (font == null) { return null; } // ignoring missing font as explained in the Javadoc Font awtFont = getAwtFontFromBundles(font.getFontName(), ((font.isBold() ? Font.BOLD : Font.PLAIN) | (font.isItalic() ? Font.ITALIC : Font.PLAIN)), font.getFontSize(), locale, true); if (awtFont == null) { awtFont = new Font(getAttributesWithoutAwtFont(new HashMap<Attribute, Object>(), font)); } else { // add underline and strikethrough attributes since these are set at // style/font level Map<Attribute, Object> attributes = new HashMap<Attribute, Object>(); if (font.isUnderline()) { attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); } if (font.isStrikeThrough()) { attributes.put(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON); } if (!attributes.isEmpty()) { awtFont = awtFont.deriveFont(attributes); } } return awtFont; }
From source file:net.sf.jasperreports.engine.util.JEditorPaneHtmlMarkupProcessor.java
@Override protected Map<Attribute, Object> getAttributes(AttributeSet attrSet) { Map<Attribute, Object> attrMap = new HashMap<Attribute, Object>(); if (attrSet.isDefined(StyleConstants.FontFamily)) { attrMap.put(TextAttribute.FAMILY, StyleConstants.getFontFamily(attrSet)); }//from w w w. ja va 2 s .co m if (attrSet.isDefined(StyleConstants.Bold)) { attrMap.put(TextAttribute.WEIGHT, StyleConstants.isBold(attrSet) ? TextAttribute.WEIGHT_BOLD : TextAttribute.WEIGHT_REGULAR); } if (attrSet.isDefined(StyleConstants.Italic)) { attrMap.put(TextAttribute.POSTURE, StyleConstants.isItalic(attrSet) ? TextAttribute.POSTURE_OBLIQUE : TextAttribute.POSTURE_REGULAR); } if (attrSet.isDefined(StyleConstants.Underline)) { attrMap.put(TextAttribute.UNDERLINE, StyleConstants.isUnderline(attrSet) ? TextAttribute.UNDERLINE_ON : null); } if (attrSet.isDefined(StyleConstants.StrikeThrough)) { attrMap.put(TextAttribute.STRIKETHROUGH, StyleConstants.isStrikeThrough(attrSet) ? TextAttribute.STRIKETHROUGH_ON : null); } if (attrSet.isDefined(StyleConstants.FontSize)) { attrMap.put(TextAttribute.SIZE, StyleConstants.getFontSize(attrSet)); } if (attrSet.isDefined(StyleConstants.Foreground)) { attrMap.put(TextAttribute.FOREGROUND, StyleConstants.getForeground(attrSet)); } if (attrSet.isDefined(StyleConstants.Background)) { attrMap.put(TextAttribute.BACKGROUND, StyleConstants.getBackground(attrSet)); } //FIXME: why StyleConstants.isSuperscript(attrSet) does return false if (attrSet.isDefined(StyleConstants.Superscript) && !StyleConstants.isSubscript(attrSet)) { attrMap.put(TextAttribute.SUPERSCRIPT, TextAttribute.SUPERSCRIPT_SUPER); } if (attrSet.isDefined(StyleConstants.Subscript) && StyleConstants.isSubscript(attrSet)) { attrMap.put(TextAttribute.SUPERSCRIPT, TextAttribute.SUPERSCRIPT_SUB); } return attrMap; }