• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java TabSet类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中javax.swing.text.TabSet的典型用法代码示例。如果您正苦于以下问题:Java TabSet类的具体用法?Java TabSet怎么用?Java TabSet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



TabSet类属于javax.swing.text包,在下文中一共展示了TabSet类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: do_setFont

import javax.swing.text.TabSet; //导入依赖的package包/类
/** Changes the font and tabsize for the document. */
public final void do_setFont(String fontName, int fontSize, int tabSize) {
   if (tabSize < 1) tabSize = 1; else if (tabSize > 100) tabSize = 100;
   if (fontName.equals(this.font) && fontSize == this.fontSize && tabSize == this.tabSize) return;
   this.font = fontName;
   this.fontSize = fontSize;
   this.tabSize = tabSize;
   for(MutableAttributeSet s: all) { StyleConstants.setFontFamily(s, fontName);  StyleConstants.setFontSize(s, fontSize); }
   do_reapplyAll();
   BufferedImage im = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB); // this is used to derive the tab width
   int gap = tabSize * im.createGraphics().getFontMetrics(new Font(fontName, Font.PLAIN, fontSize)).charWidth('X');
   TabStop[] pos = new TabStop[100];
   for(int i=0; i<100; i++) { pos[i] = new TabStop(i*gap + gap); }
   StyleConstants.setTabSet(tabset, new TabSet(pos));
   setParagraphAttributes(0, getLength(), tabset, false);
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:17,代码来源:OurSyntaxDocument.java


示例2: setTabs

import javax.swing.text.TabSet; //导入依赖的package包/类
public void setTabs(int charactersPerTab) {
    FontMetrics fm = getFontMetrics(getFont());
    int charWidth = fm.charWidth('w');
    int tabWidth = charWidth * charactersPerTab;

    TabStop[] tabs = new TabStop[10];

    for (int j = 0; j < tabs.length; j++) {
        int tab = j + 1;
        tabs[j] = new TabStop(tab * tabWidth);
    }

    TabSet tabSet = new TabSet(tabs);
    SimpleAttributeSet attributes = new SimpleAttributeSet();
    StyleConstants.setTabSet(attributes, tabSet);
}
 
开发者ID:qspin,项目名称:qtaste,代码行数:17,代码来源:NonWrappingTextPane.java


示例3: setupTabStops

import javax.swing.text.TabSet; //导入依赖的package包/类
private void setupTabStops() {
	// Ugly piece of code; needed because default tab indentation is too
	// big.
	StyleContext sc = StyleContext.getDefaultStyleContext();

	Toolkit t = Toolkit.getDefaultToolkit();
	FontMetrics fm = t.getFontMetrics(new Font("Courier", Font.PLAIN, 14));
	int cw = fm.stringWidth("    ");

	final TabStop[] tabStops = new TabStop[60];
	for (int i = 0; i < tabStops.length; i++)
		tabStops[i] = new TabStop((i + 1) * cw);

	TabSet tabs = new TabSet(tabStops);
	AttributeSet paraSet = sc.addAttribute(SimpleAttributeSet.EMPTY,
			StyleConstants.TabSet, tabs);

	pane.setParagraphAttributes(paraSet, false);
}
 
开发者ID:goblindegook,项目名称:Koopa,代码行数:20,代码来源:GrammarView.java


示例4: do_setFont

import javax.swing.text.TabSet; //导入依赖的package包/类
/** Changes the font and tabsize for the document. */
public final void do_setFont(String fontName, int fontSize, int tabSize) {
	if (tabSize < 1)
		tabSize = 1;
	else if (tabSize > 100)
		tabSize = 100;
	if (fontName.equals(this.font) && fontSize == this.fontSize && tabSize == this.tabSize)
		return;
	this.font = fontName;
	this.fontSize = fontSize;
	this.tabSize = tabSize;
	for (MutableAttributeSet s : all) {
		StyleConstants.setFontFamily(s, fontName);
		StyleConstants.setFontSize(s, fontSize);
	}
	do_reapplyAll();
	BufferedImage im = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB); // this
																				// is
																				// used
																				// to
																				// derive
																				// the
																				// tab
																				// width
	int gap = tabSize * im.createGraphics().getFontMetrics(new Font(fontName, Font.PLAIN, fontSize)).charWidth('X');
	TabStop[] pos = new TabStop[100];
	for (int i = 0; i < 100; i++) {
		pos[i] = new TabStop(i * gap + gap);
	}
	StyleConstants.setTabSet(tabset, new TabSet(pos));
	setParagraphAttributes(0, getLength(), tabset, false);
}
 
