Java Code Examples for javax.swing.JTable#getSelectedRows()

The following examples show how to use javax.swing.JTable#getSelectedRows() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ZettelkastenViewUtil.java    From Zettelkasten with GNU General Public License v3.0 6 votes vote down vote up
/**
 * This method updates a jTable and a possible linked list which holds
 * filtered values from the jTables, by completely removing an entry/value
 * from the tablemodel and the linked list.
 * <br><br>
 * If no complete removal is requested, but a decrease in the frequencies,
 * call
 * {@link #updateTableFrequencyDelete(javax.swing.JTable, java.util.LinkedList) updateTableFrequencyDelete(javax.swing.JTable, java.util.LinkedList)}
 * instead.
 *
 * @param table the table were we have to add a new value with frequency
 * @param list the possible linked list were we have to add a new value with
 * frequency
 * @param zettelkastenView
 * @return an updated linked list that was passed as parameter {@code list}
 */
public static LinkedList<Object[]> updateTableFrequencyRemove(JTable table, LinkedList<Object[]> list, ZettelkastenView zettelkastenView) {
    // get table model
    DefaultTableModel dtm = (DefaultTableModel) table.getModel();
    // retrieve selected rows
    int[] rows = table.getSelectedRows();
    for (int cnt = rows.length - 1; cnt >= 0; cnt--) {
        try {
            int selectedrow = table.convertRowIndexToModel(rows[cnt]);
            if (list != null) {
                Object[] o = new Object[2];
                o[0] = dtm.getValueAt(selectedrow, 0);
                o[1] = dtm.getValueAt(selectedrow, 1);
                int pos = findInLinkedList(list, o);
                if (pos != -1) {
                    list.remove(pos);
                }
            }
            dtm.removeRow(selectedrow);
        } catch (ArrayIndexOutOfBoundsException e) {
            Constants.zknlogger.log(Level.WARNING, e.getLocalizedMessage());
        }
    }
    return list;
}
 
Example 2
Source File: CTracesNodeComponent.java    From binnavi with Apache License 2.0 6 votes vote down vote up
/**
 * Shows a popup menu for a given mouse event.
 *
 * @param event The event that triggered the popup menu.
 */
private void showPopupMenu(final MouseEvent event) {
  final JTable traceTable = m_tracesPanel.getTracesTable();
  final int mouseRow = traceTable.rowAtPoint(event.getPoint());
  if (mouseRow != -1) {
    final int[] rows = traceTable.getSelectedRows();
    if (Ints.asList(rows).indexOf(mouseRow) != -1) {
      traceTable.setRowSelectionInterval(mouseRow, mouseRow);
    }
  }

  // Make sure at least one row is selected
  final int minIndex =
      m_tracesPanel.getTracesTable().getSelectionModel().getMinSelectionIndex();
  if (minIndex != -1) {
    final JPopupMenu popupMenu =
        new CEventListTableMenu(
            (JFrame) SwingUtilities.getWindowAncestor(CTracesNodeComponent.this),
            m_tracesPanel.getTracesTable(), m_container.getTraceProvider());
    popupMenu.show(m_tracesPanel.getTracesTable(), event.getX(), event.getY());
  }
}
 
Example 3
Source File: JtableUtils.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 6 votes vote down vote up
/**
 * Reads clipboard data and converts it into supported format and fills the
 * tmodel cells
 *
 * @param table the target tmodel
 */
private static void pasteFromClipboard(JTable table) {
    int startRow = table.getSelectedRows()[0];
    int startCol = table.getSelectedColumns()[0];
    String pasteString;
    try {
        pasteString = (String) (CLIPBOARD.getContents(CLIPBOARD).getTransferData(DataFlavor.stringFlavor));
    } catch (UnsupportedFlavorException | IOException ex) {
        Logger.getLogger(JtableUtils.class.getName()).log(Level.SEVERE, null, ex);
        return;
    }
    String[] lines = pasteString.split(LINE_BREAK);
    for (int i = 0; i < lines.length; i++) {
        String[] cells = lines[i].split(CELL_BREAK);
        if (table.getRowCount() <= startRow + i) {
            ((DefaultTableModel) table.getModel()).addRow(nullRow);
        }
        for (int j = 0; j < cells.length; j++) {
            if (table.getColumnCount() > startCol + j) {
                if (table.isCellEditable(startRow + i, startCol + j)) {
                    table.setValueAt(cells[j], startRow + i, startCol + j);
                }
            }
        }
    }
}
 
