Java Code Examples for sun.swing.SwingUtilities2#canCurrentEventAccessSystemClipboard()

The following examples show how to use sun.swing.SwingUtilities2#canCurrentEventAccessSystemClipboard() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultCaret.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void updateSystemSelection() {
    if ( ! SwingUtilities2.canCurrentEventAccessSystemClipboard() ) {
        return;
    }
    if (this.dot != this.mark && component != null && component.hasFocus()) {
        Clipboard clip = getSystemSelection();
        if (clip != null) {
            String selectedText;
            if (component instanceof JPasswordField
                && component.getClientProperty("JPasswordField.cutCopyAllowed") !=
                Boolean.TRUE) {
                //fix for 4793761
                StringBuilder txt = null;
                char echoChar = ((JPasswordField)component).getEchoChar();
                int p0 = Math.min(getDot(), getMark());
                int p1 = Math.max(getDot(), getMark());
                for (int i = p0; i < p1; i++) {
                    if (txt == null) {
                        txt = new StringBuilder();
                    }
                    txt.append(echoChar);
                }
                selectedText = (txt != null) ? txt.toString() : null;
            } else {
                selectedText = component.getSelectedText();
            }
            try {
                clip.setContents(
                    new StringSelection(selectedText), getClipboardOwner());

                ownsSelection = true;
            } catch (IllegalStateException ise) {
                // clipboard was unavailable
                // no need to provide error feedback to user since updating
                // the system selection is not a user invoked action
            }
        }
    }
}
 
Example 2
Source File: DefaultCaret.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private void updateSystemSelection() {
    if ( ! SwingUtilities2.canCurrentEventAccessSystemClipboard() ) {
        return;
    }
    if (this.dot != this.mark && component != null && component.hasFocus()) {
        Clipboard clip = getSystemSelection();
        if (clip != null) {
            String selectedText;
            if (component instanceof JPasswordField
                && component.getClientProperty("JPasswordField.cutCopyAllowed") !=
                Boolean.TRUE) {
                //fix for 4793761
                StringBuilder txt = null;
                char echoChar = ((JPasswordField)component).getEchoChar();
                int p0 = Math.min(getDot(), getMark());
                int p1 = Math.max(getDot(), getMark());
                for (int i = p0; i < p1; i++) {
                    if (txt == null) {
                        txt = new StringBuilder();
                    }
                    txt.append(echoChar);
                }
                selectedText = (txt != null) ? txt.toString() : null;
            } else {
                selectedText = component.getSelectedText();
            }
            try {
                clip.setContents(
                    new StringSelection(selectedText), getClipboardOwner());

                ownsSelection = true;
            } catch (IllegalStateException ise) {
                // clipboard was unavailable
                // no need to provide error feedback to user since updating
                // the system selection is not a user invoked action
            }
        }
    }
}
 
Example 3
Source File: DefaultCaret.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private void updateSystemSelection() {
    if ( ! SwingUtilities2.canCurrentEventAccessSystemClipboard() ) {
        return;
    }
    if (this.dot != this.mark && component != null && component.hasFocus()) {
        Clipboard clip = getSystemSelection();
        if (clip != null) {
            String selectedText;
            if (component instanceof JPasswordField
                && component.getClientProperty("JPasswordField.cutCopyAllowed") !=
                Boolean.TRUE) {
                //fix for 4793761
                StringBuilder txt = null;
                char echoChar = ((JPasswordField)component).getEchoChar();
                int p0 = Math.min(getDot(), getMark());
                int p1 = Math.max(getDot(), getMark());
                for (int i = p0; i < p1; i++) {
                    if (txt == null) {
                        txt = new StringBuilder();
                    }
                    txt.append(echoChar);
                }
                selectedText = (txt != null) ? txt.toString() : null;
            } else {
                selectedText = component.getSelectedText();
            }
            try {
                clip.setContents(
                    new StringSelection(selectedText), getClipboardOwner());

                ownsSelection = true;
            } catch (IllegalStateException ise) {
                // clipboard was unavailable
                // no need to provide error feedback to user since updating
                // the system selection is not a user invoked action
            }
        }
    }
}
 