开发者ID:AlloyTools,项目名称:org.alloytools.alloy,代码行数:33,代码来源:OurSyntaxDocument.java


示例5: setTabSize

import javax.swing.text.TabSet; //导入依赖的package包/类
private void setTabSize(int size) {
		 	TabStop[] tabs = new TabStop[1];
	        tabs[0] = new TabStop(size, TabStop.ALIGN_LEFT, TabStop.LEAD_NONE);
//	        tabs[1] = new TabStop(100, TabStop.ALIGN_LEFT, TabStop.LEAD_NONE);
//	        tabs[2] = new TabStop(200, TabStop.ALIGN_CENTER, TabStop.LEAD_NONE);
//	        tabs[3] = new TabStop(300, TabStop.ALIGN_DECIMAL, TabStop.LEAD_NONE);
	        TabSet tabset = new TabSet(tabs);

	        StyleContext sc = StyleContext.getDefaultStyleContext();
	        AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY,
	        StyleConstants.TabSet, tabset);
	        textPane.setParagraphAttributes(aset, false);
	}
 
开发者ID:Emd4600,项目名称:SporeModder,代码行数:14,代码来源:TextFileView.java


示例6: nextTabStop

import javax.swing.text.TabSet; //导入依赖的package包/类
public float nextTabStop(float x, int tabOffset)
{
	TabSet tabs = getTabSet();
	if(tabs == null)
	{
		FontMetrics fm = Toolkit.getDefaultToolkit().getFontMetrics(getContainer().getFont());
		int t = Math.round(kit.getTabSize() * fm.stringWidth(" "));
		return (getTabBase() + (((int)x / t + 1) * t));
	}

	return super.nextTabStop(x, tabOffset);
}
 
开发者ID:andy-goryachev,项目名称:PasswordSafe,代码行数:13,代码来源:XParagraphView.java


示例7: setUp

import javax.swing.text.TabSet; //导入依赖的package包/类
@Before
public void setUp(){
	task = new BattleTask();
	
	// GUI setup
	JFrame demo = new JFrame();
	demo.setSize(400, 300);
	demo.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	
	textpane = new JTextPane();
	TabStop[] tabs = new TabStop[1];
	tabs[0] = new TabStop(40, TabStop.ALIGN_LEFT, TabStop.LEAD_NONE);
	
	TabSet tabset = new TabSet(tabs);

    StyleContext sc = StyleContext.getDefaultStyleContext();
    AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY,
        StyleConstants.TabSet, tabset);
    textpane.setParagraphAttributes(aset, false);
    textpane.setEditable(false);
	
	JTextField input = new JTextField();
	InputListener listener = new InputListener();
	input.addActionListener(listener);
	
	demo.getContentPane().add(BorderLayout.CENTER, textpane);
	demo.getContentPane().add(BorderLayout.SOUTH, input);
       
       demo.setVisible(true);
       input.requestFocusInWindow();
}
 
开发者ID:shockwang,项目名称:BioHoward,代码行数:32,代码来源:PreBattleTaskTest.java


示例8: nextTabStop

