use of java.awt.event.FocusListener in project processdash by dtuma.
the class AbstractCustomProcessEditor method buildHeader.
private Component buildHeader() {
Box header = Box.createHorizontalBox();
header.add(Box.createHorizontalStrut(2));
header.add(new JLabel("Framework Name: "));
header.add(processName = new JTextField(20));
header.add(Box.createHorizontalStrut(10));
header.add(new JLabel("Framework Version: "));
header.add(processVersion = new JTextField(5));
header.add(Box.createHorizontalStrut(2));
// Notify the process of changes to the name and version
FocusListener l = new FocusAdapter() {
public void focusLost(FocusEvent e) {
process.setName(processName.getText());
processName.setText(process.getName());
process.setVersion(processVersion.getText());
processVersion.setText(process.getVersion());
}
};
processName.addFocusListener(l);
processVersion.addFocusListener(l);
Box result = Box.createVerticalBox();
result.add(Box.createVerticalStrut(2));
result.add(header);
result.add(Box.createVerticalStrut(2));
return result;
}
use of java.awt.event.FocusListener in project frostwire by frostwire.
the class LibrarySearch method setupUI.
protected void setupUI() {
setLayout(new BorderLayout());
setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
setMinimumSize(new Dimension(200, 20));
setPreferredSize(new Dimension(200, 20));
statusLabel = new JLabel();
statusLabel.setBorder(BorderFactory.createEmptyBorder(5, 10, 0, 0));
add(statusLabel, BorderLayout.CENTER);
searchField = new SearchField();
searchField.setSearchMode(SearchMode.INSTANT);
searchField.setInstantSearchDelay(50);
searchField.setPrompt(I18n.tr("Search in Library"));
Font origFont = searchField.getFont();
Font newFont = origFont.deriveFont(origFont.getSize2D() + 2f);
searchField.setFont(newFont);
searchField.addActionListener(new ActionListener() {
private SearchLibraryAction a = new SearchLibraryAction();
@Override
public void actionPerformed(ActionEvent e) {
if (searchField.getText().length() == 0) {
a.perform(".");
} else {
a.actionPerformed(null);
}
}
});
searchField.addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent e) {
// TODO Auto-generated method stub
}
@Override
public void focusGained(FocusEvent e) {
// if there's nothing selected for search, select Audio directory holder.
if (LibraryMediator.instance().getLibraryExplorer().getSelectedDirectoryHolder() == null && LibraryMediator.instance().getLibraryPlaylists().getSelectedPlaylist() == null) {
LibraryMediator.instance().getLibraryExplorer().selectAudio();
}
}
});
}
use of java.awt.event.FocusListener in project knime-core by knime.
the class LimitRowsPanel method getSkipPanel.
private Container getSkipPanel() {
m_skipLines = new JCheckBox("Skip the first");
m_skipNumber = new JTextField();
m_skipNumber.setColumns(6);
m_skipNumber.setPreferredSize(new Dimension(125, 25));
m_skipNumber.setMaximumSize(new Dimension(125, 25));
m_skipLines.setSelected(false);
m_skipNumber.setEnabled(false);
// make sure we always have a valid value. Reject invalid characters.
m_skipNumber.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void removeUpdate(final DocumentEvent e) {
checkAndFixSkipCount();
}
@Override
public void insertUpdate(final DocumentEvent e) {
checkAndFixSkipCount();
}
@Override
public void changedUpdate(final DocumentEvent e) {
checkAndFixSkipCount();
}
});
m_skipNumber.addFocusListener(new FocusListener() {
@Override
public void focusLost(final FocusEvent e) {
if (m_skipNumber.getText().trim().length() == 0) {
// can't handle no empty strings.
m_lastValidSkips = "0";
m_skipNumber.setText(m_lastValidSkips);
}
}
@Override
public void focusGained(final FocusEvent e) {
}
});
m_skipLines.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(final ChangeEvent e) {
// en/disable the textfield
m_skipNumber.setEnabled(m_skipLines.isSelected());
// also - if the textfield is enabled and empty set a value
if (m_skipNumber.isEnabled()) {
if ((m_skipNumber.getText() == null) || (m_skipNumber.getText().trim().length() == 0)) {
// set a valid value, so we can safely assume that if there is a value in there it's always valid.
m_skipNumber.setText("0");
m_lastValidSkips = "0";
}
}
}
});
Box result = Box.createHorizontalBox();
result.add(m_skipLines);
result.add(Box.createHorizontalStrut(3));
result.add(m_skipNumber);
result.add(Box.createHorizontalStrut(3));
result.add(new JLabel("lines from the beginning of the file."));
result.add(Box.createHorizontalGlue());
return result;
}
use of java.awt.event.FocusListener in project knime-core by knime.
the class FixedWidthFRNodeDialog method createColPropertyPanel.
private JPanel createColPropertyPanel() {
m_colTable = new JTable() {
private final Color m_grey = new Color(125, 125, 125);
// set font color according to included/excluded
@Override
public Component prepareRenderer(final TableCellRenderer renderer, final int row, final int column) {
Component c = super.prepareRenderer(renderer, row, column);
if (!(boolean) m_colPropModel.getValueAt(row, 4)) {
c.setForeground(m_grey);
} else {
c.setForeground(Color.BLACK);
}
return c;
}
};
m_colTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
// dis/enable remove button according to row selection
@Override
public void valueChanged(final ListSelectionEvent e) {
updateEnables();
}
});
m_colTable.addFocusListener(new FocusListener() {
@Override
public void focusGained(final FocusEvent e) {
// enable edit and remove button according to row selection
m_colIdx = m_colTable.getSelectedRow();
updateEnables();
}
@Override
public void focusLost(final FocusEvent e) {
// nothing
}
});
updateColPropTable();
JScrollPane st = new JScrollPane(m_colTable);
st.setPreferredSize(new Dimension(getPanel().getPreferredSize().width, 150));
m_edit = new JButton("Edit");
m_edit.setToolTipText("Change settings of the selected column.");
// add action listener
m_edit.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
onEdit(m_colTable.getSelectedRow());
}
});
m_add = new JButton("Add");
m_add.setToolTipText("Add a new column to the table.");
// add action listener
m_add.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
onAdd();
}
});
m_remove = new JButton("Remove");
m_remove.setToolTipText("Remove the selected column.");
// add action listener
m_remove.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent event) {
onRemove(m_colTable.getSelectedRows());
}
});
JPanel listButtons = new JPanel(new FlowLayout(FlowLayout.RIGHT));
listButtons.add(m_add);
listButtons.add(m_edit);
listButtons.add(m_remove);
// group components nicely
JPanel dlgPanel = new JPanel();
dlgPanel.setLayout(new BoxLayout(dlgPanel, BoxLayout.Y_AXIS));
dlgPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Column configuration"));
dlgPanel.add(st);
dlgPanel.add(listButtons);
return dlgPanel;
}
use of java.awt.event.FocusListener in project Spark by igniterealtime.
the class HistoryTranscript method finished.
/**
* Set the layout settings
*/
public void finished() {
pageLeft.addActionListener(arg0 -> pageLeft());
pageRight.addActionListener(arg0 -> pageRight());
periodChooser.addActionListener(e -> handlePeriodChange(periods.get(periodChooser.getSelectedIndex())));
// add search text input
searchPanel.setLayout(new GridBagLayout());
navigatorPanel.setLayout(new GridBagLayout());
controlPanel.setLayout(new BorderLayout());
filterPanel.setLayout(new GridBagLayout());
mainPanel.setLayout(new BorderLayout());
// the list of periods
// periods.add(period_oneWeek);
// periods.add(period_threeWeeks);
periods.add(period_oneMonth);
periods.add(period_oneYear);
periods.add(period_noPeriod);
// get the default preferences for the search period
int index = getPeriodIndex(pref.getSearchPeriod(periods.get(0)));
for (String period : periods) {
periodChooser.addItem(Res.getString(period));
}
periodChooser.setToolTipText(Res.getString("message.search.page.timeperiod"));
pageCounter.setToolTipText(Res.getString("message.search.page.counter"));
pageRight.setToolTipText(Res.getString("message.search.page.right"));
pageLeft.setToolTipText(Res.getString("message.search.page.left"));
searchField.setText(Res.getString("message.search.for.history"));
searchField.setToolTipText(Res.getString("message.search.for.history"));
searchField.setForeground((Color) UIManager.get("TextField.lightforeground"));
searchPanel.add(vacardPanel, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(1, 5, 1, 1), 0, 0));
filterPanel.add(periodChooser, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1, 5, 1, 1), 0, 0));
filterPanel.add(searchField, new GridBagConstraints(2, 0, GridBagConstraints.REMAINDER, 1, 1.0, 1.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(1, 1, 6, 1), 0, 0));
navigatorPanel.add(pageLeft, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1, 5, 1, 1), 0, 0));
navigatorPanel.add(pageCounter, new GridBagConstraints(1, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(1, 5, 1, 1), 0, 0));
navigatorPanel.add(pageRight, new GridBagConstraints(2, 0, GridBagConstraints.REMAINDER, 1, 1.0, 1.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(1, 1, 6, 1), 0, 0));
controlPanel.add(filterPanel, BorderLayout.NORTH);
controlPanel.add(navigatorPanel, BorderLayout.SOUTH);
overTheTopPanel.setLayout(new BorderLayout());
overTheTopPanel.add(searchPanel, BorderLayout.NORTH);
overTheTopPanel.add(controlPanel, BorderLayout.SOUTH);
mainPanel.add(overTheTopPanel, BorderLayout.NORTH);
window.setEditorKit(new HTMLEditorKit() {
@Override
public ViewFactory getViewFactory() {
return new HTMLFactory() {
public View create(Element e) {
View v = super.create(e);
if (v instanceof InlineView) {
return new InlineView(e) {
public int getBreakWeight(int axis, float pos, float len) {
if (axis == View.X_AXIS) {
checkPainter();
int p0 = getStartOffset();
int p1 = getGlyphPainter().getBoundedPosition(this, p0, pos, len);
if (p1 == p0) {
// can't even fit a single character
return View.BadBreakWeight;
}
try {
// if the view contains line break char return forced break
if (getDocument().getText(p0, p1 - p0).indexOf(SEPARATOR) >= 0) {
return View.ForcedBreakWeight;
}
} catch (BadLocationException ex) {
// should never happen
}
}
return super.getBreakWeight(axis, pos, len);
}
public View breakView(int axis, int p0, float pos, float len) {
if (axis == View.X_AXIS) {
checkPainter();
int p1 = getGlyphPainter().getBoundedPosition(this, p0, pos, len);
try {
// if the view contains line break char break the view
int index = getDocument().getText(p0, p1 - p0).indexOf(SEPARATOR);
if (index >= 0) {
GlyphView v = (GlyphView) createFragment(p0, p0 + index + 1);
return v;
}
} catch (BadLocationException ex) {
// should never happen
}
}
return super.breakView(axis, p0, pos, len);
}
};
} else if (v instanceof javax.swing.text.html.ParagraphView) {
return new javax.swing.text.html.ParagraphView(e) {
protected SizeRequirements calculateMinorAxisRequirements(int axis, SizeRequirements r) {
if (r == null) {
r = new SizeRequirements();
}
float pref = layoutPool.getPreferredSpan(axis);
float min = layoutPool.getMinimumSpan(axis);
r.minimum = (int) min;
r.preferred = Math.max(r.minimum, (int) pref);
r.maximum = Integer.MAX_VALUE;
r.alignment = 0.5f;
return r;
}
};
}
return v;
}
};
}
});
window.setBackground(Color.white);
pane.getVerticalScrollBar().setBlockIncrement(200);
pane.getVerticalScrollBar().setUnitIncrement(20);
mainPanel.add(pane, BorderLayout.CENTER);
frame.setIconImage(SparkRes.getImageIcon(SparkRes.HISTORY_16x16).getImage());
frame.getContentPane().setLayout(new BorderLayout());
frame.getContentPane().add(mainPanel, BorderLayout.CENTER);
frame.pack();
frame.setSize(600, 400);
window.setCaretPosition(0);
window.requestFocus();
GraphicUtils.centerWindowOnScreen(frame);
frame.setVisible(true);
window.setEditable(false);
searchField.addKeyListener(new KeyListener() {
@Override
public void keyTyped(KeyEvent e) {
}
@Override
public void keyReleased(KeyEvent e) {
if (e.getKeyChar() == KeyEvent.VK_ENTER) {
searchQuery = searchField.getText();
TaskEngine.getInstance().schedule(transcriptTask, 10);
searchField.requestFocus();
focusFlag = true;
}
}
@Override
public void keyPressed(KeyEvent e) {
}
});
searchField.addFocusListener(new FocusListener() {
public void focusGained(FocusEvent e) {
if (searchField.getText().equals(Res.getString("message.search.for.history"))) {
searchField.setText("");
}
searchField.setForeground((Color) UIManager.get("TextField.foreground"));
}
public void focusLost(FocusEvent e) {
searchField.setForeground((Color) UIManager.get("TextField.lightforeground"));
if (searchField.getText().length() <= 1) {
searchField.setText(Res.getString("message.search.for.history"));
}
}
});
// after initializing the period, we can load the history
isInitialized.set(true);
periodChooser.setSelectedIndex(index);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
window.setText("");
}
@Override
public void windowClosed(WindowEvent e) {
frame.removeWindowListener(this);
frame.dispose();
transcriptTask.cancel();
searchPanel.remove(vacardPanel);
}
});
}
Aggregations