use of javax.swing.DefaultCellEditor in project zaproxy by zaproxy.
the class PolicyCategoryPanel method getTableTest.
/**
* This method initializes tableTest
*
* @return javax.swing.JTable
*/
private JTable getTableTest() {
if (tableTest == null) {
tableTest = new JTable();
tableTest.setModel(getCategoryTableModel());
tableTest.setRowHeight(DisplayUtils.getScaledSize(18));
tableTest.setIntercellSpacing(new java.awt.Dimension(1, 1));
tableTest.setAutoCreateRowSorter(true);
//Default sort by name (column 0)
List<RowSorter.SortKey> sortKeys = new ArrayList<RowSorter.SortKey>(1);
sortKeys.add(new RowSorter.SortKey(0, SortOrder.ASCENDING));
tableTest.getRowSorter().setSortKeys(sortKeys);
for (int i = 0; i < tableTest.getColumnCount() - 1; i++) {
TableColumn column = tableTest.getColumnModel().getColumn(i);
column.setPreferredWidth(width[i]);
}
JComboBox<String> jcb1 = new JComboBox<>();
for (AlertThreshold level : AlertThreshold.values()) {
jcb1.addItem(Constant.messages.getString("ascan.policy.level." + level.name().toLowerCase()));
}
tableTest.getColumnModel().getColumn(1).setCellEditor(new DefaultCellEditor(jcb1));
JComboBox<String> jcb2 = new JComboBox<>();
for (AttackStrength level : AttackStrength.values()) {
jcb2.addItem(Constant.messages.getString("ascan.policy.level." + level.name().toLowerCase()));
}
tableTest.getColumnModel().getColumn(2).setCellEditor(new DefaultCellEditor(jcb2));
}
return tableTest;
}
use of javax.swing.DefaultCellEditor in project zaproxy by zaproxy.
the class PolicyPassiveScanPanel method getTableTest.
/**
* This method initializes tableTest
*
* @return javax.swing.JTable
*/
private JTable getTableTest() {
if (tableTest == null) {
tableTest = new JTable();
tableTest.setModel(getPassiveScanTableModel());
tableTest.setRowHeight(DisplayUtils.getScaledSize(18));
tableTest.setIntercellSpacing(new java.awt.Dimension(1, 1));
tableTest.setAutoCreateRowSorter(true);
//Default sort by name (column 0)
List<RowSorter.SortKey> sortKeys = new ArrayList<RowSorter.SortKey>(1);
sortKeys.add(new RowSorter.SortKey(0, SortOrder.ASCENDING));
tableTest.getRowSorter().setSortKeys(sortKeys);
for (int i = 0; i < tableTest.getColumnCount() - 1; i++) {
TableColumn column = tableTest.getColumnModel().getColumn(i);
column.setPreferredWidth(width[i]);
}
JComboBox<String> jcb1 = new JComboBox<>();
for (AlertThreshold level : AlertThreshold.values()) {
jcb1.addItem(Constant.messages.getString("ascan.policy.level." + level.name().toLowerCase()));
}
tableTest.getColumnModel().getColumn(1).setCellEditor(new DefaultCellEditor(jcb1));
}
return tableTest;
}
use of javax.swing.DefaultCellEditor in project ACS by ACS-Community.
the class CDBTable method setUpStringEditor.
public void setUpStringEditor() {
// , this);
final StringField stringField = new StringField("", 3);
DefaultCellEditor stringEditor = new DefaultCellEditor(stringField) {
public Object getCellEditorValue() {
return stringField.getValue();
}
};
setDefaultEditor(String.class, stringEditor);
}
use of javax.swing.DefaultCellEditor in project JMRI by JMRI.
the class TableFrames method makePathTurnoutFrame.
/*
* ********************* PathTurnoutFrame *****************************
*/
protected JInternalFrame makePathTurnoutFrame(OBlock block, String pathName) {
String title = Bundle.getMessage("TitlePathTurnoutTable", block.getDisplayName(), pathName);
JInternalFrame frame = new JInternalFrame(title, true, true, false, true);
if (log.isDebugEnabled()) {
log.debug("makePathTurnoutFrame for Block " + block.getDisplayName() + " and Path " + pathName);
}
frame.setName(makePathTurnoutName(block.getSystemName(), pathName));
OPath path = block.getPathByName(pathName);
if (path == null) {
return null;
}
PathTurnoutTableModel PathTurnoutModel = new PathTurnoutTableModel(path);
PathTurnoutModel.init();
JTable PathTurnoutTable = new JTable(PathTurnoutModel);
PathTurnoutTable.setTransferHandler(new jmri.util.DnDTableImportExportHandler(new int[] { PathTurnoutTableModel.SETTINGCOLUMN, PathTurnoutTableModel.DELETE_COL }));
PathTurnoutTable.setDragEnabled(true);
JComboBox<String> box = new JComboBox<String>(PathTurnoutTableModel.turnoutStates);
PathTurnoutTable.getColumnModel().getColumn(PathTurnoutTableModel.SETTINGCOLUMN).setCellEditor(new DefaultCellEditor(box));
PathTurnoutTable.getColumnModel().getColumn(PathTurnoutTableModel.DELETE_COL).setCellEditor(new ButtonEditor(new JButton()));
PathTurnoutTable.getColumnModel().getColumn(PathTurnoutTableModel.DELETE_COL).setCellRenderer(new ButtonRenderer());
//PathTurnoutTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
for (int i = 0; i < PathTurnoutModel.getColumnCount(); i++) {
int width = PathTurnoutModel.getPreferredWidth(i);
PathTurnoutTable.getColumnModel().getColumn(i).setPreferredWidth(width);
}
PathTurnoutTable.sizeColumnsToFit(-1);
int tableWidth = PathTurnoutTable.getPreferredSize().width;
PathTurnoutTable.setPreferredScrollableViewportSize(new java.awt.Dimension(tableWidth, ROW_HEIGHT * 5));
JScrollPane tablePane = new JScrollPane(PathTurnoutTable);
JPanel contentPane = new JPanel();
contentPane.setLayout(new BorderLayout(5, 5));
JLabel prompt = new JLabel(Bundle.getMessage("AddTurnoutPrompt"));
contentPane.add(prompt, BorderLayout.NORTH);
contentPane.add(tablePane, BorderLayout.CENTER);
frame.addInternalFrameListener(this);
frame.setContentPane(contentPane);
frame.setLocation(10, 270);
frame.pack();
return frame;
}
use of javax.swing.DefaultCellEditor in project JMRI by JMRI.
the class LogixTableAction method makeEditConditionalWindow.
// ********************* Edit Conditional Window and Methods *******************
/**
* Create and/or initialize the Edit Conditional window.
* <p>
* Note: you can get here via the New Conditional button (newConditionalPressed)
* or via an Edit button in the Conditional table of the Edit Logix window.
*/
void makeEditConditionalWindow() {
// deactivate this Logix
_curLogix.deActivateLogix();
conditionalUserName.setText(_curConditional.getUserName());
if (editConditionalFrame == null) {
editConditionalFrame = new JmriJFrame(rbx.getString("TitleEditConditional"), false, false);
editConditionalFrame.addHelpMenu("package.jmri.jmrit.beantable.ConditionalAddEdit", true);
Container contentPane = editConditionalFrame.getContentPane();
contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
JPanel panel1 = new JPanel();
panel1.setLayout(new FlowLayout());
panel1.add(new JLabel(Bundle.getMessage("ColumnSystemName") + ":"));
panel1.add(new JLabel(_curConditional.getSystemName()));
contentPane.add(panel1);
JPanel panel2 = new JPanel();
panel2.setLayout(new FlowLayout());
panel2.add(new JLabel(Bundle.getMessage("ColumnUserName") + ":"));
panel2.add(conditionalUserName);
conditionalUserName.setToolTipText(rbx.getString("ConditionalUserNameHint"));
contentPane.add(panel2);
// add Logical Expression Section
JPanel logicPanel = new JPanel();
logicPanel.setLayout(new BoxLayout(logicPanel, BoxLayout.Y_AXIS));
// add Antecedent Expression Panel -ONLY appears for MIXED operator statements
_antecedent = _curConditional.getAntecedentExpression();
_logicType = _curConditional.getLogicType();
_antecedentField = new JTextField(65);
_antecedentField.setFont(new Font("SansSerif", Font.BOLD, 14));
_antecedentField.setText(_antecedent);
_antecedentPanel = makeEditPanel(_antecedentField, "LabelAntecedent", "LabelAntecedentHint");
JButton helpButton = new JButton(Bundle.getMessage("MenuHelp"));
_antecedentPanel.add(helpButton);
helpButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
helpPressed(e);
}
});
_antecedentPanel.add(helpButton);
_antecedentPanel.setVisible(_logicType == Conditional.MIXED);
logicPanel.add(_antecedentPanel);
// add state variable table title
JPanel varTitle = new JPanel();
varTitle.setLayout(new FlowLayout());
varTitle.add(new JLabel(rbx.getString("StateVariableTableTitle")));
logicPanel.add(varTitle);
// set up state variables table
// initialize and populate Combo boxes for table of state variables
_notOperatorBox = new JComboBox<String>();
_notOperatorBox.addItem(" ");
_notOperatorBox.addItem(Bundle.getMessage("LogicNOT"));
_andOperatorBox = new JComboBox<String>();
_andOperatorBox.addItem(Bundle.getMessage("LogicAND"));
_andOperatorBox.addItem(Bundle.getMessage("LogicOR"));
// initialize table of state variables
_variableTableModel = new VariableTableModel();
JTable variableTable = new JTable(_variableTableModel);
variableTable.setRowHeight(_notOperatorBox.getPreferredSize().height);
variableTable.setRowSelectionAllowed(false);
int rowHeight = variableTable.getRowHeight();
TableColumnModel variableColumnModel = variableTable.getColumnModel();
TableColumn rowColumn = variableColumnModel.getColumn(VariableTableModel.ROWNUM_COLUMN);
rowColumn.setResizable(false);
rowColumn.setMaxWidth(new JTextField(3).getPreferredSize().width);
TableColumn andColumn = variableColumnModel.getColumn(VariableTableModel.AND_COLUMN);
andColumn.setResizable(false);
andColumn.setCellEditor(new DefaultCellEditor(_andOperatorBox));
andColumn.setMaxWidth(_andOperatorBox.getPreferredSize().width - 5);
TableColumn notColumn = variableColumnModel.getColumn(VariableTableModel.NOT_COLUMN);
notColumn.setCellEditor(new DefaultCellEditor(_notOperatorBox));
notColumn.setMaxWidth(_notOperatorBox.getPreferredSize().width - 5);
notColumn.setResizable(false);
TableColumn descColumn = variableColumnModel.getColumn(VariableTableModel.DESCRIPTION_COLUMN);
descColumn.setPreferredWidth(300);
descColumn.setMinWidth(200);
descColumn.setResizable(true);
TableColumn stateColumn = variableColumnModel.getColumn(VariableTableModel.STATE_COLUMN);
stateColumn.setResizable(true);
stateColumn.setMinWidth(50);
stateColumn.setMaxWidth(80);
TableColumn triggerColumn = variableColumnModel.getColumn(VariableTableModel.TRIGGERS_COLUMN);
triggerColumn.setResizable(true);
triggerColumn.setMinWidth(30);
triggerColumn.setMaxWidth(80);
TableColumn editColumn = variableColumnModel.getColumn(VariableTableModel.EDIT_COLUMN);
ButtonRenderer buttonRenderer = new ButtonRenderer();
variableTable.setDefaultRenderer(JButton.class, buttonRenderer);
TableCellEditor buttonEditor = new ButtonEditor(new JButton());
variableTable.setDefaultEditor(JButton.class, buttonEditor);
JButton testButton = new JButton("XXXXXX");
variableTable.setRowHeight(testButton.getPreferredSize().height);
editColumn.setMinWidth(testButton.getPreferredSize().width);
editColumn.setMaxWidth(testButton.getPreferredSize().width);
editColumn.setResizable(false);
TableColumn deleteColumn = variableColumnModel.getColumn(VariableTableModel.DELETE_COLUMN);
// ButtonRenderer and TableCellEditor already set
deleteColumn.setMinWidth(testButton.getPreferredSize().width);
deleteColumn.setMaxWidth(testButton.getPreferredSize().width);
deleteColumn.setResizable(false);
// add a scroll pane
JScrollPane variableTableScrollPane = new JScrollPane(variableTable);
Dimension dim = variableTable.getPreferredSize();
dim.height = 7 * rowHeight;
variableTableScrollPane.getViewport().setPreferredSize(dim);
logicPanel.add(variableTableScrollPane);
// set up state variable buttons and logic
JPanel panel42 = new JPanel();
panel42.setLayout(new FlowLayout());
// Add State Variable
JButton addVariableButton = new JButton(rbx.getString("AddVariableButton"));
panel42.add(addVariableButton);
addVariableButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
addVariablePressed(e);
}
});
addVariableButton.setToolTipText(rbx.getString("AddVariableButtonHint"));
JButton checkVariableButton = new JButton(rbx.getString("CheckVariableButton"));
panel42.add(checkVariableButton);
checkVariableButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
checkVariablePressed(e);
}
});
checkVariableButton.setToolTipText(rbx.getString("CheckVariableButtonHint"));
logicPanel.add(panel42);
// logic type area
_operatorBox = new JComboBox<String>(new String[] { Bundle.getMessage("LogicAND"), Bundle.getMessage("LogicOR"), Bundle.getMessage("LogicMixed") });
JPanel typePanel = makeEditPanel(_operatorBox, "LabelLogicType", "TypeLogicHint");
_operatorBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
logicTypeChanged(e);
}
});
_operatorBox.setSelectedIndex(_logicType - 1);
logicPanel.add(typePanel);
logicPanel.add(Box.createHorizontalStrut(STRUT));
Border logicPanelBorder = BorderFactory.createEtchedBorder();
Border logicPanelTitled = BorderFactory.createTitledBorder(logicPanelBorder, rbx.getString("TitleLogicalExpression") + " ");
logicPanel.setBorder(logicPanelTitled);
contentPane.add(logicPanel);
// End of Logic Expression Section
JPanel triggerPanel = new JPanel();
triggerPanel.setLayout(new BoxLayout(triggerPanel, BoxLayout.Y_AXIS));
ButtonGroup tGroup = new ButtonGroup();
_triggerOnChangeButton = new JRadioButton(rbx.getString("triggerOnChange"));
_triggerOnChangeButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
_actionTableModel.fireTableDataChanged();
}
});
tGroup.add(_triggerOnChangeButton);
triggerPanel.add(_triggerOnChangeButton);
JRadioButton triggerOnAny = new JRadioButton(rbx.getString("triggerOnAny"));
triggerOnAny.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
_actionTableModel.fireTableDataChanged();
}
});
tGroup.add(triggerOnAny);
triggerPanel.add(triggerOnAny);
triggerOnAny.setSelected(true);
JPanel trigPanel = new JPanel();
trigPanel.add(triggerPanel);
contentPane.add(trigPanel);
_triggerOnChangeButton.setSelected(_curConditional.getTriggerOnChange());
// add Action Consequents Section
JPanel conseqentPanel = new JPanel();
conseqentPanel.setLayout(new BoxLayout(conseqentPanel, BoxLayout.Y_AXIS));
JPanel actTitle = new JPanel();
actTitle.setLayout(new FlowLayout());
actTitle.add(new JLabel(rbx.getString("ActionTableTitle")));
conseqentPanel.add(actTitle);
// set up action consequents table
_actionTableModel = new ActionTableModel();
JTable actionTable = new JTable(_actionTableModel);
actionTable.setRowSelectionAllowed(false);
actionTable.setRowHeight(testButton.getPreferredSize().height);
JPanel actionPanel = new JPanel();
actionPanel.setLayout(new BoxLayout(actionPanel, BoxLayout.Y_AXIS));
JPanel actionTitle = new JPanel();
actionTitle.setLayout(new FlowLayout());
conseqentPanel.add(actionPanel);
TableColumnModel actionColumnModel = actionTable.getColumnModel();
TableColumn descriptionColumn = actionColumnModel.getColumn(ActionTableModel.DESCRIPTION_COLUMN);
descriptionColumn.setResizable(true);
descriptionColumn.setPreferredWidth(600);
descriptionColumn.setMinWidth(300);
//descriptionColumn.setMaxWidth(760);
TableColumn actionEditColumn = actionColumnModel.getColumn(ActionTableModel.EDIT_COLUMN);
// ButtonRenderer already exists
actionTable.setDefaultRenderer(JButton.class, buttonRenderer);
TableCellEditor editButEditor = new ButtonEditor(new JButton());
actionTable.setDefaultEditor(JButton.class, editButEditor);
actionEditColumn.setMinWidth(testButton.getPreferredSize().width);
actionEditColumn.setMaxWidth(testButton.getPreferredSize().width);
actionEditColumn.setResizable(false);
TableColumn actionDeleteColumn = actionColumnModel.getColumn(ActionTableModel.DELETE_COLUMN);
// ButtonRenderer and TableCellEditor already set
actionDeleteColumn.setMinWidth(testButton.getPreferredSize().width);
actionDeleteColumn.setMaxWidth(testButton.getPreferredSize().width);
actionDeleteColumn.setResizable(false);
// add a scroll pane
JScrollPane actionTableScrollPane = new JScrollPane(actionTable);
dim = actionTableScrollPane.getPreferredSize();
dim.height = 7 * rowHeight;
actionTableScrollPane.getViewport().setPreferredSize(dim);
conseqentPanel.add(actionTableScrollPane);
// add action buttons to Action Section
JPanel panel43 = new JPanel();
panel43.setLayout(new FlowLayout());
JButton addActionButton = new JButton(rbx.getString("addActionButton"));
panel43.add(addActionButton);
addActionButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
addActionPressed(e);
}
});
addActionButton.setToolTipText(rbx.getString("addActionButtonHint"));
conseqentPanel.add(panel43);
// - Reorder action button
JButton reorderButton = new JButton(rbx.getString("ReorderButton"));
panel43.add(reorderButton);
reorderButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
reorderActionPressed(e);
}
});
reorderButton.setToolTipText(rbx.getString("ReorderButtonHint"));
conseqentPanel.add(panel43);
Border conseqentPanelBorder = BorderFactory.createEtchedBorder();
Border conseqentPanelTitled = BorderFactory.createTitledBorder(conseqentPanelBorder, rbx.getString("TitleAction"));
conseqentPanel.setBorder(conseqentPanelTitled);
contentPane.add(conseqentPanel);
// End of Action Consequents Section
// Bottom Buttons - Update Conditional
JPanel panel5 = new JPanel();
panel5.setLayout(new FlowLayout());
JButton updateConditional = new JButton(rbx.getString("UpdateConditionalButton"));
panel5.add(updateConditional);
updateConditional.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
updateConditionalPressed(e);
}
});
updateConditional.setToolTipText(rbx.getString("UpdateConditionalButtonHint"));
// Cancel
JButton cancelConditional = new JButton(Bundle.getMessage("ButtonCancel"));
panel5.add(cancelConditional);
cancelConditional.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
cancelConditionalPressed(e);
}
});
cancelConditional.setToolTipText(rbx.getString("CancelConditionalButtonHint"));
// Delete Conditional
JButton deleteConditional = new JButton(Bundle.getMessage("ButtonDelete"));
panel5.add(deleteConditional);
deleteConditional.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
deleteConditionalPressed(null);
}
});
deleteConditional.setToolTipText(rbx.getString("DeleteConditionalButtonHint"));
contentPane.add(panel5);
}
// setup window closing listener
editConditionalFrame.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
cancelConditionalPressed(null);
}
});
// initialize state variable table
_variableTableModel.fireTableDataChanged();
// initialize action variables
_actionTableModel.fireTableDataChanged();
editConditionalFrame.pack();
editConditionalFrame.setVisible(true);
inEditConditionalMode = true;
// update variables to their current states
checkVariablePressed(null);
}
Aggregations