Example 4
Source File: DefaultCaret.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private void updateSystemSelection() {
    if ( ! SwingUtilities2.canCurrentEventAccessSystemClipboard() ) {
        return;
    }
    if (this.dot != this.mark && component != null && component.hasFocus()) {
        Clipboard clip = getSystemSelection();
        if (clip != null) {
            String selectedText;
            if (component instanceof JPasswordField
                && component.getClientProperty("JPasswordField.cutCopyAllowed") !=
                Boolean.TRUE) {
                //fix for 4793761
                StringBuilder txt = null;
                char echoChar = ((JPasswordField)component).getEchoChar();
                int p0 = Math.min(getDot(), getMark());
                int p1 = Math.max(getDot(), getMark());
                for (int i = p0; i < p1; i++) {
                    if (txt == null) {
                        txt = new StringBuilder();
                    }
                    txt.append(echoChar);
                }
                selectedText = (txt != null) ? txt.toString() : null;
            } else {
                selectedText = component.getSelectedText();
            }
            try {
                clip.setContents(
                    new StringSelection(selectedText), getClipboardOwner());

                ownsSelection = true;
            } catch (IllegalStateException ise) {
                // clipboard was unavailable
                // no need to provide error feedback to user since updating
                // the system selection is not a user invoked action
            }
        }
    }
}
 
Example 5
Source File: DefaultCaret.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private void updateSystemSelection() {
    if ( ! SwingUtilities2.canCurrentEventAccessSystemClipboard() ) {
        return;
    }
    if (this.dot != this.mark && component != null && component.hasFocus()) {
        Clipboard clip = getSystemSelection();
        if (clip != null) {
            String selectedText;
            if (component instanceof JPasswordField
                && component.getClientProperty("JPasswordField.cutCopyAllowed") !=
                Boolean.TRUE) {
                //fix for 4793761
                StringBuilder txt = null;
                char echoChar = ((JPasswordField)component).getEchoChar();
                int p0 = Math.min(getDot(), getMark());
                int p1 = Math.max(getDot(), getMark());
                for (int i = p0; i < p1; i++) {
                    if (txt == null) {
                        txt = new StringBuilder();
                    }
                    txt.append(echoChar);
                }
                selectedText = (txt != null) ? txt.toString() : null;
            } else {
                selectedText = component.getSelectedText();
            }
            try {
                clip.setContents(
                    new StringSelection(selectedText), getClipboardOwner());

                ownsSelection = true;
            } catch (IllegalStateException ise) {
                // clipboard was unavailable
                // no need to provide error feedback to user since updating
                // the system selection is not a user invoked action
            }
        }
    }
}
 
Example 6
Source File: DefaultCaret.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private void updateSystemSelection() {
    if ( ! SwingUtilities2.canCurrentEventAccessSystemClipboard() ) {
        return;
    }
    if (this.dot != this.mark && component != null && component.hasFocus()) {
        Clipboard clip = getSystemSelection();
        if (clip != null) {
            String selectedText;
            if (component instanceof JPasswordField
                && component.getClientProperty("JPasswordField.cutCopyAllowed") !=
                Boolean.TRUE) {
                //fix for 4793761
                StringBuilder txt = null;
                char echoChar = ((JPasswordField)component).getEchoChar();
                int p0 = Math.min(getDot(), getMark());
                int p1 = Math.max(getDot(), getMark());
                for (int i = p0; i < p1; i++) {
                    if (txt == null) {
                        txt = new StringBuilder();
                    }
                    txt.append(echoChar);
                }
                selectedText = (txt != null) ? txt.toString() : null;
            } else {
                selectedText = component.getSelectedText();
            }
            try {
                clip.setContents(
                    new StringSelection(selectedText), getClipboardOwner());

                ownsSelection = true;
            } catch (IllegalStateException ise) {
                // clipboard was unavailable
                // no need to provide error feedback to user since updating
                // the system selection is not a user invoked action
            }
        }
    }
}
 
Example 7
Source File: DefaultCaret.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private void updateSystemSelection() {
    if ( ! SwingUtilities2.canCurrentEventAccessSystemClipboard() ) {
        return;
    }
    if (this.dot != this.mark && component != null && component.hasFocus()) {
        Clipboard clip = getSystemSelection();
        if (clip != null) {
            String selectedText;
            if (component instanceof JPasswordField
                && component.getClientProperty("JPasswordField.cutCopyAllowed") !=
                Boolean.TRUE) {
                //fix for 4793761
                StringBuilder txt = null;
                char echoChar = ((JPasswordField)component).getEchoChar();
                int p0 = Math.min(getDot(), getMark());
                int p1 = Math.max(getDot(), getMark());
                for (int i = p0; i < p1; i++) {
                    if (txt == null) {
                        txt = new StringBuilder();
                    }
                    txt.append(echoChar);
                }
                selectedText = (txt != null) ? txt.toString() : null;
            } else {
                selectedText = component.getSelectedText();
            }
            try {
                clip.setContents(
                    new StringSelection(selectedText), getClipboardOwner());

                ownsSelection = true;
            } catch (IllegalStateException ise) {
                // clipboard was unavailable
                // no need to provide error feedback to user since updating
                // the system selection is not a user invoked action
            }
        }
    }
}
 
