Java Code Examples for javax.swing.table.JTableHeader#getHeaderRect()

The following examples show how to use javax.swing.table.JTableHeader#getHeaderRect() . 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: GhidraFileChooserTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
public void testSortingByFileName() throws Exception {
	pressDetailsButton();
	waitForSwing();
	JTable dirtable = getTableView();
	DirectoryTableModel model = (DirectoryTableModel) dirtable.getModel();
	JTableHeader header = dirtable.getTableHeader();
	Rectangle rect = header.getHeaderRect(DirectoryTableModel.FILE_COL);

	clickMouse(header, MouseEvent.BUTTON1, rect.x + 10, rect.y + 10, 1, 0);
	waitForChooser();
	doCompareTest(model);

	clickMouse(header, MouseEvent.BUTTON1, rect.x + 10, rect.y + 10, 1, 0);
	waitForChooser();
	doCompareTest(model);
}
 
Example 2
Source File: ExtendedJTableColumnFitMouseListener.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
private TableColumn getResizingColumn(JTableHeader header, Point p, int column) {
	if (column == -1) {
		return null;
	}

	Rectangle r = header.getHeaderRect(column);
	r.grow(-3, 0);

	if (r.contains(p)) {
		return null;
	}

	int midPoint = r.x + r.width / 2;
	int columnIndex = 0;
	if (header.getComponentOrientation().isLeftToRight()) {
		columnIndex = (p.x < midPoint) ? column - 1 : column;
	} else {
		columnIndex = (p.x < midPoint) ? column : column - 1;
	}

	if (columnIndex == -1) {
		return null;
	}

	return header.getColumnModel().getColumn(columnIndex);
}
 
Example 3
Source File: MemoryMapProvider1Test.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
public void testSortCommentDescending() {

	JTableHeader header = table.getTableHeader();
	// ascending
	Rectangle rect = header.getHeaderRect(MemoryMapModel.COMMENT);
	clickMouse(header, 1, rect.x, rect.y, 1, 0);

	// descending
	clickMouse(header, 1, rect.x, rect.y, 1, 0);

	MemoryBlock[] blocks = memory.getBlocks();
	String[] comments = new String[blocks.length];
	for (int i = 0; i < blocks.length; i++) {
		comments[i] = blocks[i].getComment();
		if (comments[i] == null) {
			comments[i] = "";
		}
	}
	Arrays.sort(comments, new StringComparator());

	for (int i = 0; i < comments.length; i++) {
		int idx = comments.length - 1 - i;
		assertEquals(comments[idx], model.getValueAt(i, MemoryMapModel.COMMENT));
	}
}
 
Example 4
Source File: MemoryMapProvider1Test.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
public void testSortComment() {

	JTableHeader header = table.getTableHeader();
	// ascending
	Rectangle rect = header.getHeaderRect(MemoryMapModel.COMMENT);
	clickMouse(header, 1, rect.x, rect.y, 1, 0);

	MemoryBlock[] blocks = memory.getBlocks();
	String[] comments = new String[blocks.length];
	for (int i = 0; i < blocks.length; i++) {
		comments[i] = blocks[i].getComment();
		if (comments[i] == null) {
			comments[i] = "";
		}
	}
	Arrays.sort(comments, new StringComparator());

	for (int i = 0; i < comments.length; i++) {
		assertEquals(comments[i], model.getValueAt(i, MemoryMapModel.COMMENT));
	}
}
 
Example 5
Source File: MemoryMapProvider1Test.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
public void testSortBlockType() throws Exception {

	// add a bit overlay block, live block, and an unitialized block
	int transactionID = program.startTransaction("test");
	memory.createBitMappedBlock(".Bit", getAddr(0), getAddr(0x01001000), 0x100, false);
	memory.createUninitializedBlock(".Uninit", getAddr(0x3000), 0x200, false);
	program.endTransaction(transactionID, true);

	JTableHeader header = table.getTableHeader();
	// ascending
	Rectangle rect = header.getHeaderRect(MemoryMapModel.BLOCK_TYPE);
	clickMouse(header, 1, rect.x, rect.y, 1, 0);
	MemoryBlock[] blocks = memory.getBlocks();

	String[] typeNames = new String[blocks.length];
	for (int i = 0; i < typeNames.length; i++) {
		typeNames[i] = blocks[i].getType().toString();
	}
	Arrays.sort(typeNames);

	for (int i = 0; i < typeNames.length; i++) {
		assertEquals(typeNames[i], model.getValueAt(i, MemoryMapModel.BLOCK_TYPE));
	}

}
 
