use of javax.swing.event.ListSelectionEvent in project jPOS by jpos.
the class ISOMsgPanel method createISOMsgTable.
private JComponent createISOMsgTable() {
TableModel dataModel = new AbstractTableModel() {
private static final long serialVersionUID = 8917029825751856951L;
@Override
public int getColumnCount() {
return 3;
}
@Override
public int getRowCount() {
return validFields.size();
}
@Override
public String getColumnName(int columnIndex) {
switch(columnIndex) {
case 0:
return "#";
case 1:
return "Content";
case 2:
return "Description";
default:
return "";
}
}
@Override
public Object getValueAt(int row, int col) {
switch(col) {
case 0:
return validFields.elementAt(row);
case 1:
int index = (Integer) validFields.elementAt(row);
Object obj = m.getValue(index);
if (obj instanceof String) {
String s = obj.toString();
switch(index) {
case 2:
case 35:
case 45:
s = ISOUtil.protect(s);
break;
case 14:
s = "----";
}
return s;
} else if (obj instanceof byte[])
return ISOUtil.hexString((byte[]) obj);
else if (obj instanceof ISOMsg)
return "<ISOMsg>";
break;
case 2:
int i = (Integer) validFields.elementAt(row);
ISOPackager p = m.getPackager();
return p.getFieldDescription(m, i);
}
return "<???>";
}
};
JTable table = new JTable(dataModel);
table.getColumnModel().getColumn(0).setPreferredWidth(10);
table.setPreferredScrollableViewportSize(new Dimension(500, table.getRowCount() * table.getRowHeight()));
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
ListSelectionModel rowSM = table.getSelectionModel();
rowSM.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
if (e.getValueIsAdjusting())
return;
ListSelectionModel lsm = (ListSelectionModel) e.getSource();
if (!lsm.isSelectionEmpty()) {
int selectedRow = lsm.getMinSelectionIndex();
int index = (Integer) validFields.elementAt(selectedRow);
Object obj = m.getValue(index);
if (obj instanceof ISOMsg) {
ISOMsg sm = (ISOMsg) obj;
JFrame f = new JFrame("ISOMsg field " + index);
ISOMsgPanel p = new ISOMsgPanel(sm, false);
f.getContentPane().add(p);
f.pack();
f.show();
}
}
}
});
return new JScrollPane(table);
}
use of javax.swing.event.ListSelectionEvent in project knime-core by knime.
the class JSnippetPanel method initComponents.
private void initComponents() {
m_colList = new JList(new DefaultListModel());
m_colList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
m_colList.addKeyListener(new KeyAdapter() {
/**
* {@inheritDoc}
*/
@Override
public void keyTyped(final KeyEvent e) {
if (e.getKeyChar() == KeyEvent.VK_ENTER) {
Object selected = m_colList.getSelectedValue();
if (selected != null) {
onSelectionInColumnList(selected);
}
}
}
});
m_colList.addMouseListener(new MouseAdapter() {
/**
* {@inheritDoc}
*/
@Override
public void mouseClicked(final MouseEvent e) {
if (e.getClickCount() == 2) {
Object selected = m_colList.getSelectedValue();
if (selected != null) {
onSelectionInColumnList(selected);
}
}
}
});
m_colList.setCellRenderer(new ListRenderer());
m_flowVarsList = new JList(new DefaultListModel());
m_flowVarsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
// enable tooltip
m_flowVarsList.setToolTipText("");
m_flowVarsList.addKeyListener(new KeyAdapter() {
/**
* {@inheritDoc}
*/
@Override
public void keyTyped(final KeyEvent e) {
if (e.getKeyChar() == KeyEvent.VK_ENTER) {
Object selected = m_flowVarsList.getSelectedValue();
if (selected != null) {
onSelectionInVariableList(selected);
}
}
}
});
m_flowVarsList.addMouseListener(new MouseAdapter() {
/**
* {@inheritDoc}
*/
@Override
public void mouseClicked(final MouseEvent e) {
if (e.getClickCount() == 2) {
Object selected = m_flowVarsList.getSelectedValue();
if (selected != null) {
onSelectionInVariableList(selected);
}
}
}
});
m_flowVarsList.setCellRenderer(new FlowVariableListCellRenderer());
m_categories = new JComboBox(m_manipProvider.getCategories().toArray());
m_categories.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
JComboBox cb = (JComboBox) e.getSource();
String category = (String) cb.getSelectedItem();
updateManipulatorList(category);
}
});
m_manipulators = new JList(new DefaultListModel());
m_manipulators.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
m_manipulators.setCellRenderer(new ManipulatorListCellRenderer());
m_manipulators.addKeyListener(new KeyAdapter() {
/**
* {@inheritDoc}
*/
@Override
public void keyTyped(final KeyEvent e) {
if (e.getKeyChar() == KeyEvent.VK_ENTER) {
Object selected = m_manipulators.getSelectedValue();
if (selected != null) {
onSelectionInManipulatorList(selected);
}
}
}
});
m_manipulators.addMouseListener(new MouseAdapter() {
/**
* {@inheritDoc}
*/
@Override
public void mouseClicked(final MouseEvent e) {
if (e.getClickCount() == 2) {
Object selected = m_manipulators.getSelectedValue();
if (selected != null) {
onSelectionInManipulatorList(selected);
}
}
}
});
m_manipulators.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(final ListSelectionEvent e) {
Object selected = m_manipulators.getSelectedValue();
if (selected != null) {
Manipulator manipulator = (Manipulator) selected;
m_description.setText(manipulator.getDescription());
m_description.setCaretPosition(0);
} else {
m_description.setText("");
}
}
});
HTMLEditorKit kit = new HTMLEditorKit();
StyleSheet css = new StyleSheet();
css.addRule("* { font-family: sans-serif; }");
kit.setStyleSheet(css);
m_description = new JTextPane();
m_description.setEditorKit(kit);
m_description.setEditable(false);
m_description.setBackground(getBackground());
updateManipulatorList(ManipulatorProvider.ALL_CATEGORY);
initSubComponents();
}
use of javax.swing.event.ListSelectionEvent in project knime-core by knime.
the class MissingValueHandling2Panel method createWestLayout.
/**
* @param setting
* @param tabPanel
* @param icon
* @param name
* @param spec
*/
private void createWestLayout(final MissingValueHandling2ColSetting setting, final JPanel tabPanel, final Icon icon, final String name, final DataColumnSpec... spec) {
String shortName = name;
if (setting.isMetaConfig()) {
if (name.length() > 15) {
shortName = name.substring(0, 14).concat("...");
}
JLabel jLabel = new JLabel(shortName, icon, SwingConstants.LEFT);
jLabel.setToolTipText(name);
JPanel typePanel = new JPanel(new BorderLayout());
typePanel.add(jLabel, BorderLayout.NORTH);
tabPanel.add(typePanel, BorderLayout.WEST);
} else {
final JList jList = new JList(spec);
jList.setCellRenderer(new DataColumnSpecListCellRenderer() {
@Override
public Component getListCellRendererComponent(final JList list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) {
// The super method will reset the icon if we call this method
// last. So we let super do its job first and then we take care
// that everything is properly set.
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
String text = null;
if (value instanceof DataColumnSpec && MissingValueHandling2NodeDialogPane.isIncompatible((DataColumnSpec) value)) {
setBorder(BorderFactory.createLineBorder(Color.YELLOW));
text = "Column " + ((DataColumnSpec) value).getName() + " is incompatible to the current settings";
}
setToolTipText(text);
return this;
}
});
jList.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(final ListSelectionEvent e) {
jList.setSelectedIndices(new int[0]);
}
});
// jList.setSE
JScrollPane columns = new JScrollPane(jList);
columns.setMaximumSize(new Dimension(150, 150));
columns.setPreferredSize(new Dimension(100, 150));
tabPanel.add(columns, BorderLayout.WEST);
}
}
use of javax.swing.event.ListSelectionEvent in project knime-core by knime.
the class RuleEngineNodeDialog method createTopPart.
/*
* top part (from left to right) = variable list, operator list, editor box
*/
private Box createTopPart() {
/*
* Variable list (column names)
*/
m_variableModel = new DefaultListModel();
m_variableList = new JList(m_variableModel);
m_variableList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
m_variableList.setCellRenderer(new DataColumnSpecListCellRenderer());
m_variableList.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(final ListSelectionEvent arg0) {
if (arg0.getValueIsAdjusting()) {
return;
}
if (m_lastUsedTextfield != null) {
String existingText = m_lastUsedTextfield.getText();
if (existingText.equals(RULE_LABEL)) {
existingText = "";
}
if (!m_variableList.isSelectionEmpty()) {
String newText = ((DataColumnSpec) m_variableList.getSelectedValue()).getName();
m_lastUsedTextfield.setText((existingText + " $" + newText + "$").trim());
m_lastUsedTextfield.requestFocusInWindow();
if (m_lastUsedTextfield == m_ruleLabelEditor) {
m_outcomeIsColumn.setSelected(true);
}
}
}
m_variableList.clearSelection();
}
});
/*
* Operators (<, >, <=, >=, =, AND, OR, etc)
*/
m_operatorModel = new DefaultListModel();
m_operatorList = new JList(m_operatorModel);
m_operatorList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
m_operatorList.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(final ListSelectionEvent arg0) {
if (!arg0.getValueIsAdjusting() && !m_operatorList.isSelectionEmpty()) {
String existingText = m_ruleEditor.getText();
if (existingText.equals(RULE_LABEL)) {
existingText = "";
}
String newText = (String) m_operatorList.getSelectedValue();
m_ruleEditor.setText(existingText + " " + newText);
m_ruleEditor.requestFocusInWindow();
m_operatorList.clearSelection();
}
}
});
Box editorBox = createEditorPart();
Box listBox = Box.createHorizontalBox();
JScrollPane variableScroller = new JScrollPane(m_variableList);
variableScroller.setBorder(BorderFactory.createTitledBorder("Columns"));
JScrollPane operatorScroller = new JScrollPane(m_operatorList);
operatorScroller.setBorder(BorderFactory.createTitledBorder("Operators"));
listBox.add(variableScroller);
listBox.add(operatorScroller);
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, listBox, editorBox);
Dimension minimumSize = new Dimension(200, 50);
listBox.setMinimumSize(minimumSize);
editorBox.setMinimumSize(minimumSize);
Box topBox = Box.createHorizontalBox();
topBox.add(splitPane);
topBox.add(Box.createHorizontalGlue());
return topBox;
}
use of javax.swing.event.ListSelectionEvent in project knime-core by knime.
the class ColumnSelectionSearchableListPanel method addKeyMouseSelectionListerersToColumnList.
private void addKeyMouseSelectionListerersToColumnList() {
m_columnList.addKeyListener(new KeyAdapter() {
/**
* {@inheritDoc}
*/
@Override
public void keyTyped(final KeyEvent e) {
if (KeyEvent.VK_ENTER == e.getKeyChar()) {
fireConfigurationRequested(Type.CREATION);
} else if (KeyEvent.VK_DELETE == e.getKeyChar()) {
fireConfigurationRequested(Type.DELETION);
}
}
});
m_columnList.addMouseListener(new MouseAdapter() {
/**
* {@inheritDoc}
*/
@Override
public void mouseClicked(final MouseEvent e) {
if (e.getClickCount() == 2) {
fireConfigurationRequested(Type.CREATION);
}
}
});
m_columnList.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(final ListSelectionEvent e) {
fireConfigurationRequested(Type.SELECTION);
}
});
}
Aggregations