Example 8
Source File: DefaultCaret.java    From Java8CN with Apache License 2.0 5 votes vote down vote up
private void updateSystemSelection() {
    if ( ! SwingUtilities2.canCurrentEventAccessSystemClipboard() ) {
        return;
    }
    if (this.dot != this.mark && component != null && component.hasFocus()) {
        Clipboard clip = getSystemSelection();
        if (clip != null) {
            String selectedText;
            if (component instanceof JPasswordField
                && component.getClientProperty("JPasswordField.cutCopyAllowed") !=
                Boolean.TRUE) {
                //fix for 4793761
                StringBuilder txt = null;
                char echoChar = ((JPasswordField)component).getEchoChar();
                int p0 = Math.min(getDot(), getMark());
                int p1 = Math.max(getDot(), getMark());
                for (int i = p0; i < p1; i++) {
                    if (txt == null) {
                        txt = new StringBuilder();
                    }
                    txt.append(echoChar);
                }
                selectedText = (txt != null) ? txt.toString() : null;
            } else {
                selectedText = component.getSelectedText();
            }
            try {
                clip.setContents(
                    new StringSelection(selectedText), getClipboardOwner());

                ownsSelection = true;
            } catch (IllegalStateException ise) {
                // clipboard was unavailable
                // no need to provide error feedback to user since updating
                // the system selection is not a user invoked action
            }
        }
    }
}
 
Example 9
Source File: DefaultCaret.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private void updateSystemSelection() {
    if ( ! SwingUtilities2.canCurrentEventAccessSystemClipboard() ) {
        return;
    }
    if (this.dot != this.mark && component != null && component.hasFocus()) {
        Clipboard clip = getSystemSelection();
        if (clip != null) {
            String selectedText;
            if (component instanceof JPasswordField
                && component.getClientProperty("JPasswordField.cutCopyAllowed") !=
                Boolean.TRUE) {
                //fix for 4793761
                StringBuilder txt = null;
                char echoChar = ((JPasswordField)component).getEchoChar();
                int p0 = Math.min(getDot(), getMark());
                int p1 = Math.max(getDot(), getMark());
                for (int i = p0; i < p1; i++) {
                    if (txt == null) {
                        txt = new StringBuilder();
                    }
                    txt.append(echoChar);
                }
                selectedText = (txt != null) ? txt.toString() : null;
            } else {
                selectedText = component.getSelectedText();
            }
            try {
                clip.setContents(
                    new StringSelection(selectedText), getClipboardOwner());

                ownsSelection = true;
            } catch (IllegalStateException ise) {
                // clipboard was unavailable
                // no need to provide error feedback to user since updating
                // the system selection is not a user invoked action
            }
        }
    }
}
 
Example 10
Source File: DefaultCaret.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
private void updateSystemSelection() {
    if ( ! SwingUtilities2.canCurrentEventAccessSystemClipboard() ) {
        return;
    }
    if (this.dot != this.mark && component != null && component.hasFocus()) {
        Clipboard clip = getSystemSelection();
        if (clip != null) {
            String selectedText;
            if (component instanceof JPasswordField
                && component.getClientProperty("JPasswordField.cutCopyAllowed") !=
                Boolean.TRUE) {
                //fix for 4793761
                StringBuilder txt = null;
                char echoChar = ((JPasswordField)component).getEchoChar();
                int p0 = Math.min(getDot(), getMark());
                int p1 = Math.max(getDot(), getMark());
                for (int i = p0; i < p1; i++) {
                    if (txt == null) {
                        txt = new StringBuilder();
                    }
                    txt.append(echoChar);
                }
                selectedText = (txt != null) ? txt.toString() : null;
            } else {
                selectedText = component.getSelectedText();
            }
            try {
                clip.setContents(
                    new StringSelection(selectedText), getClipboardOwner());

                ownsSelection = true;
            } catch (IllegalStateException ise) {
                // clipboard was unavailable
                // no need to provide error feedback to user since updating
                // the system selection is not a user invoked action
            }
        }
    }
}
 
