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
{
native void create (int width, int height, int scrollbarVisibility);
native void gtkSetFont (String name, int style, int size);
void create ()
{
Font f = awtComponent.getFont ();
if (f == null)
{
f = new Font ("Fixed", Font.PLAIN, 12);
awtComponent.setFont (f);
}
FontMetrics fm;
if (GtkToolkit.useGraphics2D ())
fm = new GdkClasspathFontPeerMetrics (f);
else
fm = new GdkFontMetrics (f);
TextArea ta = ((TextArea) awtComponent);
int rows = ta.getRows ();
int cols = ta.getColumns ();
int width = cols * fm.getMaxAdvance ();
int height = rows * (fm.getMaxDescent () + fm.getMaxAscent ());
create (width, height, ta.getScrollbarVisibility ());
}
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, cols);
}
public Dimension getPreferredSize (int rows, int cols)
{
return preferredSize (rows, 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;
if (GtkToolkit.useGraphics2D ())
fm = new GdkClasspathFontPeerMetrics (f);
else
fm = new GdkFontMetrics (f);
width += cols * fm.getMaxAdvance ();
height += rows * (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;
if (GtkToolkit.useGraphics2D ())
fm = new GdkClasspathFontPeerMetrics (f);
else
fm = new GdkFontMetrics (f);
width += cols * fm.getMaxAdvance ();
height += rows * (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);
}
public void setFont (Font f)
{
gtkSetFont (f.getName (), f.getStyle (), f.getSize ());
}
}