Java Code Examples for java.awt.peer.TextComponentPeer

The following are top voted examples for showing how to use java.awt.peer.TextComponentPeer. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: OpenJSharp   File: TextComponent.java   Source Code and License 6 votes vote down vote up
/**
 * Sets the position of the text insertion caret.
 * The caret position is constrained to be between 0
 * and the last character of the text, inclusive.
 * If the passed-in value is greater than this range,
 * the value is set to the last character (or 0 if
 * the <code>TextComponent</code> contains no text)
 * and no error is returned.  If the passed-in value is
 * less than 0, an <code>IllegalArgumentException</code>
 * is thrown.
 *
 * @param        position the position of the text insertion caret
 * @exception    IllegalArgumentException if <code>position</code>
 *               is less than zero
 * @since        JDK1.1
 */
public synchronized void setCaretPosition(int position) {
    if (position < 0) {
        throw new IllegalArgumentException("position less than zero.");
    }

    int maxposition = getText().length();
    if (position > maxposition) {
        position = maxposition;
    }

    TextComponentPeer peer = (TextComponentPeer)this.peer;
    if (peer != null) {
        peer.setCaretPosition(position);
    } else {
        select(position, position);
    }
}
 
Example 2
Project: OpenJSharp   File: TextComponent.java   Source Code and License 6 votes vote down vote up
/**
 * Returns the position of the text insertion caret.
 * The caret position is constrained to be between 0
 * and the last character of the text, inclusive.
 * If the text or caret have not been set, the default
 * caret position is 0.
 *
 * @return       the position of the text insertion caret
 * @see #setCaretPosition(int)
 * @since        JDK1.1
 */
public synchronized int getCaretPosition() {
    TextComponentPeer peer = (TextComponentPeer)this.peer;
    int position = 0;

    if (peer != null) {
        position = peer.getCaretPosition();
    } else {
        position = selectionStart;
    }
    int maxposition = getText().length();
    if (position > maxposition) {
        position = maxposition;
    }
    return position;
}
 
Example 3
Project: OpenJSharp   File: TextComponent.java   Source Code and License 6 votes vote down vote up
/**
 * Writes default serializable fields to stream.  Writes
 * a list of serializable TextListener(s) as optional data.
 * The non-serializable TextListener(s) are detected and
 * no attempt is made to serialize them.
 *
 * @serialData Null terminated sequence of zero or more pairs.
 *             A pair consists of a String and Object.
 *             The String indicates the type of object and
 *             is one of the following :
 *             textListenerK indicating and TextListener object.
 *
 * @see AWTEventMulticaster#save(ObjectOutputStream, String, EventListener)
 * @see java.awt.Component#textListenerK
 */
private void writeObject(java.io.ObjectOutputStream s)
  throws IOException
{
    // Serialization support.  Since the value of the fields
    // selectionStart, selectionEnd, and text aren't necessarily
    // up to date, we sync them up with the peer before serializing.
    TextComponentPeer peer = (TextComponentPeer)this.peer;
    if (peer != null) {
        text = peer.getText();
        selectionStart = peer.getSelectionStart();
        selectionEnd = peer.getSelectionEnd();
    }

    s.defaultWriteObject();

    AWTEventMulticaster.save(s, textListenerK, textListener);
    s.writeObject(null);
}
 
Example 4
Project: jdk8u-jdk   File: TextComponent.java   Source Code and License 6 votes vote down vote up
/**
 * Sets the position of the text insertion caret.
 * The caret position is constrained to be between 0
 * and the last character of the text, inclusive.
 * If the passed-in value is greater than this range,
 * the value is set to the last character (or 0 if
 * the <code>TextComponent</code> contains no text)
 * and no error is returned.  If the passed-in value is
 * less than 0, an <code>IllegalArgumentException</code>
 * is thrown.
 *
 * @param        position the position of the text insertion caret
 * @exception    IllegalArgumentException if <code>position</code>
 *               is less than zero
 * @since        JDK1.1
 */
public synchronized void setCaretPosition(int position) {
    if (position < 0) {
        throw new IllegalArgumentException("position less than zero.");
    }

    int maxposition = getText().length();
    if (position > maxposition) {
        position = maxposition;
    }

    TextComponentPeer peer = (TextComponentPeer)this.peer;
    if (peer != null) {
        peer.setCaretPosition(position);
    } else {
        select(position, position);
    }
}
 
Example 5
Project: jdk8u-jdk   File: TextComponent.java   Source Code and License 6 votes vote down vote up
/**
 * Returns the position of the text insertion caret.
 * The caret position is constrained to be between 0
 * and the last character of the text, inclusive.
 * If the text or caret have not been set, the default
 * caret position is 0.
 *
 * @return       the position of the text insertion caret
 * @see #setCaretPosition(int)
 * @since        JDK1.1
 */
public synchronized int getCaretPosition() {
    TextComponentPeer peer = (TextComponentPeer)this.peer;
    int position = 0;

    if (peer != null) {
        position = peer.getCaretPosition();
    } else {
        position = selectionStart;
    }
    int maxposition = getText().length();
    if (position > maxposition) {
        position = maxposition;
    }
    return position;
}
 
Example 6
Project: jdk8u-jdk   File: TextComponent.java   Source Code and License 6 votes vote down vote up
/**
 * Writes default serializable fields to stream.  Writes
 * a list of serializable TextListener(s) as optional data.
 * The non-serializable TextListener(s) are detected and
 * no attempt is made to serialize them.
 *
 * @serialData Null terminated sequence of zero or more pairs.
 *             A pair consists of a String and Object.
 *             The String indicates the type of object and
 *             is one of the following :
 *             textListenerK indicating and TextListener object.
 *
 * @see AWTEventMulticaster#save(ObjectOutputStream, String, EventListener)
 * @see java.awt.Component#textListenerK
 */
private void writeObject(java.io.ObjectOutputStream s)
  throws IOException
{
    // Serialization support.  Since the value of the fields
    // selectionStart, selectionEnd, and text aren't necessarily
    // up to date, we sync them up with the peer before serializing.
    TextComponentPeer peer = (TextComponentPeer)this.peer;
    if (peer != null) {
        text = peer.getText();
        selectionStart = peer.getSelectionStart();
        selectionEnd = peer.getSelectionEnd();
    }

    s.defaultWriteObject();

    AWTEventMulticaster.save(s, textListenerK, textListener);
    s.writeObject(null);
}
 
Example 7
Project: openjdk-jdk10   File: TextComponent.java   Source Code and License 6 votes vote down vote up
/**
 * Sets the text that is presented by this
 * text component to be the specified text.
 * @param       t   the new text;
 *                  if this parameter is {@code null} then
 *                  the text is set to the empty string ""
 * @see         java.awt.TextComponent#getText
 */
public synchronized void setText(String t) {
    if (t == null) {
        t = "";
    }
    TextComponentPeer peer = (TextComponentPeer)this.peer;
    if (peer != null) {
        text = peer.getText();
        // Please note that we do not want to post an event
        // if TextArea.setText() or TextField.setText() replaces text
        // by same text, that is, if component's text remains unchanged.
        if (!t.equals(text)) {
            text = t;
            peer.setText(text);
        }
    } else {
        text = t;
    }
}
 
Example 8
Project: openjdk-jdk10   File: TextComponent.java   Source Code and License 6 votes vote down vote up
/**
 * Sets the position of the text insertion caret.
 * The caret position is constrained to be between 0
 * and the last character of the text, inclusive.
 * If the passed-in value is greater than this range,
 * the value is set to the last character (or 0 if
 * the {@code TextComponent} contains no text)
 * and no error is returned.  If the passed-in value is
 * less than 0, an {@code IllegalArgumentException}
 * is thrown.
 *
 * @param        position the position of the text insertion caret
 * @exception    IllegalArgumentException if {@code position}
 *               is less than zero
 * @since        1.1
 */