import javax.swing.text.TabSet; //导入依赖的package包/类
@Override
public float nextTabStop(float x, int tabOffset) {
   	float tabBase = this.getTabBase();

	// If the text isn't left justified, offset by 10 pixels!
   	if(createRow().getAlignment(View.X_AXIS) != 0)
   		return x + 10.0f;
   	/*
   	 * This hack mimics the following, which is a private variable! ARGH!
   	 * 
	 * if (justification != StyleConstants.ALIGN_LEFT)
	 * 	return x + 10.0f;
	 */
   	
	x -= tabBase;
	TabSet tabs = getTabSet();
	if (tabs == null) {
		// a tab every 72 pixels.
		return (tabBase + (((int) x / 72 + 1) * 72));
	}
	TabStop tab = tabs.getTabAfter(x + .01f);
	if (tab == null) {
		// no tab, do a default of 5 pixels.
		// Should this cause a wrapping of the line?
		return tabBase + x + 5.0f;
	}
	int alignment = tab.getAlignment();
	int offset;
	switch (alignment) {
	default:
	case TabStop.ALIGN_LEFT:
		// Simple case, left tab.
		return tabBase + tab.getPosition();
	case TabStop.ALIGN_BAR:
		// PENDING: what does this mean?
		return tabBase + tab.getPosition();
	case TabStop.ALIGN_RIGHT:
	case TabStop.ALIGN_CENTER:
		offset = findOffsetToCharactersInString(mutantTabChars, tabOffset + 1);
		break;
	case TabStop.ALIGN_DECIMAL:
		offset = findOffsetToCharactersInString(mutantTabDecimalChars,
				tabOffset + 1);
		break;
	}
	if (offset == -1) {
		offset = getEndOffset();
	}
	float charsSize = getPartialSize(tabOffset + 1, offset);
	switch (alignment) {
	case TabStop.ALIGN_RIGHT:
	case TabStop.ALIGN_DECIMAL:
		// right and decimal are treated the same way, the new
		// position will be the location of the tab less the
		// partialSize.
		return tabBase + Math.max(x, tab.getPosition() - charsSize);
	case TabStop.ALIGN_CENTER:
		// Similar to right, but half the partialSize.
		return tabBase
				+ Math.max(x, tab.getPosition() - charsSize / 2.0f);
	}
	// will never get here!
	return x;
}
 
开发者ID:ltrr-arizona-edu,项目名称:tellervo,代码行数:65,代码来源:SamplePrintEditor.java


示例9: makeTabs

import javax.swing.text.TabSet; //导入依赖的package包/类
private void makeTabs(int width) {
	Style style;
	StringBuffer sb = new StringBuffer();
	TabSet tabset;

	// build the summed data tab specification
	sb.setLength(0);
	sb.append("< 4%");
	for(int i = 0; i < 10; i++) {
		sb.append(" 5.7%"); // data
	}
	sb.append(" 3.3%");
	for (int i = 0; i < 10; i++)
		sb.append(" 3.4%"); // count
	/*
	sb.append("> 4% <");
	for (int i = 0; i < 10; i++)
		sb.append(" 5.7%"); // data
	sb.append(" 5%");
	for (int i = 0; i < 10; i++)
		sb.append(" 3.4%"); // count
		*/

	style = textpane.getStyle("summed data");
	tabset = EditorTabSetFactory.buildTabset(sb.toString(), width);
	StyleConstants.setTabSet(style, tabset);
			
	// raw data and weiserjahre are very similar, but weiserjahre uses our
	// hacked "decimal" coding
	sb.setLength(0);
	sb.append("> 5% <");
	for (int i = 0; i < 10; i++)
		sb.append(" 9%");

	style = textpane.getStyle("raw data");
	tabset = EditorTabSetFactory.buildTabset(sb.toString(), width);
	StyleConstants.setTabSet(style, tabset);

	sb.setLength(0);
	sb.append("> 5% *");
	for (int i = 0; i < 10; i++)
		sb.append(" 9%");
	
	style = textpane.getStyle("weiserjahre data");
	tabset = EditorTabSetFactory.buildTabset(sb.toString(), width);
	StyleConstants.setTabSet(style, tabset);

	style = textpane.getStyle("elements");
	//> 12% <> 58% ^ 7% ^ 8% ^ 8% ^ 7% <		
	tabset = EditorTabSetFactory.buildTabset(
			"< 12% < 1% 50% ^ 7% 8% 8% 7%", 
			width);
	StyleConstants.setTabSet(style, tabset);		
}
 
开发者ID:ltrr-arizona-edu,项目名称:tellervo,代码行数:55,代码来源:SamplePrintEditor.java


示例10: insertString

