Java JTabbedPane getVirtualWidth(Segment seg, int tabSize)

Here you can find the source of getVirtualWidth(Segment seg, int tabSize)

Description

Returns the virtual column number (taking tabs into account) of the specified offset in the segment.

License

Open Source License

Parameter

Parameter Description
seg The segment
tabSize The tab size

Declaration

public static int getVirtualWidth(Segment seg, int tabSize) 

Method Source Code

//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;
    }
}

Related

  1. getTabComponentIndex(JTabbedPane tbp, Component component)
  2. getTabIndex(final JTabbedPane tabs, final String title)
  3. getTabIndexAt(JTabbedPane tabbedPane, int x, int y)
  4. getTabPaneLeadingPlacement()
  5. getTabsHeight()
  6. installPrefsHandler(final Preferences prefs, final String name, final JTabbedPane tabbedPane)
  7. installPrefsHandler(Preferences prefs, String string, JTabbedPane tabbedPane)
  8. isInTabbedContainer(Component c)
  9. moveTab(JTabbedPane tabPane, int srcIndex, int dstIndex)