Example 6
Source File: MemoryMapProvider1Test.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
public void testSortLengthDescending() {
	JTableHeader header = table.getTableHeader();
	// ascending
	Rectangle rect = header.getHeaderRect(MemoryMapModel.LENGTH);
	clickMouse(header, 1, rect.x, rect.y, 1, 0);
	MemoryBlock[] blocks = memory.getBlocks();
	long[] lengths = new long[blocks.length];
	for (int i = 0; i < blocks.length; i++) {
		lengths[i] = blocks[i].getSize();
	}
	Arrays.sort(lengths);

	// descending
	clickMouse(header, 1, rect.x, rect.y, 1, 0);

	for (int i = 0; i < lengths.length; i++) {
		int idx = lengths.length - 1 - i;
		assertEquals("0x" + Long.toHexString(lengths[idx]),
			model.getValueAt(i, MemoryMapModel.LENGTH));
	}
}
 
Example 7
Source File: MemoryMapProvider1Test.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
public void testSortEndDescending() {
	JTableHeader header = table.getTableHeader();
	// ascending
	Rectangle rect = header.getHeaderRect(MemoryMapModel.END);
	clickMouse(header, 1, rect.x, rect.y, 1, 0);

	// descending
	clickMouse(header, 1, rect.x, rect.y, 1, 0);

	MemoryBlock[] blocks = memory.getBlocks();
	ArrayList<Address> list = new ArrayList<>();
	for (MemoryBlock element : blocks) {
		list.add(element.getEnd());
	}
	for (int i = 0; i < list.size(); i++) {
		int idx = list.size() - 1 - i;
		assertEquals(list.get(idx).toString(), model.getValueAt(i, MemoryMapModel.END));
	}

}
 
Example 8
Source File: MemoryMapProvider1Test.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
public void testSortEnd() {
	// sort ascending
	JTableHeader header = table.getTableHeader();
	Rectangle rect = header.getHeaderRect(MemoryMapModel.END);
	clickMouse(header, 1, rect.x, rect.y, 1, 0);

	MemoryBlock[] blocks = memory.getBlocks();
	ArrayList<Address> list = new ArrayList<>();
	for (MemoryBlock element : blocks) {
		list.add(element.getEnd());
	}
	for (int i = 0; i < list.size(); i++) {
		assertEquals(list.get(i).toString(), model.getValueAt(i, MemoryMapModel.END));
	}
}
 
Example 9
Source File: MemoryMapProvider1Test.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
public void testSortStart() {
	// sort descending
	JTableHeader header = table.getTableHeader();
	Rectangle rect = header.getHeaderRect(MemoryMapModel.START);
	clickMouse(header, 1, rect.x, rect.y, 1, 0);

	MemoryBlock[] blocks = memory.getBlocks();
	ArrayList<Address> list = new ArrayList<>();
	for (MemoryBlock element : blocks) {
		list.add(element.getStart());
	}
	for (int i = 0; i < list.size(); i++) {
		int idx = list.size() - 1 - i;
		assertEquals(list.get(idx).toString(), model.getValueAt(i, MemoryMapModel.START));
	}
}
 
Example 10
Source File: MemoryMapProvider1Test.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
public void testSortNamesDescending() {
	// ascending
	JTableHeader header = table.getTableHeader();
	Rectangle rect = header.getHeaderRect(MemoryMapModel.NAME);
	clickMouse(header, 1, rect.x, rect.y, 1, 0);

	// descending
	clickMouse(header, 1, rect.x, rect.y, 1, 0);

	MemoryBlock[] blocks = memory.getBlocks();
	String[] names = new String[blocks.length];
	for (int i = 0; i < names.length; i++) {
		names[i] = blocks[i].getName();
	}
	Arrays.sort(names);
	for (int i = 0; i < names.length; i++) {
		int idx = names.length - 1 - i;
		assertEquals(names[idx], model.getValueAt(i, MemoryMapModel.NAME));
	}
}
 
Example 11
Source File: MemoryMapProvider1Test.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
public void testSortNames() {
	JTableHeader header = table.getTableHeader();
	Rectangle rect = header.getHeaderRect(MemoryMapModel.NAME);
	clickMouse(header, 1, rect.x, rect.y, 1, 0);

	MemoryBlock[] blocks = memory.getBlocks();
	String[] names = new String[blocks.length];
	for (int i = 0; i < names.length; i++) {
		names[i] = blocks[i].getName();
	}
	// sort ascending
	Arrays.sort(names);
	for (int i = names.length - 1; i >= 0; i--) {
		assertEquals(names[i], model.getValueAt(i, MemoryMapModel.NAME));
	}
}
 