Example 11
Source File: DefaultCaret.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
private void updateSystemSelection() {
    if ( ! SwingUtilities2.canCurrentEventAccessSystemClipboard() ) {
        return;
    }
    if (this.dot != this.mark && component != null && component.hasFocus()) {
        Clipboard clip = getSystemSelection();
        if (clip != null) {
            String selectedText;
            if (component instanceof JPasswordField
                && component.getClientProperty("JPasswordField.cutCopyAllowed") !=
                Boolean.TRUE) {
                //fix for 4793761
                StringBuilder txt = null;
                char echoChar = ((JPasswordField)component).getEchoChar();
                int p0 = Math.min(getDot(), getMark());
                int p1 = Math.max(getDot(), getMark());
                for (int i = p0; i < p1; i++) {
                    if (txt == null) {
                        txt = new StringBuilder();
                    }
                    txt.append(echoChar);
                }
                selectedText = (txt != null) ? txt.toString() : null;
            } else {
                selectedText = component.getSelectedText();
            }
            try {
                clip.setContents(
                    new StringSelection(selectedText), getClipboardOwner());

                ownsSelection = true;
            } catch (IllegalStateException ise) {
                // clipboard was unavailable
                // no need to provide error feedback to user since updating
                // the system selection is not a user invoked action
            }
        }
    }
}
 
Example 12
Source File: DefaultCaret.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private void updateSystemSelection() {
    if ( ! SwingUtilities2.canCurrentEventAccessSystemClipboard() ) {
        return;
    }
    if (this.dot != this.mark && component != null && component.hasFocus()) {
        Clipboard clip = getSystemSelection();
        if (clip != null) {
            String selectedText;
            if (component instanceof JPasswordField
                && component.getClientProperty("JPasswordField.cutCopyAllowed") !=
                Boolean.TRUE) {
                //fix for 4793761
                StringBuilder txt = null;
                char echoChar = ((JPasswordField)component).getEchoChar();
                int p0 = Math.min(getDot(), getMark());
                int p1 = Math.max(getDot(), getMark());
                for (int i = p0; i < p1; i++) {
                    if (txt == null) {
                        txt = new StringBuilder();
                    }
                    txt.append(echoChar);
                }
                selectedText = (txt != null) ? txt.toString() : null;
            } else {
                selectedText = component.getSelectedText();
            }
            try {
                clip.setContents(
                    new StringSelection(selectedText), getClipboardOwner());

                ownsSelection = true;
            } catch (IllegalStateException ise) {
                // clipboard was unavailable
                // no need to provide error feedback to user since updating
                // the system selection is not a user invoked action
            }
        }
    }
}
 
Example 13
Source File: DefaultCaret.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private void updateSystemSelection() {
    if ( ! SwingUtilities2.canCurrentEventAccessSystemClipboard() ) {
        return;
    }
    if (this.dot != this.mark && component != null && component.hasFocus()) {
        Clipboard clip = getSystemSelection();
        if (clip != null) {
            String selectedText;
            if (component instanceof JPasswordField
                && component.getClientProperty("JPasswordField.cutCopyAllowed") !=
                Boolean.TRUE) {
                //fix for 4793761
                StringBuilder txt = null;
                char echoChar = ((JPasswordField)component).getEchoChar();
                int p0 = Math.min(getDot(), getMark());
                int p1 = Math.max(getDot(), getMark());
                for (int i = p0; i < p1; i++) {
                    if (txt == null) {
                        txt = new StringBuilder();
                    }
                    txt.append(echoChar);
                }
                selectedText = (txt != null) ? txt.toString() : null;
            } else {
                selectedText = component.getSelectedText();
            }
            try {
                clip.setContents(
                    new StringSelection(selectedText), getClipboardOwner());

                ownsSelection = true;
            } catch (IllegalStateException ise) {
                // clipboard was unavailable
                // no need to provide error feedback to user since updating
                // the system selection is not a user invoked action
            }
        }
    }
}
 
Example 14
Source File: DefaultCaret.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
private void updateSystemSelection() {
    if ( ! SwingUtilities2.canCurrentEventAccessSystemClipboard() ) {
        return;
    }
    if (this.dot != this.mark && component != null && component.hasFocus()) {
        Clipboard clip = getSystemSelection();
        if (clip != null) {
            String selectedText;
            if (component instanceof JPasswordField
                && component.getClientProperty("JPasswordField.cutCopyAllowed") !=
                Boolean.TRUE) {
                //fix for 4793761
                StringBuilder txt = null;
                char echoChar = ((JPasswordField)component).getEchoChar();
                int p0 = Math.min(getDot(), getMark());
                int p1 = Math.max(getDot(), getMark());
                for (int i = p0; i < p1; i++) {
                    if (txt == null) {
                        txt = new StringBuilder();
                    }
                    txt.append(echoChar);
                }
                selectedText = (txt != null) ? txt.toString() : null;
            } else {
                selectedText = component.getSelectedText();
            }
            try {
                clip.setContents(
                    new StringSelection(selectedText), getClipboardOwner());

                ownsSelection = true;
            } catch (IllegalStateException ise) {
                // clipboard was unavailable
                // no need to provide error feedback to user since updating
                // the system selection is not a user invoked action
            }
        }
    }
}
 
