Java 类java.awt.im.InputContext 实例源码

项目:OpenJSharp    文件:JTextComponent.java   
public boolean importData(JComponent comp, Transferable t) {
    if (comp instanceof JTextComponent) {
        DataFlavor flavor = getFlavor(t.getTransferDataFlavors());

        if (flavor != null) {
            InputContext ic = comp.getInputContext();
            if (ic != null) {
                ic.endComposition();
            }
            try {
                String data = (String)t.getTransferData(flavor);

                ((JTextComponent)comp).replaceSelection(data);
                return true;
            } catch (UnsupportedFlavorException ufe) {
            } catch (IOException ioe) {
            }
        }
    }
    return false;
}
项目:jdk8u-jdk    文件:JTextComponent.java   
public boolean importData(JComponent comp, Transferable t) {
    if (comp instanceof JTextComponent) {
        DataFlavor flavor = getFlavor(t.getTransferDataFlavors());

        if (flavor != null) {
            InputContext ic = comp.getInputContext();
            if (ic != null) {
                ic.endComposition();
            }
            try {
                String data = (String)t.getTransferData(flavor);

                ((JTextComponent)comp).replaceSelection(data);
                return true;
            } catch (UnsupportedFlavorException ufe) {
            } catch (IOException ioe) {
            }
        }
    }
    return false;
}
项目:openjdk-jdk10    文件:JTextComponent.java   
public boolean importData(JComponent comp, Transferable t) {
    if (comp instanceof JTextComponent) {
        DataFlavor flavor = getFlavor(t.getTransferDataFlavors());

        if (flavor != null) {
            InputContext ic = comp.getInputContext();
            if (ic != null) {
                ic.endComposition();
            }
            try {
                String data = (String)t.getTransferData(flavor);

                ((JTextComponent)comp).replaceSelection(data);
                return true;
            } catch (UnsupportedFlavorException ufe) {
            } catch (IOException ioe) {
            }
        }
    }
    return false;
}
项目:openjdk9    文件:JTextComponent.java   
public boolean importData(JComponent comp, Transferable t) {
    if (comp instanceof JTextComponent) {
        DataFlavor flavor = getFlavor(t.getTransferDataFlavors());

        if (flavor != null) {
            InputContext ic = comp.getInputContext();
            if (ic != null) {
                ic.endComposition();
            }
            try {
                String data = (String)t.getTransferData(flavor);

                ((JTextComponent)comp).replaceSelection(data);
                return true;
            } catch (UnsupportedFlavorException ufe) {
            } catch (IOException ioe) {
            }
        }
    }
    return false;
}
项目:Java8CN    文件:JTextComponent.java   
public boolean importData(JComponent comp, Transferable t) {
    if (comp instanceof JTextComponent) {
        DataFlavor flavor = getFlavor(t.getTransferDataFlavors());

        if (flavor != null) {
            InputContext ic = comp.getInputContext();
            if (ic != null) {
                ic.endComposition();
            }
            try {
                String data = (String)t.getTransferData(flavor);

                ((JTextComponent)comp).replaceSelection(data);
                return true;
            } catch (UnsupportedFlavorException ufe) {
            } catch (IOException ioe) {
            }
        }
    }
    return false;
}
项目:jdk8u_jdk    文件:JTextComponent.java   
public boolean importData(JComponent comp, Transferable t) {
    if (comp instanceof JTextComponent) {
        DataFlavor flavor = getFlavor(t.getTransferDataFlavors());

        if (flavor != null) {
            InputContext ic = comp.getInputContext();
            if (ic != null) {
                ic.endComposition();
            }
            try {
                String data = (String)t.getTransferData(flavor);

                ((JTextComponent)comp).replaceSelection(data);
                return true;
            } catch (UnsupportedFlavorException ufe) {
            } catch (IOException ioe) {
            }
        }
    }
    return false;
}
项目:lookaside_java-1.8.0-openjdk    文件:JTextComponent.java   
public boolean importData(JComponent comp, Transferable t) {
    if (comp instanceof JTextComponent) {
        DataFlavor flavor = getFlavor(t.getTransferDataFlavors());

        if (flavor != null) {
            InputContext ic = comp.getInputContext();
            if (ic != null) {
                ic.endComposition();
            }
            try {
                String data = (String)t.getTransferData(flavor);

                ((JTextComponent)comp).replaceSelection(data);
                return true;
            } catch (UnsupportedFlavorException ufe) {
            } catch (IOException ioe) {
            }
        }
    }
    return false;
}
项目:intellij-ce-playground    文件:UIUtil.java   
@Nullable
public static String getCurrentKeyboardLayout() {
  InputContext instance = InputContext.getInstance();
  Class<? extends InputContext> instanceClass = instance.getClass();
  Class<?> superclass = instanceClass.getSuperclass();
  if (superclass.getName().equals("sun.awt.im.InputContext")) {
    try {
      Object inputMethodLocator = ReflectionUtil.getField(superclass, instance, null, "inputMethodLocator");
      Locale locale = ReflectionUtil.getField(inputMethodLocator.getClass(), inputMethodLocator, Locale.class, "locale");
      return locale.getLanguage().toUpperCase(Locale.getDefault());
    }
    catch (Exception ignored) {
    }
  }
  return null;
}
项目:jcadencii    文件:LyricTextBox.java   
public boolean isImeModeOn() {
    try {
        JTextField jtf = getJTextField();

        if (jtf == null) {
            return false;
        }

        InputContext ic = jtf.getInputContext();

        if (ic == null) {
            return false;
        }

        boolean ret = ic.isCompositionEnabled();

        return ret;
    } catch (Exception ex) {
        System.err.println("TextBoxEx#isImeModeOn; ex=" + ex);
    }

    return false;
}
项目:jcadencii    文件:LyricTextBox.java   
public void setImeModeOn(boolean value) {
    try {
        JTextField jtf = getJTextField();

        if (jtf == null) {
            return;
        }

        InputContext ic = jtf.getInputContext();

        if (ic == null) {
            return;
        }

        ic.setCompositionEnabled(value);
    } catch (Exception ex) {
        System.err.println("TextBoxEx#setImeModeOn; ex=" + ex);
    }
}
项目:jcadencii    文件:BTextBox.java   
public boolean isImeModeOn() {
    try {
        InputContext ic = getInputContext();

        if (ic == null) {
            return false;
        }

        boolean ret = ic.isCompositionEnabled();

        return ret;
    } catch (Exception ex) {
        System.err.println("BTextBox#isImeModeOn; ex=" + ex);
    }

    return false;
}
项目:infobip-open-jdk-8    文件:JTextComponent.java   
public boolean importData(JComponent comp, Transferable t) {
    if (comp instanceof JTextComponent) {
        DataFlavor flavor = getFlavor(t.getTransferDataFlavors());

        if (flavor != null) {
            InputContext ic = comp.getInputContext();
            if (ic != null) {
                ic.endComposition();
            }
            try {
                String data = (String)t.getTransferData(flavor);

                ((JTextComponent)comp).replaceSelection(data);
                return true;
            } catch (UnsupportedFlavorException ufe) {
            } catch (IOException ioe) {
            }
        }
    }
    return false;
}
项目:jdk8u-dev-jdk    文件:JTextComponent.java   
public boolean importData(JComponent comp, Transferable t) {
    if (comp instanceof JTextComponent) {
        DataFlavor flavor = getFlavor(t.getTransferDataFlavors());

        if (flavor != null) {
            InputContext ic = comp.getInputContext();
            if (ic != null) {
                ic.endComposition();
            }
            try {
                String data = (String)t.getTransferData(flavor);

                ((JTextComponent)comp).replaceSelection(data);
                return true;
            } catch (UnsupportedFlavorException ufe) {
            } catch (IOException ioe) {
            }
        }
    }
    return false;
}
项目:jdk7-jdk    文件:JTextComponent.java   
public boolean importData(JComponent comp, Transferable t) {
    if (comp instanceof JTextComponent) {
        DataFlavor flavor = getFlavor(t.getTransferDataFlavors());

        if (flavor != null) {
            InputContext ic = comp.getInputContext();
            if (ic != null) {
                ic.endComposition();
            }
            try {
                String data = (String)t.getTransferData(flavor);

                ((JTextComponent)comp).replaceSelection(data);
                return true;
            } catch (UnsupportedFlavorException ufe) {
            } catch (IOException ioe) {
            }
        }
    }
    return false;
}
项目:openjdk-source-code-learn    文件:JTextComponent.java   
public boolean importData(JComponent comp, Transferable t) {
    if (comp instanceof JTextComponent) {
        DataFlavor flavor = getFlavor(t.getTransferDataFlavors());

        if (flavor != null) {
            InputContext ic = comp.getInputContext();
            if (ic != null) {
                ic.endComposition();
            }
            try {
                String data = (String)t.getTransferData(flavor);

                ((JTextComponent)comp).replaceSelection(data);
                return true;
            } catch (UnsupportedFlavorException ufe) {
            } catch (IOException ioe) {
            }
        }
    }
    return false;
}
项目:OLD-OpenJDK8    文件:JTextComponent.java   
public boolean importData(JComponent comp, Transferable t) {
    if (comp instanceof JTextComponent) {
        DataFlavor flavor = getFlavor(t.getTransferDataFlavors());

        if (flavor != null) {
            InputContext ic = comp.getInputContext();
            if (ic != null) {
                ic.endComposition();
            }
            try {
                String data = (String)t.getTransferData(flavor);

                ((JTextComponent)comp).replaceSelection(data);
                return true;
            } catch (UnsupportedFlavorException ufe) {
            } catch (IOException ioe) {
            }
        }
    }
    return false;
}
项目:openjdk-jdk7u-jdk    文件:JTextComponent.java   
public boolean importData(JComponent comp, Transferable t) {
    if (comp instanceof JTextComponent) {
        DataFlavor flavor = getFlavor(t.getTransferDataFlavors());

        if (flavor != null) {
            InputContext ic = comp.getInputContext();
            if (ic != null) {
                ic.endComposition();
            }
            try {
                String data = (String)t.getTransferData(flavor);

                ((JTextComponent)comp).replaceSelection(data);
                return true;
            } catch (UnsupportedFlavorException ufe) {
            } catch (IOException ioe) {
            }
        }
    }
    return false;
}
项目:openjdk-icedtea7    文件:JTextComponent.java   
public boolean importData(JComponent comp, Transferable t) {
    if (comp instanceof JTextComponent) {
        DataFlavor flavor = getFlavor(t.getTransferDataFlavors());

        if (flavor != null) {
            InputContext ic = comp.getInputContext();
            if (ic != null) {
                ic.endComposition();
            }
            try {
                String data = (String)t.getTransferData(flavor);

                ((JTextComponent)comp).replaceSelection(data);
                return true;
            } catch (UnsupportedFlavorException ufe) {
            } catch (IOException ioe) {
            }
        }
    }
    return false;
}
项目:JavaGame    文件:Game.java   
/**
 * @author Redomar
 * @version Alpha 1.8.4
 */
