javax.swing.text.Style Java Examples

The following examples show how to use javax.swing.text.Style. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LogArea.java    From gate-core with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Try and recover from a BadLocationException thrown when inserting a string
 * into the log area. This method must only be called on the AWT event
 * handling thread.
 */
private void handleBadLocationException(BadLocationException e,
    String textToInsert, Style style) {
  originalErr.println("BadLocationException encountered when writing to "
      + "the log area: " + e);
  originalErr.println("trying to recover...");

  Document newDocument = new DefaultStyledDocument();
  try {
    StringBuilder sb = new StringBuilder();
    sb.append("An error occurred when trying to write a message to the log area.  The log\n");
    sb.append("has been cleared to try and recover from this problem.\n\n");
    sb.append(textToInsert);

    newDocument.insertString(0, sb.toString(), style);
  } catch(BadLocationException e2) {
    // oh dear, all bets are off now...
    e2.printStackTrace(originalErr);
    return;
  }
  // replace the log area's document with the new one
  setDocument(newDocument);
}
 
Example #2
Source File: AnnotationDisplayCustomizationFrame.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the customization panel.
 *
 * @param typeName the new customization panel
 */
private void setCustomizationPanel(String typeName) {
  this.currentTypeName = typeName;
  Style defaultAnnotStyle = this.styleMap.get(CAS.TYPE_NAME_ANNOTATION);
  Style style = this.styleMap.get(typeName);
  if (style == null) {
    style = defaultAnnotStyle;
  }
  // Style defaultStyle = StyleContext.getDefaultStyleContext().getStyle(
  // StyleContext.DEFAULT_STYLE);
  setCurrentStyle(style);
  this.fgColor = StyleConstants.getForeground(this.currentStyle);
  this.bgColor = StyleConstants.getBackground(this.currentStyle);
  this.fgIcon.setColor(this.fgColor);
  this.bgIcon.setColor(this.bgColor);
  setTextPane();
  enableButtons(false);
  this.repaint();
}
 
Example #3
Source File: BaseTypeTableCellRenderer.java    From binnavi with Apache License 2.0 6 votes vote down vote up
private static void renderAtomic(
    final TypeInstance instance, final StyledDocument document, final boolean renderData) {
  final Style atomicStyle = createDeclarationStyle(document);
  try {
    document.remove(0, document.getLength());
    final BaseType baseType = instance.getBaseType();
    appendString(document, baseType.getName(), atomicStyle);
    if (renderData) {
      appendString(document,
          renderInstanceData(baseType, instance.getAddress().getOffset(), instance.getSection()),
          createDataStyle(document));
    }
  } catch (final BadLocationException exception) {
    CUtilityFunctions.logException(exception);
  }
}
 
Example #4
Source File: MessageColorizerEditor.java    From otroslogviewer with Apache License 2.0 6 votes vote down vote up
private void refreshView() {
  LOGGER.info("refreshing view");
  Style defaultStyle = textPane.getStyle(StyleContext.DEFAULT_STYLE);
  String text = textPane.getText();
  textPane.getStyledDocument().setCharacterAttributes(0, text.length(), defaultStyle, true);
  try {
    PropertyPatternMessageColorizer propertyPatternMessageColorize = createMessageColorizer();
    if (propertyPatternMessageColorize.colorizingNeeded(text)) {
      Collection<MessageFragmentStyle> colorize = propertyPatternMessageColorize.colorize(text);
      for (MessageFragmentStyle mfs : colorize) {
        textPane.getStyledDocument().setCharacterAttributes(mfs.getOffset(), mfs.getLength(), mfs.getStyle(), mfs.isReplace());
      }
    }
  } catch (Exception e) {
    LOGGER.error(String.format("Can't init PropertyPatternMessageColorizer:%s", e.getMessage()));
    statusObserver.updateStatus(String.format("Error: %s", e.getMessage()), StatusObserver.LEVEL_ERROR);
  }

}
 
Example #5
Source File: JViewPortBackingStoreImageTest.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
static void addParagraph(Paragraph p) {
    try {
        Style s = null;
        for (int i = 0; i < p.data.length; i++) {
            AttributedContent run = p.data[i];
            s = contentAttributes.get(run.attr);
            doc.insertString(doc.getLength(), run.content, s);
        }

        Style ls = styles.getStyle(p.logical);
        doc.setLogicalStyle(doc.getLength() - 1, ls);
        doc.insertString(doc.getLength(), "\n", null);
    } catch (BadLocationException e) {
        throw new RuntimeException(e);
    }
}
 