Example 15
Source File: DefaultCaret.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private void updateSystemSelection() {
    if ( ! SwingUtilities2.canCurrentEventAccessSystemClipboard() ) {
        return;
    }
    if (this.dot != this.mark && component != null && component.hasFocus()) {
        Clipboard clip = getSystemSelection();
        if (clip != null) {
            String selectedText;
            if (component instanceof JPasswordField
                && component.getClientProperty("JPasswordField.cutCopyAllowed") !=
                Boolean.TRUE) {
                //fix for 4793761
                StringBuilder txt = null;
                char echoChar = ((JPasswordField)component).getEchoChar();
                int p0 = Math.min(getDot(), getMark());
                int p1 = Math.max(getDot(), getMark());
                for (int i = p0; i < p1; i++) {
                    if (txt == null) {
                        txt = new StringBuilder();
                    }
                    txt.append(echoChar);
                }
                selectedText = (txt != null) ? txt.toString() : null;
            } else {
                selectedText = component.getSelectedText();
            }
            try {
                clip.setContents(
                    new StringSelection(selectedText), getClipboardOwner());

                ownsSelection = true;
            } catch (IllegalStateException ise) {
                // clipboard was unavailable
                // no need to provide error feedback to user since updating
                // the system selection is not a user invoked action
            }
        }
    }
}
 
Example 16
Source File: DefaultCaret.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private void updateSystemSelection() {
    if ( ! SwingUtilities2.canCurrentEventAccessSystemClipboard() ) {
        return;
    }
    if (this.dot != this.mark && component != null && component.hasFocus()) {
        Clipboard clip = getSystemSelection();
        if (clip != null) {
            String selectedText;
            if (component instanceof JPasswordField
                && component.getClientProperty("JPasswordField.cutCopyAllowed") !=
                Boolean.TRUE) {
                //fix for 4793761
                StringBuilder txt = null;
                char echoChar = ((JPasswordField)component).getEchoChar();
                int p0 = Math.min(getDot(), getMark());
                int p1 = Math.max(getDot(), getMark());
                for (int i = p0; i < p1; i++) {
                    if (txt == null) {
                        txt = new StringBuilder();
                    }
                    txt.append(echoChar);
                }
                selectedText = (txt != null) ? txt.toString() : null;
            } else {
                selectedText = component.getSelectedText();
            }
            try {
                clip.setContents(
                    new StringSelection(selectedText), getClipboardOwner());

                ownsSelection = true;
            } catch (IllegalStateException ise) {
                // clipboard was unavailable
                // no need to provide error feedback to user since updating
                // the system selection is not a user invoked action
            }
        }
    }
}
 
Example 17
Source File: DefaultCaret.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private void updateSystemSelection() {
    if ( ! SwingUtilities2.canCurrentEventAccessSystemClipboard() ) {
        return;
    }
    if (this.dot != this.mark && component != null && component.hasFocus()) {
        Clipboard clip = getSystemSelection();
        if (clip != null) {
            String selectedText;
            if (component instanceof JPasswordField
                && component.getClientProperty("JPasswordField.cutCopyAllowed") !=
                Boolean.TRUE) {
                //fix for 4793761
                StringBuilder txt = null;
                char echoChar = ((JPasswordField)component).getEchoChar();
                int p0 = Math.min(getDot(), getMark());
                int p1 = Math.max(getDot(), getMark());
                for (int i = p0; i < p1; i++) {
                    if (txt == null) {
                        txt = new StringBuilder();
                    }
                    txt.append(echoChar);
                }
                selectedText = (txt != null) ? txt.toString() : null;
            } else {
                selectedText = component.getSelectedText();
            }
            try {
                clip.setContents(
                    new StringSelection(selectedText), getClipboardOwner());

                ownsSelection = true;
            } catch (IllegalStateException ise) {
                // clipboard was unavailable
                // no need to provide error feedback to user since updating
                // the system selection is not a user invoked action
            }
        }
    }
}