Example 12
Source File: MemoryMapProvider1Test.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
public void testMoveColumns() {
	// move the end column and make sure navigation is still correct
	// on the end column 
	// move column 2 to 1
	JTableHeader header = table.getTableHeader();
	Rectangle rect1 = header.getHeaderRect(MemoryMapModel.END);
	Rectangle rect2 = header.getHeaderRect(MemoryMapModel.START);
	dragMouse(header, 1, rect1.x, rect1.y, rect2.x, rect2.y, 0);
	dragMouse(header, 1, rect1.x, rect1.y, rect2.x, rect2.y, 0);

	assertEquals("End", table.getColumnName(1));

	Rectangle rect = table.getCellRect(2, 1, true);
	clickMouse(table, 1, rect.x, rect.y, 1, 0);
	CodeBrowserPlugin cb = env.getPlugin(CodeBrowserPlugin.class);
	assertEquals(getAddr(0x0100f3ff), cb.getCurrentAddress());
}
 
Example 13
Source File: GhidraFileChooserTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
public void testSortingByFileDate() throws Exception {
	pressDetailsButton();
	JTable dirtable = getTableView();
	DirectoryTableModel model = (DirectoryTableModel) dirtable.getModel();
	JTableHeader header = dirtable.getTableHeader();
	Rectangle rect = header.getHeaderRect(DirectoryTableModel.TIME_COL);

	clickMouse(header, MouseEvent.BUTTON1, rect.x + 10, rect.y + 10, 1, 0);
	waitForChooser();
	doCompareTest(model);

	clickMouse(header, MouseEvent.BUTTON1, rect.x + 10, rect.y + 10, 1, 0);
	waitForChooser();
	doCompareTest(model);
}
 
Example 14
Source File: GhidraFileChooserTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
public void testSortingByFileSzie() throws Exception {
	pressDetailsButton();
	JTable dirtable = getTableView();
	DirectoryTableModel model = (DirectoryTableModel) dirtable.getModel();
	JTableHeader header = dirtable.getTableHeader();
	Rectangle rect = header.getHeaderRect(DirectoryTableModel.SIZE_COL);

	clickMouse(header, MouseEvent.BUTTON1, rect.x + 10, rect.y + 10, 1, 0);
	waitForChooser();
	doCompareTest(model);

	clickMouse(header, MouseEvent.BUTTON1, rect.x + 10, rect.y + 10, 1, 0);
	waitForChooser();
	doCompareTest(model);
}
 
Example 15
Source File: TreesScreenShots.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private void highlightFilterIcon(Component provider, Component parent, JTableHeader header,
		int column) {

	Rectangle rectangle = header.getHeaderRect(column);
	rectangle = SwingUtilities.convertRectangle(parent, rectangle, provider);

	int padding = 8;
	int thickness = 6;
	int iconSize = 12;
	int height = rectangle.height + (padding * 2);
	int width = iconSize + (padding * 2);

	int iconPadding = 2;
	int x = rectangle.x + rectangle.width - (width - padding) - iconPadding;
	int y = rectangle.y - padding;
	Rectangle shapeBounds = new Rectangle(x, y, width, height);
	drawOval(Color.GREEN.darker(), shapeBounds, thickness);

}
 
Example 16
Source File: TableColumnManager.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
private void showPopup(int index)
{
	Object headerValue = tcm.getColumn( index ).getHeaderValue();
	int columnCount = tcm.getColumnCount();
	JPopupMenu popup = new SelectPopupMenu();

	//  Create a menu item for all columns managed by the table column
	//  manager, checking to see if the column is shown or hidden.

	for (TableColumn tableColumn : allColumns)
	{
		Object value = tableColumn.getHeaderValue();
		JCheckBoxMenuItem item = new JCheckBoxMenuItem( value.toString() );
		item.addActionListener( this );

		try
		{
			tcm.getColumnIndex( value );
			item.setSelected( true );

			if (columnCount == 1)
				item.setEnabled( false );
		}
		catch(IllegalArgumentException e)
		{
			item.setSelected( false );
		}

		popup.add( item );

		if (value == headerValue)
			popup.setSelected( item );
	}

	//  Display the popup below the TableHeader

	JTableHeader header = table.getTableHeader();
	Rectangle r = header.getHeaderRect( index );
	popup.show(header, r.x, r.height);
}
 
