List of usage examples for javax.swing JTable putClientProperty
public final void putClientProperty(Object key, Object value)
From source file:com.googlecode.vfsjfilechooser2.filepane.VFSFilePane.java
public JPanel createDetailsView() { final VFSJFileChooser chooser = getFileChooser(); JPanel p = new JPanel(new BorderLayout()); final JTable detailsTable = new JTable(getDetailsTableModel()) { // Handle Escape key events here @Override//from ww w .j a v a2 s.co m protected boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed) { if ((e.getKeyCode() == KeyEvent.VK_ESCAPE) && (getCellEditor() == null)) { // We are not editing, forward to filechooser. chooser.dispatchEvent(e); return true; } return super.processKeyBinding(ks, e, condition, pressed); } @Override public void tableChanged(TableModelEvent e) { super.tableChanged(e); if (e.getFirstRow() == TableModelEvent.HEADER_ROW) { // update header with possibly changed column set updateDetailsColumnModel(this); } } }; // detailsTable.setRowSorter(getRowSorter()); detailsTable.setAutoCreateColumnsFromModel(false); detailsTable.setComponentOrientation(chooser.getComponentOrientation()); //detailsTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); detailsTable.setShowGrid(false); detailsTable.putClientProperty("JTable.autoStartsEdit", Boolean.FALSE); // detailsTable.addKeyListener(detailsKeyListener); Font font = list.getFont(); detailsTable.setFont(font); detailsTable.setIntercellSpacing(new Dimension(0, 0)); TableCellRenderer headerRenderer = new AlignableTableHeaderRenderer( detailsTable.getTableHeader().getDefaultRenderer()); detailsTable.getTableHeader().setDefaultRenderer(headerRenderer); TableCellRenderer cellRenderer = new DetailsTableCellRenderer(chooser); detailsTable.setDefaultRenderer(Object.class, cellRenderer); // So that drag can be started on a mouse press detailsTable.getColumnModel().getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); detailsTable.addMouseListener(getMouseHandler()); // No need to addListSelectionListener because selections are forwarded // to our JList. // 4835633 : tell BasicTableUI that this is a file list detailsTable.putClientProperty("Table.isFileList", Boolean.TRUE); if (listViewWindowsStyle) { detailsTable.addFocusListener(repaintListener); } JTableHeader header = detailsTable.getTableHeader(); header.setUpdateTableInRealTime(true); header.addMouseListener(detailsTableModel.new ColumnListener()); header.setReorderingAllowed(true); // TAB/SHIFT-TAB should transfer focus and ENTER should select an item. // We don't want them to navigate within the table ActionMap am = SwingUtilities.getUIActionMap(detailsTable); am.remove("selectNextRowCell"); am.remove("selectPreviousRowCell"); am.remove("selectNextColumnCell"); am.remove("selectPreviousColumnCell"); detailsTable.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, null); detailsTable.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, null); JScrollPane scrollpane = new JScrollPane(detailsTable); scrollpane.setComponentOrientation(chooser.getComponentOrientation()); LookAndFeel.installColors(scrollpane.getViewport(), "Table.background", "Table.foreground"); // Adjust width of first column so the table fills the viewport when // first displayed (temporary listener). scrollpane.addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { JScrollPane sp = (JScrollPane) e.getComponent(); fixNameColumnWidth(sp.getViewport().getSize().width); sp.removeComponentListener(this); } }); // 4835633. // If the mouse is pressed in the area below the Details view table, the // event is not dispatched to the Table MouseListener but to the // scrollpane. Listen for that here so we can clear the selection. scrollpane.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { JScrollPane jsp = ((JScrollPane) e.getComponent()); JTable table = (JTable) jsp.getViewport().getView(); if (!e.isShiftDown() || (table.getSelectionModel().getSelectionMode() == ListSelectionModel.SINGLE_SELECTION)) { clearSelection(); TableCellEditor tce = table.getCellEditor(); if (tce != null) { tce.stopCellEditing(); } } } }); detailsTable.setForeground(list.getForeground()); detailsTable.setBackground(list.getBackground()); if (listViewBorder != null) { scrollpane.setBorder(listViewBorder); } p.add(scrollpane, BorderLayout.CENTER); detailsTableModel.fireTableStructureChanged(); return p; }
From source file:org.ut.biolab.medsavant.client.project.ProjectWizard.java
private AbstractWizardPage getPatientFieldsPage() { //setup page/*from ww w . j av a 2s. c o m*/ final DefaultWizardPage page = new DefaultWizardPage(PAGENAME_PATIENTS) { @Override public void setupWizardButtons() { fireButtonEvent(ButtonEvent.SHOW_BUTTON, ButtonNames.BACK); fireButtonEvent(ButtonEvent.ENABLE_BUTTON, ButtonNames.BACK); fireButtonEvent(ButtonEvent.HIDE_BUTTON, ButtonNames.FINISH); fireButtonEvent(ButtonEvent.ENABLE_BUTTON, ButtonNames.NEXT); } }; page.addText("Add relevant fields for patients. "); JScrollPane scrollpane = new JScrollPane(); scrollpane.setPreferredSize(new Dimension(300, 250)); scrollpane.getViewport().setBackground(Color.white); final JTable table = new JTable() { @Override public Class<?> getColumnClass(int column) { if (column == 2) { return Boolean.class; } else { return String.class; } } }; patientFormatModel = new DefaultTableModel() { @Override public boolean isCellEditable(int row, int col) { return row >= 8; } }; patientFormatModel.addColumn("Name"); patientFormatModel.addColumn("Type"); patientFormatModel.addColumn("Filterable"); patientFormatModel.addColumn("Alias"); patientFormatModel.addColumn("Description"); patientFormatModel.addRow(new Object[] { FAMILY_ID.getColumnName(), FAMILY_ID.getTypeString(), true, FAMILY_ID.getAlias(), "" }); patientFormatModel.addRow(new Object[] { HOSPITAL_ID.getColumnName(), HOSPITAL_ID.getTypeString(), true, HOSPITAL_ID.getAlias(), "" }); patientFormatModel.addRow( new Object[] { IDBIOMOM.getColumnName(), IDBIOMOM.getTypeString(), true, IDBIOMOM.getAlias(), "" }); patientFormatModel.addRow( new Object[] { IDBIODAD.getColumnName(), IDBIODAD.getTypeString(), true, IDBIODAD.getAlias(), "" }); patientFormatModel.addRow( new Object[] { GENDER.getColumnName(), GENDER.getTypeString(), true, GENDER.getAlias(), "" }); patientFormatModel.addRow( new Object[] { AFFECTED.getColumnName(), AFFECTED.getTypeString(), true, AFFECTED.getAlias(), "" }); patientFormatModel.addRow( new Object[] { DNA_IDS.getColumnName(), DNA_IDS.getTypeString(), true, DNA_IDS.getAlias(), "" }); patientFormatModel.addRow( new Object[] { BAM_URL.getColumnName(), BAM_URL.getTypeString(), true, BAM_URL.getAlias(), "" }); patientFormatModel.addRow(new Object[] { PHENOTYPES.getColumnName(), PHENOTYPES.getTypeString(), true, PHENOTYPES.getAlias(), "" }); if (modify) { for (CustomField f : customFields) { patientFormatModel.addRow(new Object[] { f.getColumnName(), f.getTypeString(), f.isFilterable(), f.getAlias(), f.getDescription() }); } } table.setModel(patientFormatModel); table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE); scrollpane.getViewport().add(table); page.addComponent(scrollpane); JButton addFieldButton = new JButton("Add Field"); addFieldButton.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { patientFormatModel.addRow(new Object[5]); table.setModel(patientFormatModel); } }); page.addComponent(addFieldButton); JButton removeFieldButton = new JButton("Remove Field"); removeFieldButton.setEnabled(false); removeFieldButton.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { int row = table.getSelectedRow(); // Minus one because patient_id isn't in the table. if (row >= BasicPatientColumns.REQUIRED_PATIENT_FIELDS.length - 1) { patientFormatModel.removeRow(row); } table.setModel(patientFormatModel); } }); table.getSelectionModel().addListSelectionListener( new RemovalEnabler(BasicPatientColumns.REQUIRED_PATIENT_FIELDS.length - 1, removeFieldButton)); page.addComponent(removeFieldButton); return page; }
From source file:org.ut.biolab.medsavant.client.project.ProjectWizard.java
private AbstractWizardPage getVCFFieldsPage() { //setup page//ww w .jav a 2 s .co m final DefaultWizardPage page = new DefaultWizardPage(PAGENAME_VCF) { @Override public void setupWizardButtons() { fireButtonEvent(ButtonEvent.SHOW_BUTTON, ButtonNames.BACK); fireButtonEvent(ButtonEvent.ENABLE_BUTTON, ButtonNames.BACK); fireButtonEvent(ButtonEvent.HIDE_BUTTON, ButtonNames.FINISH); fireButtonEvent(ButtonEvent.ENABLE_BUTTON, ButtonNames.NEXT); } }; page.addText("Add extra fields to parse from INFO text in VCF files. "); JScrollPane scrollpane = new JScrollPane(); scrollpane.setPreferredSize(new Dimension(300, 250)); scrollpane.getViewport().setBackground(Color.white); final JTable table = new JTable() { @Override public Class<?> getColumnClass(int column) { if (column == 2) { return Boolean.class; } else { return String.class; } } }; variantFormatModel = new DefaultTableModel(); variantFormatModel.addColumn("Key"); variantFormatModel.addColumn("Type"); variantFormatModel.addColumn("Filterable"); variantFormatModel.addColumn("Alias"); variantFormatModel.addColumn("Description"); if (modify) { try { int firstRef = manager.getReferenceIDsForProject(LoginController.getSessionID(), projectID)[0]; CustomField[] fields = manager.getCustomVariantFields(LoginController.getSessionID(), projectID, firstRef, manager.getNewestUpdateID(LoginController.getSessionID(), projectID, firstRef, false)); for (CustomField f : fields) { //casing of f.getColumnName should match database. variantFormatModel.addRow(new Object[] { f.getColumnName(), f.getTypeString(), f.isFilterable(), f.getAlias(), f.getDescription() }); } } catch (Exception ex) { LOG.error("Error getting reference IDs for project.", ex); } } else { variantFormatModel .addRow(new Object[] { AA.getColumnName(), AA.getTypeString(), true, AA.getAlias(), "" }); variantFormatModel .addRow(new Object[] { AC.getColumnName(), AC.getTypeString(), true, AC.getAlias(), "" }); variantFormatModel .addRow(new Object[] { AF.getColumnName(), AF.getTypeString(), true, AF.getAlias(), "" }); variantFormatModel .addRow(new Object[] { AN.getColumnName(), AN.getTypeString(), true, AN.getAlias(), "" }); variantFormatModel .addRow(new Object[] { BQ.getColumnName(), BQ.getTypeString(), true, BQ.getAlias(), "" }); variantFormatModel.addRow( new Object[] { CIGAR.getColumnName(), CIGAR.getTypeString(), true, CIGAR.getAlias(), "" }); variantFormatModel .addRow(new Object[] { DB.getColumnName(), DB.getTypeString(), true, DB.getAlias(), "" }); variantFormatModel .addRow(new Object[] { DP.getColumnName(), DP.getTypeString(), true, DP.getAlias(), "" }); //variantFormatModel.addRow(new Object[]{END.getColumnName(), END.getTypeString(), true, END.getAlias(), ""}); variantFormatModel .addRow(new Object[] { H2.getColumnName(), H2.getTypeString(), true, H2.getAlias(), "" }); variantFormatModel .addRow(new Object[] { MQ.getColumnName(), MQ.getTypeString(), true, MQ.getAlias(), "" }); variantFormatModel .addRow(new Object[] { MQ0.getColumnName(), MQ0.getTypeString(), true, MQ0.getAlias(), "" }); variantFormatModel .addRow(new Object[] { NS.getColumnName(), NS.getTypeString(), true, NS.getAlias(), "" }); variantFormatModel .addRow(new Object[] { SB.getColumnName(), SB.getTypeString(), true, SB.getAlias(), "" }); variantFormatModel.addRow(new Object[] { SOMATIC.getColumnName(), SOMATIC.getTypeString(), true, SOMATIC.getAlias(), "" }); variantFormatModel.addRow(new Object[] { VALIDATED.getColumnName(), VALIDATED.getTypeString(), true, VALIDATED.getAlias(), "" }); variantFormatModel .addRow(new Object[] { JANNOVAR_EFFECT.getColumnName(), JANNOVAR_EFFECT.getTypeString(), JANNOVAR_EFFECT.isFilterable(), JANNOVAR_EFFECT.getAlias(), "" }); variantFormatModel .addRow(new Object[] { JANNOVAR_SYMBOL.getColumnName(), JANNOVAR_SYMBOL.getTypeString(), JANNOVAR_SYMBOL.isFilterable(), JANNOVAR_SYMBOL.getAlias(), "" }); variantFormatModel.addRow(new Object[] { FORMAT.getColumnName(), FORMAT.getTypeString(), FORMAT.isFilterable(), FORMAT.getAlias(), "" }); variantFormatModel.addRow(new Object[] { SAMPLE_INFO.getColumnName(), SAMPLE_INFO.getTypeString(), SAMPLE_INFO.isFilterable(), SAMPLE_INFO.getAlias(), "" }); } table.setModel(variantFormatModel); table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE); scrollpane.getViewport().add(table); page.addComponent(scrollpane); table.addKeyListener(new KeyListener() { @Override public void keyTyped(KeyEvent e) { variantFieldsChanged = true; } @Override public void keyPressed(KeyEvent e) { variantFieldsChanged = true; } @Override public void keyReleased(KeyEvent e) { variantFieldsChanged = true; } }); JButton addFieldButton = new JButton("Add Field"); addFieldButton.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { variantFormatModel.addRow(new Object[2]); table.setModel(variantFormatModel); variantFieldsChanged = true; } }); page.addComponent(addFieldButton); JButton removeFieldButton = new JButton("Remove Field"); removeFieldButton.setEnabled(false); removeFieldButton.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { int row = table.getSelectedRow(); if (row >= 0) { variantFormatModel.removeRow(row); table.setModel(variantFormatModel); variantFieldsChanged = true; } } }); table.getSelectionModel().addListSelectionListener(new RemovalEnabler(0, removeFieldButton)); page.addComponent(removeFieldButton); return page; }