public synchronized void setCaretPosition(int position) {
    if (position < 0) {
        throw new IllegalArgumentException("position less than zero.");
    }

    int maxposition = getText().length();
    if (position > maxposition) {
        position = maxposition;
    }

    TextComponentPeer peer = (TextComponentPeer)this.peer;
    if (peer != null) {
        peer.setCaretPosition(position);
    } else {
        select(position, position);
    }
}
 
Example 9
Project: openjdk-jdk10   File: TextComponent.java   Source Code and License 6 votes vote down vote up
/**
 * Returns the position of the text insertion caret.
 * The caret position is constrained to be between 0
 * and the last character of the text, inclusive.
 * If the text or caret have not been set, the default
 * caret position is 0.
 *
 * @return       the position of the text insertion caret
 * @see #setCaretPosition(int)
 * @since        1.1
 */
public synchronized int getCaretPosition() {
    TextComponentPeer peer = (TextComponentPeer)this.peer;
    int position = 0;

    if (peer != null) {
        position = peer.getCaretPosition();
    } else {
        position = selectionStart;
    }
    int maxposition = getText().length();
    if (position > maxposition) {
        position = maxposition;
    }
    return position;
}
 
Example 10
Project: openjdk-jdk10   File: TextComponent.java   Source Code and License 6 votes vote down vote up
/**
 * Writes default serializable fields to stream.  Writes
 * a list of serializable TextListener(s) as optional data.
 * The non-serializable TextListener(s) are detected and
 * no attempt is made to serialize them.
 *
 * @serialData Null terminated sequence of zero or more pairs.
 *             A pair consists of a String and Object.
 *             The String indicates the type of object and
 *             is one of the following :
 *             textListenerK indicating and TextListener object.
 *
 * @see AWTEventMulticaster#save(ObjectOutputStream, String, EventListener)
 * @see java.awt.Component#textListenerK
 */
private void writeObject(java.io.ObjectOutputStream s)
  throws IOException
{
    // Serialization support.  Since the value of the fields
    // selectionStart, selectionEnd, and text aren't necessarily
    // up to date, we sync them up with the peer before serializing.
    TextComponentPeer peer = (TextComponentPeer)this.peer;
    if (peer != null) {
        text = peer.getText();
        selectionStart = peer.getSelectionStart();
        selectionEnd = peer.getSelectionEnd();
    }

    s.defaultWriteObject();

    AWTEventMulticaster.save(s, textListenerK, textListener);
    s.writeObject(null);
}
 
Example 11
Project: openjdk9   File: TextComponent.java   Source Code and License 6 votes vote down vote up
/**
 * Sets the text that is presented by this
 * text component to be the specified text.
 * @param       t   the new text;
 *                  if this parameter is {@code null} then
 *                  the text is set to the empty string ""
 * @see         java.awt.TextComponent#getText
 */
public synchronized void setText(String t) {
    if (t == null) {
        t = "";
    }
    TextComponentPeer peer = (TextComponentPeer)this.peer;
    if (peer != null) {
        text = peer.getText();
        // Please note that we do not want to post an event
        // if TextArea.setText() or TextField.setText() replaces text
        // by same text, that is, if component's text remains unchanged.
        if (!t.equals(text)) {
            text = t;
            peer.setText(text);
        }
    } else {
        text = t;
    }
}
 
Example 12
Project: openjdk9   File: TextComponent.java   Source Code and License 6 votes vote down vote up
/**
 * Sets the position of the text insertion caret.
 * The caret position is constrained to be between 0
 * and the last character of the text, inclusive.
 * If the passed-in value is greater than this range,
 * the value is set to the last character (or 0 if
 * the {@code TextComponent} contains no text)
 * and no error is returned.  If the passed-in value is
 * less than 0, an {@code IllegalArgumentException}
 * is thrown.
 *
 * @param        position the position of the text insertion caret
 * @exception    IllegalArgumentException if {@code position}
 *               is less than zero
 * @since        1.1
 */
public synchronized void setCaretPosition(int position) {
    if (position < 0) {
        throw new IllegalArgumentException("position less than zero.");
    }

    int maxposition = getText().length();
    if (position > maxposition) {
        position = maxposition;
    }

    TextComponentPeer peer = (TextComponentPeer)this.peer;
    if (peer != null) {
        peer.setCaretPosition(position);
    } else {
        select(position, position);
    }
}
 
Example 13
Project: openjdk9   File: TextComponent.java   Source Code and License 6 votes vote down vote up
/**
 * Returns the position of the text insertion caret.
 * The caret position is constrained to be between 0
 * and the last character of the text, inclusive.
 * If the text or caret have not been set, the default
 * caret position is 0.
 *
 * @return       the position of the text insertion caret
 * @see #setCaretPosition(int)
 * @since        1.1
 */
public synchronized int getCaretPosition() {
    TextComponentPeer peer = (TextComponentPeer)this.peer;
    int position = 0;

    if (peer != null) {
        position = peer.getCaretPosition();
    } else {
        position = selectionStart;
    }
    int maxposition = getText().length();
    if (position > maxposition) {
        position = maxposition;
    }
    return position;
}
 
Example 14
Project: openjdk9   File: TextComponent.java   Source Code and License 6 votes vote down vote up
/**
 * Writes default serializable fields to stream.  Writes
 * a list of serializable TextListener(s) as optional data.
 * The non-serializable TextListener(s) are detected and
 * no attempt is made to serialize them.
 *
 * @serialData Null terminated sequence of zero or more pairs.
 *             A pair consists of a String and Object.
 *             The String indicates the type of object and
 *             is one of the following :
 *             textListenerK indicating and TextListener object.
 *
 * @see AWTEventMulticaster#save(ObjectOutputStream, String, EventListener)
 * @see java.awt.Component#textListenerK
 */
private void writeObject(java.io.ObjectOutputStream s)
  throws IOException
{
    // Serialization support.  Since the value of the fields
    // selectionStart, selectionEnd, and text aren't necessarily
    // up to date, we sync them up with the peer before serializing.
    TextComponentPeer peer = (TextComponentPeer)this.peer;
    if (peer != null) {
        text = peer.getText();
        selectionStart = peer.getSelectionStart();
        selectionEnd = peer.getSelectionEnd();
    }

    s.defaultWriteObject();

    AWTEventMulticaster.save(s, textListenerK, textListener);
    s.writeObject(null);
}
 
Example 15
Project: Java8CN   File: TextComponent.java   Source Code and License 6 votes vote down vote up
/**
 * Sets the position of the text insertion caret.
 * The caret position is constrained to be between 0
 * and the last character of the text, inclusive.
 * If the passed-in value is greater than this range,
 * the value is set to the last character (or 0 if
 * the <code>TextComponent</code> contains no text)
 * and no error is returned.  If the passed-in value is
 * less than 0, an <code>IllegalArgumentException</code>
 * is thrown.
 *
 * @param        position the position of the text insertion caret
 * @exception    IllegalArgumentException if <code>position</code>
 *               is less than zero
 * @since        JDK1.1
 */
public synchronized void setCaretPosition(int position) {
    if (position < 0) {
        throw new IllegalArgumentException("position less than zero.");
    }

    int maxposition = getText().length();
    if (position > maxposition) {
        position = maxposition;
    }

    TextComponentPeer peer = (TextComponentPeer)this.peer;
    if (peer != null) {
        peer.setCaretPosition(position);
    } else {
        select(position, position);
    }
}
 