import javax.swing.text.TabSet; //导入依赖的package包/类
@Override
        public void insertString(DocumentFilter.FilterBypass fb, int offset, String str, AttributeSet attr) throws BadLocationException {
            if(!isEditable()) {return;}
            if(!flagInsert || offset!=lastPosition) {undo.valider(); flagInsert=true;}
            flagRemove=false;
            
            if(str.equals("\t")) {
                try {
                    insererHTML("<span class='tab'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>", offset, Tag.SPAN);
                    return;
                } catch (IOException ex) {
                    Logger.getLogger(JMathTextPane.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            
            MutableAttributeSet att;

            //HACK en cas d'écriture proche d'un Component. On va chercher un style qui convient
            int pos = offset;
            do {
                att = new SimpleAttributeSet(getHTMLdoc().getCharacterElement(pos).getAttributes());
                pos--;
                if(pos<0 && att.getAttribute(StyleConstants.ComponentAttribute)!=null) {att = new SimpleAttributeSet(defaultAttributeSet);}
            } while(pos>=0 && att.getAttribute(StyleConstants.ComponentAttribute)!=null);

            if(str.equals("\n") && editeurKit!=null && keepStyleUpdated) {//on réinitialise le style après un retour à le ligne.
                getEditeurKit().reset();
//                getInputAttributes().addAttributes(getEditeurKit().getStyleAttributes());
            }

            if(editeurKit!=null) {
                att.addAttributes(getEditeurKit().getStyleAttributes());
                att.removeAttribute(HTML.Attribute.COLOR);//"color", HTML.Attribute.COLOR et "foreground" sont 3 attributs redondants, mais différents.
                att.addAttribute("color", ColorManager.getRGBHexa(getEditeurKit().getForeground()));//HACK car addAttribute ne remplace pas l'attribut color du html par l'attribut foreground du java
            }
                
            
            //Capture des caractères spéciaux
            if(str.equals("/")) {
                replaceBy(fb, offset, str, att, "&divide;");
                return;
            } else if(str.equals("*")) {
                replaceBy(fb, offset, str, att, "&times;");
                return;
            }//XXX ajouter ici le remplacements des caractères littéraux
 
//            attrs = att.copyAttributes();

            //remplacerReturn(fb, offset, length, str, attrs);
//            remplacerEspaces(fb, offset, length, str, attrs);
            
            fb.insertString(offset, str, att);
            
            if(str.equals("\n") && keepStyleUpdated) {//on réinitialise le style après un retour à le ligne.
                //Fixe la taille des tabulations
                StyleContext sc = StyleContext.getDefaultStyleContext();
                TabSet tabs = new TabSet(new TabStop[] { new TabStop(TAB_SIZE) });
                AttributeSet paraSet = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.TabSet, tabs);
                setParagraphAttributes(paraSet, false);
                
                new HTMLEditorKit.AlignmentAction("toLeft", StyleConstants.ALIGN_LEFT).actionPerformed(null);
                new HTMLEditorKit.ForegroundAction("toBlack", getDefaultForeground()).actionPerformed(null);
                undo.valider();
            }
            
            lastPosition = getCaretPosition();
        }
 
开发者ID:Sharcoux,项目名称:MathEOS,代码行数:68,代码来源:JMathTextPane.java


示例11: JavaSourceDocument

import javax.swing.text.TabSet; //导入依赖的package包/类
public JavaSourceDocument(String title, Reader in, SourceFile theSource) throws IOException {
    doc = new DefaultStyledDocument();
    this.title = title;
    this.sourceFile = theSource;
    Debug.println("Created JavaSourceDocument for " + title);
    try {
        dek.read(in, doc, 0);
    } catch (BadLocationException e) {
        throw new RuntimeException(e);
    }
    in.close();
    doc.putProperty(Document.TitleProperty, title);
    root = doc.getDefaultRootElement();
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    FontMetrics fontMetrics = toolkit.getFontMetrics(sourceFont);
    TabStop[] tabs = new TabStop[50];
    float width = fontMetrics.stringWidth(" ");

    int tabSize = GUISaveState.getInstance().getTabSize();
    for (int i = 0; i < tabs.length; i++)
        tabs[i] = new TabStop(width * (tabSize + tabSize * i));
    TAB_SET = new TabSet(tabs);
    StyleConstants.setTabSet(commentAttributes, TAB_SET);
    StyleConstants.setTabSet(javadocAttributes, TAB_SET);

    StyleConstants.setTabSet(quotesAttributes, TAB_SET);

    StyleConstants.setTabSet(keywordsAttributes, TAB_SET);

    StyleConstants.setTabSet(commentAttributes, TAB_SET);

    StyleConstants.setTabSet(whiteAttributes, TAB_SET);
    StyleConstants.setFontFamily(whiteAttributes, sourceFont.getFamily());
    StyleConstants.setFontSize(whiteAttributes, sourceFont.getSize());
    StyleConstants.setLeftIndent(whiteAttributes, NumberedParagraphView.NUMBERS_WIDTH);

    doc.setParagraphAttributes(0, doc.getLength(), whiteAttributes, true);
    JavaScanner parser = new JavaScanner(new DocumentCharacterIterator(doc));
    while (parser.next() != JavaScanner.EOF) {
        int kind = parser.getKind();
        switch (kind) {
        case JavaScanner.COMMENT:
            doc.setCharacterAttributes(parser.getStartPosition(), parser.getLength(), commentAttributes, true);

            break;
        case JavaScanner.KEYWORD:
            doc.setCharacterAttributes(parser.getStartPosition(), parser.getLength(), keywordsAttributes, true);

            break;
        case JavaScanner.JAVADOC:
            doc.setCharacterAttributes(parser.getStartPosition(), parser.getLength(), javadocAttributes, true);

            break;
        case JavaScanner.QUOTE:
            doc.setCharacterAttributes(parser.getStartPosition(), parser.getLength(), quotesAttributes, true);

            break;
        }

    }

}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:63,代码来源:JavaSourceDocument.java


示例12: initialize

import javax.swing.text.TabSet; //导入依赖的package包/类
private void initialize() {
	final int espacesByTab=3;
	final int maxTabsNumber=28;
	//Calculate size and height
	BufferedImage dummy= new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
	Graphics g= dummy.getGraphics();
	regularFont=new Font("Monospaced", Font.PLAIN,size);
	charSize = g.getFontMetrics(regularFont).charWidth('0');
	charHeight = g.getFontMetrics(regularFont).getHeight();
	int tabSize = charSize * espacesByTab;
	TabStop[] tabs = new TabStop[maxTabsNumber];
	for (int j = 0; j < tabs.length; j++){
		tabs[j] = new TabStop( (j+1) * tabSize , TabStop.ALIGN_LEFT, TabStop.LEAD_NONE);
	}
	TabSet tabSet = new TabSet(tabs);
	regular = new SimpleAttributeSet();
	StyleConstants.setFontFamily(regular, "Monospaced");
	StyleConstants.setFontSize(regular, size);
	StyleConstants.ColorConstants.setForeground(regular, Color.black);
	StyleConstants.ColorConstants.setBackground(regular, backgroud);
	StyleConstants.setTabSet(regular, tabSet);
	regularBackground = new SimpleAttributeSet();
	StyleConstants.ColorConstants.setBackground(regularBackground, backgroud);
	comment = new SimpleAttributeSet();
	comment.addAttributes(regular);
	StyleConstants.ColorConstants.setForeground(comment, new Color(0x78B078)); //green
	string = new SimpleAttributeSet();
	string.addAttributes(regular);
	StyleConstants.ColorConstants.setForeground(string, Color.blue);
	reserved = new SimpleAttributeSet();
	reserved.addAttributes(regular);
	StyleConstants.ColorConstants.setForeground(reserved, new Color(0x000080)); //Dark blue
	StyleConstants.setBold(reserved, true);
	preprocesor = new SimpleAttributeSet();
	preprocesor.addAttributes(regular);
	StyleConstants.ColorConstants.setForeground(preprocesor, Color.red); //red
	StyleConstants.setBold(preprocesor, true);
	variable = new SimpleAttributeSet();
	variable.addAttributes(regular);
	StyleConstants.ColorConstants.setItalic(variable, true);
	function = new SimpleAttributeSet();
	function.addAttributes(regular);
	StyleConstants.ColorConstants.setItalic(function, true);
	StyleConstants.ColorConstants.setForeground(function, Color.BLUE.darker()); // blue
	lineNumber = new SimpleAttributeSet();
	lineNumber.addAttributes(regular);
	StyleConstants.ColorConstants.setBackground(lineNumber, new Color(220, 220, 255)); //light blue 
	highlightedBackground= new SimpleAttributeSet();
	StyleConstants.ColorConstants.setBackground(highlightedBackground, new Color(0xff,0xff,0x99)); //Yellow
}
 
开发者ID:jcrodriguez-dis,项目名称:ACodeEditor,代码行数:51,代码来源:Highlights.java



注:本文中的javax.swing.text.TabSet类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java CraftStatistic类代码示例发布时间:2022-05-21
下一篇:
Java DefaultTableXYDataset类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap