Package javax.swing.text

Examples of javax.swing.text.StyleContext$KeyBuilder


        super(doc);
        init();
    }
   
    private void init() {
        StyleContext styleContext = StyleContext.getDefaultStyleContext();
        Style defaultStyle = styleContext.getStyle(StyleContext.DEFAULT_STYLE);
       
        Style comment = styleContext.addStyle(COMMENT, defaultStyle);
        StyleConstants.setForeground(comment, COMMENT_COLOR);
        StyleConstants.setItalic(comment, true);
       
        Style quotes = styleContext.addStyle(QUOTES, defaultStyle);
        StyleConstants.setForeground(quotes, Color.MAGENTA.darker().darker());
       
        Style charQuotes = styleContext.addStyle(SINGLE_QUOTES, defaultStyle);
        StyleConstants.setForeground(charQuotes, Color.GREEN.darker().darker());
       
        Style slashyQuotes = styleContext.addStyle(SLASHY_QUOTES, defaultStyle);
        StyleConstants.setForeground(slashyQuotes, Color.ORANGE.darker());
       
        Style digit = styleContext.addStyle(DIGIT, defaultStyle);
        StyleConstants.setForeground(digit, Color.RED.darker());
       
        Style operation = styleContext.addStyle(OPERATION, defaultStyle);
        StyleConstants.setBold(operation, true);
       
        Style ident = styleContext.addStyle(IDENT, defaultStyle);
       
        Style reservedWords = styleContext.addStyle(RESERVED_WORD, defaultStyle);
        StyleConstants.setBold(reservedWords, true);
        StyleConstants.setForeground(reservedWords, Color.BLUE.darker().darker());
       
        Style leftParens = styleContext.addStyle(IDENT, defaultStyle);
       
        getRootNode().putStyle(SLASH_STAR_COMMENT, comment);
        getRootNode().putStyle(SLASH_SLASH_COMMENT, comment);
        getRootNode().putStyle(QUOTES, quotes);
        getRootNode().putStyle(SINGLE_QUOTES, charQuotes);
View Full Code Here


   * @param size The size of the font.
   * @return The font.
   */
  private static Font getFont(String family, int style, int size) {
    // Use StyleContext to get a composite font for Asian glyphs.
    StyleContext sc = StyleContext.getDefaultStyleContext();
    return sc.getFont(family, style, size);
  }
View Full Code Here

      Style style = styles[i];
      if (style!=null && style.font!=null) {
        if (style.font.getFamily().equals(old.getFamily()) &&
            style.font.getSize()==old.getSize()) {
          int s = style.font.getStyle(); // Keep bold or italic
          StyleContext sc = StyleContext.getDefaultStyleContext();
          style.font= sc.getFont(font.getFamily(), s, font.getSize());
        }
      }
    }
  }