Example 16
Project: Java8CN   File: TextComponent.java   Source Code and License 6 votes vote down vote up
/**
 * Returns the position of the text insertion caret.
 * The caret position is constrained to be between 0
 * and the last character of the text, inclusive.
 * If the text or caret have not been set, the default
 * caret position is 0.
 *
 * @return       the position of the text insertion caret
 * @see #setCaretPosition(int)
 * @since        JDK1.1
 */
public synchronized int getCaretPosition() {
    TextComponentPeer peer = (TextComponentPeer)this.peer;
    int position = 0;

    if (peer != null) {
        position = peer.getCaretPosition();
    } else {
        position = selectionStart;
    }
    int maxposition = getText().length();
    if (position > maxposition) {
        position = maxposition;
    }
    return position;
}
 
Example 17
Project: Java8CN   File: TextComponent.java   Source Code and License 6 votes vote down vote up
/**
 * Writes default serializable fields to stream.  Writes
 * a list of serializable TextListener(s) as optional data.
 * The non-serializable TextListener(s) are detected and
 * no attempt is made to serialize them.
 *
 * @serialData Null terminated sequence of zero or more pairs.
 *             A pair consists of a String and Object.
 *             The String indicates the type of object and
 *             is one of the following :
 *             textListenerK indicating and TextListener object.
 *
 * @see AWTEventMulticaster#save(ObjectOutputStream, String, EventListener)
 * @see java.awt.Component#textListenerK
 */
private void writeObject(java.io.ObjectOutputStream s)
  throws IOException
{
    // Serialization support.  Since the value of the fields
    // selectionStart, selectionEnd, and text aren't necessarily
    // up to date, we sync them up with the peer before serializing.
    TextComponentPeer peer = (TextComponentPeer)this.peer;
    if (peer != null) {
        text = peer.getText();
        selectionStart = peer.getSelectionStart();
        selectionEnd = peer.getSelectionEnd();
    }

    s.defaultWriteObject();

    AWTEventMulticaster.save(s, textListenerK, textListener);
    s.writeObject(null);
}
 
Example 18
Project: jdk8u_jdk   File: TextComponent.java   Source Code and License 6 votes vote down vote up
/**
 * Sets the position of the text insertion caret.
 * The caret position is constrained to be between 0
 * and the last character of the text, inclusive.
 * If the passed-in value is greater than this range,
 * the value is set to the last character (or 0 if
 * the <code>TextComponent</code> contains no text)
 * and no error is returned.  If the passed-in value is
 * less than 0, an <code>IllegalArgumentException</code>
 * is thrown.
 *
 * @param        position the position of the text insertion caret
 * @exception    IllegalArgumentException if <code>position</code>
 *               is less than zero
 * @since        JDK1.1
 */
public synchronized void setCaretPosition(int position) {
    if (position < 0) {
        throw new IllegalArgumentException("position less than zero.");
    }

    int maxposition = getText().length();
    if (position > maxposition) {
        position = maxposition;
    }

    TextComponentPeer peer = (TextComponentPeer)this.peer;
    if (peer != null) {
        peer.setCaretPosition(position);
    } else {
        select(position, position);
    }
}
 
Example 19
Project: jdk8u_jdk   File: TextComponent.java   Source Code and License 6 votes vote down vote up
/**
 * Returns the position of the text insertion caret.
 * The caret position is constrained to be between 0
 * and the last character of the text, inclusive.
 * If the text or caret have not been set, the default
 * caret position is 0.
 *
 * @return       the position of the text insertion caret
 * @see #setCaretPosition(int)
 * @since        JDK1.1
 */
public synchronized int getCaretPosition() {
    TextComponentPeer peer = (TextComponentPeer)this.peer;
    int position = 0;

    if (peer != null) {
        position = peer.getCaretPosition();
    } else {
        position = selectionStart;
    }
    int maxposition = getText().length();
    if (position > maxposition) {
        position = maxposition;
    }
    return position;
}
 
Example 20
Project: jdk8u_jdk   File: TextComponent.java   Source Code and License 6 votes vote down vote up
/**
 * Writes default serializable fields to stream.  Writes
 * a list of serializable TextListener(s) as optional data.
 * The non-serializable TextListener(s) are detected and
 * no attempt is made to serialize them.
 *
 * @serialData Null terminated sequence of zero or more pairs.
 *             A pair consists of a String and Object.
 *             The String indicates the type of object and
 *             is one of the following :
 *             textListenerK indicating and TextListener object.
 *
 * @see AWTEventMulticaster#save(ObjectOutputStream, String, EventListener)
 * @see java.awt.Component#textListenerK
 */
private void writeObject(java.io.ObjectOutputStream s)
  throws IOException
{
    // Serialization support.  Since the value of the fields
    // selectionStart, selectionEnd, and text aren't necessarily
    // up to date, we sync them up with the peer before serializing.
    TextComponentPeer peer = (TextComponentPeer)this.peer;
    if (peer != null) {
        text = peer.getText();
        selectionStart = peer.getSelectionStart();
        selectionEnd = peer.getSelectionEnd();
    }

    s.defaultWriteObject();

    AWTEventMulticaster.save(s, textListenerK, textListener);
    s.writeObject(null);
}
 
Example 21
Project: lookaside_java-1.8.0-openjdk   File: TextComponent.java   Source Code and License 6 votes vote down vote up
/**
 * Sets the position of the text insertion caret.
 * The caret position is constrained to be between 0
 * and the last character of the text, inclusive.
 * If the passed-in value is greater than this range,
 * the value is set to the last character (or 0 if
 * the <code>TextComponent</code> contains no text)
 * and no error is returned.  If the passed-in value is
 * less than 0, an <code>IllegalArgumentException</code>
 * is thrown.
 *
 * @param        position the position of the text insertion caret
 * @exception    IllegalArgumentException if <code>position</code>
 *               is less than zero
 * @since        JDK1.1
 */
public synchronized void setCaretPosition(int position) {
    if (position < 0) {
        throw new IllegalArgumentException("position less than zero.");
    }

    int maxposition = getText().length();
    if (position > maxposition) {
        position = maxposition;
    }

    TextComponentPeer peer = (TextComponentPeer)this.peer;
    if (peer != null) {
        peer.setCaretPosition(position);
    } else {
        select(position, position);
    }
}
 
Example 22
Project: lookaside_java-1.8.0-openjdk   File: TextComponent.java   Source Code and License 6 votes vote down vote up
/**
 * Returns the position of the text insertion caret.
 * The caret position is constrained to be between 0
 * and the last character of the text, inclusive.
 * If the text or caret have not been set, the default
 * caret position is 0.
 *
 * @return       the position of the text insertion caret
 * @see #setCaretPosition(int)
 * @since        JDK1.1
 */
public synchronized int getCaretPosition() {
    TextComponentPeer peer = (TextComponentPeer)this.peer;
    int position = 0;

    if (peer != null) {
        position = peer.getCaretPosition();
    } else {
        position = selectionStart;
    }
    int maxposition = getText().length();
    if (position > maxposition) {
        position = maxposition;
    }
    return position;
}
 
Example 23
Project: lookaside_java-1.8.0-openjdk   File: TextComponent.java   Source Code and License 6 votes vote down vote up
/**
 * Writes default serializable fields to stream.  Writes
 * a list of serializable TextListener(s) as optional data.
 * The non-serializable TextListener(s) are detected and
 * no attempt is made to serialize them.
 *
 * @serialData Null terminated sequence of zero or more pairs.
 *             A pair consists of a String and Object.
 *             The String indicates the type of object and
 *             is one of the following :
 *             textListenerK indicating and TextListener object.
 *
 * @see AWTEventMulticaster#save(ObjectOutputStream, String, EventListener)
 * @see java.awt.Component#textListenerK
 */
