use of java.awt.event.FocusListener in project azure-tools-for-java by Microsoft.
the class AppSettingsTableUtils method createAppSettingPanel.
public static JPanel createAppSettingPanel(AppSettingsTable appSettingsTable) {
final JPanel result = new JPanel();
// create the parent panel which contains app settings table and prompt panel
result.setLayout(new GridLayoutManager(2, 1));
final JTextPane promptPanel = new JTextPane();
final GridConstraints paneConstraint = new GridConstraints(1, 0, 1, 1, 0, GridConstraints.FILL_BOTH, 7, 7, null, null, null);
promptPanel.setFocusable(false);
result.add(promptPanel, paneConstraint);
final AnActionButton btnAdd = new AnActionButton(message("common.add"), AllIcons.General.Add) {
@Override
public void actionPerformed(AnActionEvent anActionEvent) {
final String key = DefaultLoader.getUIHelper().showInputDialog(appSettingsTable, message("function.appSettings.add.key.message"), message("function.appSettings.add.key.title"), null);
if (StringUtils.isEmpty(key)) {
return;
}
final String value = DefaultLoader.getUIHelper().showInputDialog(appSettingsTable, message("function.appSettings.add.value.message"), message("function.appSettings.add.value.title"), null);
appSettingsTable.addAppSettings(key, value);
appSettingsTable.repaint();
}
};
final AnActionButton btnRemove = new AnActionButton(message("common.remove"), AllIcons.General.Remove) {
@Override
public void actionPerformed(AnActionEvent anActionEvent) {
try {
appSettingsTable.removeAppSettings(appSettingsTable.getSelectedRow());
appSettingsTable.repaint();
} catch (IllegalArgumentException iae) {
PluginUtil.displayErrorDialog(message("function.appSettings.remove.error.title"), iae.getMessage());
}
}
};
final AnActionButton importButton = new AnActionButton(message("common.import"), AllIcons.ToolbarDecorator.Import) {
@Override
@AzureOperation(name = "function.import_app_settings", type = AzureOperation.Type.TASK)
public void actionPerformed(AnActionEvent anActionEvent) {
final ImportAppSettingsDialog importAppSettingsDialog = new ImportAppSettingsDialog(appSettingsTable.getLocalSettingsPath());
importAppSettingsDialog.addWindowListener(new WindowAdapter() {
@Override
public void windowClosed(WindowEvent windowEvent) {
super.windowClosed(windowEvent);
final Map<String, String> appSettings = importAppSettingsDialog.getAppSettings();
if (importAppSettingsDialog.shouldErase()) {
appSettingsTable.clear();
}
if (appSettings != null) {
appSettingsTable.addAppSettings(appSettings);
}
}
});
importAppSettingsDialog.setLocationRelativeTo(appSettingsTable);
importAppSettingsDialog.pack();
importAppSettingsDialog.setVisible(true);
}
};
final AnActionButton exportButton = new AnActionButton(message("function.appSettings.export.title"), AllIcons.ToolbarDecorator.Export) {
@Override
public void actionPerformed(AnActionEvent anActionEvent) {
try {
final File file = DefaultLoader.getUIHelper().showFileSaver(message("function.appSettings.export.description"), LOCAL_SETTINGS_JSON);
if (file != null) {
AppSettingsTableUtils.exportLocalSettingsJsonFile(file, appSettingsTable.getAppSettings());
PluginUtil.displayInfoDialog(message("function.appSettings.export.succeed.title"), message("function.appSettings.export.succeed.message"));
}
} catch (IOException e) {
final String title = message("function.appSettings.export.error.title");
final String message = message("function.appSettings.export.error.failedToSave", e.getMessage());
PluginUtil.displayErrorDialog(title, message);
}
}
};
appSettingsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent listSelectionEvent) {
final String prompt = AzureFunctionsConstants.getAppSettingHint(appSettingsTable.getSelectedKey());
promptPanel.setText(prompt);
}
});
appSettingsTable.addFocusListener(new FocusListener() {
@Override
public void focusGained(FocusEvent focusEvent) {
final String prompt = AzureFunctionsConstants.getAppSettingHint(appSettingsTable.getSelectedKey());
promptPanel.setText(prompt);
}
@Override
public void focusLost(FocusEvent focusEvent) {
promptPanel.setText("");
}
});
final ToolbarDecorator tableToolbarDecorator = ToolbarDecorator.createDecorator(appSettingsTable).addExtraActions(btnAdd, btnRemove, importButton, exportButton).setToolbarPosition(ActionToolbarPosition.RIGHT);
final JPanel tablePanel = tableToolbarDecorator.createPanel();
final GridConstraints tableConstraint = new GridConstraints(0, 0, 1, 1, 0, GridConstraints.FILL_BOTH, 7, 7, null, null, null);
result.add(tablePanel, tableConstraint);
result.setMinimumSize(new Dimension(-1, 100));
return result;
}
use of java.awt.event.FocusListener 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.FocusListener in project ChatGameFontificator by GlitchCog.
the class ControlPanelIrc method build.
@Override
protected void build() {
userInput = new LabeledInput("Username", 11);
authInput = new LabeledInput("OAuth Token", true, 25);
authHelpButton = new JButton("Get OAuth Token");
chanInput = new LabeledInput("Channel", 11);
hostInput = new LabeledInput("Host", 7);
portInput = new LabeledInput("Port", 3);
anonymous = new JCheckBox("Read Only (Credentials not required)");
anonymous.setToolTipText("Connect without credentials, but also without access to custom Twitch badges");
anonymous.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
userInput.setEnabled(!anonymous.isSelected());
authInput.setEnabled(!anonymous.isSelected());
config.setAnonymous(anonymous.isSelected());
}
});
FocusListener fl = new FocusListener() {
@Override
public void focusGained(FocusEvent e) {
}
@Override
public void focusLost(FocusEvent e) {
// the configuration
try {
fillConfigFromInput();
} catch (Exception ex) {
logger.trace(ex.toString(), ex);
}
}
};
userInput.addFocusListener(fl);
authInput.addFocusListener(fl);
chanInput.addFocusListener(fl);
hostInput.addFocusListener(fl);
portInput.addFocusListener(fl);
authHelpButton.addActionListener(new ActionListener() {
final String url = "http://www.twitchapps.com/tmi/";
@Override
public void actionPerformed(ActionEvent e) {
try {
Desktop.getDesktop().browse(URI.create(url));
} catch (java.io.IOException ex) {
ChatWindow.popup.handleProblem("Unable to open website at URL: " + url);
}
}
});
connectButton = new JButton(BUTTON_TEXT_CONNECT);
connectButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JButton source = (JButton) e.getSource();
// Reset it just in case
source.setText(bot.isConnected() ? BUTTON_TEXT_DISCONNECT : BUTTON_TEXT_CONNECT);
if (bot.isConnected()) {
bot.setDisconnectExpected(true);
bot.disconnect();
} else {
try {
LoadConfigReport report = validateInputForConnect();
if (report.isErrorFree()) {
// Connect to the IRC channel
connect();
emojiControl.loadAndRunEmojiWork();
} else {
ChatWindow.popup.handleProblem(report);
}
} catch (NumberFormatException ex) {
ChatWindow.popup.handleProblem("Invalid login port value", ex);
} catch (NickAlreadyInUseException ex) {
ChatWindow.popup.handleProblem("Nickname already in use", ex);
} catch (IOException ex) {
ChatWindow.popup.handleProblem("Error connecting to the IRC server. Verify the Internet connection and then the host and port values.", ex);
} catch (IrcException ex) {
ChatWindow.popup.handleProblem("The host IRC server rejected the connection", ex);
} catch (Exception ex) {
ChatWindow.popup.handleProblem("Unanticipated error connecting", ex);
}
}
}
});
clearChatButton = new JButton("Clear Chat");
clearChatButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
chat.clearChat();
chat.repaint();
}
});
autoReconnectBox = new JCheckBox("Automatically attempt to reconnect if connection is lost");
autoReconnectBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
config.setAutoReconnect(autoReconnectBox.isSelected());
}
});
JPanel everything = new JPanel(new GridBagLayout());
everything.setBorder(new TitledBorder(baseBorder, "IRC Connection Properties / Clear Chat", TitledBorder.CENTER, TitledBorder.TOP));
JPanel topRow = new JPanel(new GridBagLayout());
JPanel midRow = new JPanel(new GridBagLayout());
JPanel botRow = new JPanel(new GridBagLayout());
gbc.weightx = 0.0;
gbc.fill = GridBagConstraints.NONE;
topRow.add(anonymous, gbc);
gbc.gridx++;
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.weightx = 1.0;
gbc.weighty = 0.0;
topRow.add(userInput, gbc);
gbc.gridx++;
topRow.add(chanInput, gbc);
gbc.gridx++;
gbc.gridx = 0;
midRow.add(authInput, gbc);
gbc.gridx++;
gbc.weightx = 0.0;
gbc.fill = GridBagConstraints.NONE;
midRow.add(authHelpButton, gbc);
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.weightx = 1.0;
gbc.gridx = 0;
botRow.add(hostInput, gbc);
gbc.gridx++;
botRow.add(portInput, gbc);
gbc.gridx++;
gbc.anchor = GridBagConstraints.NORTHEAST;
botRow.add(connectButton, gbc);
gbc.gridx++;
botRow.add(clearChatButton, gbc);
gbc.gridx++;
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 0;
everything.add(topRow, gbc);
gbc.gridy++;
everything.add(midRow, gbc);
gbc.gridy++;
everything.add(botRow, gbc);
gbc.gridy++;
everything.add(autoReconnectBox, gbc);
gbc.gridx = 0;
gbc.gridy = 0;
gbc.weightx = 1.0;
gbc.weighty = 0.0;
gbc.anchor = GridBagConstraints.NORTH;
add(everything, gbc);
gbc.gridy++;
gbc.weightx = 1.0;
gbc.weighty = 1.0;
gbc.anchor = GridBagConstraints.SOUTH;
gbc.fill = GridBagConstraints.BOTH;
add(logBox, gbc);
}
use of java.awt.event.FocusListener in project ceylon by eclipse.
the class SelectToolTask method createPane.
JOptionPane createPane(final Properties props) {
JPanel body = new JPanel(new GridBagLayout());
GridBagConstraints lc = new GridBagConstraints();
lc.insets.right = 10;
lc.insets.bottom = 3;
GridBagConstraints fc = new GridBagConstraints();
fc.anchor = GridBagConstraints.WEST;
fc.gridx = 1;
fc.gridwidth = GridBagConstraints.REMAINDER;
fc.insets.bottom = 3;
JLabel toolLabel = new JLabel("Tool:");
body.add(toolLabel, lc);
String[] toolChoices = { "apt", "javac", "javadoc", "javah", "javap" };
if (true || toolProperty == null) {
// include empty value in setup mode
List<String> l = new ArrayList<String>(Arrays.asList(toolChoices));
l.add(0, "");
toolChoices = l.toArray(new String[l.size()]);
}
toolChoice = new JComboBox(toolChoices);
if (toolName != null)
toolChoice.setSelectedItem(toolName);
toolChoice.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
String tn = (String) e.getItem();
argsField.setText(getDefaultArgsForTool(props, tn));
if (toolProperty != null)
okButton.setEnabled(!tn.equals(""));
}
});
body.add(toolChoice, fc);
argsField = new JTextField(getDefaultArgsForTool(props, toolName), 40);
if (toolProperty == null || argsProperty != null) {
JLabel argsLabel = new JLabel("Args:");
body.add(argsLabel, lc);
body.add(argsField, fc);
argsField.addFocusListener(new FocusListener() {
public void focusGained(FocusEvent e) {
}
public void focusLost(FocusEvent e) {
String toolName = (String) toolChoice.getSelectedItem();
if (toolName.length() > 0)
props.put(toolName + ".args", argsField.getText());
}
});
}
defaultCheck = new JCheckBox("Set as default");
if (toolProperty == null)
defaultCheck.setSelected(true);
else
body.add(defaultCheck, fc);
final JOptionPane p = new JOptionPane(body);
okButton = new JButton("OK");
okButton.setEnabled(toolProperty == null || (toolName != null && !toolName.equals("")));
okButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JDialog d = (JDialog) SwingUtilities.getAncestorOfClass(JDialog.class, p);
d.setVisible(false);
}
});
p.setOptions(new Object[] { okButton });
return p;
}
use of java.awt.event.FocusListener in project qi4j-sdk by Qi4j.
the class BoundProperty method use.
public void use(Property<T> actualProperty) {
T value = null;
if (actualProperty != null) {
value = actualProperty.get();
}
stateModel.use(value);
for (JComponent component : components) {
SwingAdapter adapter = adapters.get(component.getClass());
adapter.fromPropertyToSwing(component, actualProperty);
for (FocusListener listener : component.getFocusListeners()) {
if (PropertyFocusLostListener.class.isInstance(listener)) {
((PropertyFocusLostListener) listener).use(adapter, actualProperty);
}
}
}
}
Aggregations