Java Code Examples for javax.swing.text.Segment#length()

The following examples show how to use javax.swing.text.Segment#length() . 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: UniTools.java    From jpexs-decompiler with GNU General Public License v3.0 6 votes vote down vote up
public static int getTabbedTextOffset(Segment segment, FontMetrics metrics, int tabBase,int x,TabExpander e, int startOffset){
    List<Segment> segments=new ArrayList<Segment>();
    List<Boolean> unis=new ArrayList<Boolean>();
    
    Font origFont=metrics.getFont();
    getSegments(origFont, segment, segments, unis);
    Graphics g=new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB).getGraphics();
    Font uniFont = defaultUniFont.deriveFont(origFont.getStyle(),origFont.getSize2D());       
    int ofs=0;
    int totalto = 0;
    for(int i=0;i<segments.size();i++){
        Segment seg=segments.get(i);
        FontMetrics fm=unis.get(i)?g.getFontMetrics(uniFont):metrics;
        int to = Utilities.getTabbedTextOffset(seg, fm, tabBase+ofs,x, e, startOffset);
        totalto += to;
        ofs+=fm.stringWidth(seg.toString());
        if(to<seg.length()){
            break;
        }            
    }        
    return totalto;
}
 
Example 2
Source File: UniTools.java    From jpexs-decompiler with GNU General Public License v3.0 6 votes vote down vote up
public static int drawTabbedText(Segment segment, int x, int y, Graphics g, TabExpander e, int startOffset){
    
    List<Segment> segments=new ArrayList<Segment>();
    List<Boolean> unis=new ArrayList<Boolean>();
    getSegments(g.getFont(), segment, segments, unis);
    Font origFont=g.getFont();
    Font uniFont = defaultUniFont.deriveFont(origFont.getStyle(),origFont.getSize2D());
    int ret=x;
    int pos=0;
    for(int i=0;i<segments.size();i++){
        Segment seg=segments.get(i);
        if(unis.get(i)){
            g.setFont(uniFont);
        }else{
            g.setFont(origFont);
        }
        ret = Utilities.drawTabbedText(seg, ret, y, g, e, startOffset+pos);   
        pos += seg.length();
    }
    g.setFont(origFont);
    return ret;         
}
 
Example 3
Source File: UniTools.java    From jpexs-decompiler with GNU General Public License v3.0 5 votes vote down vote up
public static int getTabbedTextWidth(Graphics g,Segment segment,int x,TabExpander e, int startOffset){
    List<Segment> segments=new ArrayList<Segment>();
    List<Boolean> unis=new ArrayList<Boolean>();
    getSegments(g.getFont(), segment, segments, unis);
    Font origFont=g.getFont();
    Font uniFont = defaultUniFont.deriveFont(origFont.getStyle(),origFont.getSize2D());
    int ret=0;
    int pos=0;
    for(int i=0;i<segments.size();i++){
        Segment seg=segments.get(i);
        ret += Utilities.getTabbedTextWidth(seg, g.getFontMetrics(unis.get(i)?uniFont:origFont), 0, e, startOffset+pos);     
        pos += seg.length();
    }
    return ret;       
}