Example 4
Source File: FlatTableCellBorder.java    From FlatLaf with Apache License 2.0 6 votes vote down vote up
/**
 * Checks whether at least one selected cell is editable.
 */
protected boolean isSelectionEditable( JTable table ) {
	if( table.getRowSelectionAllowed() ) {
		int columnCount = table.getColumnCount();
		int[] selectedRows = table.getSelectedRows();
		for( int selectedRow : selectedRows ) {
			for( int column = 0; column < columnCount; column++ ) {
				if( table.isCellEditable( selectedRow, column ) )
					return true;
			}
		}
	}

	if( table.getColumnSelectionAllowed() ) {
		int rowCount = table.getRowCount();
		int[] selectedColumns = table.getSelectedColumns();
		for( int selectedColumn : selectedColumns ) {
			for( int row = 0; row < rowCount; row++ ) {
				if( table.isCellEditable( row, selectedColumn ) )
					return true;
			}
		}
	}

	return false;
}
 
Example 5
Source File: JtableUtils.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
public static void pasteFromAbove(JTable table) {
    int startRow = table.getSelectedRows()[0];
    int[] cols = table.getSelectedColumns();
    for (int col : cols) {
        table.setValueAt(table.getValueAt(startRow - 1, col), startRow, col);
    }
}
 
Example 6
Source File: EquipInfoTab.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void valueChanged(ListSelectionEvent e)
{
	JTable target = equipmentTable;
	if (equipmentSetTable.getSelectionModel().equals(e.getSource()))
	{
		target = equipmentSetTable;
	}
	if (!e.getValueIsAdjusting())
	{
		int[] selectedRows = target.getSelectedRows();
		StringBuilder sb = new StringBuilder(2000);
		for (int row : selectedRows)
		{
			EquipmentFacade equip = null;
			if (row != -1)
			{
				Object value = target.getModel().getValueAt(row, 0);
				if (value instanceof EquipmentFacade)
				{
					equip = (EquipmentFacade) value;
				}
				else if (value instanceof EquipNode)
				{
					equip = ((EquipNode) value).getEquipment();
				}
			}
			if (equip != null)
			{
				sb.append(character.getInfoFactory().getHTMLInfo(equip));
			}
		}
		text = "<html>" + sb + "</html>"; //$NON-NLS-1$ //$NON-NLS-2$
		infoPane.setText(text);
	}
}
 
Example 7
Source File: XTable.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    JComponent comp = (JComponent) defCellRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    Boolean rowSelected = false;
    for (int srow : table.getSelectedRows()) {
        if (srow == row) {
            rowSelected = true;
            break;
        }
    }

    setSelectionColor(rowSelected, isSelected, comp, table.getBackground());
    setSearchColor(comp, row, column, isSelected);
    return comp;
}
 
Example 8
Source File: XTableUtils.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
public static void pasteFromClipboard(JTable table) {
    int startRow = table.getSelectedRows()[0];
    int startCol = table.getSelectedColumns()[0];

    String pasteString;
    try {
        pasteString = (String) (CLIPBOARD.getContents(null).getTransferData(DataFlavor.stringFlavor));
    } catch (Exception e) {
        Logger.getLogger(XTableUtils.class.getName()).log(Level.WARNING, "Invalid Paste Type", e);
        return;
    }
    if (table.getModel() instanceof UndoRedoModel) {
        ((UndoRedoModel) table.getModel()).startGroupEdit();
    }
    String[] lines = pasteString.split(LINE_BREAK);

    for (int i = 0; i < lines.length; i++) {
        String[] cells = lines[i].split(CELL_BREAK);
        for (int j = 0; j < cells.length; j++) {
            if (table.getRowCount() <= startRow + i) {
                if (table.getModel() instanceof DataModel) {
                    if (!((DataModel) table.getModel()).addRow()) {
                        return;
                    }
                }
            }
            if (table.getRowCount() > startRow + i && table.getColumnCount() > startCol + j) {
                table.setValueAt(cells[j], startRow + i, startCol + j);
            }
        }
    }
    if (table.getModel() instanceof UndoRedoModel) {
        ((UndoRedoModel) table.getModel()).stopGroupEdit();
    }
}
 