Example #6
Source File: MainPanel.java    From java-swing-tips with MIT License 6 votes vote down vote up
private int getOtherToken(String content, int startOffset, int endOffset) {
  int endOfToken = startOffset + 1;
  while (endOfToken <= endOffset) {
    if (isDelimiter(content.substring(endOfToken, endOfToken + 1))) {
      break;
    }
    endOfToken++;
  }
  String token = content.substring(startOffset, endOfToken);
  Style s = getStyle(token);
  // if (keywords.containsKey(token)) {
  //  setCharacterAttributes(startOffset, endOfToken - startOffset, keywords.get(token), false);
  if (Objects.nonNull(s)) {
    setCharacterAttributes(startOffset, endOfToken - startOffset, s, false);
  }
  return endOfToken + 1;
}
 
Example #7
Source File: MainFrame.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Save color preferences.
 *
 * @param file the file
 * @throws IOException Signals that an I/O exception has occurred.
 */
public void saveColorPreferences(File file) throws IOException {
  Properties prefs1 = new Properties();
  Iterator<String> it = this.styleMap.keySet().iterator();
  String type;
  Style style;
  Color fg, bg;
  while (it.hasNext()) {
    type = it.next();
    style = this.styleMap.get(type);
    fg = StyleConstants.getForeground(style);
    bg = StyleConstants.getBackground(style);
    prefs1.setProperty(type, Integer.toString(fg.getRGB()) + "+" + Integer.toString(bg.getRGB()));
  }
  FileOutputStream out = new FileOutputStream(file);
  prefs1.store(out, "Color preferences for annotation viewer.");
}
 
Example #8
Source File: BaseTypeTableCellRenderer.java    From binnavi with Apache License 2.0 6 votes vote down vote up
private static void renderArray(
    final TypeInstance instance, final StyledDocument document, final boolean renderData) {
  final Style arrayStyle = createDeclarationStyle(document);
  try {
    document.remove(0, document.getLength());
    final BaseType baseType = instance.getBaseType();
    appendString(document, baseType.getName(), arrayStyle);
    if (renderData) {
      appendString(document,
          renderInstanceData(baseType, instance.getAddress().getOffset(), instance.getSection()),
          createDataStyle(document));
    }
  } catch (final BadLocationException exception) {
    CUtilityFunctions.logException(exception);
  }
}
 
Example #9
Source File: JTextPaneUtils.java    From WorldGrower with GNU General Public License v3.0 6 votes vote down vote up
public static void appendIconAndText(JTextPane textPane, Image image, String message) {
	StyledDocument document = (StyledDocument)textPane.getDocument();
	image = StatusMessageImageConverter.convertImage(image);
	
       try {
		JLabel jl  = JLabelFactory.createJLabel("<html>" + message + "</html>", image);
		jl.setHorizontalAlignment(SwingConstants.LEFT);

		String styleName = "style"+message;
		Style textStyle = document.addStyle(styleName, null);
	    StyleConstants.setComponent(textStyle, jl);

	    document.insertString(document.getLength(), " ", document.getStyle(styleName));
	} catch (BadLocationException e) {
		throw new IllegalStateException(e);
	}
}
 
Example #10
Source File: MainPanel.java    From java-swing-tips with MIT License 6 votes vote down vote up
private MainPanel() {
  super(new GridLayout(3, 1));

  JTextPane label1 = new JTextPane();
  // MutableAttributeSet attr = new SimpleAttributeSet();
  Style attr = label1.getStyle(StyleContext.DEFAULT_STYLE);
  StyleConstants.setLineSpacing(attr, -.2f);
  label1.setParagraphAttributes(attr, true);
  label1.setText("JTextPane\n" + DUMMY_TEXT);
  // [XP Style Icons - Download](https://xp-style-icons.en.softonic.com/)
  ImageIcon icon = new ImageIcon(getClass().getResource("wi0124-32.png"));
  add(makeLeftIcon(label1, icon));

  JTextArea label2 = new JTextArea("JTextArea\n" + DUMMY_TEXT);
  add(makeLeftIcon(label2, icon));

  JLabel label3 = new JLabel("<html>JLabel+html<br>" + DUMMY_TEXT);
  label3.setIcon(icon);
  add(label3);

  setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
  setPreferredSize(new Dimension(320, 240));
}
 
