/** * Set the current open DarwinCSV. You should really, really, really setCurrentCSV(null) before * you load a new DarwinCSV. * * @param csv The new DarwinCSV object. */ private void setCurrentCSV(DarwinCSV csv) { // Clear the old currentCSV object and matchAgainst object. currentCSV = null; matchAgainst(null); // Load the new currentCSV object. currentCSV = csv; table.removeAll(); table.setDefaultRenderer(Name.class, this); // Set the currentCSV // TODO: This causes an exception occasionally, because we shouldn't // be calling setModel outside of the Event Queue thread; however, we're // currently in a worker thread, so dipping back into the Event thread // would just cause more problems. Sorry! if (csv != null) { table.setModel(currentCSV.getRowIndex()); } else { table.setModel(blankDataModel); } columnInfoPanel.loadedFileChanged(csv); columnInfoPanel.columnChanged(-1); table.repaint(); }
/** * Create a Transferable to use as the source for a data transfer. * * @param c The component holding the data to be transfered. This argument is provided to enable * sharing of TransferHandlers by multiple components. * @return The representation of the data to be transfered. */ protected Transferable createTransferable(JComponent c) { Object[] values = null; if (c instanceof JList) { values = ((JList) c).getSelectedValues(); } else if (c instanceof JTable) { JTable table = (JTable) c; int[] rows = table.getSelectedRows(); if (rows != null) { values = new Object[rows.length]; for (int i = 0; i < rows.length; i++) { values[i] = table.getValueAt(rows[i], 0); } } } if (values == null || values.length == 0) { return null; } StringBuffer plainBuf = new StringBuffer(); StringBuffer htmlBuf = new StringBuffer(); htmlBuf.append("<html>\n<body>\n<ul>\n"); for (Object obj : values) { String val = ((obj == null) ? "" : obj.toString()); plainBuf.append(val + "\n"); htmlBuf.append(" <li>" + val + "\n"); } // remove the last newline plainBuf.deleteCharAt(plainBuf.length() - 1); htmlBuf.append("</ul>\n</body>\n</html>"); return new FileTransferable(plainBuf.toString(), htmlBuf.toString(), values); }
private Vector<String> getColumnNames() { Vector<String> columnNames = new Vector<String>(); for (int i = 0; i < jTable1.getColumnCount(); i++) columnNames.add(jTable1.getColumnName(i)); return columnNames; }
BusinessPane() { setLayout(null); add(info_label); info_label.setBounds(10, 10, 300, 20); info_label.setFont(new Font("TimesRoman", Font.BOLD, 12)); add(info_scroll); info_scroll.setBounds(5, 35, 615, 400); info_name.add(columnName[0]); info_name.add(columnName[1]); info_name.add(columnName[2]); info_name.add(columnName[3]); DefaultTableModel info_model = new DefaultTableModel(info_data, info_name); info_table.setModel(info_model); info_table.getColumnModel().getColumn(0).setWidth(25); info_table.addMouseListener( new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 1) { // click to trigger the event // show_selected(); // System.out.print(table_selected(0)); } } }); add(B_refresh); B_refresh.setMargin(new java.awt.Insets(1, 1, 1, 1)); B_refresh.setBounds(530, 440, 90, 25); B_refresh.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { update_table(); } }); }
public void secureDelete() { int rw = tblItems.getSelectedRow(); if (rw == -1) { JOptionPane.showMessageDialog(frm, "No item selected", "Error", JOptionPane.ERROR_MESSAGE); return; } int idx = tblItems.convertRowIndexToModel(rw); if (JOptionPane.showConfirmDialog( frm, "Delete " + store.plainName(idx) + "?", "Confirm Delete", JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) return; File del = store.delete(idx); store.fireTableDataChanged(); if (del != null) { if (del.delete()) { // successful needsSave = true; } else { System.err.println("Delete " + del.getAbsolutePath() + " failed"); } } updateStatus(); }
private Component getTable() { if (tableView == null) { JTable table = new JTable(getTableModel(), getTableColumnModel()); JScrollPane scrollPane = new JScrollPane(table); table.setPreferredScrollableViewportSize(new Dimension(500, 70)); tableView = scrollPane; } return tableView; }
public void secureAnalysis() { int rw = tblItems.getSelectedRow(); if (rw != -1) { int idx = tblItems.convertRowIndexToModel(rw); String desc = store.describe(idx); if (JOptionPane.showConfirmDialog(frm, desc, "Details", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.CANCEL_OPTION) return; } if (JOptionPane.showConfirmDialog(frm, store.tagDesc(), "Tags", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.CANCEL_OPTION) return; if (JOptionPane.showConfirmDialog( frm, store.storeDesc(), "Storage", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.CANCEL_OPTION) return; }
// Panel que muestra la tabla private Container tabla() { JPanel pnl = new JPanel(new GridLayout(2, 0)); String[] columnNames = { "Marca", "Modelo", "Color", "Precio", "Clave", "Procesador", "RAM", "HDD", "Tarjeta de video", "Tarjeta de audio" }; final JTable table = new JTable(getModeloDatos(), columnNames); table.setPreferredScrollableViewportSize(new Dimension(470, 340)); table.setFillsViewportHeight(true); JScrollPane scrollPane = new JScrollPane(table); pnl.add(scrollPane); // Se añaden los botones al panel regresar = new JButton("Regresar"); comprar = new JButton("Comprar"); buscar = new JButton("Buscar"); add(regresar); add(comprar); add(buscar); // Event-handles para los botones de Regresar, Comprar y Buscar regresar.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { sistema.mostrarPanel(PanelBase.PANEL_INICIO); } }); comprar.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { comprar(table); } }); buscar.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { buscarComputadora(table); } }); return pnl; }
public void buscarComputadora(JTable table) { JTextField marca = new JTextField(); JTextField clave = new JTextField(); Object[] mensaje = { "Marca:", marca, "Clave:", clave }; int opcion = JOptionPane.showConfirmDialog(this, mensaje, "Buscar", JOptionPane.OK_CANCEL_OPTION); if (opcion == JOptionPane.OK_OPTION) { for (int i = 0; i < sistema.getEmpresa().getProductos().size(); i++) { try { if (marca .getText() .equalsIgnoreCase(sistema.getEmpresa().getProductos().get(i).getMarca()) && Integer.parseInt(clave.getText()) == sistema.getEmpresa().getProductos().get(i).getClave()) { table.changeSelection(i, 0, false, false); JOptionPane.showMessageDialog(this, "Encontrado"); return; } } catch (NumberFormatException ex) { JOptionPane.showMessageDialog(this, "Número inválido"); } } } JOptionPane.showMessageDialog(this, "No se encontró el producto"); }
stab(ResultSet k) { super("PATIENT FOUND"); String[] chd = { "Date", "Patient ID", "Name", "Gender", "Age", "Weight", "Address", "Contact No.", "Doctor Name", "Symptoms", "Dignosis", "Fee: Rs.", "Blood Group" }; // DefaultTableModel dtm=new DefaultTableModel(); // jt.setModel(new DefaultTableModel(arr,chd)); jt = new JTable(); jsp = new JScrollPane(jt); btn = new JButton("CLOSE"); btn.addActionListener(this); int i = 0; try { while (k.next()) { arr[i][0] = k.getString(1); // System.out.println("ddddddddddddd"+arr[i][0]); arr[i][1] = "" + k.getInt(2); arr[i][2] = k.getString(3) + " " + k.getString(4) + " " + k.getString(5); arr[i][3] = k.getString(6); arr[i][4] = "" + k.getInt(7); arr[i][5] = k.getString(8); arr[i][6] = k.getString(9); arr[i][7] = k.getString(10); arr[i][8] = k.getString(11); arr[i][9] = k.getString(12); arr[i][10] = k.getString(13); arr[i][11] = "" + k.getInt(14); arr[i][12] = k.getString(15); arr[i][13] = k.getString(16); // dtm.insertRow(i,new Object[]{patient.rs.getString(1), // patient.rs.getInt(2),patient.rs.getString(3)+patient.rs.getString(4)+patient.rs.getString(5),patient.rs.getString(6),patient.rs.getInt(7),patient.rs.getString(8),patient.rs.getString(9),patient.rs.getString(10),patient.rs.getString(11),patient.rs.getString(12),patient.rs.getString(13),patient.rs.getInt(14)}); i++; } } catch (Exception e12) { System.out.println("" + e12); } jt.setModel(new DefaultTableModel(arr, chd)); Container con = getContentPane(); con.setLayout(null); jsp.setBounds(20, 20, 1230, 600); btn.setBounds(685, 630, 100, 30); add(jsp); add(btn); setSize(1330, 800); setVisible(true); }
public void updateActionTableFor(EditorClient client) { if (client == null) { DefaultTableModel model = new DefaultTableModel(); tblActions.setModel(getClearTableModel()); return; } else if (currClient == client) { DefaultTableModel model = getClearTableModel(); Iterator i = client.getActions(self).iterator(); while (i.hasNext()) { EditorAction ea = (EditorAction) i.next(); model.addRow(ea.getTableRow()); } tblActions.setModel(model); } }
public void secureMove() { int rw = tblItems.getSelectedRow(); if (rw == -1) { JOptionPane.showMessageDialog(frm, "No item selected", "Error", JOptionPane.ERROR_MESSAGE); return; } int idx = tblItems.convertRowIndexToModel(rw); String[] opts = new String[storeLocs.size()]; for (int i = 0; i < opts.length; i++) opts[i] = storeLocs.get(i).getAbsolutePath(); JComboBox cmbMove = new JComboBox(opts); cmbMove.setSelectedIndex(store.curStore(idx)); if (JOptionPane.showConfirmDialog(frm, cmbMove, "Move item", JOptionPane.OK_CANCEL_OPTION) != JOptionPane.OK_OPTION) return; File newLoc = store.move(idx, cmbMove.getSelectedIndex()); if (newLoc == null) System.err.println("move " + store.plainName(idx) + " unsuccessful"); else needsSave = true; }
/** * Set the DarwinCSV to match this against. * * @param against The DarwinCSV object to match against. */ private void matchAgainst(DarwinCSV against) { // System.err.println("matchAgainst: " + against); // Reset previous match information. currentMatch = null; table.repaint(); // If all we're doing is a reset, we can get out now. if (against == null) return; // long t1 = System.currentTimeMillis(); currentMatch = currentCSV.getRowIndex().matchAgainst(against.getRowIndex()); table.repaint(); matchInfoPanel.matchChanged(currentMatch); // long t2 = System.currentTimeMillis(); // System.err.println("matchAgainst finished: " + (t2 - t1) + " ms"); }
public void setTournament(File file, Tournament newTournament) { assert newTournament != null; this.currentFile = file; this.tournament = newTournament; rosterModel = new RosterModel(newTournament); rosterTable.setModel(rosterModel); refresh(); }
protected void toWindow() { table = new JTable(model); if (!viewHeaders) { table.setTableHeader(null); } table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); // table.setCellSelectionEnabled(true); table.setEnabled(false); scrollPane = new JScrollPane(table); /* * scrollPane.setPreferredSize(getSize()); * scrollPane.setSize(getSize()); */ add(scrollPane, BorderLayout.CENTER); }
public void comprar(JTable table) { Cliente c = null; Producto p = null; double precio = 0; try { c = busquedaCliente(table); p = sistema.getEmpresa().getProductos().get(table.getSelectedRow()); precio = p.getPrecio(); // Codigo para la compra sistema .getEmpresa() .nuevaCompra( c.getNombre(), c.getApellido(), c.getCedula(), p.getMarca(), p.getModelo(), p.getPrecio(), p.getClave()); JOptionPane.showMessageDialog( this, "El cliente " + "ha comprado exitosamente este producto.\n" + "Producto: " + sistema.getEmpresa().getProductos().get(table.getSelectedRow()).getMarca() + " " + sistema.getEmpresa().getProductos().get(table.getSelectedRow()).getModelo() + "\n" + "Ingreso para la empresa: " + precio); sistema.getGuardar().guardarVentas(sistema, null); sistema.getEmpresa().setIngreso(precio); sistema.getEmpresa().setNumVentas(1); guardarVentaIngreso(); abrirMenuFacturar(c, p); sistema.mostrarPanel(PanelBase.PANEL_INICIO); } catch (ArrayIndexOutOfBoundsException ex) { JOptionPane.showMessageDialog(this, "No se ha seleccionado una computadora"); } }
/** 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()); } }
/** Listener to handle table selection changes */ public void valueChanged(ListSelectionEvent e) { int row = table.getSelectedRow(); // Check if they selected a specific row if (row > 0) { remove_button.setEnabled(true); } else { remove_button.setEnabled(false); } // Check for "most recent" selection if (row == 0) { row = model.getRowCount() - 1; if (row == 0) { row = -1; } } if (row == -1) { // Clear the details panel details_time_value.setText(""); details_target_value.setText(""); details_status_value.setText(""); request_text.setText(""); response_text.setText(""); } else { // Show the details for the row SOAPMonitorData soap = model.getData(row); details_time_value.setText(soap.getTime()); details_target_value.setText(soap.getTargetService()); details_status_value.setText(soap.getStatus()); if (soap.getSOAPRequest() == null) { request_text.setText(""); } else { request_text.setText(soap.getSOAPRequest()); request_text.setCaretPosition(0); } if (soap.getSOAPResponse() == null) { response_text.setText(""); } else { response_text.setText(soap.getSOAPResponse()); response_text.setCaretPosition(0); } } }
public MainWindow() { setTitle(PRODUCT_NAME); rosterTable = new JTable(); rosterScrollPane = new JScrollPane(rosterTable); rosterTable.setFillsViewportHeight(true); getContentPane().add(rosterScrollPane, BorderLayout.CENTER); makeMenu(); pack(); setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); setLocationRelativeTo(null); addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent ev) { closeWindow(); } }); setTournament(null, new Tournament()); }
public TableModelDemo() { try { // Load the JDBC driver Class.forName("com.mysql.jdbc.Driver"); Class.forName("oracle.jdbc.driver.OracleDriver"); System.out.println("Driver loaded"); // Create a row set rowSet = new CachedRowSetImpl(); // Set RowSet properties // rowSet.setUrl("jdbc:mysql://localhost/javabook"); rowSet.setUrl("jdbc:oracle:thin:@liang.armstrong.edu:1521:orcl"); rowSet.setUsername("scott"); rowSet.setPassword("tiger"); rowSet.setCommand("select * from StateCapital"); rowSet.setConcurrency(ResultSet.CONCUR_UPDATABLE); rowSet.execute(); tableModel.setRowSet(rowSet); rowSet.addRowSetListener(tableModel); } catch (Exception ex) { ex.printStackTrace(); } JPanel panel1 = new JPanel(); panel1.setLayout(new GridLayout(2, 2)); panel1.add(jbtAddRow); panel1.add(jbtAddColumn); panel1.add(jbtDeleteRow); panel1.add(jbtDeleteColumn); JPanel panel2 = new JPanel(); panel2.add(jbtSave); panel2.add(jbtClear); panel2.add(jbtRestore); JPanel panel3 = new JPanel(); panel3.setLayout(new BorderLayout(5, 0)); panel3.add(new JLabel("Selection Mode"), BorderLayout.WEST); panel3.add(jcboSelectionMode, BorderLayout.CENTER); JPanel panel4 = new JPanel(); panel4.setLayout(new FlowLayout(FlowLayout.LEFT)); panel4.add(jchkRowSelectionAllowed); panel4.add(jchkColumnSelectionAllowed); JPanel panel5 = new JPanel(); panel5.setLayout(new GridLayout(2, 1)); panel5.add(panel3); panel5.add(panel4); JPanel panel6 = new JPanel(); panel6.setLayout(new BorderLayout()); panel6.add(panel1, BorderLayout.SOUTH); panel6.add(panel2, BorderLayout.CENTER); add(panel5, BorderLayout.NORTH); add(new JScrollPane(jTable1), BorderLayout.CENTER); add(panel6, BorderLayout.SOUTH); // Initialize table selection mode jTable1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); jbtAddRow.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { rowSet.absolute(2); rowSet.moveToInsertRow(); rowSet.updateString("state", "Georia"); rowSet.updateString("capital", "Atlanta"); rowSet.insertRow(); ((CachedRowSetImpl) rowSet).acceptChanges(); rowSet.moveToCurrentRow(); } catch (Exception ex) { ex.printStackTrace(); } // if (jTable1.getSelectedRow() >= 0) // tableModel.insertRow(jTable1.getSelectedRow(), // new java.util.Vector()); // else // tableModel.addRow(new java.util.Vector()); } }); jbtAddColumn.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // String name = JOptionPane.showInputDialog("New Column Name"); // tableModel.addColumn(name, new java.util.Vector()); } }); jbtDeleteRow.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (jTable1.getSelectedRow() >= 0) { try { rowSet.absolute(jTable1.getSelectedRow() + 1); rowSet.deleteRow(); ((CachedRowSetImpl) rowSet).acceptChanges(); } catch (Exception ex) { ex.printStackTrace(); } } } }); jbtDeleteColumn.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (jTable1.getSelectedColumn() >= 0) { TableColumnModel columnModel = jTable1.getColumnModel(); TableColumn tableColumn = columnModel.getColumn(jTable1.getSelectedColumn()); columnModel.removeColumn(tableColumn); } } }); jbtSave.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("tablemodel.dat")); // out.writeObject(tableModel.getDataVector()); out.writeObject(getColumnNames()); out.close(); } catch (Exception ex) { ex.printStackTrace(); } } }); jbtClear.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // tableModel.setRowCount(0); } }); jbtRestore.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { ObjectInputStream in = new ObjectInputStream(new FileInputStream("tablemodel.dat")); Vector rowData = (Vector) in.readObject(); Vector columnNames = (Vector) in.readObject(); // tableModel.setDataVector(rowData, columnNames); in.close(); } catch (Exception ex) { ex.printStackTrace(); } } }); jchkRowSelectionAllowed.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { jTable1.setRowSelectionAllowed(jchkRowSelectionAllowed.isSelected()); } }); jchkColumnSelectionAllowed.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { jTable1.setColumnSelectionAllowed(jchkColumnSelectionAllowed.isSelected()); } }); jcboSelectionMode.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String selectedItem = (String) jcboSelectionMode.getSelectedItem(); if (selectedItem.equals("SINGLE_SELECTION")) jTable1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); else if (selectedItem.equals("SINGLE_INTERVAL_SELECTION")) jTable1.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); else if (selectedItem.equals("MULTIPLE_INTERVAL_SELECTION")) jTable1.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); } }); }
/** Constructor (create and layout page) */ public SOAPMonitorPage(String host_name) { host = host_name; // Set up default filter (show all messages) filter = new SOAPMonitorFilter(); // Use borders to help improve appearance etched_border = new EtchedBorder(); // Build top portion of split (list panel) model = new SOAPMonitorTableModel(); table = new JTable(model); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.setRowSelectionInterval(0, 0); table.setPreferredScrollableViewportSize(new Dimension(600, 96)); table.getSelectionModel().addListSelectionListener(this); scroll = new JScrollPane(table); remove_button = new JButton("Remove"); remove_button.addActionListener(this); remove_button.setEnabled(false); remove_all_button = new JButton("Remove All"); remove_all_button.addActionListener(this); filter_button = new JButton("Filter ..."); filter_button.addActionListener(this); list_buttons = new JPanel(); list_buttons.setLayout(new FlowLayout()); list_buttons.add(remove_button); list_buttons.add(remove_all_button); list_buttons.add(filter_button); list_panel = new JPanel(); list_panel.setLayout(new BorderLayout()); list_panel.add(scroll, BorderLayout.CENTER); list_panel.add(list_buttons, BorderLayout.SOUTH); list_panel.setBorder(empty_border); // Build bottom portion of split (message details) details_time = new JLabel("Time: ", SwingConstants.RIGHT); details_target = new JLabel("Target Service: ", SwingConstants.RIGHT); details_status = new JLabel("Status: ", SwingConstants.RIGHT); details_time_value = new JLabel(); details_target_value = new JLabel(); details_status_value = new JLabel(); Dimension preferred_size = details_time.getPreferredSize(); preferred_size.width = 1; details_time.setPreferredSize(preferred_size); details_target.setPreferredSize(preferred_size); details_status.setPreferredSize(preferred_size); details_time_value.setPreferredSize(preferred_size); details_target_value.setPreferredSize(preferred_size); details_status_value.setPreferredSize(preferred_size); details_header = new JPanel(); details_header_layout = new GridBagLayout(); details_header.setLayout(details_header_layout); details_header_constraints = new GridBagConstraints(); details_header_constraints.fill = GridBagConstraints.BOTH; details_header_constraints.weightx = 0.5; details_header_layout.setConstraints(details_time, details_header_constraints); details_header.add(details_time); details_header_layout.setConstraints(details_time_value, details_header_constraints); details_header.add(details_time_value); details_header_layout.setConstraints(details_target, details_header_constraints); details_header.add(details_target); details_header_constraints.weightx = 1.0; details_header_layout.setConstraints(details_target_value, details_header_constraints); details_header.add(details_target_value); details_header_constraints.weightx = .5; details_header_layout.setConstraints(details_status, details_header_constraints); details_header.add(details_status); details_header_layout.setConstraints(details_status_value, details_header_constraints); details_header.add(details_status_value); details_header.setBorder(etched_border); request_label = new JLabel("SOAP Request", SwingConstants.CENTER); request_text = new SOAPMonitorTextArea(); request_text.setEditable(false); request_scroll = new JScrollPane(request_text); request_panel = new JPanel(); request_panel.setLayout(new BorderLayout()); request_panel.add(request_label, BorderLayout.NORTH); request_panel.add(request_scroll, BorderLayout.CENTER); response_label = new JLabel("SOAP Response", SwingConstants.CENTER); response_text = new SOAPMonitorTextArea(); response_text.setEditable(false); response_scroll = new JScrollPane(response_text); response_panel = new JPanel(); response_panel.setLayout(new BorderLayout()); response_panel.add(response_label, BorderLayout.NORTH); response_panel.add(response_scroll, BorderLayout.CENTER); details_soap = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); details_soap.setTopComponent(request_panel); details_soap.setRightComponent(response_panel); details_soap.setResizeWeight(.5); details_panel = new JPanel(); layout_button = new JButton("Switch Layout"); layout_button.addActionListener(this); reflow_xml = new JCheckBox("Reflow XML text"); reflow_xml.addActionListener(this); details_buttons = new JPanel(); details_buttons.setLayout(new FlowLayout()); details_buttons.add(reflow_xml); details_buttons.add(layout_button); details_panel.setLayout(new BorderLayout()); details_panel.add(details_header, BorderLayout.NORTH); details_panel.add(details_soap, BorderLayout.CENTER); details_panel.add(details_buttons, BorderLayout.SOUTH); details_panel.setBorder(empty_border); // Add the two parts to the age split pane split = new JSplitPane(JSplitPane.VERTICAL_SPLIT); split.setTopComponent(list_panel); split.setRightComponent(details_panel); // Build status area start_button = new JButton("Start"); start_button.addActionListener(this); stop_button = new JButton("Stop"); stop_button.addActionListener(this); status_buttons = new JPanel(); status_buttons.setLayout(new FlowLayout()); status_buttons.add(start_button); status_buttons.add(stop_button); status_text = new JLabel(); status_text.setBorder(new BevelBorder(BevelBorder.LOWERED)); status_text_panel = new JPanel(); status_text_panel.setLayout(new BorderLayout()); status_text_panel.add(status_text, BorderLayout.CENTER); status_text_panel.setBorder(empty_border); status_area = new JPanel(); status_area.setLayout(new BorderLayout()); status_area.add(status_buttons, BorderLayout.WEST); status_area.add(status_text_panel, BorderLayout.CENTER); status_area.setBorder(etched_border); // Add the split and status area to page setLayout(new BorderLayout()); add(split, BorderLayout.CENTER); add(status_area, BorderLayout.SOUTH); }
public String table_selected(int i) { int row = info_table.getSelectedRow(); return info_table.getValueAt(row, i).toString(); }
/** Background thread used to receive data from the server. */ public void run() { Long id; Integer message_type; String target; String soap; SOAPMonitorData data; int selected; int row; boolean update_needed; while (socket != null) { try { // Get the data from the server message_type = (Integer) in.readObject(); // Process the data depending on its type switch (message_type.intValue()) { case SOAPMonitorConstants.SOAP_MONITOR_REQUEST: // Get the id, target and soap info id = (Long) in.readObject(); target = (String) in.readObject(); soap = (String) in.readObject(); // Add new request data to the table data = new SOAPMonitorData(id, target, soap); model.addData(data); // If "most recent" selected then update // the details area if needed selected = table.getSelectedRow(); if ((selected == 0) && model.filterMatch(data)) { valueChanged(null); } break; case SOAPMonitorConstants.SOAP_MONITOR_RESPONSE: // Get the id and soap info id = (Long) in.readObject(); soap = (String) in.readObject(); data = model.findData(id); if (data != null) { update_needed = false; // Get the selected row selected = table.getSelectedRow(); // If "most recent", then always // update details area if (selected == 0) { update_needed = true; } // If the data being updated is // selected then update details row = model.findRow(data); if ((row != -1) && (row == selected)) { update_needed = true; } // Set the response and update table data.setSOAPResponse(soap); model.updateData(data); // Refresh details area (if needed) if (update_needed) { valueChanged(null); } } break; } } catch (Exception e) { // Exceptions are expected here when the // server communication has been terminated. if (stop_button.isEnabled()) { stop(); setErrorStatus(STATUS_CLOSED); } } } }
public IdeMain() { cpu = new Dcpu(); debugger = new Debugger(); debugger.breakpointListener = new PreListener<Character>() { public void preExecute(Character arg) { breakpointHit(arg); } }; debugger.attachTo(cpu); asmMap = new AsmMap(); MonitorLEM1802 monitor = new MonitorLEM1802(); cpu.attach(monitor); MonitorWindow window = new MonitorWindow(cpu, monitor, false); window.show(); Sped3 sped = new Sped3(); cpu.attach(sped); SpedWindow spedWindow = new SpedWindow(cpu, sped, false); spedWindow.show(); spedWindow.getFrame().setSize(600, 600); GenericClock clock = new GenericClock(MonitorLEM1802.MANUFACTURER_ID); // Nya Elektriska GenericKeyboard keyboard = new GenericKeyboard(MonitorLEM1802.MANUFACTURER_ID, 16); cpu.attach(clock); cpu.attach(keyboard); window.addKeyListener(keyboard); fileChooser = new JFileChooser(); fileChooser.setCurrentDirectory(new File(".")); registersModel = new RegistersModel(cpu, debugger); registersTable.setModel(registersModel); memoryModel = new MemoryModel(cpu, debugger); memoryTable.setModel(memoryModel); sourceRowHeader = new SourceRowHeader(sourceTextarea, srcBreakpoints); sourceRowHeader.setBackground(Color.LIGHT_GRAY); sourceScrollPane.setRowHeaderView(sourceRowHeader); frame = new JFrame("JA-DCPU IDE"); frame.setContentPane(rootPanel); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); openSrcButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { openSrc(); } }); asmButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { assemble(); } }); saveSrcButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { saveSrc(); } }); hardResetButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { cpu.memzero(); memoryModel.fireUpdate(0, RAM_SIZE); cpu.reset(); registersModel.fireUpdate(); } }); resetButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { cpu.reset(); registersModel.fireUpdate(); } }); saveBinButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { saveBin(); } }); openBinButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { openBin(); } }); stepButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { step(); } }); breakpointButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { toggleBreakpoint(); } }); runButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { debugger.breakpointsHalt = true; runCpu(); } }); execButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { debugger.breakpointsHalt = false; runCpu(); } }); pauseButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { cpu.halt = true; } }); }
public void makeGUI() { frm = new JFrame(); c = frm.getContentPane(); btnImport = new JButton("Import"); btnImport.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent arg0) { secureImport(); } }); btnMove = new JButton("Move"); btnMove.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent arg0) { secureMove(); } }); btnDelete = new JButton("Delete"); btnDelete.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent arg0) { secureDelete(); } }); btnAnalyse = new JButton("Analyse"); btnAnalyse.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent arg0) { secureAnalysis(); } }); tblItems = new JTable(store); tblItems.setRowSorter(tableSorter); tblItems.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); tblItems.setFillsViewportHeight(true); tblItems.getRowSorter().toggleSortOrder(Storage.COL_DATE); tblItems.addMouseListener( new MouseListener() { public void mouseClicked(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON3) { tblItems.setRowSelectionInterval( e.getY() / tblItems.getRowHeight(), e.getY() / tblItems.getRowHeight()); } if (e.getClickCount() > 1 || e.getButton() == MouseEvent.BUTTON3) { int idx = tblItems.convertRowIndexToModel(tblItems.getSelectedRow()); secureExport(idx); } } public void mouseEntered(MouseEvent arg0) {} public void mouseExited(MouseEvent arg0) {} public void mousePressed(MouseEvent arg0) {} public void mouseReleased(MouseEvent arg0) {} }); txaStatus = new JTextArea(TXA_HEIGHT, TXA_WIDTH); txaStatus.setEditable(false); txaStatus.setBorder(BorderFactory.createTitledBorder("Status")); txaSearch = new JTextArea(4, TXA_WIDTH); txaSearch.setBorder(BorderFactory.createTitledBorder("Search")); txaSearch.addKeyListener( new KeyListener() { public void keyPressed(KeyEvent arg0) {} public void keyReleased(KeyEvent arg0) { filterBase(txaSearch.getText()); // EXPORT settings here, as in mass export (export everything) if (allowExport && txaSearch.getText().equalsIgnoreCase(CMD_EXPORT)) { // txaSearch.setText(""); if (JOptionPane.showConfirmDialog( frm, "Do you really want to export the whole secure base?", "Confirm Export", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) { totalExport(); } } // LOST X IMPORT asin look through the store for files not listed if (txaSearch.getText().equalsIgnoreCase(CMD_STOCKTAKE)) { for (int i = 0; i < storeLocs.size(); i++) { if (store.stockTake(i)) needsSave = true; } } } public void keyTyped(KeyEvent arg0) {} }); JPanel pnlTop = new JPanel(new GridLayout(1, 4)); JPanel pnlEast = new JPanel(new BorderLayout()); JPanel pnlCenterEast = new JPanel(new BorderLayout()); JScrollPane jspItems = new JScrollPane(tblItems); pnlTop.add(btnImport); pnlTop.add(btnMove); pnlTop.add(btnDelete); pnlTop.add(btnAnalyse); pnlCenterEast.add(txaStatus, BorderLayout.CENTER); pnlCenterEast.add(txaSearch, BorderLayout.NORTH); // pnlEast.add(pswPass, BorderLayout.NORTH); pnlEast.add(pnlCenterEast, BorderLayout.CENTER); c.setLayout(new BorderLayout()); c.add(pnlTop, BorderLayout.NORTH); c.add(pnlEast, BorderLayout.EAST); c.add(jspItems, BorderLayout.CENTER); frm.setContentPane(c); }
MemberPane() { setLayout(null); /*add(B_add); B_add.setMargin(new java.awt.Insets(1, 1, 1, 1)); B_add.setBounds(230,440,90,25); B_add.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event){ String[] data={T_title.getText(),T_director.getText(),T_actor.getText(),T_actress.getText()}; DBcore.addData("movie_info",data); DBcore.showDB("movie_info", movie_column,info_data,info_table); } });*/ add(B_delete); B_delete.setMargin(new java.awt.Insets(1, 1, 1, 1)); B_delete.setBounds(330, 440, 90, 25); B_delete.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { if (id != null) { int confirm = JOptionPane.showConfirmDialog( mainFrame, "是否删除该用户?", "删除提示", JOptionPane.OK_CANCEL_OPTION); if (confirm == JOptionPane.OK_OPTION) { Database.deleteData("member", "id", id); } T_title.setText(""); T_director.setText(""); T_actor.setText(""); T_actress.setText(""); } update_table(); } }); /*add(B_edit); B_edit.setMargin(new java.awt.Insets(1, 1, 1, 1)); B_edit.setBounds(430,440,90,25); B_edit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event){ String[] data={T_title.getText(),T_director.getText(),T_actor.getText(),T_actress.getText()}; if(id!=null){ DBcore.updateData("movie_info", "no", id, detail_column, data); } DBcore.showDB("movie_info", movie_column,info_data,info_table); } });*/ add(B_refresh); B_refresh.setMargin(new java.awt.Insets(1, 1, 1, 1)); B_refresh.setBounds(530, 440, 90, 25); B_refresh.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { update_table(); } }); add(info_label); info_label.setBounds(10, 10, 300, 20); info_label.setFont(new Font("TimesRoman", Font.BOLD, 12)); add(info_scroll); info_scroll.setBounds(5, 35, 615, 400); info_name.add(columnName[0]); info_name.add(columnName[1]); info_name.add(columnName[2]); info_name.add(columnName[3]); info_name.add(columnName[4]); DefaultTableModel info_model = new DefaultTableModel(info_data, info_name); info_table.setModel(info_model); info_table.getColumnModel().getColumn(0).setWidth(25); info_table.addMouseListener( new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 1) { // click to trigger the event show_selected(); System.out.print(table_selected(0)); } } }); /*add(edit_panel); Border border=BorderFactory.createEtchedBorder(1); Border title1=BorderFactory.createTitledBorder(border,"Edit Area"); edit_panel.setBorder(title1); edit_panel.setBounds(5,470,615,125); edit_panel.setLayout(null); edit_panel.add(L_title); edit_panel.add(L_director); edit_panel.add(L_actor); edit_panel.add(L_actress); edit_panel.add(T_title); edit_panel.add(T_director); edit_panel.add(T_actor); edit_panel.add(T_actress); L_title.setBounds(40,30,100,25); L_director.setBounds(325,30,100,25); L_actor.setBounds(40,75,100,25); L_actress.setBounds(325,75,100,25); T_title.setBounds(140,30,150,25); T_director.setBounds(425,30,150,25); T_actor.setBounds(140,75,150,25); T_actress.setBounds(425,75,150,25);*/ }
/** * Move the currently selected cell up or down by one cell. * * @param direction -1 for previous, +1 for next. */ public void goToRow(int direction) { int row = table.getSelectedRow(); int column = table.getSelectedColumn(); table.changeSelection(row + direction, column, false, false); }
/** * Create a new, empty, not-visible TaxRef window. Really just activates the setup frame and setup * memory monitor components, then starts things off. */ public MainFrame() { setupMemoryMonitor(); // Set up the main frame. mainFrame = new JFrame(basicTitle); mainFrame.setJMenuBar(setupMenuBar()); mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Set up the JTable. table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.setSelectionBackground(COLOR_SELECTION_BACKGROUND); table.setShowGrid(true); // Add a blank table model so that the component renders properly on // startup. table.setModel(blankDataModel); // Add a list selection listener so we can tell the matchInfoPanel // that a new name was selected. table .getSelectionModel() .addListSelectionListener( new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (currentCSV == null) return; int row = table.getSelectedRow(); int column = table.getSelectedColumn(); columnInfoPanel.columnChanged(column); Object o = table.getModel().getValueAt(row, column); if (Name.class.isAssignableFrom(o.getClass())) { matchInfoPanel.nameSelected(currentCSV.getRowIndex(), (Name) o, row, column); } else { matchInfoPanel.nameSelected(currentCSV.getRowIndex(), null, -1, -1); } } }); // Set up the left panel (table + matchInfoPanel) JPanel leftPanel = new JPanel(); matchInfoPanel = new MatchInformationPanel(this); leftPanel.setLayout(new BorderLayout()); leftPanel.add(matchInfoPanel, BorderLayout.SOUTH); leftPanel.add(new JScrollPane(table)); // Set up the right panel (columnInfoPanel) JPanel rightPanel = new JPanel(); columnInfoPanel = new ColumnInformationPanel(this); progressBar.setStringPainted(true); rightPanel.setLayout(new BorderLayout()); rightPanel.add(columnInfoPanel); rightPanel.add(progressBar, BorderLayout.SOUTH); // Set up a JSplitPane to split the panels up. JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, false, leftPanel, rightPanel); split.setResizeWeight(1); mainFrame.add(split); mainFrame.pack(); // Set up a drop target so we can pick up files mainFrame.setDropTarget( new DropTarget( mainFrame, new DropTargetAdapter() { @Override public void dragEnter(DropTargetDragEvent dtde) { // Accept any drags. dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE); } @Override public void dragOver(DropTargetDragEvent dtde) {} @Override public void dropActionChanged(DropTargetDragEvent dtde) {} @Override public void dragExit(DropTargetEvent dte) {} @Override public void drop(DropTargetDropEvent dtde) { // Accept a drop as long as its File List. if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); Transferable t = dtde.getTransferable(); try { java.util.List<File> files = (java.util.List<File>) t.getTransferData(DataFlavor.javaFileListFlavor); // If we're given multiple files, pick up only the last file and load that. File f = files.get(files.size() - 1); loadFile(f, DarwinCSV.FILE_CSV_DELIMITED); } catch (UnsupportedFlavorException ex) { dtde.dropComplete(false); } catch (IOException ex) { dtde.dropComplete(false); } } } })); }
public void testClientProp() throws Exception { // IDEA-46372 JComponent rootComponent = getInstrumentedRootComponent("TestClientProp.form", "BindingTest"); assertEquals(1, rootComponent.getComponentCount()); JTable table = (JTable) rootComponent.getComponent(0); assertSame(Boolean.TRUE, table.getClientProperty("terminateEditOnFocusLost")); }
void goToSpecificColumn(int selectedIndex) { int row = table.getSelectedRow(); table.changeSelection(row, selectedIndex, true, true); }