Example 9
Source File: XTableUtils.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
public static void copyToClipboard(JTable table, boolean isCut) {
    int numCols = table.getSelectedColumnCount();
    int numRows = table.getSelectedRowCount();
    int[] rowsSelected = table.getSelectedRows();
    int[] colsSelected = table.getSelectedColumns();
    if (numRows != rowsSelected[rowsSelected.length - 1] - rowsSelected[0] + 1 || numRows != rowsSelected.length
            || numCols != colsSelected[colsSelected.length - 1] - colsSelected[0] + 1 || numCols != colsSelected.length) {

        Logger.getLogger(XTableUtils.class.getName()).info("Invalid Copy Selection");
        return;
    }
    if (table.getModel() instanceof UndoRedoModel) {
        ((UndoRedoModel) table.getModel()).startGroupEdit();
    }

    StringBuilder excelStr = new StringBuilder();

    for (int i = 0; i < numRows; i++) {
        for (int j = 0; j < numCols; j++) {
            excelStr.append(escape(table.getValueAt(rowsSelected[i], colsSelected[j])));
            if (isCut) {
                table.setValueAt("", rowsSelected[i], colsSelected[j]);
            }
            if (j < numCols - 1) {
                excelStr.append(CELL_BREAK);
            }
        }
        excelStr.append(LINE_BREAK);
    }

    if (table.getModel() instanceof UndoRedoModel) {
        ((UndoRedoModel) table.getModel()).stopGroupEdit();
    }

    StringSelection sel = new StringSelection(excelStr.toString());

    CLIPBOARD.setContents(sel, sel);
}
 
Example 10
Source File: TableUtils.java    From IrScrutinizer with GNU General Public License v3.0 5 votes vote down vote up
void deleteTableSelectedRows(JTable table) throws ErroneousSelectionException {
    barfIfNoneSelected(table);
    int[] rows = table.getSelectedRows();
    for (int i = 0; i < rows.length; i++)
        rows[i] = table.convertRowIndexToModel(rows[i]);

    Arrays.sort(rows);

    DefaultTableModel tableModel = (DefaultTableModel) table.getModel();

    for (int i = rows.length - 1; i >= 0; i--)
        tableModel.removeRow(rows[i]);
}
 
Example 11
Source File: JtableUtils.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
/**
 * clear selection by setting empty values
 *
 * @param table to be cleared
 */
private static void ClearSelection(JTable table) {
    int[] srow = table.getSelectedRows();
    int[] scol = table.getSelectedColumns();
    int lastSrow = srow.length;
    int lastScol = scol.length;
    for (int i = 0; i < lastSrow; i++) {
        for (int j = 0; j < lastScol; j++) {
            if (table.isCellEditable(srow[i], scol[j])) {
                table.setValueAt("", srow[i], scol[j]);
            }
        }
    }
}
 
Example 12
Source File: EquipInfoTab.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void valueChanged(ListSelectionEvent e)
{
	JTable target = equipmentTable;
	if (equipmentSetTable.getSelectionModel().equals(e.getSource()))
	{
		target = equipmentSetTable;
	}
	if (!e.getValueIsAdjusting())
	{
		int[] selectedRows = target.getSelectedRows();
		StringBuilder sb = new StringBuilder(2000);
		for (int row : selectedRows)
		{
			EquipmentFacade equip = null;
			if (row != -1)
			{
				Object value = target.getModel().getValueAt(row, 0);
				if (value instanceof EquipmentFacade)
				{
					equip = (EquipmentFacade) value;
				}
				else if (value instanceof EquipNode)
				{
					equip = ((EquipNode) value).getEquipment();
				}
			}
			if (equip != null)
			{
				sb.append(character.getInfoFactory().getHTMLInfo(equip));
			}
		}
		text = "<html>" + sb + "</html>"; //$NON-NLS-1$ //$NON-NLS-2$
		infoPane.setText(text);
	}
}
 
Example 13
Source File: UITools.java    From MtgDesktopCompanion with GNU General Public License v3.0 5 votes vote down vote up
public static <T> List<T> getTableSelections(JTable tableCards,int columnID) {
	int[] viewRow = tableCards.getSelectedRows();
	List<T> listCards = new ArrayList<>();
	for (int i : viewRow) {
		int modelRow = tableCards.convertRowIndexToModel(i);
		T mc = (T) tableCards.getModel().getValueAt(modelRow, columnID);
		listCards.add(mc);
	}
	return listCards;
}
 
