use of javax.swing.JFormattedTextField in project Smack by igniterealtime.
the class EnhancedDebugger method addInformationPanel.
private void addInformationPanel() {
// Create UI elements for connection information.
JPanel informationPanel = new JPanel();
informationPanel.setLayout(new BorderLayout());
// Add the Host information
JPanel connPanel = new JPanel();
connPanel.setLayout(new GridBagLayout());
connPanel.setBorder(BorderFactory.createTitledBorder("XMPPConnection information"));
JLabel label = new JLabel("Host: ");
label.setMinimumSize(new java.awt.Dimension(150, 14));
label.setMaximumSize(new java.awt.Dimension(150, 14));
connPanel.add(label, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, 21, 0, new Insets(0, 0, 0, 0), 0, 0));
JFormattedTextField field = new JFormattedTextField(connection.getXMPPServiceDomain());
field.setMinimumSize(new java.awt.Dimension(150, 20));
field.setMaximumSize(new java.awt.Dimension(150, 20));
field.setEditable(false);
field.setBorder(null);
connPanel.add(field, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, 10, 2, new Insets(0, 0, 0, 0), 0, 0));
// Add the Port information
label = new JLabel("Port: ");
label.setMinimumSize(new java.awt.Dimension(150, 14));
label.setMaximumSize(new java.awt.Dimension(150, 14));
connPanel.add(label, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, 21, 0, new Insets(0, 0, 0, 0), 0, 0));
field = new JFormattedTextField(connection.getPort());
field.setMinimumSize(new java.awt.Dimension(150, 20));
field.setMaximumSize(new java.awt.Dimension(150, 20));
field.setEditable(false);
field.setBorder(null);
connPanel.add(field, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, 10, 2, new Insets(0, 0, 0, 0), 0, 0));
// Add the connection's User information
label = new JLabel("User: ");
label.setMinimumSize(new java.awt.Dimension(150, 14));
label.setMaximumSize(new java.awt.Dimension(150, 14));
connPanel.add(label, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, 21, 0, new Insets(0, 0, 0, 0), 0, 0));
userField = new JFormattedTextField();
userField.setMinimumSize(new java.awt.Dimension(150, 20));
userField.setMaximumSize(new java.awt.Dimension(150, 20));
userField.setEditable(false);
userField.setBorder(null);
connPanel.add(userField, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0, 10, 2, new Insets(0, 0, 0, 0), 0, 0));
// Add the connection's creationTime information
label = new JLabel("Creation time: ");
label.setMinimumSize(new java.awt.Dimension(150, 14));
label.setMaximumSize(new java.awt.Dimension(150, 14));
connPanel.add(label, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, 21, 0, new Insets(0, 0, 0, 0), 0, 0));
field = new JFormattedTextField(new SimpleDateFormat("yyyy.MM.dd HH:mm:ss:SS"));
field.setMinimumSize(new java.awt.Dimension(150, 20));
field.setMaximumSize(new java.awt.Dimension(150, 20));
field.setValue(creationTime);
field.setEditable(false);
field.setBorder(null);
connPanel.add(field, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0, 10, 2, new Insets(0, 0, 0, 0), 0, 0));
// Add the connection's creationTime information
label = new JLabel("Status: ");
label.setMinimumSize(new java.awt.Dimension(150, 14));
label.setMaximumSize(new java.awt.Dimension(150, 14));
connPanel.add(label, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, 21, 0, new Insets(0, 0, 0, 0), 0, 0));
statusField = new JFormattedTextField();
statusField.setMinimumSize(new java.awt.Dimension(150, 20));
statusField.setMaximumSize(new java.awt.Dimension(150, 20));
statusField.setValue("Active");
statusField.setEditable(false);
statusField.setBorder(null);
connPanel.add(statusField, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0, 10, 2, new Insets(0, 0, 0, 0), 0, 0));
// Add the connection panel to the information panel
informationPanel.add(connPanel, BorderLayout.NORTH);
// Add the Number of sent packets information
JPanel packetsPanel = new JPanel();
packetsPanel.setLayout(new GridLayout(1, 1));
packetsPanel.setBorder(BorderFactory.createTitledBorder("Transmitted Packets"));
statisticsTable = new DefaultTableModel(new Object[][] { { "IQ", 0, 0 }, { "Message", 0, 0 }, { "Presence", 0, 0 }, { "Other", 0, 0 }, { "Total", 0, 0 } }, new Object[] { "Type", "Received", "Sent" }) {
// CHECKSTYLE:OFF
private static final long serialVersionUID = -6793886085109589269L;
@Override
public boolean isCellEditable(int rowIndex, int mColIndex) {
// CHECKSTYLE:ON
return false;
}
};
JTable table = new JTable(statisticsTable);
// Allow only single a selection
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
packetsPanel.add(new JScrollPane(table));
// Add the packets panel to the information panel
informationPanel.add(packetsPanel, BorderLayout.CENTER);
tabbedPane.add("Information", new JScrollPane(informationPanel));
tabbedPane.setToolTipTextAt(4, "Information and statistics about the debugged connection");
}
use of javax.swing.JFormattedTextField in project libgdx by libgdx.
the class Hiero method initializeEvents.
private void initializeEvents() {
fontList.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent evt) {
if (evt.getValueIsAdjusting())
return;
prefs.put("system.font", (String) fontList.getSelectedValue());
updateFont();
}
});
class FontUpdateListener implements ChangeListener, ActionListener {
public void stateChanged(ChangeEvent evt) {
updateFont();
}
public void actionPerformed(ActionEvent evt) {
updateFont();
}
public void addSpinners(JSpinner[] spinners) {
for (int i = 0; i < spinners.length; i++) {
final JSpinner spinner = spinners[i];
spinner.addChangeListener(this);
((JSpinner.DefaultEditor) spinner.getEditor()).getTextField().addKeyListener(new KeyAdapter() {
String lastText;
public void keyReleased(KeyEvent evt) {
JFormattedTextField textField = ((JSpinner.DefaultEditor) spinner.getEditor()).getTextField();
String text = textField.getText();
if (text.length() == 0)
return;
if (text.equals(lastText))
return;
lastText = text;
int caretPosition = textField.getCaretPosition();
try {
spinner.setValue(Integer.valueOf(text));
} catch (NumberFormatException ex) {
}
textField.setCaretPosition(caretPosition);
}
});
}
}
}
FontUpdateListener listener = new FontUpdateListener();
listener.addSpinners(new JSpinner[] { padTopSpinner, padRightSpinner, padBottomSpinner, padLeftSpinner, padAdvanceXSpinner, padAdvanceYSpinner });
fontSizeSpinner.addChangeListener(listener);
gammaSpinner.addChangeListener(listener);
glyphPageWidthCombo.addActionListener(listener);
glyphPageHeightCombo.addActionListener(listener);
boldCheckBox.addActionListener(listener);
italicCheckBox.addActionListener(listener);
monoCheckBox.addActionListener(listener);
resetCacheButton.addActionListener(listener);
javaRadio.addActionListener(listener);
nativeRadio.addActionListener(listener);
freeTypeRadio.addActionListener(listener);
sampleTextRadio.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
glyphCachePanel.setVisible(false);
}
});
glyphCacheRadio.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
glyphCachePanel.setVisible(true);
}
});
fontFileText.getDocument().addDocumentListener(new DocumentListener() {
public void removeUpdate(DocumentEvent evt) {
changed();
}
public void insertUpdate(DocumentEvent evt) {
changed();
}
public void changedUpdate(DocumentEvent evt) {
changed();
}
private void changed() {
File file = new File(fontFileText.getText());
if (fontList.isEnabled() && (!file.exists() || !file.isFile()))
return;
prefs.put("font.file", fontFileText.getText());
updateFont();
}
});
final ActionListener al = new ActionListener() {
public void actionPerformed(ActionEvent evt) {
updateFontSelector();
updateFont();
}
};
systemFontRadio.addActionListener(al);
fontFileRadio.addActionListener(al);
browseButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
FileDialog dialog = new FileDialog(Hiero.this, "Choose TrueType font file", FileDialog.LOAD);
dialog.setLocationRelativeTo(null);
dialog.setFile("*.ttf");
dialog.setDirectory(prefs.get("dir.font", ""));
dialog.setVisible(true);
if (dialog.getDirectory() != null) {
prefs.put("dir.font", dialog.getDirectory());
}
String fileName = dialog.getFile();
if (fileName == null)
return;
fontFileText.setText(new File(dialog.getDirectory(), fileName).getAbsolutePath());
}
});
backgroundColorLabel.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent evt) {
java.awt.Color color = JColorChooser.showDialog(null, "Choose a background color", EffectUtil.fromString(prefs.get("background", "000000")));
if (color == null)
return;
renderingBackgroundColor = new Color(color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, 1);
backgroundColorLabel.setIcon(getColorIcon(color));
prefs.put("background", EffectUtil.toString(color));
}
});
effectsList.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent evt) {
ConfigurableEffect selectedEffect = (ConfigurableEffect) effectsList.getSelectedValue();
boolean enabled = selectedEffect != null;
for (Iterator iter = effectPanels.iterator(); iter.hasNext(); ) {
ConfigurableEffect effect = ((EffectPanel) iter.next()).getEffect();
if (effect == selectedEffect) {
enabled = false;
break;
}
}
addEffectButton.setEnabled(enabled);
}
});
effectsList.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent evt) {
if (evt.getClickCount() == 2 && addEffectButton.isEnabled())
addEffectButton.doClick();
}
});
addEffectButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
new EffectPanel((ConfigurableEffect) effectsList.getSelectedValue());
}
});
openMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
FileDialog dialog = new FileDialog(Hiero.this, "Open Hiero settings file", FileDialog.LOAD);
dialog.setLocationRelativeTo(null);
dialog.setFile("*.hiero");
dialog.setDirectory(prefs.get("dir.open", ""));
dialog.setVisible(true);
if (dialog.getDirectory() != null) {
prefs.put("dir.open", dialog.getDirectory());
}
String fileName = dialog.getFile();
if (fileName == null)
return;
lastOpenFilename = fileName;
open(new File(dialog.getDirectory(), fileName));
}
});
saveMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
FileDialog dialog = new FileDialog(Hiero.this, "Save Hiero settings file", FileDialog.SAVE);
dialog.setLocationRelativeTo(null);
dialog.setFile("*.hiero");
dialog.setDirectory(prefs.get("dir.save", ""));
if (lastSaveFilename.length() > 0) {
dialog.setFile(lastSaveFilename);
} else if (lastOpenFilename.length() > 0) {
dialog.setFile(lastOpenFilename);
}
dialog.setVisible(true);
if (dialog.getDirectory() != null) {
prefs.put("dir.save", dialog.getDirectory());
}
String fileName = dialog.getFile();
if (fileName == null)
return;
if (!fileName.endsWith(".hiero"))
fileName += ".hiero";
lastSaveFilename = fileName;
File file = new File(dialog.getDirectory(), fileName);
try {
save(file);
} catch (IOException ex) {
throw new RuntimeException("Error saving Hiero settings file: " + file.getAbsolutePath(), ex);
}
}
});
saveBMFontMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
FileDialog dialog = new FileDialog(Hiero.this, "Save BMFont files", FileDialog.SAVE);
dialog.setLocationRelativeTo(null);
dialog.setFile("*.fnt");
dialog.setDirectory(prefs.get("dir.savebm", ""));
if (lastSaveBMFilename.length() > 0) {
dialog.setFile(lastSaveBMFilename);
} else if (lastOpenFilename.length() > 0) {
dialog.setFile(lastOpenFilename.replace(".hiero", ".fnt"));
}
dialog.setVisible(true);
if (dialog.getDirectory() != null) {
prefs.put("dir.savebm", dialog.getDirectory());
}
String fileName = dialog.getFile();
if (fileName == null)
return;
lastSaveBMFilename = fileName;
saveBm(new File(dialog.getDirectory(), fileName));
}
});
exitMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
dispose();
}
});
sampleNeheButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
sampleTextPane.setText(NEHE_CHARS);
resetCacheButton.doClick();
}
});
sampleAsciiButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
StringBuilder buffer = new StringBuilder();
buffer.append(NEHE_CHARS);
buffer.append('\n');
int count = 0;
for (int i = 33; i <= 255; i++) {
if (buffer.indexOf(Character.toString((char) i)) != -1)
continue;
buffer.append((char) i);
if (++count % 30 == 0)
buffer.append('\n');
}
sampleTextPane.setText(buffer.toString());
resetCacheButton.doClick();
}
});
sampleExtendedButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
sampleTextPane.setText(EXTENDED_CHARS);
resetCacheButton.doClick();
}
});
}
use of javax.swing.JFormattedTextField in project smile by haifengl.
the class DoubleArrayCellEditor method getCellEditorValue.
@Override
public Object getCellEditorValue() {
JFormattedTextField ftf = (JFormattedTextField) getComponent();
Object o = ftf.getValue();
if (o instanceof double[]) {
return o;
} else {
LOGGER.log(Level.FINE, "getCellEditorValue: can't parse o{0}", o);
return null;
}
}
use of javax.swing.JFormattedTextField in project smile by haifengl.
the class DoubleCellEditor method getCellEditorValue.
@Override
public Object getCellEditorValue() {
JFormattedTextField ftf = (JFormattedTextField) getComponent();
Object o = ftf.getValue();
if (o instanceof Double) {
return o;
} else if (o instanceof Number) {
return new Double(((Number) o).doubleValue());
} else {
try {
return doubleFormat.parseObject(o.toString());
} catch (ParseException ex) {
LOGGER.log(Level.FINE, "getCellEditorValue: can't parse {0}", o);
return null;
}
}
}
use of javax.swing.JFormattedTextField in project smile by haifengl.
the class DoubleCellEditor method getTableCellEditorComponent.
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
JFormattedTextField ftf = (JFormattedTextField) super.getTableCellEditorComponent(table, value, isSelected, row, column);
ftf.setValue(value);
return ftf;
}
Aggregations