Example 17
Source File: MemoryMapProvider1Test.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Test
public void testSortBlockTypeDescending() throws Exception {
	// add a bit overlay block, live block, and an unitialized block
	int transactionID = program.startTransaction("test");
	memory.createBitMappedBlock(".Bit", getAddr(0), getAddr(0x01001000), 0x100, false);
	memory.createUninitializedBlock(".Uninit", getAddr(0x3000), 0x200, false);
	program.endTransaction(transactionID, true);

	JTableHeader header = table.getTableHeader();
	// ascending
	Rectangle rect = header.getHeaderRect(MemoryMapModel.BLOCK_TYPE);
	clickMouse(header, 1, rect.x, rect.y, 1, 0);

	// descending
	clickMouse(header, 1, rect.x, rect.y, 1, 0);

	MemoryBlock[] blocks = memory.getBlocks();

	String[] typeNames = new String[blocks.length];
	for (int i = 0; i < blocks.length; i++) {
		typeNames[i] = blocks[i].getType().toString();
	}
	Arrays.sort(typeNames);

	for (int i = 0; i < typeNames.length; i++) {
		int idx = typeNames.length - 1 - i;
		assertEquals(typeNames[idx], model.getValueAt(i, MemoryMapModel.BLOCK_TYPE));
	}

}
 
Example 18
Source File: MemoryMapProvider1Test.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Test
public void testSortSource() throws Exception {
	//
	int transactionID = program.startTransaction("test");
	MemoryBlock block =
		memory.createBitMappedBlock(".Bit", getAddr(0), getAddr(0x01001000), 0x100, false);
	block.setSourceName("this is a test");
	block = memory.createUninitializedBlock(".Uninit", getAddr(0x3000), 0x200, false);
	block.setSourceName("other source");
	program.endTransaction(transactionID, true);

	JTableHeader header = table.getTableHeader();
	// ascending
	Rectangle rect = header.getHeaderRect(MemoryMapModel.SOURCE);
	clickMouse(header, 1, rect.x, rect.y, 1, 0);
	MemoryBlock[] blocks = memory.getBlocks();
	String[] sources = new String[blocks.length];
	for (int i = 0; i < blocks.length; i++) {
		sources[i] = blocks[i].getSourceName();
	}
	Arrays.sort(sources, new StringComparator());

	for (int i = 0; i < sources.length; i++) {
		boolean doAssert = true;
		for (MemoryBlock memBlock : blocks) {
			if (memBlock.getSourceName().equals(sources[i]) &&
				memBlock.getType() == MemoryBlockType.BIT_MAPPED) {
				MemoryBlockSourceInfo info = memBlock.getSourceInfos().get(0);
				Address addr = info.getMappedRange().get().getMinAddress();

				assertEquals(addr.toString(), model.getValueAt(i, MemoryMapModel.SOURCE));
				doAssert = false;
				break;
			}
		}
		if (doAssert) {
			assertEquals(sources[i], model.getValueAt(i, MemoryMapModel.SOURCE));
		}
	}
}
 
Example 19
Source File: MemoryMapProvider1Test.java    From ghidra with Apache License 2.0 4 votes vote down vote up
@Test
public void testSortSourceDescending() throws Exception {
	//
	int transactionID = program.startTransaction("test");
	MemoryBlock block =
		memory.createBitMappedBlock(".Bit", getAddr(0), getAddr(0x01001000), 0x100, false);
	block.setSourceName("this is a test");
	block = memory.createUninitializedBlock(".Uninit", getAddr(0x3000), 0x200, false);
	block.setSourceName("other source");
	program.endTransaction(transactionID, true);

	JTableHeader header = table.getTableHeader();
	// ascending
	Rectangle rect = header.getHeaderRect(MemoryMapModel.SOURCE);
	clickMouse(header, 1, rect.x, rect.y, 1, 0);

	// descending
	clickMouse(header, 1, rect.x, rect.y, 1, 0);

	MemoryBlock[] blocks = memory.getBlocks();
	String[] sources = new String[blocks.length];
	for (int i = 0; i < blocks.length; i++) {
		sources[i] = blocks[i].getSourceName();
	}
	Arrays.sort(sources, new StringComparator());
	for (int i = 0; i < sources.length; i++) {
		int idx = sources.length - 1 - i;
		boolean doAssert = true;
		for (MemoryBlock memBlock : blocks) {
			if (memBlock.getSourceName().equals(sources[idx]) &&
				memBlock.getType() == MemoryBlockType.BIT_MAPPED) {
				MemoryBlockSourceInfo info = memBlock.getSourceInfos().get(0);
				Address addr = info.getMappedRange().get().getMinAddress();
				assertEquals(addr.toString(), model.getValueAt(i, MemoryMapModel.SOURCE));
				doAssert = false;
				break;
			}
		}
		if (doAssert) {
			assertEquals(sources[idx], model.getValueAt(i, MemoryMapModel.SOURCE));
		}
	}
}
 
Example 20
Source File: UnitCategoryTableModel.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public int getMinWidth (JTableHeader header, int col) {
    return header.getHeaderRect (col).width;
}