Example 14
Source File: PurchaseInfoTab.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void valueChanged(ListSelectionEvent e)
{
	JTable target = availableTable;
	if (purchasedTable.getSelectionModel().equals(e.getSource()))
	{
		target = purchasedTable;
	}
	if (!e.getValueIsAdjusting())
	{
		int[] selectedRows = target.getSelectedRows();
		List<EquipmentFacade> newList = new ArrayList<>(selectedRows.length);
		for (int row : selectedRows)
		{
			if (row != -1)
			{
				Object value = target.getModel().getValueAt(row, 0);
				if (value instanceof EquipmentFacade)
				{
					newList.add((EquipmentFacade) value);
				}
			}
		}
		if (newList.isEmpty() || newList.equals(oldList))
		{
			return;
		}
		oldList = newList;
		StringBuilder sb = new StringBuilder(2000);
		for (EquipmentFacade equip : newList)
		{
			sb.append(character.getInfoFactory().getHTMLInfo(equip));
		}
		text = "<html>" + sb + "</html>"; //$NON-NLS-1$ //$NON-NLS-2$
		infoPane.setText(text);
	}
}
 
Example 15
Source File: ResultsSelectionListener.java    From HBaseClient with GNU General Public License v3.0 5 votes vote down vote up
public void valueChanged(ListSelectionEvent e) 
{
    JTable v_JTable = (JTable)XJava.getObject("xtDataList");
    
	// 如果事件非快速连续事件之一
	if ( !e.getValueIsAdjusting() )
	{
		int [] v_RowIndexArr = v_JTable.getSelectedRows();
		
		if ( v_RowIndexArr.length == 1 )
		{
		    ((JTextComponent)XJava.getObject("Edit_RowKey"))     .setText(        v_JTable.getValueAt(v_RowIndexArr[0] ,1).toString());
		    ((JComboBox)     XJava.getObject("Edit_ColumnName")) .setSelectedItem(v_JTable.getValueAt(v_RowIndexArr[0] ,3).toString());
		    ((JTextComponent)XJava.getObject("Edit_ColumnValue")).setText(        v_JTable.getValueAt(v_RowIndexArr[0] ,4).toString());
		    ((JButton)       XJava.getObject("xbCopy"))          .setEnabled(false);
		    
	        // 设置列族名下拉列表框
	        String    v_FamilyName    = v_JTable.getValueAt(v_RowIndexArr[0] ,2).toString();
	        JComboBox v_FamilyNameObj = (JComboBox)XJava.getObject("Edit_FamilyName");
	        for (int i=0; i<v_FamilyNameObj.getItemCount(); i++)
	        {
	            if ( v_FamilyNameObj.getItemAt(i).toString().equals(v_FamilyName) )
	            {
	                v_FamilyNameObj.setSelectedIndex(i);
	                return;
	            }
	        }
		}
		else
		{
		    // 多行选择的情况
		    ((JTextComponent)XJava.getObject("Edit_RowKey"))     .setText("");
		    ((JComboBox)     XJava.getObject("Edit_FamilyName")) .setSelectedIndex(0);
               ((JComboBox)     XJava.getObject("Edit_ColumnName")) .setSelectedIndex(0);
               ((JTextComponent)XJava.getObject("Edit_ColumnValue")).setText("");
               ((JButton)       XJava.getObject("xbCopy"))          .setEnabled(this.getAppFrame().getSelectColCount() >= 2);
		}
	}
}
 
Example 16
Source File: GenericTableModel.java    From armitage with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public Object[][] getSelectedValuesFromColumns(JTable t, String cols[]) {
	synchronized (this) {
		int row[] = t.getSelectedRows();
		Object[][] rv = new Object[row.length][cols.length];

		for (int x = 0; x < row.length; x++) {
			int r = t.convertRowIndexToModel(row[x]);
			for (int y = 0; y < cols.length; y++) {
				rv[x][y] = ( (Map)rows.get(r) ).get(cols[y]);
			}
		}

		return rv;
	}
}
 