public Game() {
    context = InputContext.getInstance();

    // The game can only be played in one distinct window size
    setMinimumSize(new Dimension(WIDTH * SCALE, HEIGHT * SCALE));
    setMaximumSize(new Dimension(WIDTH * SCALE, HEIGHT * SCALE));
    setPreferredSize(new Dimension(WIDTH * SCALE, HEIGHT * SCALE));

    setFrame(new JFrame(NAME));                                             // Creates the frame with a defined name
    getFrame().setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);              // Exits the program when user closes the frame
    getFrame().setLayout(new BorderLayout());
    getFrame().add(this, BorderLayout.CENTER);                       // Centers the canvas inside the JFrame
    getFrame().pack();                                                      // Sizes the frame so that all its contents are at or above their preferred sizes
    getFrame().setResizable(false);
    getFrame().setLocationRelativeTo(null);                                 // Centres the window on the screen
    getFrame().setVisible(true);

    requestFocus();
    setDevMode(false);
    setClosing(false);
}
项目:powertext    文件:RTATextTransferHandler.java   
/**
 * This method causes a transfer to a component from a clipboard or a
 * DND drop operation.  The Transferable represents the data to be
 * imported into the component.
 *
 * @param comp  The component to receive the transfer.  This
 *  argument is provided to enable sharing of TransferHandlers by
 *  multiple components.
 * @param t The data to import
 * @return <code>true</code> iff the data was inserted into the component.
 */
