Here you can find the source of getVirtualWidth(Segment seg, int tabSize)
Parameter | Description |
---|---|
seg | The segment |
tabSize | The tab size |
public static int getVirtualWidth(Segment seg, int tabSize)
//package com.java2s; /*/*from w w w . java 2s . co m*/ * StandardUtilities.java - Various miscallaneous utility functions * :tabSize=4:indentSize=4:noTabs=false: * :folding=explicit:collapseFolds=1: * * Copyright (C) 1999, 2006 Matthieu Casanova, Slava Pestov * Portions copyright (C) 2000 Richard S. Hall * Portions copyright (C) 2001 Dirk Moebius * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ import javax.swing.text.Segment; public class Main { /** * Returns the virtual column number (taking tabs into account) of the * specified offset in the segment. * * @param seg The segment * @param tabSize The tab size */ public static int getVirtualWidth(Segment seg, int tabSize) { int virtualPosition = 0; for (int i = 0; i < seg.count; i++) { char ch = seg.array[seg.offset + i]; if (ch == '\t') { virtualPosition += tabSize - virtualPosition % tabSize; } else { ++virtualPosition; } } return virtualPosition; } }