Example 17
Source File: MenuManager.java    From jeveassets with GNU General Public License v2.0 4 votes vote down vote up
private void selectClickedCell(final MouseEvent e) {
	Object source = e.getSource();
	if (source instanceof JTable) {
		JTable jSelectTable = (JTable) source;

		Point point = e.getPoint();
		if (!jSelectTable.getVisibleRect().contains(point)) { //Ignore clickes outside table
			return;
		}

		int clickedRow = jSelectTable.rowAtPoint(point);
		int clickedColumn = jSelectTable.columnAtPoint(point);

		//Rows
		boolean clickInRowsSelection;
		if (jSelectTable.getRowSelectionAllowed()) { //clicked in selected rows?
			clickInRowsSelection = false;
			int[] selectedRows = jSelectTable.getSelectedRows();
			for (int i = 0; i < selectedRows.length; i++) {
				if (selectedRows[i] == clickedRow) {
					clickInRowsSelection = true;
					break;
				}
			}
		} else { //Row selection not allowed - all rows selected
			clickInRowsSelection = true;
		}

		//Column
		boolean clickInColumnsSelection;
		if (jSelectTable.getColumnSelectionAllowed()) { //clicked in selected columns?
			clickInColumnsSelection = false;
			int[] selectedColumns = jSelectTable.getSelectedColumns();
			for (int i = 0; i < selectedColumns.length; i++) {
				if (selectedColumns[i] == clickedColumn) {
					clickInColumnsSelection = true;
					break;
				}
			}
		} else { //Column selection not allowed - all columns selected
			clickInColumnsSelection = true;
		}

		//Clicked outside selection, select clicked cell
		if ( (!clickInRowsSelection || !clickInColumnsSelection) && clickedRow >= 0 && clickedColumn >= 0) {
			jSelectTable.setRowSelectionInterval(clickedRow, clickedRow);
			jSelectTable.setColumnSelectionInterval(clickedColumn, clickedColumn);
		}
	}
}
 
Example 18
Source File: ExportActionListener.java    From HBaseClient with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onClick(ActionEvent arg0)
{
    if ( JavaHelp.isNull(this.getAppFrame().getTableName()) )
    {
        this.getAppFrame().showHintInfo("请先选择要导出的表" ,Color.BLUE);
        return;
    }
    
    if ( this.getAppFrame().getRowCount() == 0 )
    {
        this.getAppFrame().showHintInfo("查询结果无数据,无法导出" ,Color.BLUE);
        return;
    }
    
    
    JTable        v_JTable      = (JTable)XJava.getObject("xtDataList");
    int []        v_RowIndexArr = v_JTable.getSelectedRows();
    StringBuilder v_FileName    = new StringBuilder();
    
    // 生成文件名称
    v_FileName.append(this.getTableName());
    if ( v_RowIndexArr.length <= 0 )
    {
        String v_Text = "";
        
        v_Text = ((JTextComponent)XJava.getObject("RowKey"))     .getText();
        if ( !JavaHelp.isNull(v_Text) )
        {
            v_FileName.append("_R.").append(v_Text.trim());
        }
        
        v_Text = ((JComboBox)     XJava.getObject("FamilyName")) .getSelectedItem().toString();
        if ( !JavaHelp.isNull(v_Text) ) 
        {
            v_FileName.append("_F.").append(v_Text.trim());
        }
        
        v_Text = ((JComboBox)     XJava.getObject("ColumnName")) .getSelectedItem().toString();
        if ( !JavaHelp.isNull(v_Text) ) 
        {
            v_FileName.append("_C.").append(v_Text.trim());
        }
        
        v_Text = ((JTextComponent)XJava.getObject("ColumnValue")).getText();
        if ( !JavaHelp.isNull(v_Text) ) 
        {
            v_FileName.append("_V.").append(v_Text.trim());
        }
    }
    else
    {
        v_FileName.append("_CCount.").append(v_RowIndexArr.length);
        v_FileName.append("_").append(Date.getNowTime().getFull_ID());
    }
    v_FileName.append(".txt");
    
    
    
    File         v_SaveFile    = new File(v_FileName.toString());
    JFileChooser v_FileChooser = new JFileChooser();
    v_FileChooser.setSelectedFile(v_SaveFile);
    
    int v_Result = v_FileChooser.showSaveDialog(this.getAppFrame());
    if ( v_Result == JFileChooser.APPROVE_OPTION )
    {
        v_SaveFile = v_FileChooser.getSelectedFile();
        
        this.writeContents(v_JTable ,v_RowIndexArr ,v_SaveFile);
    }
}
 