@Override
public boolean importData(JComponent comp, Transferable t) {

    JTextComponent c = (JTextComponent)comp;
    withinSameComponent = c==exportComp;

    // if we are importing to the same component that we exported from
    // then don't actually do anything if the drop location is inside
    // the drag location and set shouldRemove to false so that exportDone
    // knows not to remove any data
    if (withinSameComponent && c.getCaretPosition()>=p0 && c.getCaretPosition()<=p1) {
        shouldRemove = false;
        return true;
    }

    boolean imported = false;
    DataFlavor importFlavor = getImportFlavor(t.getTransferDataFlavors(), c);
    if (importFlavor != null) {
        try {
            InputContext ic = c.getInputContext();
            if (ic != null) {
                ic.endComposition();
            }
            Reader r = importFlavor.getReaderForText(t);
            handleReaderImport(r, c);
            imported = true;
        } catch (UnsupportedFlavorException ufe) {
            ufe.printStackTrace();
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
    }

    return imported;

}
项目:OpenJSharp    文件:Window.java   
/**
 * Gets the input context for this window. A window always has an input context,
 * which is shared by subcomponents unless they create and set their own.
 * @see Component#getInputContext
 * @since 1.2
 */
public InputContext getInputContext() {
    synchronized (inputContextLock) {
        if (inputContext == null) {
            inputContext = InputContext.getInstance();
        }
    }
    return inputContext;
}
项目:OpenJSharp    文件:JFormattedTextField.java   
/**
 * Processes any focus events, such as
 * <code>FocusEvent.FOCUS_GAINED</code> or
 * <code>FocusEvent.FOCUS_LOST</code>.
 *
 * @param e the <code>FocusEvent</code>
 * @see FocusEvent
 */
protected void processFocusEvent(FocusEvent e) {
    super.processFocusEvent(e);

    // ignore temporary focus event
    if (e.isTemporary()) {
        return;
    }

    if (isEdited() && e.getID() == FocusEvent.FOCUS_LOST) {
        InputContext ic = getInputContext();
        if (focusLostHandler == null) {
            focusLostHandler = new FocusLostHandler();
        }

        // if there is a composed text, process it first
        if ((ic != null) && composedTextExists) {
            ic.endComposition();
            EventQueue.invokeLater(focusLostHandler);
        } else {
            focusLostHandler.run();
        }
    }
    else if (!isEdited()) {
        // reformat
        setValue(getValue(), true, true);
    }
}
项目:jdk8u-jdk    文件:Window.java   
/**
 * Gets the input context for this window. A window always has an input context,
 * which is shared by subcomponents unless they create and set their own.
 * @see Component#getInputContext
 * @since 1.2
 */
public InputContext getInputContext() {
    synchronized (inputContextLock) {
        if (inputContext == null) {
            inputContext = InputContext.getInstance();
        }
    }
    return inputContext;
}
项目:jdk8u-jdk    文件:JFormattedTextField.java   
/**
 * Processes any focus events, such as
 * <code>FocusEvent.FOCUS_GAINED</code> or
 * <code>FocusEvent.FOCUS_LOST</code>.
 *
 * @param e the <code>FocusEvent</code>
 * @see FocusEvent
 */
protected void processFocusEvent(FocusEvent e) {
    super.processFocusEvent(e);

    // ignore temporary focus event
    if (e.isTemporary()) {
        return;
    }

    if (isEdited() && e.getID() == FocusEvent.FOCUS_LOST) {
        InputContext ic = getInputContext();
        if (focusLostHandler == null) {
            focusLostHandler = new FocusLostHandler();
        }

        // if there is a composed text, process it first
        if ((ic != null) && composedTextExists) {
            ic.endComposition();
            EventQueue.invokeLater(focusLostHandler);
        } else {
            focusLostHandler.run();
        }
    }
    else if (!isEdited()) {
        // reformat
        setValue(getValue(), true, true);
    }
}
项目:openjdk-jdk10    文件:Window.java   
/**
 * Gets the input context for this window. A window always has an input context,
 * which is shared by subcomponents unless they create and set their own.
 * @see Component#getInputContext
 * @since 1.2
 */
public InputContext getInputContext() {
    synchronized (inputContextLock) {
        if (inputContext == null) {
            inputContext = InputContext.getInstance();
        }
    }
    return inputContext;
}
项目:openjdk-jdk10    文件:JFormattedTextField.java   
/**
 * Processes any focus events, such as
 * <code>FocusEvent.FOCUS_GAINED</code> or
 * <code>FocusEvent.FOCUS_LOST</code>.
 *
 * @param e the <code>FocusEvent</code>
 * @see FocusEvent
 */
protected void processFocusEvent(FocusEvent e) {
    super.processFocusEvent(e);

    // ignore temporary focus event
    if (e.isTemporary()) {
        return;
    }

    if (isEdited() && e.getID() == FocusEvent.FOCUS_LOST) {
        InputContext ic = getInputContext();
        if (focusLostHandler == null) {
            focusLostHandler = new FocusLostHandler();
        }

        // if there is a composed text, process it first
        if ((ic != null) && composedTextExists) {
            ic.endComposition();
            EventQueue.invokeLater(focusLostHandler);
        } else {
            focusLostHandler.run();
        }
    }
    else if (!isEdited()) {
        // reformat
        setValue(getValue(), true, true);
    }
}
项目:openjdk-jdk10    文件:HeadlessInputContext.java   
public static void main(String args[]) {
    InputContext ic = InputContext.getInstance();

    for (Locale locale : Locale.getAvailableLocales())
        ic.selectInputMethod(locale);

    ic.getLocale();
}
项目:openjdk-jdk10    文件:ComponentOperator.java   
/**
 * Maps {@code Component.getInputContext()} through queue
 */
public InputContext getInputContext() {
    return (runMapping(new MapAction<InputContext>("getInputContext") {
        @Override
        public InputContext map() {
            return getSource().getInputContext();
        }
    }));
}
项目:openjdk9    文件:Window.java   
/**
 * Gets the input context for this window. A window always has an input context,
 * which is shared by subcomponents unless they create and set their own.
 * @see Component#getInputContext
 * @since 1.2
 */
public InputContext getInputContext() {
    synchronized (inputContextLock) {
        if (inputContext == null) {
            inputContext = InputContext.getInstance();
        }
    }
    return inputContext;
}
项目:openjdk9    文件:JFormattedTextField.java   
/**
 * Processes any focus events, such as
 * <code>FocusEvent.FOCUS_GAINED</code> or
 * <code>FocusEvent.FOCUS_LOST</code>.
 *
 * @param e the <code>FocusEvent</code>
 * @see FocusEvent
 */
protected void processFocusEvent(FocusEvent e) {
    super.processFocusEvent(e);

    // ignore temporary focus event
    if (e.isTemporary()) {
        return;
    }

    if (isEdited() && e.getID() == FocusEvent.FOCUS_LOST) {
        InputContext ic = getInputContext();
        if (focusLostHandler == null) {
            focusLostHandler = new FocusLostHandler();
        }

        // if there is a composed text, process it first
        if ((ic != null) && composedTextExists) {
            ic.endComposition();
            EventQueue.invokeLater(focusLostHandler);
        } else {
            focusLostHandler.run();
        }
    }
    else if (!isEdited()) {
        // reformat
        setValue(getValue(), true, true);
    }
}
项目:openjdk9    文件:HeadlessInputContext.java   
public static void main(String args[]) {
    InputContext ic = InputContext.getInstance();

    for (Locale locale : Locale.getAvailableLocales())
        ic.selectInputMethod(locale);

    ic.getLocale();
}
项目:openjdk9    文件:ComponentOperator.java   
/**
 * Maps {@code Component.getInputContext()} through queue
 */
public InputContext getInputContext() {
    return (runMapping(new MapAction<InputContext>("getInputContext") {
        @Override
        public InputContext map() {
            return getSource().getInputContext();
        }
    }));
}
项目:Java8CN    文件:Window.java   
/**
 * Gets the input context for this window. A window always has an input context,
 * which is shared by subcomponents unless they create and set their own.
 * @see Component#getInputContext
 * @since 1.2
 */
public InputContext getInputContext() {
    synchronized (inputContextLock) {
        if (inputContext == null) {
            inputContext = InputContext.getInstance();
        }
    }
    return inputContext;
}
项目:Java8CN    文件:JFormattedTextField.java   
/**
 * Processes any focus events, such as
 * <code>FocusEvent.FOCUS_GAINED</code> or
 * <code>FocusEvent.FOCUS_LOST</code>.
 *
 * @param e the <code>FocusEvent</code>
 * @see FocusEvent
 */
protected void processFocusEvent(FocusEvent e) {
    super.processFocusEvent(e);

    // ignore temporary focus event
    if (e.isTemporary()) {
        return;
    }

    if (isEdited() && e.getID() == FocusEvent.FOCUS_LOST) {
        InputContext ic = getInputContext();
        if (focusLostHandler == null) {
            focusLostHandler = new FocusLostHandler();
        }

        // if there is a composed text, process it first
        if ((ic != null) && composedTextExists) {
            ic.endComposition();
            EventQueue.invokeLater(focusLostHandler);
        } else {
            focusLostHandler.run();
        }
    }
    else if (!isEdited()) {
        // reformat
        setValue(getValue(), true, true);
    }
}
项目:ftc    文件:RTATextTransferHandler.java   
/**
 * This method causes a transfer to a component from a clipboard or a 
 * DND drop operation.  The Transferable represents the data to be
 * imported into the component.  
 *
 * @param comp  The component to receive the transfer.  This
 *  argument is provided to enable sharing of TransferHandlers by
 *  multiple components.
 * @param t The data to import
 * @return <code>true</code> iff the data was inserted into the component.
 */
@Override
public boolean importData(JComponent comp, Transferable t) {

    JTextComponent c = (JTextComponent)comp;
    withinSameComponent = c==exportComp;

    // if we are importing to the same component that we exported from
    // then don't actually do anything if the drop location is inside
    // the drag location and set shouldRemove to false so that exportDone
    // knows not to remove any data
    if (withinSameComponent && c.getCaretPosition()>=p0 && c.getCaretPosition()<=p1) {
        shouldRemove = false;
        return true;
    }

    boolean imported = false;
    DataFlavor importFlavor = getImportFlavor(t.getTransferDataFlavors(), c);
    if (importFlavor != null) {
        try {
            InputContext ic = c.getInputContext();
            if (ic != null)
                ic.endComposition();
            Reader r = importFlavor.getReaderForText(t);
            handleReaderImport(r, c);
            imported = true;
        } catch (UnsupportedFlavorException ufe) {
            ufe.printStackTrace();
        } catch (BadLocationException ble) {
            ble.printStackTrace();
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
    }

    return imported;

}
项目:jdk8u_jdk    文件:Window.java   
/**
 * Gets the input context for this window. A window always has an input context,
 * which is shared by subcomponents unless they create and set their own.
 * @see Component#getInputContext
 * @since 1.2
 */
public InputContext getInputContext() {
    synchronized (inputContextLock) {
        if (inputContext == null) {
            inputContext = InputContext.getInstance();
        }
    }
    return inputContext;
}
项目:jdk8u_jdk    文件:JFormattedTextField.java   
/**
 * Processes any focus events, such as
 * <code>FocusEvent.FOCUS_GAINED</code> or
 * <code>FocusEvent.FOCUS_LOST</code>.
 *
 * @param e the <code>FocusEvent</code>
 * @see FocusEvent
 */
protected void processFocusEvent(FocusEvent e) {
    super.processFocusEvent(e);

    // ignore temporary focus event
    if (e.isTemporary()) {
        return;
    }

    if (isEdited() && e.getID() == FocusEvent.FOCUS_LOST) {
        InputContext ic = getInputContext();
        if (focusLostHandler == null) {
            focusLostHandler = new FocusLostHandler();
        }

        // if there is a composed text, process it first
        if ((ic != null) && composedTextExists) {
            ic.endComposition();
            EventQueue.invokeLater(focusLostHandler);
        } else {
            focusLostHandler.run();
        }
    }
    else if (!isEdited()) {
        // reformat
        setValue(getValue(), true, true);
    }
}
项目:lookaside_java-1.8.0-openjdk    文件:Window.java   
/**
 * Gets the input context for this window. A window always has an input context,
 * which is shared by subcomponents unless they create and set their own.
 * @see Component#getInputContext
 * @since 1.2
 */
public InputContext getInputContext() {
    synchronized (inputContextLock) {
        if (inputContext == null) {
            inputContext = InputContext.getInstance();
        }
    }
    return inputContext;
}
项目:lookaside_java-1.8.0-openjdk    文件:JFormattedTextField.java   
/**
 * Processes any focus events, such as
 * <code>FocusEvent.FOCUS_GAINED</code> or
 * <code>FocusEvent.FOCUS_LOST</code>.
 *
 * @param e the <code>FocusEvent</code>
 * @see FocusEvent
 */
protected void processFocusEvent(FocusEvent e) {
    super.processFocusEvent(e);

    // ignore temporary focus event
    if (e.isTemporary()) {
        return;
    }

    if (isEdited() && e.getID() == FocusEvent.FOCUS_LOST) {
        InputContext ic = getInputContext();
        if (focusLostHandler == null) {
            focusLostHandler = new FocusLostHandler();
        }

        // if there is a composed text, process it first
        if ((ic != null) && composedTextExists) {
            ic.endComposition();
            EventQueue.invokeLater(focusLostHandler);
        } else {
            focusLostHandler.run();
        }
    }
    else if (!isEdited()) {
        // reformat
        setValue(getValue(), true, true);
    }
}
项目:Tank    文件:RTATextTransferHandler.java   
/**
 * This method causes a transfer to a component from a clipboard or a DND drop operation. The Transferable
 * represents the data to be imported into the component.
 * 
 * @param comp
 *            The component to receive the transfer. This argument is provided to enable sharing of TransferHandlers
 *            by multiple components.
 * @param t
 *            The data to import
 * @return <code>true</code> iff the data was inserted into the component.
 */
public boolean importData(JComponent comp, Transferable t) {

    JTextComponent c = (JTextComponent) comp;
    withinSameComponent = c == exportComp;

    // if we are importing to the same component that we exported from
    // then don't actually do anything if the drop location is inside
    // the drag location and set shouldRemove to false so that exportDone
    // knows not to remove any data
    if (withinSameComponent && c.getCaretPosition() >= p0 && c.getCaretPosition() <= p1) {
        shouldRemove = false;
        return true;
    }

    boolean imported = false;
    DataFlavor importFlavor = getImportFlavor(t.getTransferDataFlavors(), c);
    if (importFlavor != null) {
        try {
            InputContext ic = c.getInputContext();
            if (ic != null)
                ic.endComposition();
            Reader r = importFlavor.getReaderForText(t);
            handleReaderImport(r, c);
            imported = true;
        } catch (UnsupportedFlavorException ufe) {
            ufe.printStackTrace();
        } catch (BadLocationException ble) {
            ble.printStackTrace();
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
    }

    return imported;

}