private void writeObject(java.io.ObjectOutputStream s)
  throws IOException
{
    // Serialization support.  Since the value of the fields
    // selectionStart, selectionEnd, and text aren't necessarily
    // up to date, we sync them up with the peer before serializing.
    TextComponentPeer peer = (TextComponentPeer)this.peer;
    if (peer != null) {
        text = peer.getText();
        selectionStart = peer.getSelectionStart();
        selectionEnd = peer.getSelectionEnd();
    }

    s.defaultWriteObject();

    AWTEventMulticaster.save(s, textListenerK, textListener);
    s.writeObject(null);
}
 
Example 24
Project: javify   File: TextComponent.java   Source Code and License 6 votes vote down vote up
/**
 * This method sets the selected text range to the text between the
 * specified start and end positions.  Illegal values for these
 * positions are silently fixed.
 *
 * @param selectionStart The new start position for the selected text.
 * @param selectionEnd The new end position for the selected text.
 */
public synchronized void select(int selectionStart, int selectionEnd)
{
  if (selectionStart < 0)
    selectionStart = 0;

  if (selectionStart > getText().length())
    selectionStart = text.length();

  if (selectionEnd > text.length())
    selectionEnd = text.length();

  if (selectionStart > selectionEnd)
    selectionStart = selectionEnd;

  this.selectionStart = selectionStart;
  this.selectionEnd = selectionEnd;

  TextComponentPeer tcp = (TextComponentPeer) getPeer();
  if (tcp != null)
    tcp.select(selectionStart, selectionEnd);
}
 
Example 25
Project: jvm-stm   File: TextComponent.java   Source Code and License 6 votes vote down vote up
/**
 * This method sets the selected text range to the text between the
 * specified start and end positions.  Illegal values for these
 * positions are silently fixed.
 *
 * @param selectionStart The new start position for the selected text.
 * @param selectionEnd The new end position for the selected text.
 */
public synchronized void select(int selectionStart, int selectionEnd)
{
  if (selectionStart < 0)
    selectionStart = 0;

  if (selectionStart > getText().length())
    selectionStart = text.length();

  if (selectionEnd > text.length())
    selectionEnd = text.length();

  if (selectionStart > selectionEnd)
    selectionStart = selectionEnd;

  this.selectionStart = selectionStart;
  this.selectionEnd = selectionEnd;
  
  TextComponentPeer tcp = (TextComponentPeer) getPeer();
  if (tcp != null)
    tcp.select(selectionStart, selectionEnd);
}
 
Example 26
Project: VarJ   File: TextComponent.java   Source Code and License 6 votes vote down vote up
/**
    * Sets the position of the text insertion caret.
    * The caret position is constrained to be between 0
    * and the last character of the text, inclusive.
    * If the passed-in value is greater than this range,
    * the value is set to the last character (or 0 if
    * the <code>TextComponent</code> contains no text)
    * and no error is returned.  If the passed-in value is
    * less than 0, an <code>IllegalArgumentException</code>
    * is thrown.
    * 
    * @param        position the position of the text insertion caret
    * @exception    IllegalArgumentException if <code>position</code>
    *               is less than zero
    * @since        JDK1.1
    */
   public synchronized void setCaretPosition(int position) {
if (position < 0) {
    throw new IllegalArgumentException("position less than zero.");
}

int maxposition = getText().length();
if (position > maxposition) {
    position = maxposition;
}

TextComponentPeer peer = (TextComponentPeer)this.peer;
if (peer != null) {
    peer.setCaretPosition(position);
} else {
    select(position, position);
}
   }
 
Example 27
Project: VarJ   File: TextComponent.java   Source Code and License 6 votes vote down vote up
/**
    * Returns the position of the text insertion caret.
    * The caret position is constrained to be between 0
    * and the last character of the text, inclusive.
    * If the text or caret have not been set, the default
    * caret position is 0.
    *
    * @return       the position of the text insertion caret
    * @see #setCaretPosition(int)
    * @since        JDK1.1
    */
   public synchronized int getCaretPosition() {
       TextComponentPeer peer = (TextComponentPeer)this.peer;
int position = 0;

if (peer != null) {
    position = peer.getCaretPosition();
} else {
    position = selectionStart;
}
       int maxposition = getText().length();
       if (position > maxposition) {
           position = maxposition;
       }
       return position;
   }
 
Example 28
Project: VarJ   File: TextComponent.java   Source Code and License 6 votes vote down vote up
/**
 * Writes default serializable fields to stream.  Writes
 * a list of serializable TextListener(s) as optional data.
 * The non-serializable TextListener(s) are detected and
 * no attempt is made to serialize them.
 *
 * @serialData Null terminated sequence of zero or more pairs.
 *             A pair consists of a String and Object.
 *             The String indicates the type of object and
 *             is one of the following :
 *             textListenerK indicating and TextListener object.
 *
 * @see AWTEventMulticaster#save(ObjectOutputStream, String, EventListener)
 * @see java.awt.Component#textListenerK
 */
private void writeObject(java.io.ObjectOutputStream s)
  throws IOException 
{
    // Serialization support.  Since the value of the fields
    // selectionStart, selectionEnd, and text aren't necessarily
    // up to date, we sync them up with the peer before serializing.
    TextComponentPeer peer = (TextComponentPeer)this.peer;
    if (peer != null) {
        text = peer.getText();
        selectionStart = peer.getSelectionStart();
        selectionEnd = peer.getSelectionEnd();
    }

    s.defaultWriteObject();

    AWTEventMulticaster.save(s, textListenerK, textListener);
    s.writeObject(null);
}
 
Example 29
Project: jdk-1.7-annotated   File: TextComponent.java   Source Code and License 6 votes vote down vote up
/**
 * Sets the position of the text insertion caret.
 * The caret position is constrained to be between 0
 * and the last character of the text, inclusive.
 * If the passed-in value is greater than this range,
 * the value is set to the last character (or 0 if
 * the <code>TextComponent</code> contains no text)
 * and no error is returned.  If the passed-in value is
 * less than 0, an <code>IllegalArgumentException</code>
 * is thrown.
 *
 * @param        position the position of the text insertion caret
 * @exception    IllegalArgumentException if <code>position</code>
 *               is less than zero
 * @since        JDK1.1
 */
public synchronized void setCaretPosition(int position) {
    if (position < 0) {
        throw new IllegalArgumentException("position less than zero.");
    }

    int maxposition = getText().length();
    if (position > maxposition) {
        position = maxposition;
    }

    TextComponentPeer peer = (TextComponentPeer)this.peer;
    if (peer != null) {
        peer.setCaretPosition(position);
    } else {
        select(position, position);
    }
}
 
Example 30
Project: jdk-1.7-annotated   File: TextComponent.java   Source Code and License 6 votes vote down vote up
/**
 * Returns the position of the text insertion caret.
 * The caret position is constrained to be between 0
 * and the last character of the text, inclusive.
 * If the text or caret have not been set, the default
 * caret position is 0.
 *
 * @return       the position of the text insertion caret
 * @see #setCaretPosition(int)
 * @since        JDK1.1
 */
public synchronized int getCaretPosition() {
    TextComponentPeer peer = (TextComponentPeer)this.peer;
    int position = 0;

    if (peer != null) {
        position = peer.getCaretPosition();
    } else {
        position = selectionStart;
    }
    int maxposition = getText().length();
    if (position > maxposition) {
        position = maxposition;
    }
    return position;
}
 
