private JComponent createNoPlannerFoundTextField() { String infoMessage = "No planner benchmarks have been found in the benchmarkDirectory (" + benchmarkAggregator.getBenchmarkDirectory() + ")."; JTextPane textPane = new JTextPane(); textPane.setEditable(false); textPane.setText(infoMessage); // center info message StyledDocument styledDocument = textPane.getStyledDocument(); SimpleAttributeSet center = new SimpleAttributeSet(); StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER); StyleConstants.setBold(center, true); styledDocument.setParagraphAttributes(0, styledDocument.getLength(), center, false); return textPane; }
int right = 10; SimpleAttributeSet set = new SimpleAttributeSet(); StyleConstants.setAlignment(set, StyleConstants.ALIGN_LEFT); StyleConstants.setSpaceAbove(set, top); StyleConstants.setSpaceBelow(set, bottom);
import javax.swing.SwingUtilities; import javax.swing.JFrame; import javax.swing.JTextPane; import javax.swing.text.SimpleAttributeSet; import javax.swing.text.StyleConstants; class Demo{ public static void main(String[]args){ SwingUtilities.invokeLater(()->{ JFrame frame=new JFrame("Right-Left"); JTextPane box=new JTextPane(); frame.getContentPane().add(box); SimpleAttributeSet attr = new SimpleAttributeSet(); StyleConstants.setAlignment(attr, StyleConstants.ALIGN_RIGHT); box.setParagraphAttributes(attr, true); frame.setSize(300,200); frame.setLocationByPlatform(true); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); }); } }
@Override public void setText(String t) { // TODO Auto-generated method stub super.setText(t); StyledDocument doc = this.getStyledDocument(); SimpleAttributeSet center = new SimpleAttributeSet(); StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER); doc.setParagraphAttributes(0, doc.getLength(), center, false); }
/** * Sets the horizontal alignment of the text. This method should not * fire any events! * @param alignment the horizontal alignment of the text */ protected void setHorizontalAlignmentOnly(HorizontalAlignment alignment) { horizontalAlignment = alignment; if (inited){ StyleConstants.setAlignment(attributeSet, alignment.getStyleConstant(this.getComponentOrientation())); configureHtmlText(); } }
public void insereIcone(final String _name, final Icon _icon, final String _text) { if (type_ == HTML) { return; } final Document dk = getDocument(); final Style defaultStyle = getStyle(StyleContext.DEFAULT_STYLE); final Style iconStyle = addStyle(_name + "-icon", defaultStyle); StyleConstants.setIcon(iconStyle, _icon); StyleConstants.setAlignment(iconStyle, StyleConstants.ALIGN_CENTER); try { dk.insertString(dk.getLength(), CtuluLibString.LINE_SEP, iconStyle); } catch (final BadLocationException ex) {} if (!"".equals(_text)) { final Style textStyle = addStyle(_name + "-text", defaultStyle); StyleConstants.setAlignment(textStyle, StyleConstants.ALIGN_CENTER); StyleConstants.setItalic(iconStyle, true); StyleConstants.setFontSize(iconStyle, 10); try { dk.insertString(dk.getLength(), _text + CtuluLibString.LINE_SEP, textStyle); } catch (final BadLocationException ex) {} } }
@Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { setText((String) value); StyleConstants.setAlignment(attribs, ((PersonnelEventLogModel)table.getModel()).getAlignment(column)); setParagraphAttributes(attribs, false); int fontHeight = metrics.getHeight(); int textLength = metrics.stringWidth(getText()) + 10; int lines = (int) Math.ceil(1.0 * textLength / table.getColumnModel().getColumn(column).getWidth()); if (lines == 0) { lines = 1; } // check for new lines int newLines = getText().split("\r\n|\r|\n").length; //$NON-NLS-1$ lines = Math.max(lines, newLines); int height = fontHeight * lines + 4; if(table.getRowHeight(row) < height) { table.setRowHeight(row, height); } setForeground(Color.BLACK); // tiger stripes if (row % 2 == 0) { setBackground(new Color(230,230,230)); } else { setBackground(Color.WHITE); } return this; } }
public void insereEnteteEtude(final BuInformationsDocument _id) { final Document dk = getDocument(); final Style defaultStyle = getStyle(StyleContext.DEFAULT_STYLE); final Style boldStyle = addStyle("bold", defaultStyle); StyleConstants.setBold(boldStyle, true); final Style titleStyle = addStyle("title", boldStyle); StyleConstants.setFontSize(titleStyle, 16); StyleConstants.setSpaceBelow(titleStyle, 10); StyleConstants.setAlignment(titleStyle, StyleConstants.ALIGN_CENTER); final Style smallStyle = addStyle("small", defaultStyle); StyleConstants.setFontSize(smallStyle, 10); insereIcone(_id.logo); try { /* * if(_id.logo!=null) StyleConstants.setIcon(title_style,_id.logo); */ dk.insertString(dk.getLength(), _id.name, titleStyle); dk.insertString(dk.getLength(), CtuluLibString.LINE_SEP, defaultStyle); dk.insertString(dk.getLength(), BuResource.BU.getString("Version") + getDot(), boldStyle); dk.insertString(dk.getLength(), _id.version + CtuluLibString.LINE_SEP, defaultStyle); dk.insertString(dk.getLength(), BuResource.BU.getString("Date") + getDot(), boldStyle); dk.insertString(dk.getLength(), _id.date + CtuluLibString.LINE_SEP, defaultStyle); dk.insertString(dk.getLength(), BuResource.BU.getString("Auteur") + getDot(), boldStyle); dk.insertString(dk.getLength(), _id.author + " ", defaultStyle); dk.insertString(dk.getLength(), "(" + _id.contact + ")\n", smallStyle); dk.insertString(dk.getLength(), BuResource.BU.getString("Organisme") + getDot(), boldStyle); dk.insertString(dk.getLength(), _id.organization + CtuluLibString.LINE_SEP, defaultStyle); } catch (final BadLocationException ex) {} }
@Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { setText((String) value); StyleConstants.setAlignment(attribs, ((PersonnelKillLogModel)table.getModel()).getAlignment(column)); setParagraphAttributes(attribs, false); int fontHeight = metrics.getHeight(); int textLength = metrics.stringWidth(getText()); int lines = (int) Math.ceil(1.0 * textLength / table.getColumnModel().getColumn(column).getWidth()); if (lines == 0) { lines = 1; } int height = fontHeight * lines + 4; if(table.getRowHeight(row) < height) { table.setRowHeight(row, height); } setForeground(Color.BLACK); // tiger stripes if (row % 2 == 0) { setBackground(new Color(230,230,230)); } else { setBackground(Color.WHITE); } return this; } }
private static void updateStyles(final StyleSheet _styles) { if (_styles != null) { final int font = 12 * BuPreferences.BU.getFontScaling() / 100; final Enumeration rules = _styles.getStyleNames(); while (rules.hasMoreElements()) { final String name = (String) rules.nextElement(); final Style rule = _styles.getStyle(name); if (StyleConstants.ALIGN_JUSTIFIED == StyleConstants.getAlignment(rule)) { StyleConstants.setAlignment(rule, StyleConstants.ALIGN_LEFT); } if (StyleConstants.getFontSize(rule) <= font) { // FuLog.debug("WBP: font size="+StyleConstants.getFontSize(rule)); StyleConstants.setFontSize(rule, font); } } } }
private static final void updateStyles(StyleSheet _styles) { if(_styles!=null) { int FONT=12*BuPreferences.BU.getFontScaling()/100; Enumeration rules=_styles.getStyleNames(); while(rules.hasMoreElements()) { String name=(String)rules.nextElement(); Style rule=_styles.getStyle(name); if(StyleConstants.ALIGN_JUSTIFIED ==StyleConstants.getAlignment(rule)) StyleConstants.setAlignment (rule,StyleConstants.ALIGN_LEFT); if(StyleConstants.getFontSize(rule)<=FONT) { //FuLog.debug("WBP: font size="+StyleConstants.getFontSize(rule)); StyleConstants.setFontSize(rule,FONT); } } } }
public TextPane() { super(); Style style = getStyle("default"); StyleConstants.setAlignment(style, StyleConstants.ALIGN_CENTER); artistStyle = addStyle("artist", null); titleStyle = addStyle("title", null); setEditable(false); setOpaque(true); setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); updateUI(); }
private void buildDocument() { StyleContext context = new StyleContext(); document = new DefaultStyledDocument(context); Style style = context.getStyle(StyleContext.DEFAULT_STYLE); StyleConstants.setAlignment(style, StyleConstants.ALIGN_LEFT); StyleConstants.setFontSize(style, 14); StyleConstants.setSpaceAbove(style, 4); StyleConstants.setSpaceBelow(style, 4); // Insert content try { document.insertString(document.getLength(), message, style); } catch (BadLocationException badLocationException) { log.error("failed to build document", badLocationException); } SimpleAttributeSet attributes = new SimpleAttributeSet(); StyleConstants.setBold(attributes, true); StyleConstants.setItalic(attributes, true); // Third style for icon/component Style labelStyle = context.getStyle(StyleContext.DEFAULT_STYLE); Icon icon = new ImageIcon("Computer.gif"); JLabel label = new JLabel(icon); StyleConstants.setComponent(labelStyle, label); } }
private void RebuildStyles() { send(" "); StyleConstants.setAlignment(m_objMainStyle, StyleConstants.ALIGN_LEFT); StyleConstants.setFontFamily(m_objMainStyle, m_objChatterFont.getFamily()); StyleConstants.setFontSize(m_objMainStyle, m_objChatterFont.getSize()); StyleConstants.setSpaceAbove(m_objMainStyle, 2); StyleConstants.setSpaceBelow(m_objMainStyle, 2); send("- Chatter font changed"); send(" "); FontMetrics l_objFM = m_objChatPanel.getFontMetrics(m_objChatterFont); float l_f = (float)l_objFM.stringWidth(BEFORE_CATEGORY + ASLDiceBot.OTHER_CATEGORY + "XXX"); TabStop[] lar_objTabs = new TabStop[10]; // this sucks for(int l_i = 0; l_i < lar_objTabs.length; l_i++) { lar_objTabs[l_i] = new TabStop(l_f * (l_i + 1), TabStop.ALIGN_LEFT, TabStop.LEAD_NONE); } TabSet l_objTabset = new TabSet(lar_objTabs); StyleConstants.setTabSet(m_objMainStyle, new TabSet(new TabStop[0])); StyleConstants.setTabSet(m_objMainStyle, l_objTabset); m_objChatPanel.setParagraphAttributes(m_objMainStyle, true); }
BasicDocument(Font defaultFont, Color foreground, TextAlignment textAlignment, float rightIndent) { setFontAndColor(defaultFont, foreground); MutableAttributeSet attr = new SimpleAttributeSet(); StyleConstants.setAlignment(attr, textAlignment.getValue()); getStyle("default").addAttributes(attr); attr = new SimpleAttributeSet(); StyleConstants.setRightIndent(attr, rightIndent); getStyle("default").addAttributes(attr); }
BasicDocument(Font defaultFont, Color foreground, TextAlignment textAlignment, float rightIndent) { setFontAndColor(defaultFont, foreground); MutableAttributeSet attr = new SimpleAttributeSet(); StyleConstants.setAlignment(attr, textAlignment.getValue()); getStyle("default").addAttributes(attr); attr = new SimpleAttributeSet(); StyleConstants.setRightIndent(attr, rightIndent); getStyle("default").addAttributes(attr); }
BasicDocument(Font defaultFont, Color foreground, TextAlignment textAlignment, float rightIndent) { setFontAndColor(defaultFont, foreground); MutableAttributeSet attr = new SimpleAttributeSet(); StyleConstants.setAlignment(attr, textAlignment.getValue()); getStyle("default").addAttributes(attr); attr = new SimpleAttributeSet(); StyleConstants.setRightIndent(attr, rightIndent); getStyle("default").addAttributes(attr); }
BasicDocument(Font defaultFont, Color foreground, TextAlignment textAlignment, float rightIndent) { setFontAndColor(defaultFont, foreground); MutableAttributeSet attr = new SimpleAttributeSet(); StyleConstants.setAlignment(attr, textAlignment.getValue()); getStyle("default").addAttributes(attr); attr = new SimpleAttributeSet(); StyleConstants.setRightIndent(attr, rightIndent); getStyle("default").addAttributes(attr); }
BasicDocument(Font defaultFont, Color foreground, TextAlignment textAlignment, float rightIndent) { setFontAndColor(defaultFont, foreground); MutableAttributeSet attr = new SimpleAttributeSet(); StyleConstants.setAlignment(attr, textAlignment.getValue()); getStyle("default").addAttributes(attr); attr = new SimpleAttributeSet(); StyleConstants.setRightIndent(attr, rightIndent); getStyle("default").addAttributes(attr); }
private void prepareStyles() { StyledDocument doc = trgQueryTextPane.getStyledDocument(); plainStyle = doc.addStyle("PLAIN_STYLE", null); StyleConstants.setItalic(plainStyle, false); boldStyle = doc.addStyle("BOLD_STYLE", null); StyleConstants.setBold(boldStyle, true); nonBoldStyle = doc.addStyle("NON_BOLD_STYLE", null); StyleConstants.setBold(nonBoldStyle, false); selectionForeground = doc.addStyle("SEL_FG_STYPE", null); // we know that it is possible for SELECTION_FOREGROUND to be null // and an exception here means that Protege doesn't start if (selectionForeground != null && SELECTION_FOREGROUND != null) { StyleConstants.setForeground(selectionForeground, SELECTION_FOREGROUND); } foreground = doc.addStyle("FG_STYLE", null); if (foreground != null && FOREGROUND != null) { StyleConstants.setForeground(foreground, FOREGROUND); } background = doc.addStyle("BG_STYLE", null); if (background != null) { // StyleConstants.setBackground(background, Color.WHITE); } alignment = doc.addStyle("ALIGNMENT_STYLE", null); if (alignment != null) { StyleConstants.setAlignment(alignment, StyleConstants.ALIGN_LEFT); } fontSizeStyle = doc.addStyle("FONT_SIZE", null); StyleConstants.setFontSize(fontSizeStyle, 40); }