Example 19
Source File: CopyHandler.java    From jeveassets with GNU General Public License v2.0 4 votes vote down vote up
private static void copy(JTable jTable) {
	//Rows
	int[] rows;
	if (jTable.getRowSelectionAllowed()) { //Selected rows
		rows = jTable.getSelectedRows();
	} else { //All rows (if row selection is not allowed)
		rows = new int[jTable.getRowCount()];
		for (int i = 0; i < jTable.getRowCount(); i++) {
			rows[i] = i;
		}
	}

	//Columns
	int[] columns;
	if (jTable.getColumnSelectionAllowed()) { //Selected columns
		columns = jTable.getSelectedColumns();
	} else { //All columns (if column selection is not allowed)
		columns = new int[jTable.getColumnCount()];
		for (int i = 0; i < jTable.getColumnCount(); i++) {
			columns[i] = i;
		}
	}
	StringBuilder tableText = new StringBuilder(); //Table text buffer
	String separatorText = ""; //Separator text buffer (is never added to, only set for each separator)
	int rowCount = 0; //used to find last row

	for (int row : rows) {
		rowCount++; //count rows
		StringBuilder rowText = new StringBuilder(); //Row text buffer
		boolean firstColumn = true; //used to find first column
		for (int column : columns) {
			//Get value
			Object value = jTable.getValueAt(row, column);

			//Handle Separator
			if (value instanceof SeparatorList.Separator) {
				SeparatorList.Separator<?> separator = (SeparatorList.Separator) value;
				Object object = separator.first();
				if (object instanceof CopySeparator) {
					CopySeparator copySeparator = (CopySeparator) object;
					separatorText = copySeparator.getCopyString();
				}
				break;
			}

			//Add tab separator (except for first column)
			if (firstColumn) {
				firstColumn = false;
			} else {
				rowText.append("\t");
			}

			//Add value
			if (value != null) { //Ignore null
				//Format value to displayed value
				if (value instanceof Float) {
					rowText.append(Formater.floatFormat(value));
				} else if (value instanceof Double) {
					rowText.append(Formater.doubleFormat(value));
				} else if (value instanceof Integer) {
					rowText.append(Formater.integerFormat(value));
				} else if (value instanceof Long) {
					rowText.append(Formater.longFormat(value));
				} else if (value instanceof Date) {
					rowText.append(Formater.columnDate(value));
				} else if (value instanceof HierarchyColumn) {
					HierarchyColumn hierarchyColumn = (HierarchyColumn) value;
					rowText.append(hierarchyColumn.getExport());
				} else {
					rowText.append(value.toString()); //Default
				}
			}
		}

		//Add
		if (rowText.length() > 0 || (!separatorText.isEmpty() && rowCount == rows.length)) {
			tableText.append(separatorText); //Add separator text (will be empty for normal tables)
			if (rowText.length() > 0 && !separatorText.isEmpty()) { //Add tab separator (if needed)
				tableText.append("\t");
			}
			tableText.append(rowText.toString()); //Add row text (will be empty if only copying sinlge separator)
			if (rowCount != rows.length) {
				tableText.append("\r\n");
			} //Add end line
		}
	}
	toClipboard(tableText.toString()); //Send it all to the clipboard
}
 
Example 20
Source File: UIUtil.java    From rest-client with Apache License 2.0 4 votes vote down vote up
/**
* @Title      : move 
* @Description: Move up or down rows 
* @Param      : @param tab
* @Param      : @param tabMdl 
* @Return     : void
* @Throws     :
 */
public static void move(JTable tab, TabModel tabMdl, boolean isup)
{
    int src = tab.getSelectedRowCount();
    if (src < 1)
    {
        return;
    }

    HttpReq req = null;
    HttpRsp rsp = null;
    
    updateCache();
    
    List<Entry<String, HttpHist>> es = new ArrayList<Entry<String,HttpHist>>(RESTCache.getHists().entrySet());
    int[] row = tab.getSelectedRows();
    if (isup) // Move up
    {
        mvup(es, row);
    }
    else // Move down
    {
        mvdown(es, row);
    }

    RESTCache.getHists().clear();
    tabMdl.clear();

    int i = 1;
    String key = StringUtils.EMPTY;
    for (Entry<String, HttpHist> e : es)
    {
        req = e.getValue().getReq();
        rsp = e.getValue().getRsp();

        key = tabMdl.insertRow(i, 
                     req.getMethod() + " " + req.getUrl(),
                     rsp.getStatus(), 
                     rsp.getDate(), 
                     rsp.getTime() + "ms",
                     e.getValue().getDescr());

        RESTCache.getHists().put(key, e.getValue());
        i++;
    }
}