List of usage examples for javax.swing.table TableColumnModel getColumn
public TableColumn getColumn(int columnIndex);
TableColumn
object for the column at columnIndex
. From source file:com.qspin.qtaste.ui.reporter.TestCaseReportTable.java
private void init() { final String tableLayoutProperty = interactive ? INTERACTIVE_TABLE_LAYOUT_PROPERTY : EXECUTION_TABLE_LAYOUT_PROPERTY; final String statusColumnProperty = tableLayoutProperty + ".status"; final String testCaseColumnProperty = tableLayoutProperty + ".test_case"; final String detailsColumnProperty = tableLayoutProperty + ".details"; final String testbedColumnProperty = tableLayoutProperty + ".testbed"; final String resultColumnProperty = tableLayoutProperty + ".result"; tcModel = new DefaultTableModel( new Object[] { "Status", "Test Case", "Details", "Result", "Testbed", "Time", "." }, 0) { @Override/* ww w. j av a2 s . c o m*/ public Class<?> getColumnClass(int columnIndex) { Class<?> dataType = super.getColumnClass(columnIndex); if (columnIndex == STATUS) { dataType = Icon.class; } return dataType; } @Override public boolean isCellEditable(int rowIndex, int mColIndex) { return false; } }; tcTable = new SortableJTable(new TableSorter(tcModel)) { public String getToolTipText(MouseEvent e) { Point p = e.getPoint(); int rowIndex = rowAtPoint(p); int colIndex = columnAtPoint(p); if (colIndex < 0) { return null; } return convertObjectToToolTip(getValueAt(rowIndex, colIndex)); } }; tcTable.setColumnSelectionAllowed(false); int tcWidth = interactive ? 360 : 480; int tcStatusWidth = 40; int tcTestbedWidth = 100; int tcDetailsWidth = 360; int tcResultWidth = 150; GUIConfiguration guiConfiguration = GUIConfiguration.getInstance(); List<?> list = guiConfiguration.configurationsAt(tableLayoutProperty); if (!list.isEmpty()) { try { tcWidth = guiConfiguration.getInt(testCaseColumnProperty); } catch (NoSuchElementException ex) { guiConfiguration.setProperty(testCaseColumnProperty, tcWidth); } try { tcStatusWidth = guiConfiguration.getInt(statusColumnProperty); } catch (NoSuchElementException ex) { guiConfiguration.setProperty(statusColumnProperty, tcStatusWidth); } try { tcDetailsWidth = guiConfiguration.getInt(detailsColumnProperty); } catch (NoSuchElementException ex) { guiConfiguration.setProperty(detailsColumnProperty, tcDetailsWidth); } try { tcTestbedWidth = guiConfiguration.getInt(testbedColumnProperty); } catch (NoSuchElementException ex) { guiConfiguration.setProperty(testbedColumnProperty, tcTestbedWidth); } if (interactive) { try { tcResultWidth = guiConfiguration.getInt(resultColumnProperty); } catch (NoSuchElementException ex) { guiConfiguration.setProperty(resultColumnProperty, tcResultWidth); } } } else { tcWidth = interactive ? 360 : 480; guiConfiguration.setProperty(testCaseColumnProperty, tcWidth); guiConfiguration.setProperty(statusColumnProperty, tcStatusWidth); guiConfiguration.setProperty(detailsColumnProperty, tcDetailsWidth); guiConfiguration.setProperty(testbedColumnProperty, tcTestbedWidth); if (interactive) { guiConfiguration.setProperty(resultColumnProperty, tcResultWidth); } try { guiConfiguration.save(); } catch (ConfigurationException ex) { logger.error("Error while saving GUI configuration: " + ex.getMessage()); } } TableColumnModel tcTableColumnModel = tcTable.getColumnModel(); tcTableColumnModel.getColumn(TEST_CASE).setPreferredWidth(tcWidth); tcTableColumnModel.getColumn(STATUS).setPreferredWidth(tcStatusWidth); tcTableColumnModel.getColumn(STATUS).setMaxWidth(40); tcTableColumnModel.getColumn(DETAILS).setPreferredWidth(tcDetailsWidth); tcTableColumnModel.getColumn(TESTBED).setPreferredWidth(tcTestbedWidth); tcTableColumnModel.getColumn(EXEC_TIME).setPreferredWidth(70); tcTableColumnModel.getColumn(EXEC_TIME).setMinWidth(70); tcTableColumnModel.getColumn(EXEC_TIME).setMaxWidth(70); tcTableColumnModel.removeColumn(tcTableColumnModel.getColumn(TC)); if (!interactive) { tcTable.getSelectionModel().addListSelectionListener(new TCResultsSelectionListeners()); } tcTable.setName("tcTable"); tcTableColumnModel.addColumnModelListener(new TableColumnModelListener() { public void columnAdded(TableColumnModelEvent e) { } public void columnRemoved(TableColumnModelEvent e) { } public void columnMoved(TableColumnModelEvent e) { } public void columnMarginChanged(ChangeEvent e) { try { // save the current layout int tcStatusWidth = tcTable.getColumnModel().getColumn(STATUS).getWidth(); int tcWidth = tcTable.getColumnModel().getColumn(TEST_CASE).getWidth(); int tcDetailsWidth = tcTable.getColumnModel().getColumn(DETAILS).getWidth(); int tcResultWidth = tcTable.getColumnModel().getColumn(RESULT).getWidth(); int tcTestbedWidth = tcTable.getColumnModel().getColumn(TESTBED).getWidth(); // save it into the settings GUIConfiguration guiConfiguration = GUIConfiguration.getInstance(); guiConfiguration.setProperty(statusColumnProperty, tcStatusWidth); guiConfiguration.setProperty(testCaseColumnProperty, tcWidth); guiConfiguration.setProperty(detailsColumnProperty, tcDetailsWidth); guiConfiguration.setProperty(testbedColumnProperty, tcTestbedWidth); if (interactive) { guiConfiguration.setProperty(resultColumnProperty, tcResultWidth); } guiConfiguration.save(); } catch (ConfigurationException ex) { logger.error("Error while saving GUI configuration: " + ex.getMessage()); } } public void columnSelectionChanged(ListSelectionEvent e) { } }); try { tcTable.setDefaultRenderer(Class.forName("java.lang.Object"), new TableCellRenderer()); } catch (ClassNotFoundException ex) { } if (interactive) { displayTableForInteractiveMode(); } else { displayTableForExecutionMode(); } tcTable.addMouseListener(new TableMouseListener()); // use timer for updating elapsed time every seconds timer.schedule(new TimerTask() { @Override public void run() { updateRunningTestCaseElapsedTime(); } }, 1000, 1000); }
From source file:com.diversityarrays.kdxplore.curate.TraitsAndInstancesPanel2.java
public Map<String, TableColumn[]> createInstanceTableColumnsByChoice() { TableColumnModel tcm = traitInstanceStatsTable.getColumnModel(); Map<String, List<TableColumn>> tmp = new HashMap<String, List<TableColumn>>(); Map<Feature, Integer> fmap = tiStatsModel.getFeatureToColumnIndex(); List<TableColumn> basic = new ArrayList<>(); tmp.put(SimpleStatistics.GROUP_BASIC_STATS, basic); Integer viewColumnIndex = tiStatsModel.getViewColumnIndex(); if (viewColumnIndex != null) { basic.add(tcm.getColumn(viewColumnIndex)); }/* w ww . j a v a 2s . co m*/ for (int index : tiStatsModel.getTraitInstanceColumnIndices()) { basic.add(tcm.getColumn(index)); } for (Feature f : fmap.keySet()) { String grp = null; ExhibitColumn exhibitColumn = f.getExhibitColumn(); if (exhibitColumn != null) { grp = exhibitColumn.group(); } if (Check.isEmpty(grp)) { grp = SimpleStatistics.GROUP_BASIC_STATS; } List<TableColumn> list = tmp.get(grp); if (list == null) { list = new ArrayList<TableColumn>(); tmp.put(grp, list); } list.add(tcm.getColumn(fmap.get(f))); } Map<String, TableColumn[]> result = new HashMap<String, TableColumn[]>(); for (String grp : tmp.keySet()) { List<TableColumn> list = tmp.get(grp); result.put(grp, list.toArray(new TableColumn[list.size()])); } return result; }
From source file:com.att.aro.ui.view.menu.tools.RegexWizard.java
private void configVDTagsComboBox(JTable table, int columnIndex) { TableColumnModel columnModel = table.getColumnModel(); TableColumn comboColumn = columnModel.getColumn(columnIndex); JComboBox<String> comboBox = new JComboBox<>(); EnumSet<VideoDataTags> allVDTags = EnumSet.allOf(VideoDataTags.class); for (VideoDataTags videoDataTag : allVDTags) { comboBox.addItem(videoDataTag.toString()); }// w w w .j a va2 s.c om comboColumn.setCellEditor(new DefaultCellEditor(comboBox)); /* * allows clearing a problem when cell editor is interrupted, very deep problem. * Only shows if: (A) combobox selection is interupted, (B) dialog is * closed , and (C) Wizard is entered from the menu in this exact order */ cellEditor = comboColumn.getCellEditor(); DefaultTableCellRenderer renderer = new DefaultTableCellRenderer(); renderer.setToolTipText(ResourceBundleHelper.getMessageString("videoTab.tooltip")); comboColumn.setCellRenderer(renderer); }
From source file:io.heming.accountbook.ui.MainFrame.java
public MainFrame() throws Exception { categoryFacade = new CategoryFacade(); recordFacade = new RecordFacade(); builder = new Pages.Builder(); builder.order("id", false); pages = builder.make();// w w w . j a va 2 s.c om date_chooser_visible = false; disable = false; // Create widgets model = new TableModel(); table = new JTable(model) { /** * tip. * * @param evt * @return */ @Override public String getToolTipText(MouseEvent evt) { String tip = null; java.awt.Point point = evt.getPoint(); int row = rowAtPoint(point); int col = columnAtPoint(point); Rectangle bounds = getCellRect(row, col, false); Component comp = prepareRenderer(getCellRenderer(row, col), row, col); try { if (comp.getPreferredSize().width > bounds.width) { tip = getValueAt(row, col).toString(); } } catch (RuntimeException e) { //catch null pointer exception if mouse is over an empty line } return tip; } }; if (pages.hasNext()) { model.setRecords(pages.next()); } // ? table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); TableColumnModel columnModel = table.getColumnModel(); columnModel.getColumn(0).setPreferredWidth(80); columnModel.getColumn(1).setPreferredWidth(160); columnModel.getColumn(2).setPreferredWidth(80); columnModel.getColumn(3).setPreferredWidth(100); columnModel.getColumn(4).setPreferredWidth(100); columnModel.getColumn(5).setPreferredWidth(360); // Layout JScrollPane pane = new JScrollPane(table); add(pane, BorderLayout.CENTER); table.getTableHeader().setReorderingAllowed(false); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // table header table.getTableHeader().addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { int col = table.columnAtPoint(e.getPoint()); String name = table.getColumnName(col); // TODO } }); // ? addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { quit(); } }); categories = categoryFacade.listBySale(); initMenuBar(); initToolBar(); initStatusBar(); initTablePopupMenu(); searchRecords(); setIconImage(new ImageIcon(getClass().getResource("64.png")).getImage()); setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); setTitle(""); setSize(860, 620); }
From source file:modnlp.capte.AlignmentInterfaceWS.java
public void actionPerformed(ActionEvent e) { //Handle open button action. if (e.getSource() == openButton) { int returnVal = fc.showOpenDialog(AlignmentInterfaceWS.this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); //This is where a real application would open the file. sourceFile = file.getAbsolutePath(); log.append("Source File: " + sourceFile + "." + newline); } else {/*from w w w.ja va 2 s .c om*/ log.append("Open command cancelled by user." + newline); } log.setCaretPosition(log.getDocument().getLength()); } //deleteSegment else if (e.getSource() == deleteSegment) { Object[] o; String ivalue; int[] selected = table.getSelectedRows(); ExampleTableModel em = (ExampleTableModel) table.getModel(); if (selected.length < 1) { System.out.println("Please select at least one row"); JOptionPane.showMessageDialog(edit, "Please select at least one row"); } else { System.out.println("Deleting rows..."); for (int i = selected.length - 1; i > -1; i--) { em.removeRow(selected[i]); //update numbers System.out.println("Removed row " + selected[i]); } } //Table should update itself automatically } else if (e.getSource() == moveUp) { int[] selected = table.getSelectedRows(); ExampleTableModel em = (ExampleTableModel) table.getModel(); if (selected.length > 1) { System.out.println("You can only move one segment at a time!"); JOptionPane.showMessageDialog(edit, "You can only move one segment at a time!"); } else if (selected[0] == 0) { System.out.println("Can't move up anymore!"); JOptionPane.showMessageDialog(edit, "Can't move up anymore!"); } else { System.out.println("Moving " + selected[0]); em.moveSegmentUp(selected[0]); //Table should repaint } } else if (e.getSource() == moveDown) { int[] selected = table.getSelectedRows(); ExampleTableModel em = (ExampleTableModel) table.getModel(); if (selected.length > 1) { System.out.println("You can only move one segment at a time!"); JOptionPane.showMessageDialog(edit, "You can only move one segment at a time!"); } else if (selected[0] == em.getRowCount() - 1) { System.out.println("Can't move down anymore!"); JOptionPane.showMessageDialog(edit, "Can't move down anymore"); } else { System.out.println("Moving " + selected[0]); em.moveSegmentDown(selected[0]); //Table should repaint } } else if (e.getSource() == mergeSource) { int[] selected = table.getSelectedRows(); ExampleTableModel em = (ExampleTableModel) table.getModel(); if (selected.length < 2 || selected.length > 2) { System.out.println("Please select two rows to merge "); JOptionPane.showMessageDialog(edit, "Please select two rows to merge"); } else if (selected[0] - selected[1] > 1 || selected[0] - selected[1] < -1) { System.out.println("Can only merge adjacent rows"); JOptionPane.showMessageDialog(edit, "Can only merge adjacent rows"); } else { System.out.println("Merging source in rows " + selected[0] + " " + selected[1]); em.mergeSource(selected[0], selected[1]); } } else if (e.getSource() == mergeTarget) { int[] selected = table.getSelectedRows(); ExampleTableModel em = (ExampleTableModel) table.getModel(); if (selected.length < 2 || selected.length > 2) { System.out.println("Please select two rows to merge "); JOptionPane.showMessageDialog(edit, "Please select two rows to merge"); } else if (selected[0] - selected[1] > 1 || selected[0] - selected[1] < -1) { System.out.println("Can only merge adjacent rows"); JOptionPane.showMessageDialog(edit, "Can only merge adjacent rows"); } else { System.out.println("Merging target in " + selected[0] + " " + selected[1]); em.mergeTarget(selected[0], selected[1]); } } else if (e.getSource() == newSegment) { int[] selected = table.getSelectedRows(); ExampleTableModel em = (ExampleTableModel) table.getModel(); if (selected.length < 1) { System.out.println("Please select a position to insert at:"); JOptionPane.showMessageDialog(edit, "Please select a position to insert at"); } else { System.out.println("Inserting new segment at " + (selected[0] + 1)); //insert empty string array Object[] sa = new Object[6]; sa[0] = ""; sa[1] = ""; sa[2] = "0.0"; sa[3] = new Boolean(false); sa[4] = "0"; sa[5] = em.getValueAt((selected[0]), 5) + "(+)"; em.insertRow(sa, (selected[0] + 1)); } } else if (e.getSource() == lockSelected) { int[] selected = table.getSelectedRows(); ExampleTableModel em = (ExampleTableModel) table.getModel(); if (selected.length < 1) { System.out.println("Please select some rows to lock:"); JOptionPane.showMessageDialog(edit, "Please select some rows to lock:"); } else { //lock selected rows for (int i = 0; i < selected.length; i++) { em.lockRow(selected[i]); System.out.println("Locking row " + selected[i]); } } } else if (e.getSource() == unlockSelected) { int[] selected = table.getSelectedRows(); ExampleTableModel em = (ExampleTableModel) table.getModel(); if (selected.length < 1) { System.out.println("Please select some rows to unlock:"); JOptionPane.showMessageDialog(edit, "Please select some rows to unlock:"); } else { //lock selected rows for (int i = 0; i < selected.length; i++) { em.unlockRow(selected[i]); System.out.println("Unlocking row " + selected[i]); } } } else if (e.getSource() == reAlign) { // if(true){ // JOptionPane.showMessageDialog(edit,"This feature is currently disabled"); // }else{ reNumber++; ExampleTableModel em = (ExampleTableModel) table.getModel(); // Get list of locked segments // Find lowest locked segment // Realign from lowest locked segment // Join the realigned bit back up with the locked bit // refresh the table int lowestlock = 0; Vector<Object[]> slice = new Vector<Object[]>(); Vector<Object[]> result = new Vector<Object[]>(); Vector<Object[]> locked = new Vector<Object[]>(); Boolean b = new Boolean(true); for (int i = 0; i < em.getRowCount(); i++) { b = (Boolean) em.getValueAt(i, 3); if (b.booleanValue() == true) { lowestlock = i; } } //get slice of table for realignment System.out.println("The lowest lock point is " + (lowestlock)); System.out.println("Realigning from row:" + (lowestlock + 1) + " to : " + em.getRowCount()); System.out.println("Total size of realign array =:" + (em.getRowCount() - (lowestlock))); //Get locked bits for (int h = 0; h < lowestlock + 1; h++) { locked.add(em.getRow(h)); } //Get bits to realign for (int j = lowestlock + 1; j < em.getRowCount(); j++) { slice.add(em.getRow(j)); } //flush em.flush(); for (int z = 0; z < locked.size(); z++) { em.insertRow(locked.get(z), z); } // System.out.println("Total size of array after bits removed = " + (em.getRowCount())); //get the directory where the source files came from File parent = new File(sourceFile).getParentFile(); String dir = parent.getAbsolutePath(); //create files File sf = null; File tf = null; try { sf = File.createTempFile("source", "tmp"); tf = File.createTempFile("target", "tmp"); } catch (IOException ef) { ef.printStackTrace(); } System.out.println("Writing temp file:" + sf.getName()); System.out.println("Writing temp file:" + tf.getName()); // File mf = new File("merged.tmp"); //get absolute paths String sourceF = sf.getAbsolutePath(); String targetF = tf.getAbsolutePath(); //String alignF = mf.getAbsolutePath(); //write out source and target to files //NEW write files to server and return string String alignment = ""; AlignerUtils.reWriteAlignment(targetF, sourceF, slice); try { alignment = AlignerUtils.MultiPartFileUpload(targetF, sourceF); } catch (IOException es) { es.printStackTrace(); } //convert the String to a Vector form result = AlignerUtils.StringToData(alignment, true, reNumber); // append the resultant file to the table //System.out.println("Total size of array before bits inserted = " + (em.getRowCount())); for (int y = 0, z = em.getRowCount(); y < result.size(); y++, z++) { em.insertRow(result.get(y), z); System.out.println("Inserting at position: " + z); System.out.println("Inserting from position: " + y); } // System.out.println("Total size of array after bits inserted = " + (em.getRowCount())); // } } else if (e.getSource() == saveButton) { int returnVal = fc.showSaveDialog(AlignmentInterfaceWS.this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); //This is where a real application would save the file. targetFile = file.getAbsolutePath(); log.append("Target File " + targetFile + "." + newline); } else { log.append("Save command cancelled by user." + newline); } log.setCaretPosition(log.getDocument().getLength()); } else if (e.getSource() == export) { int returnVal = fc.showSaveDialog(AlignmentInterfaceWS.this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); outputFile = file.getAbsolutePath(); //aserver.writeAlignment(targetFile,data); AlignerUtils.writeAlignment(outputFile, data); log.append(newline + "Saving " + outputFile + "." + newline); } else { log.append("Save command cancelled by user." + newline); } log.setCaretPosition(log.getDocument().getLength()); } else if (e.getSource() == alignButton) { if (sl.getText().length() >= 2 && tl.getText().length() >= 2) { log.append("Attempting to align texts"); sourcel = sl.getText(); targetl = tl.getText(); String aligned = ""; try { aligned = AlignerUtils.MultiPartFileUpload(sourceFile, targetFile); } catch (IOException ed) { ed.printStackTrace(); } //Convert string to alignment format data = AlignerUtils.StringToData(aligned, false, 0); int i = 0; // // AlreadyRun = true; if (i == 0) { //log.setCaretPosition(log.getDocument().getLength()); log.append("\nAutomatic alignment successful!"); log.append("\nOpening display window......"); //Set up the editor window JFrame edit = new JFrame("Alignment Editor"); cols = new Vector<String>(); cols.add("Source"); cols.add("Target"); cols.add("Score"); cols.add("Lock"); cols.add("Index"); cols.add("Orig"); System.out.println("Size of data array " + data.size()); System.out.println(data.get(0)[0]); ex = new ExampleTableModel(cols, data); //ex.addTableModelListener(this); table = new JTable(ex); table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); TableColumnModel cmodel = table.getColumnModel(); cmodel.getColumn(0).setCellRenderer(new TextAreaRenderer()); cmodel.getColumn(1).setCellRenderer(new TextAreaRenderer()); cmodel.getColumn(2).setCellRenderer(new TextAreaRenderer()); cmodel.getColumn(4).setCellRenderer(new TextAreaRenderer()); cmodel.getColumn(5).setCellRenderer(new TextAreaRenderer()); TextAreaEditor textEditor = new TextAreaEditor(); textEditor.addCellEditorListener(this); cmodel.getColumn(0).setCellEditor(textEditor); cmodel.getColumn(1).setCellEditor(textEditor); cmodel.getColumn(2).setCellEditor(textEditor); cmodel.getColumn(4).setCellEditor(textEditor); cmodel.getColumn(5).setCellEditor(textEditor); mergeTarget = new JButton("Merge target"); mergeSource = new JButton("Merge source"); export = new JButton("Export to File"); newSegment = new JButton("Create New Segment"); deleteSegment = new JButton("Delete Selected"); moveUp = new JButton("Move Segment Up"); moveDown = new JButton("Move Segment Down"); lockSelected = new JButton("Lock Selected"); unlockSelected = new JButton("Unlock Selected"); reAlign = new JButton("Realign"); reAlign.addActionListener(this); lockSelected.addActionListener(this); unlockSelected.addActionListener(this); mergeSource.addActionListener(this); mergeTarget.addActionListener(this); export.addActionListener(this); newSegment.addActionListener(this); deleteSegment.addActionListener(this); moveUp.addActionListener(this); moveDown.addActionListener(this); JPanel control = new JPanel(); JPanel manipulate = new JPanel(); control.add(moveUp); control.add(moveDown); control.add(mergeTarget); control.add(mergeSource); //control.add(export); control.add(newSegment); control.add(deleteSegment); manipulate.add(reAlign); manipulate.add(lockSelected); manipulate.add(unlockSelected); manipulate.add(export); edit.add(control, BorderLayout.PAGE_START); edit.add(manipulate, BorderLayout.PAGE_END); JScrollPane scr = new JScrollPane(table); // JTable rowTable = new FirstRowNumberTable(table); //scr.add(table); //scr.setRowHeaderView(rowTable); //scr.setCorner(JScrollPane.UPPER_LEFT_CORNER, rowTable.getTableHeader()); scr.repaint(); edit.add(scr, BorderLayout.CENTER); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); edit.setSize(screenSize.width - 4, screenSize.height - 50); int totwidth = screenSize.width - 50; table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); cmodel.getColumn(0).setPreferredWidth((totwidth / 36) * 15); cmodel.getColumn(1).setPreferredWidth((totwidth / 36) * 15); cmodel.getColumn(2).setPreferredWidth(totwidth / 36 * 2); cmodel.getColumn(3).setPreferredWidth(totwidth / 36 * 2); cmodel.getColumn(4).setPreferredWidth(totwidth / 36 * 2); cmodel.getColumn(4).setPreferredWidth(totwidth / 36 * 2); edit.validate(); // Make sure layout is ok //edit.setSize(1024,700); edit.setVisible(true); } else { //log.setCaretPosition(log.getDocument().getLength()); log.append("\nAutomatic alignment unsuccessful..check error logs"); } } else { log.append("Please enter valid two letter language codes"); } log.setCaretPosition(log.getDocument().getLength()); } }
From source file:com.limegroup.gnutella.gui.library.LibraryTableMediator.java
/** * Sets the default editors./*from w w w . j av a 2 s . c o m*/ */ protected void setDefaultEditors() { TableColumnModel model = TABLE.getColumnModel(); TableColumn tc = model.getColumn(LibraryTableDataLine.NAME_IDX); tc.setCellEditor(new LibraryTableCellEditor(this)); }
From source file:it.iit.genomics.cru.igb.bundles.mi.view.MITable.java
public MITable(MITableModel model, IgbService service, final MIQuery query) { super(model); this.query = query; igbLogger = IGBLogger.getInstance(query.getLabel()); this.igbService = service; this.SymSelectionListener = new MouseListener() { @SuppressWarnings("unchecked") @Override//from ww w .j a v a 2 s. co m public void mouseClicked(MouseEvent e) { if (e.getComponent().isEnabled() && e.getButton() == MouseEvent.BUTTON1) { if (getSelectedRow() >= 0) { int modelRow = convertRowIndexToModel(getSelectedRow()); MIResult interaction = ((MITableModel) getModel()).getResult(modelRow); structuresPanel.setCurrentInteraction(interaction); } MITable table = (MITable) e.getComponent(); int modelRow = convertRowIndexToModel(table.getSelectedRow()); int column = table.getSelectedColumn(); if (e.getClickCount() == 1) { if (column == MITableModel.TRACK_COLUMN) { Object value = table.getValueAt(table.getSelectedRow(), column); if (value instanceof JButton) { MIResult result = ((MITableModel) table.getModel()).getResult(modelRow); TypeContainerAnnot interactorTrack = result.createTrack(); igbService.addTrack(interactorTrack, interactorTrack.getID()); igbService.getSeqMapView().updatePanel(); for (TierGlyph t : igbService.getAllTierGlyphs()) { if (TierGlyph.TierType.ANNOTATION.equals(t.getTierType()) && (t.getAnnotStyle().getTrackName().equals(interactorTrack.getID()))) { SimpleTrackStyle style = new SimpleTrackStyle(interactorTrack.getID(), false) { @Override public boolean drawCollapseControl() { return false; } }; t.getAnnotStyle().copyPropertiesFrom(style); t.getAnnotStyle().setColorProvider(new RGB()); interactorTrack.setProperty(TrackLineParser.ITEM_RGB, "on"); } } igbService.getSeqMapView().updatePanel(); ((JButton) value).setText(interactorTrack.getID()); ((JButton) value).setEnabled(false); updateUI(); } } } else { // symmetry: zoom-in if (column == MITableModel.SYMS1_COLUMN) { MoleculeEntry entry = ((MITableModel) table.getModel()).getResult(modelRow) .getInteractor1(); if (query.getTaxid().equals(entry.getTaxid())) { Collection<SeqSymmetry> syms = ((MITableModel) table.getModel()).getResult(modelRow) .getSymmetries1(); zoomToSym(syms); } } else if (column == MITableModel.SYMS2_COLUMN) { MoleculeEntry entry = ((MITableModel) table.getModel()).getResult(modelRow) .getInteractor2(); if (query.getTaxid().equals(entry.getTaxid())) { Collection<SeqSymmetry> syms = ((MITableModel) table.getModel()).getResult(modelRow) .getSymmetries2(); zoomToSym(syms); } } // Protein: link to uniprot if (column == MITableModel.INTERACTOR1_COLUMN || column == MITableModel.INTERACTOR2_COLUMN) { MIResult miResult = ((MITableModel) table.getModel()).getResult(modelRow); String id; String taxid; MoleculeEntry interactor; if (column == MITableModel.INTERACTOR1_COLUMN) { interactor = miResult.getInteractor1(); } else { interactor = miResult.getInteractor2(); } taxid = interactor.getTaxid(); String query; String anchor = ""; switch (taxid) { case MoleculeEntry.TAXID_DNA: case MoleculeEntry.TAXID_RNA: if (miResult.getInteractionStructures().isEmpty()) { return; } query = "http://www.pdb.org/pdb/explore/explore.do?structureId=" + miResult.getInteractionStructures().iterator().next().getStructureID(); break; case MoleculeEntry.TAXID_LIGAND: if (miResult.getInteractionStructures().isEmpty()) { return; } query = DrugBankMapper.getInstance().isDrug(interactor.getGeneName()) ? DrugBankMapper.getInstance().getDrugBankLink(interactor.getGeneName()) : "http://www.ebi.ac.uk/pdbe-srv/pdbechem/chemicalCompound/show/" + interactor.getGeneName(); break; case MoleculeEntry.TAXID_MODIFICATION: query = "http://www.uniprot.org/uniprot/" + miResult.getInteractor1().getUniprotAc(); anchor = "#ptm_processing"; break; default: id = interactor.getUniprotAc(); query = "http://www.uniprot.org/uniprot/" + id; break; } try { URI uri = new URI(URIUtil.encodeQuery(query) + anchor); Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null; if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) { desktop.browse(uri); } } catch (IOException ioe) { JOptionPane.showMessageDialog(null, "Cannot reach Uniprot website."); return; } catch (URISyntaxException ue) { JOptionPane.showMessageDialog(null, "Cannot reach Uniprot website: " + query); } } // interaction type: link to psicquic if (column == MITableModel.INTERACTION_TYPE_COLUMN) { MIResult miResult = ((MITableModel) table.getModel()).getResult(modelRow); String queryURL; String idA = miResult.getInteractor1().getUniprotAc(); String idB = miResult.getInteractor2().getUniprotAc(); if (null == miResult.getPsicquicUrl()) { // from the structure database if (query.searchDSysMap()) { queryURL = "http://http://dsysmap.irbbarcelona.org/results.php?type=proteins&neigh=2&value=" + idA + "," + idB; } else if (query.searchInteractome3D()) { try { queryURL = "http://interactome3d.irbbarcelona.org/interaction.php?ids=" + idA + ";" + idB + "&dataset=" + it.iit.genomics.cru.bridges.interactome3d.ws.Utils .getDataset(query.getTaxid()); } catch (Interactome3DException e3d) { // it will never happend: if the taxid was not known by // I3D, we wouldn't have an interaction return; } } else { return; } } else { if (false == idA.equals(idB)) { queryURL = miResult.getPsicquicUrl() + "query/id:" + miResult.getInteractor1().getUniprotAc() + "* AND id:" + miResult.getInteractor2().getUniprotAc() + "*"; } else { queryURL = miResult.getPsicquicUrl() + "query/idA:" + miResult.getInteractor1().getUniprotAc() + "* AND idB:" + miResult.getInteractor2().getUniprotAc() + "*"; } } try { URI uri = new URI(URIUtil.encodeQuery(queryURL)); Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null; if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) { desktop.browse(uri); } } catch (IOException ioe) { JOptionPane.showMessageDialog(null, "Cannot reach psicquic server."); } catch (URISyntaxException ue) { JOptionPane.showMessageDialog(null, "Cannot reach psicquic server: " + queryURL); } } } } } @Override public void mousePressed(MouseEvent me) { } @Override public void mouseReleased(MouseEvent me) { } @Override public void mouseEntered(MouseEvent me) { } @Override public void mouseExited(MouseEvent me) { } }; TableRowSorter<MITableModel> sorter = new MITableRowSorter(model); setRowSorter(sorter); sorter.setRowFilter(evidenceRowFilter()); model.fireTableDataChanged(); this.getTableHeader().setReorderingAllowed(false); TableCellRenderer rend = getTableHeader().getDefaultRenderer(); TableColumnModel tcm = getColumnModel(); for (int j = 0; j < tcm.getColumnCount(); j += 1) { TableColumn tc = tcm.getColumn(j); TableCellRenderer rendCol = tc.getHeaderRenderer(); // likely null if (rendCol == null) { rendCol = rend; } Component c = rendCol.getTableCellRendererComponent(this, tc.getHeaderValue(), false, false, 0, j); tc.setPreferredWidth(c.getPreferredSize().width); } TableCellRenderer buttonRenderer = new JTableButtonRenderer(); getColumn(model.getColumnName(MITableModel.TRACK_COLUMN)).setCellRenderer(buttonRenderer); getColumn(model.getColumnName(MITableModel.SYMS1_COLUMN)).setCellRenderer(new GeneRenderer()); getColumn(model.getColumnName(MITableModel.SYMS2_COLUMN)).setCellRenderer(new GeneRenderer()); getColumn(model.getColumnName(MITableModel.INTERACTOR1_COLUMN)).setCellRenderer(new MoleculeRenderer()); getColumn(model.getColumnName(MITableModel.INTERACTOR2_COLUMN)).setCellRenderer(new MoleculeRenderer()); getColumn(model.getColumnName(MITableModel.INTERACTION_TYPE_COLUMN)) .setCellRenderer(new EvidenceRenderer()); getColumn(model.getColumnName(MITableModel.STRUCTURES_COLUMN)).setCellRenderer(new StructuresRenderer()); setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS); int smallWidth = 75; int mediumWidth = 120; int largeWidth = 200; getColumnModel().getColumn(MITableModel.TRACK_COLUMN).setMinWidth(smallWidth); getColumnModel().getColumn(MITableModel.STRUCTURES_COLUMN).setMinWidth(smallWidth); getColumnModel().getColumn(MITableModel.STRUCTURES_COLUMN).setMaxWidth(smallWidth); getColumnModel().getColumn(MITableModel.STRUCTURES_COLUMN).setPreferredWidth(smallWidth); addMouseListener(SymSelectionListener); getSelectionModel().addListSelectionListener(new RowSelectionListener()); }
From source file:userInterface.HospitalAdminRole.ManagePatientsJPanel.java
private void saveReportBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveReportBtnActionPerformed try {//ww w . jav a2s.c o m HSSFWorkbook fWorkbook = new HSSFWorkbook(); HSSFSheet fSheet = fWorkbook.createSheet("new Sheet"); HSSFFont sheetTitleFont = fWorkbook.createFont(); File file = new File("C:\\Users\\Reshmi\\OneDrive\\Documents\\reports.xls"); HSSFCellStyle cellStyle = fWorkbook.createCellStyle(); sheetTitleFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); //sheetTitleFont.setColor(); TableModel model = vitalSignjTable.getModel(); TableColumnModel tcm = vitalSignjTable.getColumnModel(); HSSFRow fRow1 = fSheet.createRow((short) 0); for (int j = 0; j < tcm.getColumnCount(); j++) { HSSFCell cell = fRow1.createCell((short) j); cell.setCellValue(tcm.getColumn(j).getHeaderValue().toString()); } for (int i = 0; i < model.getRowCount(); i++) { HSSFRow fRow = fSheet.createRow((short) i + 1); for (int j = 0; j < model.getColumnCount(); j++) { HSSFCell cell = fRow.createCell((short) j); cell.setCellValue(tcm.getColumn(j).getHeaderValue().toString()); cell.setCellValue(model.getValueAt(i, j).toString()); cell.setCellStyle(cellStyle); } } FileOutputStream fileOutputStream; fileOutputStream = new FileOutputStream(file); BufferedOutputStream bos = new BufferedOutputStream(fileOutputStream); fWorkbook.write(bos); bos.close(); fileOutputStream.close(); JOptionPane.showMessageDialog(null, "File saved as reports.xls ", "Export", JOptionPane.INFORMATION_MESSAGE); // Runtime run = Runtime.getRuntime(); // run.exec("cmd.exetart " + file); } catch (Exception e) { JOptionPane.showMessageDialog(null, "File not saved", "Export", JOptionPane.INFORMATION_MESSAGE); } }
From source file:com.frostwire.gui.library.LibraryFilesTableMediator.java
/** * Sets the default editors.//from w w w.j a va 2 s .com */ protected void setDefaultEditors() { TableColumnModel model = TABLE.getColumnModel(); TableColumn tc = model.getColumn(LibraryFilesTableDataLine.SHARE_IDX); tc.setCellEditor(new FileShareCellEditor(FILE_SHARE_CELL_RENDERER)); tc = model.getColumn(LibraryFilesTableDataLine.ACTIONS_IDX); tc.setCellEditor(new GenericCellEditor(getAbstractActionsRenderer())); tc = model.getColumn(LibraryFilesTableDataLine.PAYMENT_OPTIONS_IDX); tc.setCellEditor(new GenericCellEditor(new PaymentOptionsRenderer())); }
From source file:edu.ku.brc.specify.tasks.subpane.ESResultsTablePanel.java
/** * Constructor of a results "table" which is really a panel * @param esrPane the parent// w ww. ja v a 2 s . c o m * @param erTableInfo the info describing the results * @param installServices indicates whether services should be installed * @param isExpandedAtStartUp enough said * @param inclCloseBtn whether to include the close button on the bar */ public ESResultsTablePanel(final ExpressSearchResultsPaneIFace esrPane, final QueryForIdResultsIFace results, final boolean installServices, final boolean isExpandedAtStartUp, final boolean inclCloseBtn) { super(new BorderLayout()); this.esrPane = esrPane; this.results = results; this.bannerColor = results.getBannerColor(); this.isEditable = results.isEditingEnabled(); table = new JTable(); table.setShowVerticalLines(false); table.setRowSelectionAllowed(true); table.setSelectionMode(results.isMultipleSelection() ? ListSelectionModel.MULTIPLE_INTERVAL_SELECTION : ListSelectionModel.SINGLE_SELECTION); setBackground(table.getBackground()); if (isEditable) { addContextMenu(); } topTitleBar = new GradiantLabel(results.getTitle(), SwingConstants.LEFT); topTitleBar.setBGBaseColor(bannerColor); topTitleBar.setTextColor(Color.WHITE); topTitleBar.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { expandBtn.doClick(); } } }); String description = results.getDescription(); if (StringUtils.isNotEmpty(description)) { topTitleBar.setToolTipText(description); } expandBtn = new TriangleButton(); expandBtn.setToolTipText(getResourceString("CollapseTBL")); expandBtn.setForeground(bannerColor); expandBtn.setTextColor(Color.WHITE); showTopNumEntriesBtn = new GradiantButton( String.format(getResourceString("ShowTopEntries"), new Object[] { topNumEntries })); showTopNumEntriesBtn.setForeground(bannerColor); showTopNumEntriesBtn.setTextColor(Color.WHITE); showTopNumEntriesBtn.setVisible(false); showTopNumEntriesBtn.setCursor(handCursor); List<ServiceInfo> services = installServices ? getServices() : null; //System.out.println("["+tableInfo.getTableId()+"]["+services.size()+"]"); StringBuffer colDef = new StringBuffer("p,0px,p:g,0px,p,0px,"); int numCols = (installServices ? services.size() : 0) + (inclCloseBtn ? 1 : 0); colDef.append(UIHelper.createDuplicateJGoodiesDef("p", "0px", numCols)); // add additional col defs for services PanelBuilder builder = new PanelBuilder(new FormLayout(colDef.toString(), "f:p:g")); CellConstraints cc = new CellConstraints(); int col = 1; builder.add(expandBtn, cc.xy(col, 1)); col += 2; builder.add(topTitleBar, cc.xy(col, 1)); col += 2; builder.add(showTopNumEntriesBtn, cc.xy(col, 1)); col += 2; if (installServices && services.size() > 0) { serviceBtns = new Hashtable<ServiceInfo, JButton>(); //IconManager.IconSize size = IconManager. int iconSize = AppPreferences.getLocalPrefs().getInt("banner.icon.size", 20); // Install the buttons on the banner with available services for (ServiceInfo serviceInfo : services) { GradiantButton btn = new GradiantButton(serviceInfo.getIcon(iconSize)); // XXX PREF btn.setToolTipText(serviceInfo.getTooltip()); btn.setForeground(bannerColor); builder.add(btn, cc.xy(col, 1)); ESTableAction esta = new ESTableAction(serviceInfo.getCommandAction(), table, serviceInfo.getTooltip()); esta.setProperty("gridtitle", results.getTitle()); btn.addActionListener(esta); serviceBtns.put(serviceInfo, btn); col += 2; } } GradiantButton closeBtn = null; if (inclCloseBtn) { closeBtn = new GradiantButton(IconManager.getIcon("Close")); closeBtn.setToolTipText(getResourceString("ESCloseTable")); closeBtn.setForeground(bannerColor); closeBtn.setRolloverEnabled(true); closeBtn.setRolloverIcon(IconManager.getIcon("CloseHover")); closeBtn.setPressedIcon(IconManager.getIcon("CloseHover")); builder.add(closeBtn, cc.xy(col, 1)); col += 2; } add(builder.getPanel(), BorderLayout.NORTH); tablePane = new JPanel(new BorderLayout()); setupTablePane(); if (isEditable) { //delRSItems = UIHelper.createI18NButton("RESTBL_DEL_ITEMS"); delRSItems = UIHelper.createIconBtn("DelRec", "ESDelRowsTT", null); delRSItems.addActionListener(createRemoveItemAL()); delRSItems.setEnabled(false); table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { delRSItems.setEnabled(table.getSelectedRowCount() > 0); } } }); } add(tablePane, BorderLayout.CENTER); moveToRSCmd = new DragSelectedRowsBtn(IconManager.getIcon("Record_Set", IconManager.IconSize.Std16)); if (installServices) { PanelBuilder bottomBar = new PanelBuilder( new FormLayout("4px,p,4px,p,4px,p," + (delRSItems != null ? "4px,p," : "") + "f:p:g", "p")); bottomBar.add(moveToRSCmd, cc.xy(2, 1)); bottomBar.add(selectAllBtn, cc.xy(4, 1)); bottomBar.add(deselectAllBtn, cc.xy(6, 1)); if (delRSItems != null) { bottomBar.add(delRSItems, cc.xy(8, 1)); } botBtnPanel = bottomBar.getPanel(); deselectAllBtn.setEnabled(false); selectAllBtn.setEnabled(true); moveToRSCmd.setEnabled(true); deselectAllBtn.setToolTipText(getResourceString("SELALLTOOLTIP")); selectAllBtn.setToolTipText(getResourceString("DESELALLTOOLTIP")); moveToRSCmd.setToolTipText(getResourceString("MOVEROWSTOOLTIP")); selectAllBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { table.selectAll(); } }); deselectAllBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { table.clearSelection(); } }); moveToRSCmd.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { RecordSetIFace src = (RecordSetIFace) moveToRSCmd.getData(); CommandDispatcher .dispatch(new CommandAction(RecordSetTask.RECORD_SET, "AskForNewRS", src, null, null)); } }); add(botBtnPanel, BorderLayout.SOUTH); } else { botBtnPanel = null; } expandBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { expandTable(false); } }); if (!isExpandedAtStartUp) { expandTable(true); } showTopNumEntriesBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { morePanel.setVisible(true); showTopNumEntriesBtn.setVisible(false); showingAllRows = false; setDisplayRows(rowCount, topNumEntries); // If it is collapsed then expand it if (!expandBtn.isDown()) { tablePane.setVisible(true); expandBtn.setDown(true); } // Make sure the layout is updated invalidate(); doLayout(); esrPane.revalidateScroll(); } }); if (closeBtn != null) { closeBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { SwingUtilities.invokeLater(new Runnable() { public void run() { removeMe(); } }); } }); } ResultSetTableModel rsm = createModel(); rsm.setPropertyListener(this); resultSetTableModel = rsm; table.setRowSorter(new TableRowSorter<ResultSetTableModel>(resultSetTableModel)); table.setRowSelectionAllowed(true); table.setModel(rsm); configColumns(); rowCount = rsm.getRowCount(); if (rowCount > topNumEntries + 2) { buildMorePanel(); setDisplayRows(rowCount, topNumEntries); } else { setDisplayRows(rowCount, Integer.MAX_VALUE); } invalidate(); doLayout(); UIRegistry.forceTopFrameRepaint(); table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { if (botBtnPanel != null) { deselectAllBtn.setEnabled(table.getSelectedRowCount() > 0); selectAllBtn.setEnabled(table.getSelectedRowCount() != table.getRowCount()); moveToRSCmd.setEnabled(table.getSelectedRowCount() > 0); } } if (propChangeListener != null) { if (!e.getValueIsAdjusting()) { propChangeListener.propertyChange( new PropertyChangeEvent(this, "selection", table.getSelectedRowCount(), 0)); } else { propChangeListener.propertyChange( new PropertyChangeEvent(this, "selection", table.getSelectedRowCount(), 0)); } } } }); table.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { //synchronized (((JTable)e.getSource()).getTreeLock()) //{ doDoubleClickOnRow(e); //} } }); // Horizontal Alignment is set later TableColumnModel tableColModel = table.getColumnModel(); for (int i = 0; i < tableColModel.getColumnCount(); i++) { tableColModel.getColumn(i).setCellRenderer(new BiColorTableCellRenderer()); } }