/*
 * Java-Gnome Bindings Library
 *
 * Copyright 1998-2004 the Java-Gnome Team, all rights reserved.
 *
 * The Java-Gnome bindings library is free software distributed under
 * the terms of the GNU Library General Public License version 2.
 */

package org.gnu.pango;
import org.gnu.glib.Boxed;
import org.gnu.glib.Handle;

/**
 * A PangoTabArray struct contains an array of tab stops. Each tab stop has an
 * alignment and a position.
 */
public class TabArray extends Boxed 
{

	/**
	 * Creates an array of <code>initialSize</code> tab stops. Tab stops are
	 * specified in pixel units if <code>positionsInPixels<code> is
	 * <code>true</code>, otherwise in Pango units. All stops are initially at
	 * position 0.
	 */
	public TabArray(int initialSize, boolean positionsInPixels){
		super(pango_tab_array_new(initialSize, positionsInPixels));
	}

    /**
     * Create a TabArray that is a copy of the provided TabArray.
     * @param tabArray
     */
	public TabArray(TabArray tabArray) {
        super(pango_tab_array_copy(tabArray.getHandle()));
    }
    
	/**
	 * Constructs new Tab array from handle to native resources. Used internally
	 * by Java-Gnome.
	 */
	public TabArray(Handle handle){
		super(handle);
	}


	/**
	 * Get the number of tab stops in the array
	 */
	public int getSize(){
		return pango_tab_array_get_size(handle);
	}

	/**
	 * Resizes a tab array. You must subsequently initialize any tabs that were
	 * added as a result of growing the array.
	 */
	public void resize(int newSize){
		pango_tab_array_resize(handle, newSize);
	}

	/**
	 * Sets the alignment and location of a tab stop. Alignment must always be
	 * {@link TabAlign#LEFT} in the current implementation.
	 * @param tabIndex The index of a tab stop
	 * @param alignment Tab alignment
	 * @param location Tab location in pango units
	 */
	public void setTab(int tabIndex, TabAlign alignment, int location){
		pango_tab_array_set_tab(handle, tabIndex, alignment.getValue(), location);
	}

	/**
	 * Returns the position of the tab stops
	 */
	public int getPosition(int tabIndex){
		return pango_tab_array_get_tabLocation(handle, tabIndex);
	}

	/**
	 * Returns the alignment ofthe tab stop
	 */
	public TabAlign getAligment(int tabIndex){
		return TabAlign.intern( pango_tab_array_get_tabAlignment(handle, tabIndex));
	}

	/**
     * Returns true if the tab positions are in pixels and false if
     * they are in Pango units. 
     */
    public boolean positionInPixels() {
        return pango_tab_array_get_positions_in_pixels(getHandle());
    }
    

	
    protected void finalize() throws Throwable {
        super.finalize();
        pango_tab_array_free(getHandle());
    }

    native static final protected Handle pango_tab_array_new (int initialSize, boolean 
        positionInPixels);
    native static final protected int pango_tab_array_get_type ();
    native static final protected Handle pango_tab_array_copy (Handle src);
    native static final protected void pango_tab_array_free (Handle tabArray);
    native static final protected int pango_tab_array_get_size (Handle tabArray);
    native static final protected void pango_tab_array_resize (Handle tabArray, int newSize);
    native static final protected void pango_tab_array_set_tab (Handle tabArray, int tabIndex, int 
        alignment, int location);
    native static final protected void pango_tab_array_get_tab (Handle tabArray, int tabIndex, int 
        alignment, int [] location);
    native static final protected boolean pango_tab_array_get_positions_in_pixels (Handle tabArray);
    native static final protected int pango_tab_array_get_tabLocation (Handle tabArray, int tabIndex);
    native static final protected int pango_tab_array_get_tabAlignment (Handle tabArray, int tabIndex);

}

