use of javax.swing.JTextField in project GNS by MobilityFirst.
the class Sudo method main.
/**
*
* @param arg
*/
public static void main(String[] arg) {
try {
JSch jsch = new JSch();
Session session = SSHClient.authenticateWithKey(jsch, null, null, null);
UserInfo ui = new UserInfoPrompted();
session.setUserInfo(ui);
session.connect();
String command = JOptionPane.showInputDialog("Enter command, execed with sudo", "printenv SUDO_USER");
String sudo_pass = null;
{
JTextField passwordField = new JPasswordField(8);
Object[] ob = { passwordField };
int result = JOptionPane.showConfirmDialog(null, ob, "Enter password for sudo", JOptionPane.OK_CANCEL_OPTION);
if (result != JOptionPane.OK_OPTION) {
System.exit(-1);
}
sudo_pass = passwordField.getText();
}
Channel channel = session.openChannel("exec");
// man sudo
// -S The -S (stdin) option causes sudo to read the password from the
// standard input instead of the terminal device.
// -p The -p (prompt) option allows you to override the default
// password prompt and use a custom one.
((ChannelExec) channel).setCommand("sudo -S -p '' " + command);
InputStream in = channel.getInputStream();
OutputStream out = channel.getOutputStream();
((ChannelExec) channel).setErrStream(System.err);
((ChannelExec) channel).setPty(true);
channel.connect();
out.write((sudo_pass + "\n").getBytes());
out.flush();
byte[] tmp = new byte[1024];
while (true) {
while (in.available() > 0) {
int i = in.read(tmp, 0, 1024);
if (i < 0) {
break;
}
System.out.print(new String(tmp, 0, i));
}
if (channel.isClosed()) {
System.out.println("exit-status: " + channel.getExitStatus());
break;
}
try {
Thread.sleep(1000);
} catch (Exception ee) {
}
}
channel.disconnect();
session.disconnect();
} catch (JSchException | HeadlessException | IOException e) {
System.out.println(e);
}
}
use of javax.swing.JTextField in project nhin-d by DirectProject.
the class PKCS11SecretKeyManager method addTextKey.
private void addTextKey() {
final JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
final JPanel topPanel = new JPanel();
final JLabel aliasLabel = new JLabel("Alias:");
aliasLabel.setSize(60, 30);
final JTextField aliasField = new JTextField(40);
topPanel.add(aliasLabel);
topPanel.add(aliasField);
final JPanel bottomPanel = new JPanel();
final JLabel keyLabel = new JLabel("Key:");
keyLabel.setSize(60, 30);
final JTextField keyField = new JTextField(40);
bottomPanel.add(keyLabel);
bottomPanel.add(keyField);
panel.add(topPanel, BorderLayout.NORTH);
panel.add(bottomPanel, BorderLayout.SOUTH);
final String[] options = new String[] { "OK", "Cancel" };
int option = JOptionPane.showOptionDialog(null, panel, "Generate New Text Based Secret Key ", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
if (option == JOptionPane.OK_OPTION) {
final String alias = aliasField.getText();
final String keyText = keyField.getText();
if ((alias != null && !alias.trim().isEmpty()) && keyText != null && !keyText.trim().isEmpty()) {
// generate a new random secret key
try {
mgr.clearKey(alias);
mgr.setKey(alias, new SecretKeySpec(keyText.getBytes(), ""));
updateKeyTableData();
} catch (Exception e) {
JOptionPane.showMessageDialog(this, "Failed to add new text based secret key: " + e.getMessage(), "Add Key Error", JOptionPane.ERROR_MESSAGE);
}
}
}
}
use of javax.swing.JTextField in project jdk8u_jdk by JetBrains.
the class DeadKeyMacOSXInputText method createAndShowGUI.
static void createAndShowGUI() {
Frame frame = new Frame();
frame.setSize(300, 300);
Panel panel = new Panel(new BorderLayout());
JTextField textField = new JTextField();
textField.addKeyListener(new DeadKeyListener());
panel.add(textField, BorderLayout.CENTER);
frame.add(panel);
frame.setVisible(true);
toolkit.realSync();
textField.requestFocusInWindow();
toolkit.realSync();
}
use of javax.swing.JTextField in project jdk8u_jdk by JetBrains.
the class Test8015300 method main.
public static void main(String[] args) throws Exception {
UIManager.LookAndFeelInfo[] array = UIManager.getInstalledLookAndFeels();
for (UIManager.LookAndFeelInfo info : array) {
UIManager.setLookAndFeel(info.getClassName());
System.err.println("L&F: " + info.getName());
invokeAndWait(new Runnable() {
@Override
public void run() {
combo = new JComboBox<>(ITEMS);
combo.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent event) {
if (ItemEvent.SELECTED == event.getStateChange() && combo.isEditable()) {
ComboBoxEditor editor = combo.getEditor();
Object component = editor.getEditorComponent();
if (component instanceof JTextField) {
JTextField text = (JTextField) component;
boolean selected = null != text.getSelectedText();
StringBuilder sb = new StringBuilder();
sb.append(" - ").append(combo.getSelectedIndex());
sb.append(": ").append(event.getItem());
if (selected) {
sb.append("; selected");
}
System.err.println(sb);
if ((editor instanceof WindowsComboBoxEditor) == (null == text.getSelectedText())) {
throw new Error("unexpected state of text selection");
}
}
}
}
});
JFrame frame = new JFrame(getClass().getSimpleName());
frame.add(combo);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
frame.setVisible(true);
}
});
for (int i = 0; i < ITEMS.length; ++i) {
select(i, true);
select(1, false);
}
invokeAndWait(new Runnable() {
@Override
public void run() {
windowForComponent(combo).dispose();
}
});
}
}
use of javax.swing.JTextField in project jdk8u_jdk by JetBrains.
the class InputContextMemoryLeakTest method init.
public static void init() throws Throwable {
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
frame = new JFrame();
frame.setLayout(new FlowLayout());
JPanel p1 = new JPanel();
button = new JButton("Test");
p1.add(button);
frame.add(p1);
text = new WeakReference<JTextField>(new JTextField("Text"));
p = new WeakReference<JPanel>(new JPanel(new FlowLayout()));
p.get().add(text.get());
frame.add(p.get());
frame.setBounds(500, 400, 200, 200);
frame.setVisible(true);
}
});
Util.focusComponent(text.get(), 500);
Util.clickOnComp(button, new Robot());
//References to objects testes for memory leak are stored in Util.
//Need to clean them
Util.cleanUp();
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
frame.remove(p.get());
}
});
Util.waitForIdle(null);
//After the next caret blink it automatically TextField references
Thread.sleep(text.get().getCaret().getBlinkRate() * 2);
Util.waitForIdle(null);
assertGC();
}
Aggregations