Example 31
Project: jdk-1.7-annotated   File: TextComponent.java   Source Code and License 6 votes vote down vote up
/**
 * Writes default serializable fields to stream.  Writes
 * a list of serializable TextListener(s) as optional data.
 * The non-serializable TextListener(s) are detected and
 * no attempt is made to serialize them.
 *
 * @serialData Null terminated sequence of zero or more pairs.
 *             A pair consists of a String and Object.
 *             The String indicates the type of object and
 *             is one of the following :
 *             textListenerK indicating and TextListener object.
 *
 * @see AWTEventMulticaster#save(ObjectOutputStream, String, EventListener)
 * @see java.awt.Component#textListenerK
 */
private void writeObject(java.io.ObjectOutputStream s)
  throws IOException
{
    // Serialization support.  Since the value of the fields
    // selectionStart, selectionEnd, and text aren't necessarily
    // up to date, we sync them up with the peer before serializing.
    TextComponentPeer peer = (TextComponentPeer)this.peer;
    if (peer != null) {
        text = peer.getText();
        selectionStart = peer.getSelectionStart();
        selectionEnd = peer.getSelectionEnd();
    }

    s.defaultWriteObject();

    AWTEventMulticaster.save(s, textListenerK, textListener);
    s.writeObject(null);
}
 
Example 32
Project: infobip-open-jdk-8   File: TextComponent.java   Source Code and License 6 votes vote down vote up
/**
 * Sets the position of the text insertion caret.
 * The caret position is constrained to be between 0
 * and the last character of the text, inclusive.
 * If the passed-in value is greater than this range,
 * the value is set to the last character (or 0 if
 * the <code>TextComponent</code> contains no text)
 * and no error is returned.  If the passed-in value is
 * less than 0, an <code>IllegalArgumentException</code>
 * is thrown.
 *
 * @param        position the position of the text insertion caret
 * @exception    IllegalArgumentException if <code>position</code>
 *               is less than zero
 * @since        JDK1.1
 */
public synchronized void setCaretPosition(int position) {
    if (position < 0) {
        throw new IllegalArgumentException("position less than zero.");
    }

    int maxposition = getText().length();
    if (position > maxposition) {
        position = maxposition;
    }

    TextComponentPeer peer = (TextComponentPeer)this.peer;
    if (peer != null) {
        peer.setCaretPosition(position);
    } else {
        select(position, position);
    }
}
 
Example 33
Project: infobip-open-jdk-8   File: TextComponent.java   Source Code and License 6 votes vote down vote up
/**
 * Returns the position of the text insertion caret.
 * The caret position is constrained to be between 0
 * and the last character of the text, inclusive.
 * If the text or caret have not been set, the default
 * caret position is 0.
 *
 * @return       the position of the text insertion caret
 * @see #setCaretPosition(int)
 * @since        JDK1.1
 */
public synchronized int getCaretPosition() {
    TextComponentPeer peer = (TextComponentPeer)this.peer;
    int position = 0;

    if (peer != null) {
        position = peer.getCaretPosition();
    } else {
        position = selectionStart;
    }
    int maxposition = getText().length();
    if (position > maxposition) {
        position = maxposition;
    }
    return position;
}
 
Example 34
Project: infobip-open-jdk-8   File: TextComponent.java   Source Code and License 6 votes vote down vote up
/**
 * Writes default serializable fields to stream.  Writes
 * a list of serializable TextListener(s) as optional data.
 * The non-serializable TextListener(s) are detected and
 * no attempt is made to serialize them.
 *
 * @serialData Null terminated sequence of zero or more pairs.
 *             A pair consists of a String and Object.
 *             The String indicates the type of object and
 *             is one of the following :
 *             textListenerK indicating and TextListener object.
 *
 * @see AWTEventMulticaster#save(ObjectOutputStream, String, EventListener)
 * @see java.awt.Component#textListenerK
 */
private void writeObject(java.io.ObjectOutputStream s)
  throws IOException
{
    // Serialization support.  Since the value of the fields
    // selectionStart, selectionEnd, and text aren't necessarily
    // up to date, we sync them up with the peer before serializing.
    TextComponentPeer peer = (TextComponentPeer)this.peer;
    if (peer != null) {
        text = peer.getText();
        selectionStart = peer.getSelectionStart();
        selectionEnd = peer.getSelectionEnd();
    }

    s.defaultWriteObject();

    AWTEventMulticaster.save(s, textListenerK, textListener);
    s.writeObject(null);
}
 
Example 35
Project: jdk8u-dev-jdk   File: TextComponent.java   Source Code and License 6 votes vote down vote up
/**
 * Sets the position of the text insertion caret.
 * The caret position is constrained to be between 0
 * and the last character of the text, inclusive.
 * If the passed-in value is greater than this range,
 * the value is set to the last character (or 0 if
 * the <code>TextComponent</code> contains no text)
 * and no error is returned.  If the passed-in value is
 * less than 0, an <code>IllegalArgumentException</code>
 * is thrown.
 *
 * @param        position the position of the text insertion caret
 * @exception    IllegalArgumentException if <code>position</code>
 *               is less than zero
 * @since        JDK1.1
 */
public synchronized void setCaretPosition(int position) {
    if (position < 0) {
        throw new IllegalArgumentException("position less than zero.");
    }

    int maxposition = getText().length();
    if (position > maxposition) {
        position = maxposition;
    }

    TextComponentPeer peer = (TextComponentPeer)this.peer;
    if (peer != null) {
        peer.setCaretPosition(position);
    } else {
        select(position, position);
    }
}
 
Example 36
Project: jdk8u-dev-jdk   File: TextComponent.java   Source Code and License 6 votes vote down vote up
/**
 * Returns the position of the text insertion caret.
 * The caret position is constrained to be between 0
 * and the last character of the text, inclusive.
 * If the text or caret have not been set, the default
 * caret position is 0.
 *
 * @return       the position of the text insertion caret
 * @see #setCaretPosition(int)
 * @since        JDK1.1
 */
public synchronized int getCaretPosition() {
    TextComponentPeer peer = (TextComponentPeer)this.peer;
    int position = 0;

    if (peer != null) {
        position = peer.getCaretPosition();
    } else {
        position = selectionStart;
    }
    int maxposition = getText().length();
    if (position > maxposition) {
        position = maxposition;
    }
    return position;
}
 
Example 37
Project: jdk8u-dev-jdk   File: TextComponent.java   Source Code and License 6 votes vote down vote up
/**
 * Writes default serializable fields to stream.  Writes
 * a list of serializable TextListener(s) as optional data.
 * The non-serializable TextListener(s) are detected and
 * no attempt is made to serialize them.
 *
 * @serialData Null terminated sequence of zero or more pairs.
 *             A pair consists of a String and Object.
 *             The String indicates the type of object and
 *             is one of the following :
 *             textListenerK indicating and TextListener object.
 *
 * @see AWTEventMulticaster#save(ObjectOutputStream, String, EventListener)
 * @see java.awt.Component#textListenerK
 */
private void writeObject(java.io.ObjectOutputStream s)
  throws IOException
{
    // Serialization support.  Since the value of the fields
    // selectionStart, selectionEnd, and text aren't necessarily
    // up to date, we sync them up with the peer before serializing.
    TextComponentPeer peer = (TextComponentPeer)this.peer;
    if (peer != null) {
        text = peer.getText();
        selectionStart = peer.getSelectionStart();
        selectionEnd = peer.getSelectionEnd();
    }

    s.defaultWriteObject();

    AWTEventMulticaster.save(s, textListenerK, textListener);
    s.writeObject(null);
}
 
