GtkTextAreaPeer.java [plain text]
package gnu.java.awt.peer.gtk;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.TextArea;
import java.awt.peer.TextAreaPeer;
public class GtkTextAreaPeer extends GtkTextComponentPeer
implements TextAreaPeer
{
private static transient int DEFAULT_ROWS = 10;
private static transient int DEFAULT_COLS = 80;
native void create (int width, int height, int scrollbarVisibility);
native void gtkWidgetModifyFont (String name, int style, int size);
native void gtkWidgetRequestFocus ();
void create ()
{
Font f = awtComponent.getFont ();
if (f == null)
{
f = new Font ("Dialog", Font.PLAIN, 12);
awtComponent.setFont (f);
}
FontMetrics fm = getFontMetrics (f);
TextArea ta = ((TextArea) awtComponent);
int sizeRows = ta.getRows ();
int sizeCols = ta.getColumns ();
sizeRows = sizeRows == 0 ? DEFAULT_ROWS : sizeRows;
sizeCols = sizeCols == 0 ? DEFAULT_COLS : sizeCols;
int width = sizeCols * fm.getMaxAdvance ();
int height = sizeRows * (fm.getMaxDescent () + fm.getMaxAscent ());
create (width, height, ta.getScrollbarVisibility ());
setEditable (ta.isEditable ());
}
public GtkTextAreaPeer (TextArea ta)
{
super (ta);
}
public native void insert (String str, int pos);
public native void replaceRange (String str, int start, int end);
public Dimension getMinimumSize (int rows, int cols)
{
return minimumSize (rows == 0 ? DEFAULT_ROWS : rows,
cols == 0 ? DEFAULT_COLS : cols);
}
public Dimension getPreferredSize (int rows, int cols)
{
return preferredSize (rows == 0 ? DEFAULT_ROWS : rows,
cols == 0 ? DEFAULT_COLS : cols);
}
native int getHScrollbarHeight ();
native int getVScrollbarWidth ();
public Dimension minimumSize (int rows, int cols)
{
TextArea ta = ((TextArea) awtComponent);
int height = 0;
int width = 0;
if (ta.getScrollbarVisibility () == TextArea.SCROLLBARS_BOTH
|| ta.getScrollbarVisibility () == TextArea.SCROLLBARS_HORIZONTAL_ONLY)
height = getHScrollbarHeight ();
if (ta.getScrollbarVisibility () == TextArea.SCROLLBARS_BOTH
|| ta.getScrollbarVisibility () == TextArea.SCROLLBARS_VERTICAL_ONLY)
width = getVScrollbarWidth ();
Font f = awtComponent.getFont ();
if (f == null)
return new Dimension (width, height);
FontMetrics fm = getFontMetrics (f);
int sizeRows = rows == 0 ? DEFAULT_ROWS : rows;
int sizeCols = cols == 0 ? DEFAULT_COLS : cols;
width += sizeCols * fm.getMaxAdvance ();
height += sizeRows * (fm.getMaxDescent () + fm.getMaxAscent ());
return new Dimension (width, height);
}
public Dimension preferredSize (int rows, int cols)
{
TextArea ta = ((TextArea) awtComponent);
int height = 0;
int width = 0;
if (ta.getScrollbarVisibility () == TextArea.SCROLLBARS_BOTH
|| ta.getScrollbarVisibility () == TextArea.SCROLLBARS_HORIZONTAL_ONLY)
height = getHScrollbarHeight ();
if (ta.getScrollbarVisibility () == TextArea.SCROLLBARS_BOTH
|| ta.getScrollbarVisibility () == TextArea.SCROLLBARS_VERTICAL_ONLY)
width = getVScrollbarWidth ();
Font f = awtComponent.getFont ();
if (f == null)
return new Dimension (width, height);
FontMetrics fm = getFontMetrics (f);
int sizeRows = rows == 0 ? DEFAULT_ROWS : rows;
int sizeCols = cols == 0 ? DEFAULT_COLS : cols;
width += sizeCols * fm.getMaxAdvance ();
height += sizeRows * (fm.getMaxDescent () + fm.getMaxAscent ());
return new Dimension (width, height);
}
public void replaceText (String str, int start, int end)
{
replaceRange (str, start, end);
}
public void insertText (String str, int pos)
{
insert (str, pos);
}
}