Example #11
Source File: ModelItem.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void printHeaders(JTextPane pane, JSONObject headers,
        StyledDocument doc, Style boldStyle, Style defaultStyle) throws BadLocationException {

    assert headers != null;
    Set keys = new TreeSet(new Comparator<Object>() {
        @Override
        public int compare(Object o1, Object o2) {
            return ((String)o1).compareToIgnoreCase((String)o2);
        }

    });
    keys.addAll(headers.keySet());
    for (Object oo : keys) {
        String key = (String)oo;
        doc.insertString(doc.getLength(), key+": ", boldStyle);
        String value = (String)headers.get(key);
        doc.insertString(doc.getLength(), value+"\n", defaultStyle);
    }
}
 
Example #12
Source File: Browser.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void setupStyle() {
  Document document = myHTMLViewer.getDocument();
  if (!(document instanceof StyledDocument)) {
    return;
  }

  StyledDocument styledDocument = (StyledDocument)document;

  EditorColorsManager colorsManager = EditorColorsManager.getInstance();
  EditorColorsScheme scheme = colorsManager.getGlobalScheme();

  Style style = styledDocument.addStyle("active", null);
  StyleConstants.setFontFamily(style, scheme.getEditorFontName());
  StyleConstants.setFontSize(style, scheme.getEditorFontSize());
  styledDocument.setCharacterAttributes(0, document.getLength(), style, false);
}
 
Example #13
Source File: JViewPortBackingStoreImageTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
static void addParagraph(Paragraph p) {
    try {
        Style s = null;
        for (int i = 0; i < p.data.length; i++) {
            AttributedContent run = p.data[i];
            s = contentAttributes.get(run.attr);
            doc.insertString(doc.getLength(), run.content, s);
        }

        Style ls = styles.getStyle(p.logical);
        doc.setLogicalStyle(doc.getLength() - 1, ls);
        doc.insertString(doc.getLength(), "\n", null);
    } catch (BadLocationException e) {
        throw new RuntimeException(e);
    }
}
 
Example #14
Source File: VCSHyperlinkSupport.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void insertString(StyledDocument sd, Style style) throws BadLocationException {
    if(style == null) {
        style = authorStyle;
    }
    sd.insertString(sd.getLength(), author, style);

    String iconStyleName = AUTHOR_ICON_STYLE + author;
    Style iconStyle = sd.getStyle(iconStyleName);
    if(iconStyle == null) {
        iconStyle = sd.addStyle(iconStyleName, null);
        StyleConstants.setIcon(iconStyle, kenaiUser.getIcon());
    }
    sd.insertString(sd.getLength(), " ", style);
    sd.insertString(sd.getLength(), " ", iconStyle);
}
 
Example #15
Source File: StackTraceColorizer.java    From otroslogviewer with Apache License 2.0 6 votes vote down vote up
protected void initStyles() {
  styleContext = new StyleContext();
  Style defaultStyle = styleContext.getStyle(StyleContext.DEFAULT_STYLE);
  StyleConstants.setFontFamily(defaultStyle, "courier");
  styleStackTrace = styleContext.addStyle("stackTrace", defaultStyle);

  StyleConstants.setBackground(styleStackTrace, theme.getColor(ThemeKey.LOG_DETAILS_STACKTRACE_BACKGROUND));
  StyleConstants.setForeground(styleStackTrace, theme.getColor(ThemeKey.LOG_DETAILS_STACKTRACE_FOREGROUND));
  stylePackage = styleContext.addStyle("stylePackage", styleStackTrace);
  styleClass = styleContext.addStyle("styleClass", stylePackage);
  StyleConstants.setForeground(styleClass, theme.getColor(ThemeKey.LOG_DETAILS_STACKTRACE_CLASS));
  StyleConstants.setBold(styleClass, true);
  styleMethod = styleContext.addStyle("styleMethod", styleStackTrace);
  StyleConstants.setForeground(styleMethod, theme.getColor(ThemeKey.LOG_DETAILS_STACKTRACE_METHOD));
  StyleConstants.setItalic(styleMethod, true);
  StyleConstants.setBold(styleMethod, true);
  styleFile = styleContext.addStyle("styleFile", styleStackTrace);
  StyleConstants.setForeground(styleFile, theme.getColor(ThemeKey.LOG_DETAILS_STACKTRACE_FLE));
  StyleConstants.setUnderline(styleFile, true);

  styleCodeComment = styleContext.addStyle("styleCodeComment", defaultStyle);
  StyleConstants.setForeground(styleCodeComment, theme.getColor(ThemeKey.LOG_DETAILS_STACKTRACE_COMMENT));
  StyleConstants.setItalic(styleCodeComment, true);
}
 
