/** Creates and displays the main GUI This GUI has the list and the main * buttons */ public void showGUI() { final JScrollPane scrollPane = new JScrollPane(); table = new JTable( new DefaultTableModel( new Object[][] {}, new String[] {"Username", "Password", "Pin", "Reward"})); AccountManager.loadAccounts(); if (AccountManager.hasAccounts()) { for (Account account : AccountManager.getAccounts()) { ((DefaultTableModel) table.getModel()) .addRow( new Object[] { account.getUsername(), account.getReward(), account.getPin(), account.getReward() }); } } final JToolBar bar = new JToolBar(); bar.setMargin(new Insets(1, 1, 1, 1)); bar.setFloatable(false); removeButton = new JButton("Remove"); final JButton newButton = new JButton("Add"); final JButton doneButton = new JButton("Save"); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.getSelectionModel().addListSelectionListener(new TableSelectionListener()); table.setShowGrid(true); final TableColumnModel cm = table.getColumnModel(); cm.getColumn(cm.getColumnIndex("Password")).setCellRenderer(new PasswordCellRenderer()); cm.getColumn(cm.getColumnIndex("Password")).setCellEditor(new PasswordCellEditor()); cm.getColumn(cm.getColumnIndex("Pin")).setCellRenderer(new PasswordCellRenderer()); cm.getColumn(cm.getColumnIndex("Pin")).setCellEditor(new PasswordCellEditor()); cm.getColumn(cm.getColumnIndex("Reward")).setCellEditor(new RandomRewardEditor()); scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); scrollPane.setViewportView(table); add(scrollPane, BorderLayout.CENTER); newButton.setFocusable(false); newButton.setToolTipText(newButton.getText()); newButton.setText("+"); bar.add(newButton); removeButton.setFocusable(false); removeButton.setToolTipText(removeButton.getText()); removeButton.setText("-"); bar.add(removeButton); bar.add(Box.createHorizontalGlue()); doneButton.setToolTipText(doneButton.getText()); bar.add(doneButton); newButton.addActionListener(this); removeButton.addActionListener(this); doneButton.addActionListener(this); add(bar, BorderLayout.SOUTH); final int row = table.getSelectedRow(); removeButton.setEnabled(row >= 0 && row < table.getRowCount()); table.clearSelection(); doneButton.requestFocus(); setPreferredSize(new Dimension(600, 300)); pack(); setLocationRelativeTo(getOwner()); setResizable(false); }
/** Listener to handle button actions */ public void actionPerformed(ActionEvent e) { // Check if the user pressed the remove button if (e.getSource() == remove_button) { int row = table.getSelectedRow(); model.removeRow(row); table.clearSelection(); table.repaint(); valueChanged(null); } // Check if the user pressed the remove all button if (e.getSource() == remove_all_button) { model.clearAll(); table.setRowSelectionInterval(0, 0); table.repaint(); valueChanged(null); } // Check if the user pressed the filter button if (e.getSource() == filter_button) { filter.showDialog(); if (filter.okPressed()) { // Update the display with new filter model.setFilter(filter); table.repaint(); } } // Check if the user pressed the start button if (e.getSource() == start_button) { start(); } // Check if the user pressed the stop button if (e.getSource() == stop_button) { stop(); } // Check if the user wants to switch layout if (e.getSource() == layout_button) { details_panel.remove(details_soap); details_soap.removeAll(); if (details_soap.getOrientation() == JSplitPane.HORIZONTAL_SPLIT) { details_soap = new JSplitPane(JSplitPane.VERTICAL_SPLIT); } else { details_soap = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); } details_soap.setTopComponent(request_panel); details_soap.setRightComponent(response_panel); details_soap.setResizeWeight(.5); details_panel.add(details_soap, BorderLayout.CENTER); details_panel.validate(); details_panel.repaint(); } // Check if the user is changing the reflow option if (e.getSource() == reflow_xml) { request_text.setReflowXML(reflow_xml.isSelected()); response_text.setReflowXML(reflow_xml.isSelected()); } }
public void setSwingFocus(ICFLibAnyObj value) { final String S_ProcName = "setSwingFocus"; if ((value == null) || (value instanceof ICFSecurityISOCountryObj)) { super.setSwingFocus(value); } else { throw CFLib.getDefaultExceptionFactory() .newUnsupportedClassException( getClass(), S_ProcName, "value", value, "ICFSecurityISOCountryObj"); } if (dataTable == null) { return; } if (value == null) { dataTable.clearSelection(); } else { ICFInternetISOCountryObj curSelected; PickerTableModel tblDataModel = getDataModel(); int selectedRow = dataTable.getSelectedRow(); int modelIndex = dataTable.convertRowIndexToModel(selectedRow); if (selectedRow >= 0) { Object selectedRowData = tblDataModel.getValueAt(modelIndex, COLID_ROW_HEADER); curSelected = (ICFInternetISOCountryObj) selectedRowData; } else { curSelected = null; } if (curSelected != value) { int len = tblDataModel.getRowCount(); int idx = 0; while ((idx < len) && (tblDataModel.getValueAt(idx, COLID_ROW_HEADER) != value)) { idx++; } if (idx < len) { int viewRow = dataTable.convertRowIndexToView(idx); dataTable.clearSelection(); dataTable.addRowSelectionInterval(viewRow, viewRow); } } } }
/** * Sets whether or not this component is enabled. Disabling this pane will * also disable its children. * * @param enabled <code>true<code> if this component and its children should * be enabled, <code>false<code> otherwise */ public void setEnabled(boolean enabled) { super.setEnabled(enabled); addButton.setEnabled(enabled); table.setEnabled(enabled); table.getTableHeader().setEnabled(enabled); if (enabled) { editButton.setEnabled(selectionModel.getSelectedValues().length == 1); removeButton.setEnabled(!selectionModel.isSelectionEmpty()); } else { table.clearSelection(); editButton.setEnabled(enabled); removeButton.setEnabled(enabled); } }
protected void moveSelectedRow(JTable from, JTable to) { SimpleColorTableModel fromModel = (SimpleColorTableModel) from.getModel(); SimpleColorTableModel toModel = (SimpleColorTableModel) to.getModel(); for (int index : from.getSelectedRows()) { Vector rowValue = (Vector) fromModel.getDataVector().get(index); toModel.addRow(rowValue); } int selectedRow = -1; while ((selectedRow = from.getSelectedRow()) != -1) { fromModel.removeRow(selectedRow); } from.clearSelection(); }
/** Resets the contents of this CallStackComponent. */ public void reset() { methodNames.removeAllElements(); callStackTable.revalidate(); callStackTable.clearSelection(); }
/** The action of the table loosing focus */ public void callStackTable_focusLost(FocusEvent e) { callStackTable.clearSelection(); }
/** The action of the table loosing the focus. */ public void segmentTable_focusLost(FocusEvent e) { segmentTable.clearSelection(); }
/** The action of the table gaining the focus. */ public void segmentTable_focusGained(FocusEvent e) { segmentTable.clearSelection(); notifyListeners(); }
/** Hides all selections. */ public void hideSelect() { segmentTable.clearSelection(); }
/** Resets the contents of this MemorySegmentComponent. */ public void reset() { segmentTable.clearSelection(); hideFlash(); hideHighlight(); }