Example 38
Project: jdk7-jdk   File: TextComponent.java   Source Code and License 6 votes vote down vote up
/**
 * Sets the position of the text insertion caret.
 * The caret position is constrained to be between 0
 * and the last character of the text, inclusive.
 * If the passed-in value is greater than this range,
 * the value is set to the last character (or 0 if
 * the <code>TextComponent</code> contains no text)
 * and no error is returned.  If the passed-in value is
 * less than 0, an <code>IllegalArgumentException</code>
 * is thrown.
 *
 * @param        position the position of the text insertion caret
 * @exception    IllegalArgumentException if <code>position</code>
 *               is less than zero
 * @since        JDK1.1
 */
public synchronized void setCaretPosition(int position) {
    if (position < 0) {
        throw new IllegalArgumentException("position less than zero.");
    }

    int maxposition = getText().length();
    if (position > maxposition) {
        position = maxposition;
    }

    TextComponentPeer peer = (TextComponentPeer)this.peer;
    if (peer != null) {
        peer.setCaretPosition(position);
    } else {
        select(position, position);
    }
}
 
Example 39
Project: jdk7-jdk   File: TextComponent.java   Source Code and License 6 votes vote down vote up
/**
 * Returns the position of the text insertion caret.
 * The caret position is constrained to be between 0
 * and the last character of the text, inclusive.
 * If the text or caret have not been set, the default
 * caret position is 0.
 *
 * @return       the position of the text insertion caret
 * @see #setCaretPosition(int)
 * @since        JDK1.1
 */
public synchronized int getCaretPosition() {
    TextComponentPeer peer = (TextComponentPeer)this.peer;
    int position = 0;

    if (peer != null) {
        position = peer.getCaretPosition();
    } else {
        position = selectionStart;
    }
    int maxposition = getText().length();
    if (position > maxposition) {
        position = maxposition;
    }
    return position;
}
 
Example 40
Project: jdk7-jdk   File: TextComponent.java   Source Code and License 6 votes vote down vote up
/**
 * Writes default serializable fields to stream.  Writes
 * a list of serializable TextListener(s) as optional data.
 * The non-serializable TextListener(s) are detected and
 * no attempt is made to serialize them.
 *
 * @serialData Null terminated sequence of zero or more pairs.
 *             A pair consists of a String and Object.
 *             The String indicates the type of object and
 *             is one of the following :
 *             textListenerK indicating and TextListener object.
 *
 * @see AWTEventMulticaster#save(ObjectOutputStream, String, EventListener)
 * @see java.awt.Component#textListenerK
 */
private void writeObject(java.io.ObjectOutputStream s)
  throws IOException
{
    // Serialization support.  Since the value of the fields
    // selectionStart, selectionEnd, and text aren't necessarily
    // up to date, we sync them up with the peer before serializing.
    TextComponentPeer peer = (TextComponentPeer)this.peer;
    if (peer != null) {
        text = peer.getText();
        selectionStart = peer.getSelectionStart();
        selectionEnd = peer.getSelectionEnd();
    }

    s.defaultWriteObject();

    AWTEventMulticaster.save(s, textListenerK, textListener);
    s.writeObject(null);
}
 
Example 41
Project: openjdk-source-code-learn   File: TextComponent.java   Source Code and License 6 votes vote down vote up
/**
 * Sets the position of the text insertion caret.
 * The caret position is constrained to be between 0
 * and the last character of the text, inclusive.
 * If the passed-in value is greater than this range,
 * the value is set to the last character (or 0 if
 * the <code>TextComponent</code> contains no text)
 * and no error is returned.  If the passed-in value is
 * less than 0, an <code>IllegalArgumentException</code>
 * is thrown.
 *
 * @param        position the position of the text insertion caret
 * @exception    IllegalArgumentException if <code>position</code>
 *               is less than zero
 * @since        JDK1.1
 */
public synchronized void setCaretPosition(int position) {
    if (position < 0) {
        throw new IllegalArgumentException("position less than zero.");
    }

    int maxposition = getText().length();
    if (position > maxposition) {
        position = maxposition;
    }

    TextComponentPeer peer = (TextComponentPeer)this.peer;
    if (peer != null) {
        peer.setCaretPosition(position);
    } else {
        select(position, position);
    }
}
 
Example 42
Project: openjdk-source-code-learn   File: TextComponent.java   Source Code and License 6 votes vote down vote up
/**
 * Returns the position of the text insertion caret.
 * The caret position is constrained to be between 0
 * and the last character of the text, inclusive.
 * If the text or caret have not been set, the default
 * caret position is 0.
 *
 * @return       the position of the text insertion caret
 * @see #setCaretPosition(int)
 * @since        JDK1.1
 */
public synchronized int getCaretPosition() {
    TextComponentPeer peer = (TextComponentPeer)this.peer;
    int position = 0;

    if (peer != null) {
        position = peer.getCaretPosition();
    } else {
        position = selectionStart;
    }
    int maxposition = getText().length();
    if (position > maxposition) {
        position = maxposition;
    }
    return position;
}
 
Example 43
Project: openjdk-source-code-learn   File: TextComponent.java   Source Code and License 6 votes vote down vote up
/**
 * Writes default serializable fields to stream.  Writes
 * a list of serializable TextListener(s) as optional data.
 * The non-serializable TextListener(s) are detected and
 * no attempt is made to serialize them.
 *
 * @serialData Null terminated sequence of zero or more pairs.
 *             A pair consists of a String and Object.
 *             The String indicates the type of object and
 *             is one of the following :
 *             textListenerK indicating and TextListener object.
 *
 * @see AWTEventMulticaster#save(ObjectOutputStream, String, EventListener)
 * @see java.awt.Component#textListenerK
 */
private void writeObject(java.io.ObjectOutputStream s)
  throws IOException
{
    // Serialization support.  Since the value of the fields
    // selectionStart, selectionEnd, and text aren't necessarily
    // up to date, we sync them up with the peer before serializing.
    TextComponentPeer peer = (TextComponentPeer)this.peer;
    if (peer != null) {
        text = peer.getText();
        selectionStart = peer.getSelectionStart();
        selectionEnd = peer.getSelectionEnd();
    }

    s.defaultWriteObject();

    AWTEventMulticaster.save(s, textListenerK, textListener);
    s.writeObject(null);
}
 
Example 44
Project: OLD-OpenJDK8   File: TextComponent.java   Source Code and License 6 votes vote down vote up
/**
 * Sets the position of the text insertion caret.
 * The caret position is constrained to be between 0
 * and the last character of the text, inclusive.
 * If the passed-in value is greater than this range,
 * the value is set to the last character (or 0 if
 * the <code>TextComponent</code> contains no text)
 * and no error is returned.  If the passed-in value is
 * less than 0, an <code>IllegalArgumentException</code>
 * is thrown.
 *
 * @param        position the position of the text insertion caret
 * @exception    IllegalArgumentException if <code>position</code>
 *               is less than zero
 * @since        JDK1.1
 */
public synchronized void setCaretPosition(int position) {
    if (position < 0) {
        throw new IllegalArgumentException("position less than zero.");
    }

    int maxposition = getText().length();
    if (position > maxposition) {
        position = maxposition;
    }

    TextComponentPeer peer = (TextComponentPeer)this.peer;
    if (peer != null) {
        peer.setCaretPosition(position);
    } else {
        select(position, position);
    }
}
 
Example 45
Project: OLD-OpenJDK8   File: TextComponent.java   Source Code and License 6 votes vote down vote up
/**
 * Returns the position of the text insertion caret.
 * The caret position is constrained to be between 0
 * and the last character of the text, inclusive.
 * If the text or caret have not been set, the default
 * caret position is 0.
 *
 * @return       the position of the text insertion caret
 * @see #setCaretPosition(int)
 * @since        JDK1.1
 */
