XAWTTextField(String text, XComponentPeer xwin, Container parent) { super(text); this.xwin = xwin; setDoubleBuffered(true); setFocusable(false); AWTAccessor.getComponentAccessor().setParent(this, parent); setBackground(xwin.getPeerBackground()); setForeground(xwin.getPeerForeground()); setFont(xwin.getPeerFont()); setCaretPosition(0); addActionListener(this); addNotify(); }
@Override public void dispose() { XToolkit.specialPeerMap.remove(xtext); // visible caret has a timer thread which must be stopped xtext.getCaret().setVisible(false); super.dispose(); }
@Override public void setBounds(int x, int y, int width, int height, int op) { super.setBounds(x, y, width, height, op); if (xtext != null) { /* * Fixed 6277332, 6198290: * the coordinates is coming (to peer): relatively to closest HW parent * the coordinates is setting (to textField): relatively to closest ANY parent * the parent of peer is target.getParent() * the parent of textField is the same * see 6277332, 6198290 for more information */ int childX = x; int childY = y; Component parent = target.getParent(); // we up to heavyweight parent in order to be sure // that the coordinates of the text pane is relatively to closest parent while (parent.isLightweight()) { childX -= parent.getX(); childY -= parent.getY(); parent = parent.getParent(); } xtext.setBounds(childX, childY, width, height); xtext.validate(); } }
/** @see java.awt.peer.ComponentPeer */ @Override public void setEnabled(boolean enabled) { super.setEnabled(enabled); if (xtext != null) { xtext.setEnabled(enabled); xtext.repaint(); } }
@Override @SuppressWarnings("deprecation") public void actionPerformed(ActionEvent actionEvent) { xwin.postEvent( new ActionEvent( xwin.target, ActionEvent.ACTION_PERFORMED, getText(), actionEvent.getWhen(), actionEvent.getModifiers())); }
@Override public void handleJavaMouseEvent(MouseEvent mouseEvent) { super.handleJavaMouseEvent(mouseEvent); if (xtext != null) { mouseEvent.setSource(xtext); int id = mouseEvent.getID(); if (id == MouseEvent.MOUSE_DRAGGED || id == MouseEvent.MOUSE_MOVED) xtext.processMouseMotionEventImpl(mouseEvent); else xtext.processMouseEventImpl(mouseEvent); } }
@Override public Graphics getGraphics() { return xwin.getGraphics(); }
@Override public void changedUpdate(DocumentEvent e) { if (xwin != null) { xwin.postEvent(new TextEvent(xwin.target, TextEvent.TEXT_VALUE_CHANGED)); } }
@Override public void setVisible(boolean b) { super.setVisible(b); if (xtext != null) xtext.setVisible(b); }
@Override public void focusGained(FocusEvent e) { super.focusGained(e); xtext.forwardFocusGained(e); }
@Override public void focusLost(FocusEvent e) { super.focusLost(e); xtext.forwardFocusLost(e); }