Example #16
Source File: LogDataFormatter.java    From otroslogviewer with Apache License 2.0 5 votes vote down vote up
private Style getStyleForMarkerColor(MarkerColors markerColors) {
  String styleName = "MarkerColor" + markerColors.name();
  Style style = sc.getStyle(styleName);
  if (style == null) {
    style = sc.addStyle(styleName, mainStyle);
    StyleConstants.setForeground(style, markerColors.getForeground());
    StyleConstants.setBackground(style, markerColors.getBackground());
  }
  return style;
}
 
Example #17
Source File: RLogPanel.java    From mzmine2 with GNU General Public License v2.0 5 votes vote down vote up
private void _updateActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event__updateActionPerformed
  jTextPane1.setText("");
  String text = new String(buffer, 0, pos);
  String[] lines = text.split("\n");

  Style style = jTextPane1.getStyle("INFO");
  for (String line : lines) {
    if (line.startsWith("o ")) {
      line = line.substring(2);
      style = jTextPane1.getStyle("OUTPUT");
    } else if (line.startsWith("i ")) {
      line = line.substring(2);
      style = jTextPane1.getStyle("INFO");
    } else if (line.startsWith("w ")) {
      line = line.substring(2);
      style = jTextPane1.getStyle("WARN");
    } else if (line.startsWith("e ")) {
      line = line.substring(2);
      style = jTextPane1.getStyle("ERROR");
    }

    try {
      jTextPane1.getDocument().insertString(jTextPane1.getDocument().getLength(), line + "\n",
          style);
      jTextPane1.setCaretPosition(jTextPane1.getDocument().getLength());
    } catch (Exception e) {
      e.printStackTrace(System.err);
    }
  }
}
 
Example #18
Source File: FunctionPanel.java    From osp with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Refreshes the instructions based on selected cell.
 *
 * @param source the function editor (may be null)
 * @param editing true if the table is editing
 * @param selectedColumn the selected table column, or -1 if none
 */
protected void refreshInstructions(FunctionEditor source, boolean editing, int selectedColumn) {
  StyledDocument doc = instructions.getStyledDocument();
  Style style = doc.getStyle("blue");                                                //$NON-NLS-1$
  String s = isEmpty() ? ToolsRes.getString("FunctionPanel.Instructions.GetStarted") //$NON-NLS-1$
                       : ToolsRes.getString("FunctionPanel.Instructions.General")   //$NON-NLS-1$
                         +"  "+ToolsRes.getString("FunctionPanel.Instructions.EditDescription"); //$NON-NLS-1$ //$NON-NLS-2$
  if(!editing&&hasCircularErrors()) {                                       // error condition
    s = ToolsRes.getString("FunctionPanel.Instructions.CircularErrors");    //$NON-NLS-1$
    style = doc.getStyle("red");                                            //$NON-NLS-1$
  } else if(!editing&&hasInvalidExpressions()) {                            // error condition
    s = ToolsRes.getString("FunctionPanel.Instructions.BadCell");           //$NON-NLS-1$
    style = doc.getStyle("red");                                            //$NON-NLS-1$
  } else if(source!=null) {
    if((selectedColumn==0)&&editing) {                                      // editing name
      s = ToolsRes.getString("FunctionPanel.Instructions.NameCell");        //$NON-NLS-1$
    } else if((selectedColumn==1)&&editing) {                               // editing expression
      s = source.getVariablesString(": "); //$NON-NLS-1$
    } else if(selectedColumn>-1) {
      s = ToolsRes.getString("FunctionPanel.Instructions.EditCell");        //$NON-NLS-1$
      if(selectedColumn==0) {
        s += "  "+ToolsRes.getString("FunctionPanel.Instructions.NameCell"); //$NON-NLS-1$//$NON-NLS-2$
        s += "\n"+ToolsRes.getString("FunctionPanel.Instructions.EditDescription"); //$NON-NLS-1$//$NON-NLS-2$
      } else {
        s += " "+ToolsRes.getString("FunctionPanel.Instructions.Help");     //$NON-NLS-1$//$NON-NLS-2$
      }
    }
  }
  instructions.setText(s);
  int len = instructions.getText().length();
  doc.setCharacterAttributes(0, len, style, false);
  revalidate();
}
 
