Source for gnu.java.awt.peer.qt.QtTextAreaPeer

   1: /* QtTextAreaPeer.java --
   2:    Copyright (C)  2005  Free Software Foundation, Inc.
   3: 
   4: This file is part of GNU Classpath.
   5: 
   6: GNU Classpath is free software; you can redistribute it and/or modify
   7: it under the terms of the GNU General Public License as published by
   8: the Free Software Foundation; either version 2, or (at your option)
   9: any later version.
  10: 
  11: GNU Classpath is distributed in the hope that it will be useful, but
  12: WITHOUT ANY WARRANTY; without even the implied warranty of
  13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14: General Public License for more details.
  15: 
  16: You should have received a copy of the GNU General Public License
  17: along with GNU Classpath; see the file COPYING.  If not, write to the
  18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  19: 02110-1301 USA.
  20: 
  21: Linking this library statically or dynamically with other modules is
  22: making a combined work based on this library.  Thus, the terms and
  23: conditions of the GNU General Public License cover the whole
  24: combination.
  25: 
  26: As a special exception, the copyright holders of this library give you
  27: permission to link this library with independent modules to produce an
  28: executable, regardless of the license terms of these independent
  29: modules, and to copy and distribute the resulting executable under
  30: terms of your choice, provided that you also meet, for each linked
  31: independent module, the terms and conditions of the license of that
  32: module.  An independent module is a module which is not derived from
  33: or based on this library.  If you modify this library, you may extend
  34: this exception to your version of the library, but you are not
  35: obligated to do so.  If you do not wish to do so, delete this
  36: exception statement from your version. */
  37: 
  38: package gnu.java.awt.peer.qt;
  39: 
  40: import java.awt.Dimension;
  41: import java.awt.Rectangle;
  42: import java.awt.TextArea;
  43: import java.awt.event.TextEvent;
  44: import java.awt.im.InputMethodRequests;
  45: import java.awt.peer.TextAreaPeer;
  46: 
  47: public class QtTextAreaPeer extends QtComponentPeer implements TextAreaPeer
  48: {
  49:   public QtTextAreaPeer( QtToolkit kit, TextArea owner )
  50:   {
  51:     super( kit, owner );
  52:   }
  53: 
  54:   protected native void init();
  55: 
  56:   protected void setup()
  57:   {
  58:     super.setup();
  59:     setText(((TextArea)owner).getText());
  60:     setEditable(((TextArea)owner).isEditable());
  61:   }
  62: 
  63:   /**
  64:    * Returns the start (start = true) or end (start = false) of the selection.
  65:    */
  66:   private native int getSelection(boolean start);
  67: 
  68:   /**
  69:    * Called back on a text edit.
  70:    */
  71:   private void textChanged()
  72:   {
  73:     TextEvent e = new TextEvent(owner, TextEvent.TEXT_VALUE_CHANGED);
  74:     QtToolkit.eventQueue.postEvent(e);
  75:   }
  76: 
  77:   // ************ Public methods *********************
  78: 
  79:   public long filterEvents(long filter)
  80:   {
  81:     return filter;
  82:   }
  83: 
  84:   public native int getCaretPosition();
  85: 
  86:   public Rectangle getCharacterBounds(int pos)
  87:   {
  88:     // FIXME
  89:     return new Rectangle(0,0,0,0);
  90:   }
  91: 
  92:   /**
  93:    * Implemented, but who uses it?
  94:    */
  95:   public native int getIndexAtPoint(int x, int y);
  96: 
  97: //   public void reshape(int x, int y,
  98: //                    int width, int height)
  99: //   {
 100: //     if(width != 0 || height != 0)
 101: //       super.reshape(x, y, width, height);
 102: //     else
 103: //       super.reshape(x, y, 10, 10);
 104: //   }
 105: 
 106:   public Dimension getMinimumSize(int rows, int cols)
 107:   {
 108:     // FIXME
 109:     return getMinimumSize();
 110:   }
 111: 
 112:   public Dimension getPreferredSize(int rows, int cols)
 113:   {
 114:     // FIXME
 115:     return getPreferredSize();
 116:   }
 117: 
 118:   public int getSelectionEnd()
 119:   {
 120:     return getSelection(false);
 121:   }
 122: 
 123:   public int getSelectionStart()
 124:   {
 125:     return getSelection(true);
 126:   }
 127: 
 128:   public native String getText();
 129: 
 130:   public void insert(String text, int pos)
 131:   {
 132:     // Not very efficient, no.
 133:     String s = getText();
 134:     setText(s.substring(0, pos) + text + s.substring(pos));
 135:   }
 136: 
 137:   public void insertText(String text, int pos)
 138:   {
 139:     insert(text, pos);
 140:   }
 141: 
 142:   public Dimension minimumSize(int rows, int cols)
 143:   {
 144:     return getMinimumSize(rows, cols);
 145:   }
 146: 
 147:   public Dimension preferredSize(int rows, int cols)
 148:   {
 149:     return getPreferredSize(rows, cols);
 150:   }
 151: 
 152:   public void replaceRange(String insert, int start_pos, int end_pos)
 153:   {
 154:     // Not very efficient, no.
 155:     String text = getText();
 156:     String right = text.substring(0, start_pos);
 157:     String left = text.substring(end_pos);
 158:     setText(right + insert + left);
 159:   }
 160: 
 161:   public void replaceText(String text, int start_pos, int end_pos)
 162:   {
 163:     replaceRange(text, start_pos, end_pos);
 164:   }
 165: 
 166:   public native void setText(String text);
 167: 
 168:   public native void select(int start_pos, int end_pos);
 169: 
 170:   public native void setEditable(boolean editable);
 171: 
 172:   public native void setCaretPosition(int pos);
 173: 
 174:   public InputMethodRequests getInputMethodRequests()
 175:   {
 176:     // TODO Auto-generated method stub
 177:     return null;
 178:   }
 179: }