use of java.awt.event.KeyListener in project tetrad by cmu-phil.
the class HpcAccountEditor method initiateUI.
private void initiateUI() {
setLayout(new BorderLayout());
// Header
JPanel headerPanel = new JPanel(new BorderLayout());
JLabel headerLabel = new JLabel("High-Performance Computing Account");
headerLabel.setFont(new Font(headerLabel.getFont().getName(), Font.BOLD, 20));
headerPanel.add(headerLabel, BorderLayout.CENTER);
JPanel spacePanel = new JPanel();
spacePanel.setSize(300, 100);
headerPanel.add(spacePanel, BorderLayout.SOUTH);
add(headerPanel, BorderLayout.NORTH);
// Content
Box contentBox = Box.createVerticalBox();
// Connection Name
Box connBox = Box.createHorizontalBox();
JLabel connLabel = new JLabel("Connection", JLabel.TRAILING);
connLabel.setPreferredSize(new Dimension(100, 5));
connBox.add(connLabel);
final JTextField connField = new JTextField(20);
connField.setText(hpcAccount.getConnectionName());
connField.addKeyListener(new KeyListener() {
@Override
public void keyTyped(KeyEvent e) {
}
@Override
public void keyReleased(KeyEvent e) {
hpcAccount.setConnectionName(connField.getText());
}
@Override
public void keyPressed(KeyEvent e) {
}
});
connLabel.setLabelFor(connField);
connBox.add(connField);
contentBox.add(connBox);
// Username
Box userBox = Box.createHorizontalBox();
JLabel userLabel = new JLabel("Username", JLabel.TRAILING);
userLabel.setPreferredSize(new Dimension(100, 5));
userBox.add(userLabel);
final JTextField userField = new JTextField(20);
userField.setText(hpcAccount.getUsername());
userField.addKeyListener(new KeyListener() {
@Override
public void keyTyped(KeyEvent e) {
}
@Override
public void keyReleased(KeyEvent e) {
hpcAccount.setUsername(userField.getText());
}
@Override
public void keyPressed(KeyEvent e) {
}
});
userLabel.setLabelFor(userField);
userBox.add(userField);
contentBox.add(userBox);
// Password
Box passBox = Box.createHorizontalBox();
JLabel passLabel = new JLabel("Password", JLabel.TRAILING);
passLabel.setPreferredSize(new Dimension(100, 5));
passBox.add(passLabel);
final JPasswordField passField = new JPasswordField(20);
passField.setText(hpcAccount.getPassword());
passField.addKeyListener(new KeyListener() {
@Override
public void keyTyped(KeyEvent e) {
}
@Override
public void keyReleased(KeyEvent e) {
hpcAccount.setPassword(new String(passField.getPassword()));
}
@Override
public void keyPressed(KeyEvent e) {
}
});
passLabel.setLabelFor(passField);
passBox.add(passField);
contentBox.add(passBox);
// Scheme
JPanel schemePanel = new JPanel(new BorderLayout());
JLabel schemeLabel = new JLabel("Scheme", JLabel.TRAILING);
schemeLabel.setPreferredSize(new Dimension(100, 5));
schemePanel.add(schemeLabel, BorderLayout.WEST);
final JRadioButton httpRadioButton = new JRadioButton("http");
final JRadioButton httpsRadioButton = new JRadioButton("https");
if (hpcAccount.getScheme().equalsIgnoreCase("https")) {
httpsRadioButton.setSelected(true);
} else {
httpRadioButton.setSelected(true);
}
ButtonGroup schemeGroup = new ButtonGroup();
schemeGroup.add(httpRadioButton);
schemeGroup.add(httpsRadioButton);
Box schemeRadioBox = Box.createHorizontalBox();
schemeRadioBox.add(httpRadioButton);
schemeRadioBox.add(httpsRadioButton);
schemeLabel.setLabelFor(schemeRadioBox);
ActionListener schemeActionListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (httpRadioButton.isSelected()) {
hpcAccount.setScheme("http");
} else {
hpcAccount.setScheme("https");
}
}
};
httpRadioButton.addActionListener(schemeActionListener);
httpsRadioButton.addActionListener(schemeActionListener);
schemePanel.add(schemeRadioBox, BorderLayout.CENTER);
contentBox.add(schemePanel);
// Host
Box hostBox = Box.createHorizontalBox();
JLabel hostLabel = new JLabel("Host Name", JLabel.TRAILING);
hostLabel.setPreferredSize(new Dimension(100, 5));
hostBox.add(hostLabel);
final JTextField hostField = new JTextField(20);
hostField.setText(hpcAccount.getHostname());
hostField.addKeyListener(new KeyListener() {
@Override
public void keyTyped(KeyEvent e) {
}
@Override
public void keyReleased(KeyEvent e) {
hpcAccount.setHostname(hostField.getText());
}
@Override
public void keyPressed(KeyEvent e) {
}
});
hostLabel.setLabelFor(hostField);
hostBox.add(hostField);
contentBox.add(hostBox);
// Port number
Box portBox = Box.createHorizontalBox();
JLabel portLabel = new JLabel("Port Number", JLabel.TRAILING);
portLabel.setPreferredSize(new Dimension(100, 5));
portBox.add(portLabel);
final JTextField portField = new JTextField(20);
portField.setText(String.valueOf(hpcAccount.getPort()));
portField.addKeyListener(new KeyListener() {
@Override
public void keyTyped(KeyEvent e) {
}
@Override
public void keyReleased(KeyEvent e) {
try {
int port = Integer.parseInt(portField.getText());
hpcAccount.setPort(port);
} catch (NumberFormatException e1) {
// TODO Auto-generated catch block
if (portField.getText().trim().length() > 0) {
JOptionPane.showMessageDialog(portField, "Port number is decimal number only!");
}
}
}
@Override
public void keyPressed(KeyEvent e) {
}
});
portLabel.setLabelFor(portField);
portBox.add(portField);
contentBox.add(portBox);
JPanel contentPanel = new JPanel(new BorderLayout());
contentPanel.add(contentBox, BorderLayout.NORTH);
add(contentPanel, BorderLayout.CENTER);
// Footer -> Test and Save buttons
JPanel footerPanel = new JPanel(new BorderLayout());
final JButton testConnButton = new JButton("Test Connection");
testConnButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JButton button = (JButton) e.getSource();
button.setText("Testing...");
parentComponent.updateUI();
button.setEnabled(false);
boolean success = HpcAccountUtils.testConnection(hpcAccountManager, hpcAccount);
// Pop-up the test result
JOptionPane.showMessageDialog(null, "" + hpcAccount + " Connection " + (success ? "Successful" : "Failed"), "HPC Account Setting", JOptionPane.INFORMATION_MESSAGE);
button.setEnabled(true);
button.setText("Test Connection");
hpcAccount.setLastLoginDate(new Date());
hpcAccountManager.saveAccount(hpcAccount);
}
});
JButton saveButton = new JButton("Save");
saveButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JButton button = (JButton) e.getSource();
button.setText("Saving...");
parentComponent.updateUI();
button.setEnabled(false);
hpcAccountManager.saveAccount(hpcAccount);
if (listModel.indexOf(hpcAccount) == -1) {
listModel.addElement(hpcAccount);
}
button.setEnabled(true);
button.setText("Save");
parentComponent.updateUI();
}
});
footerPanel.add(testConnButton, BorderLayout.WEST);
footerPanel.add(saveButton, BorderLayout.EAST);
add(footerPanel, BorderLayout.SOUTH);
}
use of java.awt.event.KeyListener in project OpenNotebook by jaltekruse.
the class StringAdjustmentPanel method addPanelContent.
@Override
public void addPanelContent() {
// to prevent the panel from looking too small, estimate the amount of lines needed to
// show all of the text
int numLines = 0;
if (getGraphics() != null) {
// one of these panels is constructed in the background to initialize some resources
// at that time there is no graphics object to reference to measure text
numLines = getGraphics().getFontMetrics().stringWidth(mAtt.getValue()) / 120;
} else {
numLines = mAtt.getValue().length() / 20;
}
if (numLines < 2) {
numLines = 2;
}
textArea = new JTextArea(numLines, 12);
textArea.setEditable(true);
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
textArea.setText(mAtt.getValue());
textArea.addFocusListener(new FocusListener() {
@Override
public void focusGained(FocusEvent arg0) {
}
@Override
public void focusLost(FocusEvent arg0) {
applyPanelValueToObject();
}
});
// need to decide if having this panel set with the enter key is worth
// not being able to include line breaks
textArea.addKeyListener(new KeyListener() {
@Override
public void keyPressed(KeyEvent ev) {
if (ev.getKeyCode() == KeyEvent.VK_ENTER) {
applyPanelValueToObject();
enterJustPressed = true;
}
}
@Override
public void keyReleased(KeyEvent arg0) {
if (arg0.getKeyCode() == KeyEvent.VK_ENTER && enterJustPressed) {
// had issue with hitting enter to confirm dialog, dialog disappeared but enter key release event
// was still received here if an object was selected, hence the boolean set in the keypressed
// method and checked here
String s = textArea.getText();
int caretPos = textArea.getCaretPosition() - 1;
s = s.substring(0, textArea.getCaretPosition() - 1) + s.substring(textArea.getCaretPosition());
textArea.setText(s);
textArea.setCaretPosition(caretPos);
enterJustPressed = false;
}
}
@Override
public void keyTyped(KeyEvent arg0) {
}
});
setLayout(new GridBagLayout());
GridBagConstraints con = new GridBagConstraints();
con.fill = GridBagConstraints.HORIZONTAL;
con.weightx = .5;
con.gridx = 0;
con.gridwidth = 1;
con.gridy = 0;
con.insets = new Insets(2, 5, 0, 5);
add(new JLabel(mAtt.getName()), con);
JButton keyboard = new JButton(ObjectPropertiesFrame.SMALL_KEYBOARD_IMAGE);
keyboard.setToolTipText("Show On-Screen Keyboard");
keyboard.setMargin(new Insets(3, 3, 3, 3));
keyboard.setFocusable(false);
con.insets = new Insets(2, 2, 2, 2);
con.gridx = 1;
con.weightx = .1;
con.weighty = .1;
con.gridheight = 1;
add(keyboard, con);
keyboard.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
notebookPanel.getCurrentDocViewer().setOnScreenKeyBoardVisible(true);
}
});
JButton applyChanges = new JButton("Apply");
applyChanges.setToolTipText("Value can also be applied by hitting Enter");
applyChanges.setMargin(new Insets(5, 3, 5, 3));
applyChanges.setFocusable(false);
con.gridx = 2;
con.weightx = .1;
con.weighty = .1;
con.gridheight = 1;
add(applyChanges, con);
applyChanges.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
applyPanelValueToObject();
}
});
con.fill = GridBagConstraints.BOTH;
con.weightx = 1;
con.weighty = 1;
con.gridwidth = 3;
con.gridy = 1;
con.gridx = 0;
con.gridheight = 3;
scrollPane = new JScrollPane(textArea);
scrollPane.setWheelScrollingEnabled(false);
con.insets = new Insets(0, 5, 2, 0);
add(scrollPane, con);
scrollPane.addMouseWheelListener(new MouseWheelListener() {
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
Point componentPoint = SwingUtilities.convertPoint(scrollPane, e.getPoint(), parentPanel);
parentPanel.dispatchEvent(new MouseWheelEvent(parentPanel, e.getID(), e.getWhen(), e.getModifiers(), componentPoint.x, componentPoint.y, e.getClickCount(), e.isPopupTrigger(), e.getScrollType(), e.getScrollAmount(), e.getWheelRotation()));
}
});
}
use of java.awt.event.KeyListener in project zaproxy by zaproxy.
the class OptionsConnectionPanel method getDefaultUserAgent.
private ZapTextField getDefaultUserAgent() {
if (defaultUserAgent == null) {
defaultUserAgent = new ZapTextField();
defaultUserAgent.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setUaFromString();
}
});
defaultUserAgent.addKeyListener(new KeyListener() {
@Override
public void keyTyped(KeyEvent e) {
}
@Override
public void keyPressed(KeyEvent e) {
}
@Override
public void keyReleased(KeyEvent e) {
setUaFromString();
}
});
}
return defaultUserAgent;
}
use of java.awt.event.KeyListener in project cayenne by apache.
the class ObjAttributeInfoDialog method initController.
private void initController(ObjAttribute attr) {
for (String embeddableName : embeddableNames) {
((DefaultComboBoxModel<String>) view.getTypeComboBox().getModel()).addElement(embeddableName);
}
// need to initialize this early, to react to the later call of the view.getTypeComboBox().setSelectedItem()
view.getTypeComboBox().addActionListener(e -> {
boolean isType = false;
String[] typeNames = ModelerUtil.getRegisteredTypeNames();
for (String typeName : typeNames) {
if (view.getTypeComboBox().getSelectedItem() == null || typeName.equals(view.getTypeComboBox().getSelectedItem().toString())) {
isType = true;
}
}
if (isType || !mediator.getEmbeddableNamesInCurrentDataDomain().contains((String) view.getTypeComboBox().getSelectedItem())) {
((CardLayout) view.getTypeManagerPane().getLayout()).show(view.getTypeManagerPane(), FLATTENED_PANEL);
} else {
((CardLayout) view.getTypeManagerPane().getLayout()).show(view.getTypeManagerPane(), EMBEDDABLE_PANEL);
view.getCurrentPathLabel().setText("");
}
});
this.attribute = attr;
if (attribute instanceof EmbeddedAttribute || embeddableNames.contains(attribute.getType())) {
this.attributeSaved = new EmbeddedAttribute();
} else {
this.attributeSaved = new ObjAttribute();
}
copyObjAttribute(attributeSaved, attribute);
relTargets = new ArrayList<>(attribute.getEntity().getDataMap().getDbEntities());
/*
* Register auto-selection of the target
*/
view.getPathBrowser().addTreeSelectionListener(this);
view.getAttributeName().setText(attribute.getName());
if (attribute.getDbAttributePath() != null) {
if (attribute.getDbAttributePath().contains(".")) {
String path = attribute.getDbAttributePath();
view.getCurrentPathLabel().setText(path.replace(".", " -> "));
} else {
view.getCurrentPathLabel().setText(attribute.getDbAttributePath());
}
} else {
view.getCurrentPathLabel().setText("");
}
view.getSourceEntityLabel().setText(attribute.getEntity().getName());
view.getTypeComboBox().setSelectedItem(attribute.getType());
view.getUsedForLockingCheckBox().setSelected(attribute.isUsedForLocking());
view.getLazyCheckBox().setSelected(attribute.isLazy());
view.getCommentField().setText(ObjectInfo.getFromMetaData(mediator.getApplication().getMetaData(), attr, ObjectInfo.COMMENT));
BindingBuilder builder = new BindingBuilder(getApplication().getBindingFactory(), this);
builder.bindToAction(view.getCancelButton(), "closeAction()");
builder.bindToAction(view.getSelectPathButton(), "setPath(true)");
builder.bindToAction(view.getSaveButton(), "saveMapping()");
/*
* set filter for ObjAttributePathBrowser
*/
if (view.getPathBrowser().getModel() == null) {
Entity firstEntity = null;
if (attribute.getDbAttribute() == null) {
if (attribute.getParent() instanceof ObjEntity) {
DbEntity dbEnt = ((ObjEntity) attribute.getParent()).getDbEntity();
if (dbEnt != null) {
Collection<DbAttribute> attrib = dbEnt.getAttributes();
Collection<DbRelationship> rel = dbEnt.getRelationships();
if (attrib.size() > 0) {
Iterator<DbAttribute> iter = attrib.iterator();
firstEntity = iter.next().getEntity();
} else if (rel.size() > 0) {
Iterator<DbRelationship> iter = rel.iterator();
firstEntity = iter.next().getSourceEntity();
}
}
}
} else {
firstEntity = getFirstEntity();
}
if (firstEntity != null) {
EntityTreeModel treeModel = new EntityTreeModel(firstEntity);
treeModel.setFilter(new EntityTreeAttributeRelationshipFilter());
view.getPathBrowser().setModel(treeModel);
}
}
if (attribute.getDbAttribute() != null) {
setSelectionPath();
}
view.getTypeComboBox().addItemListener(e -> {
if (lastObjectType != null) {
if (!lastObjectType.equals(e.getItemSelectable())) {
if (embeddableNames.contains(e.getItemSelectable().getSelectedObjects()[0].toString())) {
if (attributeSaved instanceof ObjAttribute) {
EmbeddedAttribute copyAttrSaved = new EmbeddedAttribute();
copyObjAttribute(copyAttrSaved, attributeSaved);
attributeSaved = copyAttrSaved;
}
} else {
if (attributeSaved instanceof EmbeddedAttribute) {
ObjAttribute copyAttrSaved = new ObjAttribute();
copyObjAttribute(copyAttrSaved, attributeSaved);
attributeSaved = copyAttrSaved;
}
}
attributeSaved.setType(e.getItemSelectable().getSelectedObjects()[0].toString());
rebuildTable();
setEnabledSaveButton();
}
}
});
view.getAttributeName().addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent e) {
if (!view.getAttributeName().getText().equals(attribute.getName())) {
setEnabledSaveButton();
}
}
public void keyReleased(KeyEvent e) {
if (!view.getAttributeName().getText().equals(attribute.getName())) {
setEnabledSaveButton();
}
}
public void keyTyped(KeyEvent e) {
}
});
rebuildTable();
}
Aggregations