Example #19
Source File: StackTraceColorizerTest.java    From otroslogviewer with Apache License 2.0 5 votes vote down vote up
@Test
public void findExceptionNameAndMessage() throws IOException, BadLocationException {
  //given
  String stacktrace = IOUtils.toString(getSystemResourceAsStream("stacktrace/stacktrace3.txt"), UTF_8).replace("\r", "");
  StackTraceColorizer colorizer = new StackTraceColorizer(new ThemeConfig(new BaseConfiguration()));
  colorizer.initStyles();
  final Style style = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);

  //when
  final Collection<MessageFragmentStyle> colorize = colorizer.findExceptionNameAndMessage(style, stacktrace);

  //then
  final List<MessageFragmentStyle> exceptions = colorize.stream()
    .filter(msf -> msf.getStyle().getAttribute(STYLE_ATTRIBUTE_EXCEPTION_MSG) != null)
    .sorted((o1, o2) -> o1.getOffset() - o2.getOffset())
    .collect(Collectors.toList());

  assertEquals(exceptions.size(), 2);
  final MessageFragmentStyle msf0 = exceptions.get(0);
  assertEquals(stacktrace.substring(msf0.getOffset(), msf0.getOffset() + msf0.getLength()), "com.datastax.driver.core.exceptions.TransportException: [null] Cannot connect");
  assertEquals(msf0.getOffset(), 97);
  assertEquals(msf0.getLength(), 77);
  assertEquals(msf0.getStyle().getAttribute(STYLE_ATTRIBUTE_EXCEPTION_MSG), "com.datastax.driver.core.exceptions.TransportException: [null] Cannot connect");
  final MessageFragmentStyle msf1 = exceptions.get(1);
  assertEquals(stacktrace.substring(msf1.getOffset(), msf1.getOffset() + msf1.getLength()), "Caused by: java.nio.channels.UnresolvedAddressException: null");
  assertEquals(msf1.getOffset(), 2540);
  assertEquals(msf1.getLength(), 61);
  assertEquals(msf1.getStyle().getAttribute(STYLE_ATTRIBUTE_EXCEPTION_MSG), "java.nio.channels.UnresolvedAddressException: null");
}
 
Example #20
Source File: bug8016833.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
static void testSubScript() {
    System.out.println("testSubScript()");
    bug8016833 b = new bug8016833() {
        @Override
        void setNormalStyle(Style style) {
            StyleConstants.setSubscript(style, true);
        }
    };
    b.testUnderline();
    b.testStrikthrough();
}
 
Example #21
Source File: AttackCalculationPanel.java    From dsworkbench with Apache License 2.0 5 votes vote down vote up
/**
 * Creates new form AttackSourcePanel
 */
AttackCalculationPanel() {
    initComponents();
    jXCollapsiblePane1.setLayout(new BorderLayout());
    jXCollapsiblePane1.add(jInfoScrollPane, BorderLayout.CENTER);
    jInfoTextPane.setText(GENERAL_INFO);
    StyledDocument doc = (StyledDocument) jTextPane1.getDocument();
    Style defaultStyle = doc.addStyle("Default", null);
    StyleConstants.setItalic(defaultStyle, true);
    StyleConstants.setFontFamily(defaultStyle, "SansSerif");
    dateFormat = new SimpleDateFormat("HH:mm:ss");
}
 