public synchronized int getCaretPosition() {
    TextComponentPeer peer = (TextComponentPeer)this.peer;
    int position = 0;

    if (peer != null) {
        position = peer.getCaretPosition();
    } else {
        position = selectionStart;
    }
    int maxposition = getText().length();
    if (position > maxposition) {
        position = maxposition;
    }
    return position;
}
 
Example 46
Project: OLD-OpenJDK8   File: TextComponent.java   Source Code and License 6 votes vote down vote up
/**
 * Writes default serializable fields to stream.  Writes
 * a list of serializable TextListener(s) as optional data.
 * The non-serializable TextListener(s) are detected and
 * no attempt is made to serialize them.
 *
 * @serialData Null terminated sequence of zero or more pairs.
 *             A pair consists of a String and Object.
 *             The String indicates the type of object and
 *             is one of the following :
 *             textListenerK indicating and TextListener object.
 *
 * @see AWTEventMulticaster#save(ObjectOutputStream, String, EventListener)
 * @see java.awt.Component#textListenerK
 */
private void writeObject(java.io.ObjectOutputStream s)
  throws IOException
{
    // Serialization support.  Since the value of the fields
    // selectionStart, selectionEnd, and text aren't necessarily
    // up to date, we sync them up with the peer before serializing.
    TextComponentPeer peer = (TextComponentPeer)this.peer;
    if (peer != null) {
        text = peer.getText();
        selectionStart = peer.getSelectionStart();
        selectionEnd = peer.getSelectionEnd();
    }

    s.defaultWriteObject();

    AWTEventMulticaster.save(s, textListenerK, textListener);
    s.writeObject(null);
}
 
Example 47
Project: JamVM-PH   File: TextComponent.java   Source Code and License 6 votes vote down vote up
/**
 * This method sets the selected text range to the text between the
 * specified start and end positions.  Illegal values for these
 * positions are silently fixed.
 *
 * @param selectionStart The new start position for the selected text.
 * @param selectionEnd The new end position for the selected text.
 */
public synchronized void select(int selectionStart, int selectionEnd)
{
  if (selectionStart < 0)
    selectionStart = 0;

  if (selectionStart > getText().length())
    selectionStart = text.length();

  if (selectionEnd > text.length())
    selectionEnd = text.length();

  if (selectionStart > selectionEnd)
    selectionStart = selectionEnd;

  this.selectionStart = selectionStart;
  this.selectionEnd = selectionEnd;
  
  TextComponentPeer tcp = (TextComponentPeer) getPeer();
  if (tcp != null)
    tcp.select(selectionStart, selectionEnd);
}
 
Example 48
Project: openjdk-jdk7u-jdk   File: TextComponent.java   Source Code and License 6 votes vote down vote up
/**
 * Sets the position of the text insertion caret.
 * The caret position is constrained to be between 0
 * and the last character of the text, inclusive.
 * If the passed-in value is greater than this range,
 * the value is set to the last character (or 0 if
 * the <code>TextComponent</code> contains no text)
 * and no error is returned.  If the passed-in value is
 * less than 0, an <code>IllegalArgumentException</code>
 * is thrown.
 *
 * @param        position the position of the text insertion caret
 * @exception    IllegalArgumentException if <code>position</code>
 *               is less than zero
 * @since        JDK1.1
 */
public synchronized void setCaretPosition(int position) {
    if (position < 0) {
        throw new IllegalArgumentException("position less than zero.");
    }

    int maxposition = getText().length();
    if (position > maxposition) {
        position = maxposition;
    }

    TextComponentPeer peer = (TextComponentPeer)this.peer;
    if (peer != null) {
        peer.setCaretPosition(position);
    } else {
        select(position, position);
    }
}
 
Example 49
Project: openjdk-jdk7u-jdk   File: TextComponent.java   Source Code and License 6 votes vote down vote up
/**
 * Returns the position of the text insertion caret.
 * The caret position is constrained to be between 0
 * and the last character of the text, inclusive.
 * If the text or caret have not been set, the default
 * caret position is 0.
 *
 * @return       the position of the text insertion caret
 * @see #setCaretPosition(int)
 * @since        JDK1.1
 */
public synchronized int getCaretPosition() {
    TextComponentPeer peer = (TextComponentPeer)this.peer;
    int position = 0;

    if (peer != null) {
        position = peer.getCaretPosition();
    } else {
        position = selectionStart;
    }
    int maxposition = getText().length();
    if (position > maxposition) {
        position = maxposition;
    }
    return position;
}
 
Example 50
Project: openjdk-jdk7u-jdk   File: TextComponent.java   Source Code and License 6 votes vote down vote up
/**
 * Writes default serializable fields to stream.  Writes
 * a list of serializable TextListener(s) as optional data.
 * The non-serializable TextListener(s) are detected and
 * no attempt is made to serialize them.
 *
 * @serialData Null terminated sequence of zero or more pairs.
 *             A pair consists of a String and Object.
 *             The String indicates the type of object and
 *             is one of the following :
 *             textListenerK indicating and TextListener object.
 *
 * @see AWTEventMulticaster#save(ObjectOutputStream, String, EventListener)
 * @see java.awt.Component#textListenerK
 */
private void writeObject(java.io.ObjectOutputStream s)
  throws IOException
{
    // Serialization support.  Since the value of the fields
    // selectionStart, selectionEnd, and text aren't necessarily
    // up to date, we sync them up with the peer before serializing.
    TextComponentPeer peer = (TextComponentPeer)this.peer;
    if (peer != null) {
        text = peer.getText();
        selectionStart = peer.getSelectionStart();
        selectionEnd = peer.getSelectionEnd();
    }

    s.defaultWriteObject();

    AWTEventMulticaster.save(s, textListenerK, textListener);
    s.writeObject(null);
}
 
Example 51
Project: classpath   File: TextComponent.java   Source Code and License 6 votes vote down vote up
/**
 * This method sets the selected text range to the text between the
 * specified start and end positions.  Illegal values for these
 * positions are silently fixed.
 *
 * @param selectionStart The new start position for the selected text.
 * @param selectionEnd The new end position for the selected text.
 */
public synchronized void select(int selectionStart, int selectionEnd)
{
  if (selectionStart < 0)
    selectionStart = 0;

  if (selectionStart > getText().length())
    selectionStart = text.length();

  if (selectionEnd > text.length())
    selectionEnd = text.length();

  if (selectionStart > selectionEnd)
    selectionStart = selectionEnd;

  this.selectionStart = selectionStart;
  this.selectionEnd = selectionEnd;

  TextComponentPeer tcp = (TextComponentPeer) getPeer();
  if (tcp != null)
    tcp.select(selectionStart, selectionEnd);
}
 
Example 52
Project: openjdk-icedtea7   File: TextComponent.java   Source Code and License 6 votes vote down vote up
/**
 * Sets the position of the text insertion caret.
 * The caret position is constrained to be between 0
 * and the last character of the text, inclusive.
 * If the passed-in value is greater than this range,
 * the value is set to the last character (or 0 if
 * the <code>TextComponent</code> contains no text)
 * and no error is returned.  If the passed-in value is
 * less than 0, an <code>IllegalArgumentException</code>
 * is thrown.
 *
 * @param        position the position of the text insertion caret
 * @exception    IllegalArgumentException if <code>position</code>
 *               is less than zero
 * @since        JDK1.1
 */
public synchronized void setCaretPosition(int position) {
    if (position < 0) {
        throw new IllegalArgumentException("position less than zero.");
    }

    int maxposition = getText().length();
    if (position > maxposition) {
        position = maxposition;
    }

    TextComponentPeer peer = (TextComponentPeer)this.peer;
    if (peer != null) {
        peer.setCaretPosition(position);
    } else {
        select(position, position);
    }
}
 
