1 package org.antlr.works.utils; 2 3 import org.antlr.works.prefs.AWPrefs; 4 5 import javax.swing.*; 6 import javax.swing.text.*; 7 import java.awt.*; 8 38 39 public class TextUtils { 40 41 public static void createTabs(JTextPane textPane) { 42 int tabSize = AWPrefs.getEditorTabSize(); 43 int charWidth = AWPrefs.getEditorFontSize(); 44 try { 45 charWidth = Toolkit.getDefaultToolkit().getFontMetrics(textPane.getFont()).stringWidth("m"); 46 } catch(Exception e) { 47 } 49 50 TabStop[] tstops = new TabStop[100]; 51 for(int i = 0; i<100; i++) { 52 tstops[i] = new TabStop(i*tabSize*charWidth); 53 } 54 TabSet tabs = new TabSet(tstops); 55 56 Style style = textPane.getLogicalStyle(); 57 if(style != null) { 58 StyleConstants.setTabSet(style, tabs); 59 textPane.setLogicalStyle(style); 60 } 61 } 62 63 public static void setDefaultTextPaneProperties(JTextPane textPane) { 64 textPane.getDocument().putProperty(DefaultEditorKit.EndOfLineStringProperty, "\n"); 66 } 67 68 } 69 | Popular Tags |