Example #22
Source File: MarkdownDocument.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
private Style createBulletStyle(Font font) {
    Style style = addStyle("bullet", null);
    style.addAttribute(StyleConstants.FontFamily, font.getFamily());
    style.addAttribute(StyleConstants.FontSize, Integer.valueOf(font.getSize()));
    int indent = TextDrawing.getSimpleWidth(font, "• ");
    style.addAttribute(StyleConstants.FirstLineIndent, Float.valueOf(-indent));
    style.addAttribute(StyleConstants.LeftIndent, Float.valueOf(indent));
    return style;
}
 
Example #23
Source File: VCSHyperlinkSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public AuthorLinker(KenaiUser kenaiUser, Style authorStyle, StyledDocument sd, String author, String insertToChat) throws BadLocationException {
    this.kenaiUser = kenaiUser;
    this.author = author;
    this.authorStyle = authorStyle;
    this.insertToChat = insertToChat;

    int doclen = sd.getLength();
    int textlen = author.length();

    docstart = doclen;
    docend = doclen + textlen;
}
 
Example #24
Source File: bug8016833.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
static void testNormalScript() {
    System.out.println("testNormalScript()");
    bug8016833 b = new bug8016833() {
        @Override
        void setNormalStyle(Style style) {
        }
    };
    b.testUnderline();
    b.testStrikthrough();
}
 
Example #25
Source File: VCSHyperlinkSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void insertString(StyledDocument sd, Style style) throws BadLocationException {
    sd.insertString(sd.getLength(), text, style);
    for (int i = 0; i < length; i++) {
        sd.setCharacterAttributes(sd.getLength() - text.length() + start[i], end[i] - start[i], issueHyperlinkStyle, false);
    }
}
 
Example #26
Source File: BaseTypeTableCellRenderer.java    From binnavi with Apache License 2.0 5 votes vote down vote up
private static Style createDataStyle(final StyledDocument document) {
  final Style declStyle = document.addStyle("DATA_STYLE", null);
  StyleConstants.setBackground(declStyle, Color.WHITE);
  StyleConstants.setForeground(declStyle, Color.BLUE);
  StyleConstants.setFontFamily(declStyle, GuiHelper.getMonospaceFont());
  StyleConstants.setFontSize(declStyle, 11);
  return declStyle;
}
 
Example #27
Source File: ResultsTextPane.java    From mzmine2 with GNU General Public License v2.0 5 votes vote down vote up
public void appendColoredText(String text, Color color) {
  StyledDocument doc = getStyledDocument();

  Style style = addStyle("Color Style", null);
  StyleConstants.setForeground(style, color);
  try {
    doc.insertString(doc.getLength(), text, style);
  } catch (BadLocationException e) {
    e.printStackTrace();
  }
}
 
Example #28
Source File: ResultsTextPane.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
public void appendText(String text, Style style) {
  StyledDocument doc = getStyledDocument();
  try {
    doc.insertString(doc.getLength(), text + "\n", style);
  } catch (BadLocationException e) {
    e.printStackTrace();
  }
}
 
Example #29
Source File: bug8016833.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
static void testSubScript() {
    System.out.println("testSubScript()");
    bug8016833 b = new bug8016833() {
        @Override
        void setNormalStyle(Style style) {
            StyleConstants.setSubscript(style, true);
        }
    };
    b.testUnderline();
    b.testStrikthrough();
}
 
Example #30
Source File: JViewPortBackingStoreImageTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
static void createStyles() {
    styles = new StyleContext();
    doc = new DefaultStyledDocument(styles);
    contentAttributes = new HashMap<>();

    // no attributes defined
    Style s = styles.addStyle(null, null);
    contentAttributes.put("none", s);

    Style def = styles.getStyle(StyleContext.DEFAULT_STYLE);

    Style heading = styles.addStyle("heading", def);
    StyleConstants.setFontFamily(heading, "SansSerif");
    StyleConstants.setBold(heading, true);
    StyleConstants.setAlignment(heading, StyleConstants.ALIGN_CENTER);
    StyleConstants.setSpaceAbove(heading, 10);
    StyleConstants.setSpaceBelow(heading, 10);
    StyleConstants.setFontSize(heading, 18);

    // Title
    Style sty = styles.addStyle("title", heading);
    StyleConstants.setFontSize(sty, 32);

    // author
    sty = styles.addStyle("author", heading);
    StyleConstants.setItalic(sty, true);
    StyleConstants.setSpaceBelow(sty, 25);
}