View Full Code Here

            tokenCount + ", found " + tokens.length);
        }

        // Use StyleContext to create fonts to get composite fonts for
        // Asian glyphs.
        StyleContext sc = StyleContext.getDefaultStyleContext();

        // Loop through each token style.  Format:
        // "index,(fg|-),(bg|-),(t|f),((font,style,size)|(-,,))"
        for (int i=0; i<tokenTypeCount; i++) {

          int pos = i*7 + 1;
          int integer = Integer.parseInt(tokens[pos]); // == i
          if (integer!=i)
            throw new Exception("Expected " + i + ", found " +
                      integer);

          Color fg = null; String temp = tokens[pos+1];
          if (!"-".equals(temp)) { // "-" => keep fg as null
            fg = stringToColor(temp);
          }
          Color bg = null; temp = tokens[pos+2];
          if (!"-".equals(temp)) { // "-" => keep bg as null
            bg = stringToColor(temp);
          }

          // Check for "true" or "false" since we don't want to
          // accidentally suck in an int representing the next
          // packed color, and any string != "true" means false.
          temp = tokens[pos+3];
          if (!"t".equals(temp) && !"f".equals(temp))
            throw new Exception("Expected 't' or 'f', found " + temp);
          boolean underline = "t".equals(temp);

          Font font = null;
          String family = tokens[pos+4];
          if (!"-".equals(family)) {
            font = sc.getFont(family,
              Integer.parseInt(tokens[pos+5])// style
              Integer.parseInt(tokens[pos+6]))// size
          }
          scheme.styles[i] = new Style(fg, bg, font, underline);

View Full Code Here

   */
  public static final Font getDefaultFont() {

    // Use StyleContext to get a composite font for better Asian language
    // support; see Sun bug S282887.
    StyleContext sc = StyleContext.getDefaultStyleContext();
    Font font = null;

    if (isOSX()) {
      // Snow Leopard (1.6) uses Menlo as default monospaced font,
      // pre-Snow Leopard used Monaco.
      font = sc.getFont("Menlo", Font.PLAIN, 12);
      if (!"Menlo".equals(font.getFamily())) {
        font = sc.getFont("Monaco", Font.PLAIN, 12);
        if (!"Monaco".equals(font.getFamily())) { // Shouldn't happen
          font = sc.getFont("Monospaced", Font.PLAIN, 13);
        }
      }
    }
    else {
      // Consolas added in Vista, used by VS2010+.
      font = sc.getFont("Consolas", Font.PLAIN, 13);
      if (!"Consolas".equals(font.getFamily())) {
        font = sc.getFont("Monospaced", Font.PLAIN, 13);
      }
    }

    //System.out.println(font.getFamily() + ", " + font.getName());
    return font;
View Full Code Here

    Font commentFont = baseFont;
    Font keywordFont = baseFont;
    if (fontStyles) {
      // WORKAROUND for Sun JRE bug 6282887 (Asian font bug in 1.4/1.5)
      // That bug seems to be hidden now, see 6289072 instead.
      StyleContext sc = StyleContext.getDefaultStyleContext();
      Font boldFont = sc.getFont(baseFont.getFamily(), Font.BOLD,
          baseFont.getSize());
      Font italicFont = sc.getFont(baseFont.getFamily(), Font.ITALIC,
          baseFont.getSize());
      commentFont = italicFont;//baseFont.deriveFont(Font.ITALIC);
      keywordFont = boldFont;//baseFont.deriveFont(Font.BOLD);
    }
View Full Code Here

        tableChordsList.setModel(chordsDB);

        panelChordShapes.setLayout(new GridLayout());
       
        StyleContext sc = new StyleContext();
        chordShapeStyle = sc.addStyle("chordShapeStyle",null);       
    }
View Full Code Here

        mFile.setMnemonic('f');

        ImageIcon iconNew = new ImageIcon("file_new.gif");
        Action actionNew = new AbstractAction("Nuevo", iconNew) {
            public void actionPerformed(ActionEvent e) {
                DefaultStyledDocument document = new DefaultStyledDocument(new StyleContext());
                textPane.setDocument(document);
            }
        };
        JMenuItem item = null;
        // JMenuItem item = mFile.add(actionNew);
        // item.setMnemonic('n');

        ImageIcon iconOpen = new ImageIcon("file_open.gif");
        Action actionOpen = new AbstractAction("Abrir...", iconOpen) {
            public void actionPerformed(ActionEvent e) {
                SVNVisorFicheroEdicion.this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                Thread runner = new Thread() {
                    public void run() {
                        if (fileChooser.showOpenDialog(SVNVisorFicheroEdicion.this) != JFileChooser.APPROVE_OPTION)
                            return;
                        SVNVisorFicheroEdicion.this.repaint();
                        File fChoosen = fileChooser.getSelectedFile();

                        // Recall that text component read/write operations are
                        // thread safe. Its ok to do this in a separate thread.
                        try {
                            InputStream in = new FileInputStream(fChoosen);
                            DefaultStyledDocument document = new DefaultStyledDocument(new StyleContext());
                            textPane.getEditorKit().read(in, document, 0);
                            textPane.setDocument(document);
                            in.close();
                        } catch (Exception ex) {
                            ex.printStackTrace();
View Full Code Here

      Style style = styles[i];
      if (style!=null && style.font!=null) {
        if (style.font.getFamily().equals(old.getFamily()) &&
            style.font.getSize()==old.getSize()) {
          int s = style.font.getStyle(); // Keep bold or italic
          StyleContext sc = StyleContext.getDefaultStyleContext();
          style.font= sc.getFont(font.getFamily(), s, font.getSize());
        }
      }
    }
  }
View Full Code Here

    // Special fonts.
    if (baseFont==null) {
      baseFont = RSyntaxTextArea.getDefaultFont();
    }
    // WORKAROUND for Sun JRE bug 6282887 (Asian font bug in 1.4/1.5)
    StyleContext sc = StyleContext.getDefaultStyleContext();
    Font boldFont = sc.getFont(baseFont.getFamily(), Font.BOLD,
        baseFont.getSize());
    Font italicFont = sc.getFont(baseFont.getFamily(), Font.ITALIC,
        baseFont.getSize());
    Font commentFont = italicFont;//baseFont.deriveFont(Font.ITALIC);
    Font keywordFont = boldFont;//baseFont.deriveFont(Font.BOLD);

    styles[Token.COMMENT_EOL]        = new Style(comment, null, commentFont);
View Full Code Here

TOP

Related Classes of javax.swing.text.StyleContext$KeyBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.