Example 53
Project: openjdk-icedtea7   File: TextComponent.java   Source Code and License 6 votes vote down vote up
/**
 * Returns the position of the text insertion caret.
 * The caret position is constrained to be between 0
 * and the last character of the text, inclusive.
 * If the text or caret have not been set, the default
 * caret position is 0.
 *
 * @return       the position of the text insertion caret
 * @see #setCaretPosition(int)
 * @since        JDK1.1
 */
public synchronized int getCaretPosition() {
    TextComponentPeer peer = (TextComponentPeer)this.peer;
    int position = 0;

    if (peer != null) {
        position = peer.getCaretPosition();
    } else {
        position = selectionStart;
    }
    int maxposition = getText().length();
    if (position > maxposition) {
        position = maxposition;
    }
    return position;
}
 
Example 54
Project: openjdk-icedtea7   File: TextComponent.java   Source Code and License 6 votes vote down vote up
/**
 * Writes default serializable fields to stream.  Writes
 * a list of serializable TextListener(s) as optional data.
 * The non-serializable TextListener(s) are detected and
 * no attempt is made to serialize them.
 *
 * @serialData Null terminated sequence of zero or more pairs.
 *             A pair consists of a String and Object.
 *             The String indicates the type of object and
 *             is one of the following :
 *             textListenerK indicating and TextListener object.
 *
 * @see AWTEventMulticaster#save(ObjectOutputStream, String, EventListener)
 * @see java.awt.Component#textListenerK
 */
private void writeObject(java.io.ObjectOutputStream s)
  throws IOException
{
    // Serialization support.  Since the value of the fields
    // selectionStart, selectionEnd, and text aren't necessarily
    // up to date, we sync them up with the peer before serializing.
    TextComponentPeer peer = (TextComponentPeer)this.peer;
    if (peer != null) {
        text = peer.getText();
        selectionStart = peer.getSelectionStart();
        selectionEnd = peer.getSelectionEnd();
    }

    s.defaultWriteObject();

    AWTEventMulticaster.save(s, textListenerK, textListener);
    s.writeObject(null);
}
 
Example 55
Project: incubator-netbeans   File: FakePeerSupport.java   Source Code and License 5 votes vote down vote up
public static boolean attachFakePeer(Component comp) {
    if (comp == null || comp.isDisplayable()
          || comp instanceof javax.swing.JComponent
          || comp instanceof javax.swing.RootPaneContainer)
        return false;

    FakePeer peer = null;

    if (comp instanceof Label)
        peer = getFakePeer(LabelPeer.class, new FakeLabelPeer((Label) comp));
    else if (comp instanceof Button)
        peer = getFakePeer(ButtonPeer.class, new FakeButtonPeer((Button) comp));                   
    else if (comp instanceof Panel)
        peer = getFakePeer(new Class[] {ContainerPeer.class, PanelPeer.class}, new FakePanelPeer((Panel) comp));
    else if (comp instanceof TextField)
        peer = getFakePeer(new Class[] {TextFieldPeer.class, TextComponentPeer.class}, new FakeTextFieldPeer((TextField) comp));
    else if (comp instanceof TextArea)
        peer = getFakePeer(new Class[] {TextAreaPeer.class, TextComponentPeer.class}, new FakeTextAreaPeer((TextArea) comp));
    else if (comp instanceof TextComponent)
        peer = getFakePeer(TextComponentPeer.class, new FakeTextComponentPeer((TextComponent) comp));
    else if (comp instanceof Checkbox)
        peer = getFakePeer(CheckboxPeer.class, new FakeCheckboxPeer((Checkbox) comp));
    else if (comp instanceof Choice)
        peer = getFakePeer(ChoicePeer.class, new FakeChoicePeer((Choice) comp));
    else if (comp instanceof List)
        peer = getFakePeer(ListPeer.class, new FakeListPeer((List) comp));
    else if (comp instanceof Scrollbar)
        peer = getFakePeer(ScrollbarPeer.class, new FakeScrollbarPeer((Scrollbar) comp));
    else if (comp instanceof ScrollPane)
        peer = getFakePeer(new Class[] {ContainerPeer.class, ScrollPanePeer.class}, new FakeScrollPanePeer((ScrollPane) comp));
    else if (comp instanceof Canvas)
        peer = getFakePeer(CanvasPeer.class, new FakeCanvasPeer((Canvas) comp));
    else
        return false;

    attachFakePeer(comp, peer);
    return true;
}
 
Example 56
Project: OpenJSharp   File: TextComponent.java   Source Code and License 5 votes vote down vote up
/**
 * Removes the <code>TextComponent</code>'s peer.
 * The peer allows us to modify the appearance of the
 * <code>TextComponent</code> without changing its
 * functionality.
 */
public void removeNotify() {
    synchronized (getTreeLock()) {
        TextComponentPeer peer = (TextComponentPeer)this.peer;
        if (peer != null) {
            text = peer.getText();
            selectionStart = peer.getSelectionStart();
            selectionEnd = peer.getSelectionEnd();
        }
        super.removeNotify();
    }
}
 
Example 57
Project: OpenJSharp   File: TextComponent.java   Source Code and License 5 votes vote down vote up
/**
 * Sets the text that is presented by this
 * text component to be the specified text.
 * @param       t   the new text;
 *                  if this parameter is <code>null</code> then
 *                  the text is set to the empty string ""
 * @see         java.awt.TextComponent#getText
 */
public synchronized void setText(String t) {
    boolean skipTextEvent = (text == null || text.isEmpty())
            && (t == null || t.isEmpty());
    text = (t != null) ? t : "";
    TextComponentPeer peer = (TextComponentPeer)this.peer;
    // Please note that we do not want to post an event
    // if TextArea.setText() or TextField.setText() replaces an empty text
    // by an empty text, that is, if component's text remains unchanged.
    if (peer != null && !skipTextEvent) {
        peer.setText(text);
    }
}
 
Example 58
Project: OpenJSharp   File: TextComponent.java   Source Code and License 5 votes vote down vote up
/**
 * Returns the text that is presented by this text component.
 * By default, this is an empty string.
 *
 * @return the value of this <code>TextComponent</code>
 * @see     java.awt.TextComponent#setText
 */
public synchronized String getText() {
    TextComponentPeer peer = (TextComponentPeer)this.peer;
    if (peer != null) {
        text = peer.getText();
    }
    return text;
}
 
Example 59
Project: OpenJSharp   File: TextComponent.java   Source Code and License 5 votes vote down vote up
/**
 * Gets the start position of the selected text in
 * this text component.
 * @return      the start position of the selected text
 * @see         java.awt.TextComponent#setSelectionStart
 * @see         java.awt.TextComponent#getSelectionEnd
 */
public synchronized int getSelectionStart() {
    TextComponentPeer peer = (TextComponentPeer)this.peer;
    if (peer != null) {
        selectionStart = peer.getSelectionStart();
    }
    return selectionStart;
}
 
Example 60
Project: OpenJSharp   File: TextComponent.java   Source Code and License 5 votes vote down vote up
/**
 * Gets the end position of the selected text in
 * this text component.
 * @return      the end position of the selected text
 * @see         java.awt.TextComponent#setSelectionEnd
 * @see         java.awt.TextComponent#getSelectionStart
 */
public synchronized int getSelectionEnd() {
    TextComponentPeer peer = (TextComponentPeer)this.peer;
    if (peer != null) {
        selectionEnd = peer.getSelectionEnd();
    }
    return selectionEnd;
}