use of javax.swing.DefaultCellEditor in project knetbuilder by Rothamsted.
the class DialogConceptLabel method makeConfigPanel.
/**
* Make Login input panel.
*
* @return JPanel
*/
private JPanel makeConfigPanel() {
// editors used for meta data selection etc.
JComboBox accessionDataSources = populateAccessionDataSources();
JComboBox filterDataSources = populateFilterDataSources();
JComboBox filterConceptClasses = populatFilterConceptClasses();
JComboBox separator = populateSeparator();
// editors for choices
JCheckBox includeParserID = new JCheckBox();
JCheckBox preferredName = new JCheckBox();
preferredName.setSelected(true);
// table headers
String[] columnNames = new String[] { Config.language.getProperty("Dialog.ConceptLabel.DataSource"), Config.language.getProperty("Dialog.ConceptLabel.ConceptClass"), Config.language.getProperty("Dialog.ConceptLabel.Accession"), Config.language.getProperty("Dialog.ConceptLabel.Separator"), Config.language.getProperty("Dialog.ConceptLabel.Prefix"), Config.language.getProperty("Dialog.ConceptLabel.RestrictLength"), Config.language.getProperty("Dialog.ConceptLabel.PreferredName"), Config.language.getProperty("Dialog.ConceptLabel.IncludeParserID") };
// table data in first row
Object[][] data = new Object[][] { { filterConceptClasses.getSelectedItem(), filterDataSources.getSelectedItem(), accessionDataSources.getSelectedItem(), separator.getSelectedItem(), "", Integer.valueOf(0), Boolean.valueOf(preferredName.isSelected()), Boolean.valueOf(includeParserID.isSelected()) } };
// put everything in a table
table = new JTable(new MyTableModel(data, columnNames));
// set data source editor
TableColumn dataSourceColumn = table.getColumnModel().getColumn(0);
dataSourceColumn.setCellEditor(new DefaultCellEditor(filterDataSources));
// set concept class editor
TableColumn conceptClassColumn = table.getColumnModel().getColumn(1);
conceptClassColumn.setCellEditor(new DefaultCellEditor(filterConceptClasses));
// set accession editor
TableColumn accessionColumn = table.getColumnModel().getColumn(2);
accessionColumn.setCellEditor(new DefaultCellEditor(accessionDataSources));
// set separator editor
TableColumn separatorColumn = table.getColumnModel().getColumn(3);
separatorColumn.setCellEditor(new DefaultCellEditor(separator));
// layout and put a border around the table
JPanel content = new JPanel(new BorderLayout());
TitledBorder contentBorder;
contentBorder = BorderFactory.createTitledBorder(Config.language.getProperty("Dialog.ConceptLabel.Label"));
content.setBorder(contentBorder);
content.add(BorderLayout.CENTER, new JScrollPane(table));
// add buttons for table control
JPanel buttons = new JPanel(new GridLayout(1, 2));
JButton addButton = new JButton("Add");
addButton.setActionCommand("add");
addButton.addActionListener(this);
buttons.add(addButton);
JButton removeButton = new JButton("Remove");
removeButton.setActionCommand("remove");
removeButton.addActionListener(this);
buttons.add(removeButton);
content.add(BorderLayout.SOUTH, buttons);
return content;
}
use of javax.swing.DefaultCellEditor in project knetbuilder by Rothamsted.
the class ImportWizard method stepThird.
/**
* creates third step of user interaction, sets GUI elements
*
* lets the user label each row and chooses a mapping
*
* @return fully constracted JPanel
*/
@SuppressWarnings("rawtypes")
private JPanel stepThird() {
// create new GridBayLayout
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
// create new JPanel which should be returned at the end
JPanel pane = new JPanel(null);
// set the minimal visible size for resize matter
pane.setMinimumSize(new Dimension(480, 350));
pane.setLayout(gridbag);
// get all necessary options
Hashtable<String, String> options = globalConfiguration.get("third");
// this is the headline
JLabel head = new JLabel();
Font fontHead = new Font("Monospaced", Font.BOLD, 24);
head.setFont(fontHead);
head.setForeground(Color.BLUE);
head.setText((String) options.get("head"));
// this textarea contains the description for the headline
String text = (String) options.get("text");
Font fontText = new Font("Helvetica", Font.BOLD, 18);
JTextArea textArea = new JTextArea(text);
textArea.setBackground(ImportWizard.this.getBackground());
textArea.setEditable(false);
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
textArea.setFont(fontText);
// the textarea width is set according to the config for line wrapping
// prupose
int xSize = Integer.parseInt((String) options.get("textsize"));
int ySize = (int) textArea.getPreferredSize().getHeight() * 2;
// this element should be resize invariant
textArea.setMinimumSize(new Dimension(xSize, ySize));
textArea.setMaximumSize(new Dimension(xSize, ySize));
textArea.setPreferredSize(new Dimension(xSize, ySize));
// a separator with height 3 Pixel
JSeparator separator = new JSeparator();
separator.setMinimumSize(new Dimension(1, 3));
/*
* this lets the user choose what mapping file should be concerned to
* map spot ids on genenames, selection will be processed later and
* results in mapping vector
*/
JLabel label = new JLabel("Choose mapping");
label.setForeground(Color.BLUE);
// get all necessary options
Hashtable<String, String> mappings = globalConfiguration.get("mappings");
String[] mappingNames = new String[mappings.size()];
String[] tooltips = new String[mappings.size()];
int countElements = 0;
for (Enumeration<String> e = mappings.keys(); e.hasMoreElements(); ) {
String keyname = e.nextElement();
mappingNames[countElements] = keyname;
tooltips[countElements] = (String) mappings.get(keyname);
countElements++;
}
// chooser for mapping spotid -> genename
jComboBoxSelectMapping = new JComboBox(mappingNames);
jComboBoxSelectMapping.setActionCommand("mapping");
jComboBoxSelectMapping.setRenderer(new MyComboBoxRenderer(tooltips));
jComboBoxSelectMapping.addActionListener(this);
// myTableModel was created in the secons step and contains all data
if (myTableModel != null) {
ResultContainer content = myTableModel.getContent();
// get headings and table content
ArrayList<String> headings = content.columnNames;
ArrayList<ArrayList<Object>> precontent = content.data;
// first row with contains column selection state
ArrayList<Object> colselect = precontent.get(0);
// create new table headings and a new first row
Vector<String> columnNames = new Vector<String>();
Vector<String> desc = new Vector<String>();
for (int i = 1; i < headings.size(); i++) {
// process only selected columns
if ((Boolean) colselect.get(i) == true) {
columnNames.add(headings.get(i));
// default String do not
desc.add(new String("none"));
// change this
}
}
// compute the new table data according to selection
Vector<Object> data = new Vector<Object>();
// add first row
data.add(desc);
for (int i = 1; i < precontent.size(); i++) {
ArrayList<Object> tmp = precontent.get(i);
// compute data rowwise
if ((Boolean) tmp.get(0) == true) {
Vector<Object> tmp2 = new Vector<Object>();
// check for each column of the row
for (int j = 1; j < tmp.size(); j++) {
// check if this column is selected
if ((Boolean) colselect.get(j) == true) {
// create new row
tmp2.add(tmp.get(j));
}
}
// add row to table data
data.add(tmp2);
}
}
// make a copy without the describtion row
vectorReturnContent = (Vector) data.clone();
vectorReturnContent.remove(0);
// create a new table with specific properties
jTableThirdStep = new MyJTable(data, columnNames, true);
// Set the font a little bit higher.
jTableThirdStep.setFont(new Font("Default", Font.PLAIN, 16));
jTableThirdStep.setRowHeight(23);
// now table editing should be prohibited
jTableThirdStep.setRowSelectionAllowed(false);
jTableThirdStep.setColumnSelectionAllowed(false);
jTableThirdStep.setCellSelectionEnabled(false);
// perfectly fit the content into the table
calcColumnWidths(jTableThirdStep);
/*
* if contentwidth is greater than the minimal width of the table
* disable the auto resizing function of the table and use the
* scrollbars of the scrollpane containing this table instead
*/
if (jTableThirdStep.getPreferredSize().width > 460) {
jTableThirdStep.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
}
Vector firstRow = (Vector) vectorReturnContent.get(0);
for (int i = 0; i < firstRow.size(); i++) {
try {
Double.parseDouble(firstRow.get(i).toString());
DefaultCellEditor cellEditor = (DefaultCellEditor) jTableThirdStep.getCellEditor(0, i);
JComboBox box = (JComboBox) cellEditor.getComponent();
// assumes the last selection to be for value
jTableThirdStep.setValueAt(box.getItemAt(box.getItemCount() - 1), 0, i);
} catch (NumberFormatException nfe) {
continue;
}
}
// for OVTK-334 set first tow columns as cname and cacc
DefaultCellEditor cellEditor = (DefaultCellEditor) jTableThirdStep.getCellEditor(0, 0);
JComboBox box = (JComboBox) cellEditor.getComponent();
jTableThirdStep.setValueAt(box.getItemAt(2), 0, 0);
jTableThirdStep.setValueAt(box.getItemAt(1), 0, 1);
}
// here to back,abort,next buttons are added
JPanel buttons = new JPanel();
addButtonsToJPanel(buttons, 3);
/*
* the following section contains a lot of formating primativs to enable
* a resizing of all the elements above using GridBagLayout
*/
c.fill = GridBagConstraints.BOTH;
c.insets = new Insets(5, 10, 0, 0);
c.gridwidth = 2;
c.weightx = 0.0;
c.gridx = 1;
c.gridy = 1;
gridbag.setConstraints(head, c);
pane.add(head);
c.insets = new Insets(5, 25, 0, 0);
c.gridy = 2;
gridbag.setConstraints(textArea, c);
pane.add(textArea);
JLabel dummyLabel = new JLabel(" ");
c.insets = new Insets(0, 0, 0, 0);
c.gridwidth = 1;
c.weightx = 1.0;
c.gridx = 3;
c.gridy = 2;
gridbag.setConstraints(dummyLabel, c);
pane.add(dummyLabel);
c.insets = new Insets(10, 0, 0, 0);
c.gridwidth = 4;
c.weightx = 0.0;
c.gridx = 1;
c.gridy = 3;
gridbag.setConstraints(separator, c);
pane.add(separator);
c.insets = new Insets(3, 10, 0, 2);
c.gridwidth = 1;
c.weightx = 0.0;
c.gridx = 1;
c.gridy = 4;
gridbag.setConstraints(label, c);
pane.add(label);
c.insets = new Insets(3, 3, 0, 10);
c.gridwidth = 3;
c.weightx = 0.8;
c.gridx = 2;
gridbag.setConstraints(jComboBoxSelectMapping, c);
pane.add(jComboBoxSelectMapping);
JScrollPane scrollPane = new JScrollPane(jTableThirdStep);
c.insets = new Insets(3, 10, 0, 10);
c.gridwidth = 3;
c.weightx = 0.0;
c.weighty = 0.8;
c.gridx = 1;
c.gridy = 5;
gridbag.setConstraints(scrollPane, c);
pane.add(scrollPane);
c.weighty = 0.0;
c.gridy = 6;
gridbag.setConstraints(buttons, c);
pane.add(buttons);
return pane;
}
use of javax.swing.DefaultCellEditor in project WorldPainter by Captain-Chaos.
the class SimpleThemeEditor method setTheme.
public void setTheme(SimpleTheme theme) {
this.theme = theme;
if (theme != null) {
terrainTableModel = new TerrainRangesTableModel(theme.getTerrainRanges());
terrainTableModel.setChangeListener(this);
tableTerrain.setModel(terrainTableModel);
tableTerrain.setDefaultRenderer(Integer.class, new DefaultTableCellRenderer());
tableTerrain.setDefaultRenderer(Terrain.class, new TerrainTableCellRenderer(colourScheme));
tableTerrain.setDefaultRenderer(JButton.class, new JButtonTableCellRenderer());
tableTerrain.setDefaultEditor(Integer.class, new JSpinnerTableCellEditor(new SpinnerNumberModel(1, 1, theme.getMaxHeight() - 1, 1)));
JComboBox terrainEditor = new JComboBox(Terrain.getConfiguredValues());
terrainEditor.setRenderer(new TerrainListCellRenderer(colourScheme));
tableTerrain.setDefaultEditor(Terrain.class, new DefaultCellEditor(terrainEditor));
tableTerrain.setDefaultEditor(JButton.class, new JButtonTableCellEditor(this));
checkBoxBeaches.setSelected(theme.isBeaches());
spinnerWaterLevel.setModel(new SpinnerNumberModel(theme.getWaterHeight(), 0, theme.getMaxHeight() - 1, 1));
spinnerWaterLevel.setEnabled(checkBoxBeaches.isSelected());
checkBoxRandomise.setSelected(theme.isRandomise());
layerTableModel = new LayerRangesTableModel(theme.getMaxHeight(), theme.getLayerMap());
tableLayers.setModel(layerTableModel);
tableLayers.setDefaultRenderer(Layer.class, new LayerTableCellRenderer());
tableLayers.setDefaultRenderer(JButton.class, new JButtonTableCellRenderer());
tableLayers.setDefaultEditor(Integer.class, new JSpinnerTableCellEditor(new SpinnerNumberModel(1, 1, theme.getMaxHeight() - 1, 1)));
tableLayers.setDefaultEditor(JButton.class, new JButtonTableCellEditor(this));
}
}
use of javax.swing.DefaultCellEditor in project josm by openstreetmap.
the class AbstractTableListEditor method build.
@Override
protected JPanel build() {
JPanel p = new JPanel(new GridBagLayout());
p.add(new JLabel(tr("Key: {0}", entry.getKey())), GBC.std(0, 0).span(2).weight(1, 0).insets(0, 0, 5, 10));
JPanel left = new JPanel(new GridBagLayout());
JScrollPane scroll = new JScrollPane(entryList);
left.add(scroll, GBC.eol().fill());
JToolBar sideButtonTB = new JToolBar(JToolBar.HORIZONTAL);
sideButtonTB.setBorderPainted(false);
sideButtonTB.setOpaque(false);
sideButtonTB.add(new NewEntryAction());
RemoveEntryAction removeEntryAction = new RemoveEntryAction();
entryList.getSelectionModel().addListSelectionListener(removeEntryAction);
sideButtonTB.add(removeEntryAction);
left.add(sideButtonTB, GBC.eol());
left.setPreferredSize(new Dimension(80, 0));
p.add(left, GBC.std(0, 1).fill().weight(0.3, 1.0));
table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
DefaultCellEditor editor = new DefaultCellEditor(new JosmTextField());
editor.setClickCountToStart(1);
table.setDefaultEditor(table.getColumnClass(0), editor);
JScrollPane pane = new JScrollPane(table);
pane.setPreferredSize(new Dimension(140, 0));
p.add(pane, GBC.std(1, 1).insets(5, 0, 0, 0).fill().weight(0.7, 1.0));
return p;
}
use of javax.swing.DefaultCellEditor in project beast2 by CompEvol.
the class AlignmentListInputEditor method createListBox.
protected Component createListBox() {
String[] columnData = new String[] { "Name", "File", "Taxa", "Sites", "Data Type", "Site Model", "Clock Model", "Tree", "Ambiguities" };
initTableData();
// set up table.
// special features: background shading of rows
// custom editor allowing only Date column to be edited.
table = new JTable(tableData, columnData) {
private static final long serialVersionUID = 1L;
// method that induces table row shading
@Override
public Component prepareRenderer(TableCellRenderer renderer, int Index_row, int Index_col) {
Component comp = super.prepareRenderer(renderer, Index_row, Index_col);
// even index, selected or not selected
if (isCellSelected(Index_row, Index_col)) {
comp.setBackground(Color.gray);
} else if (Index_row % 2 == 0 && !isCellSelected(Index_row, Index_col)) {
comp.setBackground(new Color(237, 243, 255));
} else {
comp.setBackground(Color.white);
}
JComponent jcomp = (JComponent) comp;
switch(Index_col) {
case NAME_COLUMN:
case CLOCKMODEL_COLUMN:
case TREE_COLUMN:
case SITEMODEL_COLUMN:
jcomp.setToolTipText("Set " + table.getColumnName(Index_col).toLowerCase() + " for this partition");
break;
case FILE_COLUMN:
case TAXA_COLUMN:
case SITES_COLUMN:
case TYPE_COLUMN:
jcomp.setToolTipText("Report " + table.getColumnName(Index_col).toLowerCase() + " for this partition");
break;
case USE_AMBIGUITIES_COLUMN:
jcomp.setToolTipText("<html>Flag whether to use ambiguities.<br>" + "If not set, the treelikelihood will treat ambiguities in the<br>" + "data as unknowns<br>" + "If set, the treelikelihood will use ambiguities as equally<br>" + "likely values for the tips.<br>" + "This will make the computation twice as slow.</html>");
break;
default:
jcomp.setToolTipText(null);
}
updateStatus();
return comp;
}
};
int size = table.getFont().getSize();
table.setRowHeight(25 * size / 13);
table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
table.setColumnSelectionAllowed(false);
table.setRowSelectionAllowed(true);
table.setName("alignmenttable");
setUpComboBoxes();
TableColumn col = table.getColumnModel().getColumn(NAME_COLUMN);
nameEditor = new JTextField();
nameEditor.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void removeUpdate(DocumentEvent e) {
processPartitionName();
}
@Override
public void insertUpdate(DocumentEvent e) {
processPartitionName();
}
@Override
public void changedUpdate(DocumentEvent e) {
processPartitionName();
}
});
col.setCellEditor(new DefaultCellEditor(nameEditor));
// // set up editor that makes sure only doubles are accepted as entry
// // and only the Date column is editable.
table.setDefaultEditor(Object.class, new TableCellEditor() {
JTextField m_textField = new JTextField();
int m_iRow, m_iCol;
@Override
public boolean stopCellEditing() {
// Log.warning.println("stopCellEditing()");
table.removeEditor();
String text = m_textField.getText();
try {
Double.parseDouble(text);
} catch (Exception e) {
return false;
}
tableData[m_iRow][m_iCol] = text;
return true;
}
@Override
public boolean isCellEditable(EventObject anEvent) {
// Log.warning.println("isCellEditable()");
return table.getSelectedColumn() == 0;
}
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int rowNr, int colNr) {
return null;
}
@Override
public boolean shouldSelectCell(EventObject anEvent) {
return false;
}
@Override
public void removeCellEditorListener(CellEditorListener l) {
}
@Override
public Object getCellEditorValue() {
return null;
}
@Override
public void cancelCellEditing() {
}
@Override
public void addCellEditorListener(CellEditorListener l) {
}
});
// show alignment viewer when double clicking a row
table.addMouseListener(new MouseListener() {
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() > 1) {
try {
int alignmemt = table.rowAtPoint(e.getPoint());
Alignment alignment = alignments.get(alignmemt);
int best = 0;
BeautiAlignmentProvider provider = null;
for (BeautiAlignmentProvider provider2 : doc.beautiConfig.alignmentProvider) {
int match = provider2.matches(alignment);
if (match > best) {
best = match;
provider = provider2;
}
}
provider.editAlignment(alignment, doc);
} catch (Exception e1) {
e1.printStackTrace();
}
updateStatus();
} else if (e.getButton() == e.BUTTON3) {
int alignmemt = table.rowAtPoint(e.getPoint());
Alignment alignment = alignments.get(alignmemt);
int result = JOptionPane.showConfirmDialog(null, "Do you want to replace alignment " + alignment.getID());
if (result == JOptionPane.YES_OPTION) {
replaceItem(alignment);
}
}
}
});
scrollPane = new JScrollPane(table);
int rowsToDisplay = 3;
Dimension d = table.getPreferredSize();
scrollPane.setPreferredSize(new Dimension(d.width, table.getRowHeight() * rowsToDisplay + table.getTableHeader().getHeight()));
return scrollPane;
}
Aggregations