< prev index next >

src/java.desktop/unix/classes/sun/awt/X11/XTextFieldPeer.java

Print this page




  78             setEchoChar(target.getEchoChar());
  79         }
  80         else setEchoChar((char)0);
  81 
  82         int start = target.getSelectionStart();
  83         int end = target.getSelectionEnd();
  84         // Fix for 5100200
  85         // Restoring Motif behaviour
  86         // Since the end position of the selected text can be greater then the length of the text,
  87         // so we should set caret to max position of the text
  88         setCaretPosition(Math.min(end, text.length()));
  89         if (end > start) {
  90             // Should be called after setText() and setCaretPosition()
  91             select(start, end);
  92         }
  93 
  94         setEditable(target.isEditable());
  95 
  96         // After this line we should not change the component's text
  97         firstChangeSkipped = true;

  98     }
  99 
 100     @Override
 101     public void dispose() {
 102         XToolkit.specialPeerMap.remove(xtext);
 103         // visible caret has a timer thread which must be stopped
 104         xtext.getCaret().setVisible(false);
 105         xtext.removeNotify();
 106         super.dispose();
 107     }
 108 
 109     void initTextField() {
 110         setVisible(target.isVisible());
 111 
 112         setBounds(x, y, width, height, SET_BOUNDS);
 113 
 114         AWTAccessor.ComponentAccessor compAccessor = AWTAccessor.getComponentAccessor();
 115         foreground = compAccessor.getForeground(target);
 116         if (foreground == null)
 117             foreground = SystemColor.textText;
 118 
 119         setForeground(foreground);
 120 
 121         background = compAccessor.getBackground(target);
 122         if (background == null) {
 123             if (((TextField)target).isEditable()) background = SystemColor.text;
 124             else background = SystemColor.control;
 125         }


 242     /**
 243      * to be implemented.
 244      * @see java.awt.peer.TextComponentPeer
 245      */
 246     @Override
 247     public void setCaretPosition(int position) {
 248         if (xtext != null) xtext.setCaretPosition(position);
 249     }
 250 
 251     void repaintText() {
 252         xtext.repaintNow();
 253     }
 254 
 255     @Override
 256     public void setBackground(Color c) {
 257         if (log.isLoggable(PlatformLogger.Level.FINE)) {
 258             log.fine("target="+ target + ", old=" + background + ", new=" + c);
 259         }
 260         background = c;
 261         if (xtext != null) {

 262             xtext.setBackground(c);

 263             xtext.setSelectedTextColor(c);
 264         }
 265         repaintText();
 266     }
 267 
 268     @Override
 269     public void setForeground(Color c) {
 270         foreground = c;
 271         if (xtext != null) {

 272             xtext.setForeground(foreground);

 273             xtext.setSelectionColor(foreground);
 274             xtext.setCaretColor(foreground);
 275         }
 276         repaintText();
 277     }
 278 
 279     @Override
 280     public void setFont(Font f) {
 281         synchronized (getStateLock()) {
 282             font = f;
 283             if (xtext != null) {
 284                 xtext.setFont(font);
 285             }
 286         }
 287         xtext.validate();
 288     }
 289 
 290     /**
 291      * Deselects the highlighted text.
 292      */
 293     public void deselect() {
 294         int selStart=xtext.getSelectionStart();
 295         int selEnd=xtext.getSelectionEnd();
 296         if (selStart != selEnd) {
 297             xtext.select(selStart,selStart);
 298         }
 299     }
 300 
 301     /**
 302      * to be implemented.
 303      * @see java.awt.peer.TextComponentPeer




  78             setEchoChar(target.getEchoChar());
  79         }
  80         else setEchoChar((char)0);
  81 
  82         int start = target.getSelectionStart();
  83         int end = target.getSelectionEnd();
  84         // Fix for 5100200
  85         // Restoring Motif behaviour
  86         // Since the end position of the selected text can be greater then the length of the text,
  87         // so we should set caret to max position of the text
  88         setCaretPosition(Math.min(end, text.length()));
  89         if (end > start) {
  90             // Should be called after setText() and setCaretPosition()
  91             select(start, end);
  92         }
  93 
  94         setEditable(target.isEditable());
  95 
  96         // After this line we should not change the component's text
  97         firstChangeSkipped = true;
  98         AWTAccessor.getComponentAccessor().setPeer(xtext, this);
  99     }
 100 
 101     @Override
 102     public void dispose() {
 103         XToolkit.specialPeerMap.remove(xtext);
 104         // visible caret has a timer thread which must be stopped
 105         xtext.getCaret().setVisible(false);

 106         super.dispose();
 107     }
 108 
 109     void initTextField() {
 110         setVisible(target.isVisible());
 111 
 112         setBounds(x, y, width, height, SET_BOUNDS);
 113 
 114         AWTAccessor.ComponentAccessor compAccessor = AWTAccessor.getComponentAccessor();
 115         foreground = compAccessor.getForeground(target);
 116         if (foreground == null)
 117             foreground = SystemColor.textText;
 118 
 119         setForeground(foreground);
 120 
 121         background = compAccessor.getBackground(target);
 122         if (background == null) {
 123             if (((TextField)target).isEditable()) background = SystemColor.text;
 124             else background = SystemColor.control;
 125         }


 242     /**
 243      * to be implemented.
 244      * @see java.awt.peer.TextComponentPeer
 245      */
 246     @Override
 247     public void setCaretPosition(int position) {
 248         if (xtext != null) xtext.setCaretPosition(position);
 249     }
 250 
 251     void repaintText() {
 252         xtext.repaintNow();
 253     }
 254 
 255     @Override
 256     public void setBackground(Color c) {
 257         if (log.isLoggable(PlatformLogger.Level.FINE)) {
 258             log.fine("target="+ target + ", old=" + background + ", new=" + c);
 259         }
 260         background = c;
 261         if (xtext != null) {
 262             if (xtext.getBackground() != c) {
 263                 xtext.setBackground(c);
 264             }
 265             xtext.setSelectedTextColor(c);
 266         }
 267         repaintText();
 268     }
 269 
 270     @Override
 271     public void setForeground(Color c) {
 272         foreground = c;
 273         if (xtext != null) {
 274             if (xtext.getForeground() != c) {
 275                 xtext.setForeground(foreground);
 276             }
 277             xtext.setSelectionColor(foreground);
 278             xtext.setCaretColor(foreground);
 279         }
 280         repaintText();
 281     }
 282 
 283     @Override
 284     public void setFont(Font f) {
 285         synchronized (getStateLock()) {
 286             font = f;
 287             if (xtext != null && xtext.getFont() != f) {
 288                 xtext.setFont(font);
 289             }
 290         }
 291         xtext.validate();
 292     }
 293 
 294     /**
 295      * Deselects the highlighted text.
 296      */
 297     public void deselect() {
 298         int selStart=xtext.getSelectionStart();
 299         int selEnd=xtext.getSelectionEnd();
 300         if (selStart != selEnd) {
 301             xtext.select(selStart,selStart);
 302         }
 303     }
 304 
 305     /**
 306      * to be implemented.
 307      * @see java.awt.peer.TextComponentPeer


< prev index next >