Java Code Examples for javax.swing.JTable#DropLocation

The following examples show how to use javax.swing.JTable#DropLocation . 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: MapRuleRender.java    From finalspeed-91yun with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Component getTableCellRendererComponent(JTable table, Object value,
		boolean isSelected, boolean hasFocus, int row, int column) {
	Color fg = null;
	Color bg = null;
	JTable.DropLocation dropLocation = table.getDropLocation();
	if (dropLocation != null
			&& !dropLocation.isInsertRow()
			&& !dropLocation.isInsertColumn()
			&& dropLocation.getRow() == row
			&& dropLocation.getColumn() == column) {

		fg = DefaultLookup.getColor(this, ui, "Table.dropCellForeground");
		bg = DefaultLookup.getColor(this, ui, "Table.dropCellBackground");
		isSelected = true;
	}
	if (isSelected) {
		setBackground(DefaultLookup.getColor(this, ui, "Table.dropCellBackground"));
	} else {
		setBackground( DefaultLookup.getColor(this, ui, "Table.alternateRowColor"));
	}
	MapRule rule=(MapRule)value;
	update(rule,table,row);
	return this;
}
 
Example 2
Source File: TableRowTransferHandler.java    From PyramidShader with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean importData(TransferHandler.TransferSupport info) {
    JTable target = (JTable) info.getComponent();
    JTable.DropLocation dl = (JTable.DropLocation) info.getDropLocation();
    int dropIndex = dl.getRow();
    int max = table.getModel().getRowCount();
    if (dropIndex < 0 || dropIndex > max) {
        dropIndex = max;
    }
    target.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
    try {
        Integer rowFrom = (Integer) info.getTransferable().getTransferData(localObjectFlavor);
        if (rowFrom != -1 && rowFrom != dropIndex) {
            ((Reorderable)table.getModel()).reorder(rowFrom, dropIndex);
            if (dropIndex > rowFrom) {
                dropIndex--;
            }
            target.getSelectionModel().addSelectionInterval(dropIndex, dropIndex);
            return true;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;
}
 
Example 3
Source File: SynthTableUI.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private Rectangle getHDropLineRect(JTable.DropLocation loc) {
    if (!loc.isInsertRow()) {
        return null;
    }

    int row = loc.getRow();
    int col = loc.getColumn();
    if (col >= table.getColumnCount()) {
        col--;
    }

    Rectangle rect = table.getCellRect(row, col, true);

    if (row >= table.getRowCount()) {
        row--;
        Rectangle prevRect = table.getCellRect(row, col, true);
        rect.y = prevRect.y + prevRect.height;
    }

    if (rect.y == 0) {
        rect.y = -1;
    } else {
        rect.y -= 2;
    }

    rect.height = 3;

    return rect;
}
 
Example 4
Source File: SynthTableUI.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private Rectangle getVDropLineRect(JTable.DropLocation loc) {
    if (!loc.isInsertColumn()) {
        return null;
    }

    boolean ltr = table.getComponentOrientation().isLeftToRight();
    int col = loc.getColumn();
    Rectangle rect = table.getCellRect(loc.getRow(), col, true);

    if (col >= table.getColumnCount()) {
        col--;
        rect = table.getCellRect(loc.getRow(), col, true);
        if (ltr) {
            rect.x = rect.x + rect.width;
        }
    } else if (!ltr) {
        rect.x = rect.x + rect.width;
    }

    if (rect.x == 0) {
        rect.x = -1;
    } else {
        rect.x -= 2;
    }

    rect.width = 3;

    return rect;
}
 
Example 5
Source File: SynthTableUI.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private Rectangle getVDropLineRect(JTable.DropLocation loc) {
    if (!loc.isInsertColumn()) {
        return null;
    }

    boolean ltr = table.getComponentOrientation().isLeftToRight();
    int col = loc.getColumn();
    Rectangle rect = table.getCellRect(loc.getRow(), col, true);

    if (col >= table.getColumnCount()) {
        col--;
        rect = table.getCellRect(loc.getRow(), col, true);
        if (ltr) {
            rect.x = rect.x + rect.width;
        }
    } else if (!ltr) {
        rect.x = rect.x + rect.width;
    }

    if (rect.x == 0) {
        rect.x = -1;
    } else {
        rect.x -= 2;
    }

    rect.width = 3;

    return rect;
}
 
Example 6
Source File: SynthTableUI.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
private Rectangle getVDropLineRect(JTable.DropLocation loc) {
    if (!loc.isInsertColumn()) {
        return null;
    }

    boolean ltr = table.getComponentOrientation().isLeftToRight();
    int col = loc.getColumn();
    Rectangle rect = table.getCellRect(loc.getRow(), col, true);

    if (col >= table.getColumnCount()) {
        col--;
        rect = table.getCellRect(loc.getRow(), col, true);
        if (ltr) {
            rect.x = rect.x + rect.width;
        }
    } else if (!ltr) {
        rect.x = rect.x + rect.width;
    }

    if (rect.x == 0) {
        rect.x = -1;
    } else {
        rect.x -= 2;
    }

    rect.width = 3;

    return rect;
}
 
Example 7
Source File: SynthTableUI.java    From Java8CN with Apache License 2.0 5 votes vote down vote up
private Rectangle getVDropLineRect(JTable.DropLocation loc) {
    if (!loc.isInsertColumn()) {
        return null;
    }

    boolean ltr = table.getComponentOrientation().isLeftToRight();
    int col = loc.getColumn();
    Rectangle rect = table.getCellRect(loc.getRow(), col, true);

    if (col >= table.getColumnCount()) {
        col--;
        rect = table.getCellRect(loc.getRow(), col, true);
        if (ltr) {
            rect.x = rect.x + rect.width;
        }
    } else if (!ltr) {
        rect.x = rect.x + rect.width;
    }

    if (rect.x == 0) {
        rect.x = -1;
    } else {
        rect.x -= 2;
    }

    rect.width = 3;

    return rect;
}
 
Example 8
Source File: MapRuleRender.java    From xtunnel with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Component getTableCellRendererComponent(JTable table, Object value,
		boolean isSelected, boolean hasFocus, int row, int column) {

	Color fg = null;
	Color bg = null;

	JTable.DropLocation dropLocation = table.getDropLocation();
	if (dropLocation != null
			&& !dropLocation.isInsertRow()
			&& !dropLocation.isInsertColumn()
			&& dropLocation.getRow() == row
			&& dropLocation.getColumn() == column) {

		fg = DefaultLookup.getColor(this, ui, "Table.dropCellForeground");
		bg = DefaultLookup.getColor(this, ui, "Table.dropCellBackground");

		isSelected = true;
	}

	if (isSelected) {
		setBackground(DefaultLookup.getColor(this, ui, "Table.dropCellBackground"));
	} else {
		setBackground( DefaultLookup.getColor(this, ui, "Table.alternateRowColor"));
	}

	MapRule rule=(MapRule)value;
	update(rule,table,row);
	return this;
}
 
Example 9
Source File: SynthTableUI.java    From Java8CN with Apache License 2.0 5 votes vote down vote up
private Rectangle getHDropLineRect(JTable.DropLocation loc) {
    if (!loc.isInsertRow()) {
        return null;
    }

    int row = loc.getRow();
    int col = loc.getColumn();
    if (col >= table.getColumnCount()) {
        col--;
    }

    Rectangle rect = table.getCellRect(row, col, true);

    if (row >= table.getRowCount()) {
        row--;
        Rectangle prevRect = table.getCellRect(row, col, true);
        rect.y = prevRect.y + prevRect.height;
    }

    if (rect.y == 0) {
        rect.y = -1;
    } else {
        rect.y -= 2;
    }

    rect.height = 3;

    return rect;
}
 
Example 10
Source File: SynthTableUI.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private Rectangle getVDropLineRect(JTable.DropLocation loc) {
    if (!loc.isInsertColumn()) {
        return null;
    }

    boolean ltr = table.getComponentOrientation().isLeftToRight();
    int col = loc.getColumn();
    Rectangle rect = table.getCellRect(loc.getRow(), col, true);

    if (col >= table.getColumnCount()) {
        col--;
        rect = table.getCellRect(loc.getRow(), col, true);
        if (ltr) {
            rect.x = rect.x + rect.width;
        }
    } else if (!ltr) {
        rect.x = rect.x + rect.width;
    }

    if (rect.x == 0) {
        rect.x = -1;
    } else {
        rect.x -= 2;
    }

    rect.width = 3;

    return rect;
}
 
Example 11
Source File: SynthTableUI.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private Rectangle getHDropLineRect(JTable.DropLocation loc) {
    if (!loc.isInsertRow()) {
        return null;
    }

    int row = loc.getRow();
    int col = loc.getColumn();
    if (col >= table.getColumnCount()) {
        col--;
    }

    Rectangle rect = table.getCellRect(row, col, true);

    if (row >= table.getRowCount()) {
        row--;
        Rectangle prevRect = table.getCellRect(row, col, true);
        rect.y = prevRect.y + prevRect.height;
    }

    if (rect.y == 0) {
        rect.y = -1;
    } else {
        rect.y -= 2;
    }

    rect.height = 3;

    return rect;
}
 
Example 12
Source File: SynthTableUI.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
private Rectangle getVDropLineRect(JTable.DropLocation loc) {
    if (!loc.isInsertColumn()) {
        return null;
    }

    boolean ltr = table.getComponentOrientation().isLeftToRight();
    int col = loc.getColumn();
    Rectangle rect = table.getCellRect(loc.getRow(), col, true);

    if (col >= table.getColumnCount()) {
        col--;
        rect = table.getCellRect(loc.getRow(), col, true);
        if (ltr) {
            rect.x = rect.x + rect.width;
        }
    } else if (!ltr) {
        rect.x = rect.x + rect.width;
    }

    if (rect.x == 0) {
        rect.x = -1;
    } else {
        rect.x -= 2;
    }

    rect.width = 3;

    return rect;
}
 
Example 13
Source File: SynthTableUI.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
private Rectangle getHDropLineRect(JTable.DropLocation loc) {
    if (!loc.isInsertRow()) {
        return null;
    }

    int row = loc.getRow();
    int col = loc.getColumn();
    if (col >= table.getColumnCount()) {
        col--;
    }

    Rectangle rect = table.getCellRect(row, col, true);

    if (row >= table.getRowCount()) {
        row--;
        Rectangle prevRect = table.getCellRect(row, col, true);
        rect.y = prevRect.y + prevRect.height;
    }

    if (rect.y == 0) {
        rect.y = -1;
    } else {
        rect.y -= 2;
    }

    rect.height = 3;

    return rect;
}
 
Example 14
Source File: SynthTableUI.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private Rectangle getVDropLineRect(JTable.DropLocation loc) {
    if (!loc.isInsertColumn()) {
        return null;
    }

    boolean ltr = table.getComponentOrientation().isLeftToRight();
    int col = loc.getColumn();
    Rectangle rect = table.getCellRect(loc.getRow(), col, true);

    if (col >= table.getColumnCount()) {
        col--;
        rect = table.getCellRect(loc.getRow(), col, true);
        if (ltr) {
            rect.x = rect.x + rect.width;
        }
    } else if (!ltr) {
        rect.x = rect.x + rect.width;
    }

    if (rect.x == 0) {
        rect.x = -1;
    } else {
        rect.x -= 2;
    }

    rect.width = 3;

    return rect;
}
 
Example 15
Source File: SynthTableUI.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private Rectangle getHDropLineRect(JTable.DropLocation loc) {
    if (!loc.isInsertRow()) {
        return null;
    }

    int row = loc.getRow();
    int col = loc.getColumn();
    if (col >= table.getColumnCount()) {
        col--;
    }

    Rectangle rect = table.getCellRect(row, col, true);

    if (row >= table.getRowCount()) {
        row--;
        Rectangle prevRect = table.getCellRect(row, col, true);
        rect.y = prevRect.y + prevRect.height;
    }

    if (rect.y == 0) {
        rect.y = -1;
    } else {
        rect.y -= 2;
    }

    rect.height = 3;

    return rect;
}
 
Example 16
Source File: SynthTableUI.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private Rectangle getHDropLineRect(JTable.DropLocation loc) {
    if (!loc.isInsertRow()) {
        return null;
    }

    int row = loc.getRow();
    int col = loc.getColumn();
    if (col >= table.getColumnCount()) {
        col--;
    }

    Rectangle rect = table.getCellRect(row, col, true);

    if (row >= table.getRowCount()) {
        row--;
        Rectangle prevRect = table.getCellRect(row, col, true);
        rect.y = prevRect.y + prevRect.height;
    }

    if (rect.y == 0) {
        rect.y = -1;
    } else {
        rect.y -= 2;
    }

    rect.height = 3;

    return rect;
}
 
Example 17
Source File: SynthTableUI.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private Rectangle getVDropLineRect(JTable.DropLocation loc) {
    if (!loc.isInsertColumn()) {
        return null;
    }

    boolean ltr = table.getComponentOrientation().isLeftToRight();
    int col = loc.getColumn();
    Rectangle rect = table.getCellRect(loc.getRow(), col, true);

    if (col >= table.getColumnCount()) {
        col--;
        rect = table.getCellRect(loc.getRow(), col, true);
        if (ltr) {
            rect.x = rect.x + rect.width;
        }
    } else if (!ltr) {
        rect.x = rect.x + rect.width;
    }

    if (rect.x == 0) {
        rect.x = -1;
    } else {
        rect.x -= 2;
    }

    rect.width = 3;

    return rect;
}
 
Example 18
Source File: SynthTableUI.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private Rectangle getVDropLineRect(JTable.DropLocation loc) {
    if (!loc.isInsertColumn()) {
        return null;
    }

    boolean ltr = table.getComponentOrientation().isLeftToRight();
    int col = loc.getColumn();
    Rectangle rect = table.getCellRect(loc.getRow(), col, true);

    if (col >= table.getColumnCount()) {
        col--;
        rect = table.getCellRect(loc.getRow(), col, true);
        if (ltr) {
            rect.x = rect.x + rect.width;
        }
    } else if (!ltr) {
        rect.x = rect.x + rect.width;
    }

    if (rect.x == 0) {
        rect.x = -1;
    } else {
        rect.x -= 2;
    }

    rect.width = 3;

    return rect;
}
 
Example 19
Source File: SynthTableUI.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private Rectangle getVDropLineRect(JTable.DropLocation loc) {
    if (!loc.isInsertColumn()) {
        return null;
    }

    boolean ltr = table.getComponentOrientation().isLeftToRight();
    int col = loc.getColumn();
    Rectangle rect = table.getCellRect(loc.getRow(), col, true);

    if (col >= table.getColumnCount()) {
        col--;
        rect = table.getCellRect(loc.getRow(), col, true);
        if (ltr) {
            rect.x = rect.x + rect.width;
        }
    } else if (!ltr) {
        rect.x = rect.x + rect.width;
    }

    if (rect.x == 0) {
        rect.x = -1;
    } else {
        rect.x -= 2;
    }

    rect.width = 3;

    return rect;
}
 
Example 20
Source File: EquipInfoTab.java    From pcgen with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public boolean importData(TransferSupport support)
{
	if (!canImport(support) || !support.isDrop())
	{
		return false;
	}

	JTable.DropLocation location = (JTable.DropLocation) support.getDropLocation();
	int row = location.getRow();
	EquipNode node = (EquipNode) equipmentSetTable.getValueAt(row, 0);
	EquipNode beforeNode = null;
	if (location.isInsertRow())
	{
		beforeNode = node;
		node = node.getParent();
	}
	EquipmentSetFacade equipSet = character.getEquipmentSetRef().get();

	if (support.isDataFlavorSupported(EQUIP_NODE_ARRAY_FLAVOR))
	{
		EquipNode[] equipNodeArray = getEquipNodeArray(support);
		if (equipNodeArray == null)
		{
			return false;
		}
		for (EquipNode equipNode : equipNodeArray)
		{
			int quantity = equipSet.getQuantity(equipNode);
			equipSet.removeEquipment(equipNode, quantity);
			equipSet.addEquipment(node, equipNode.getEquipment(), quantity, beforeNode);
		}
	}
	else if (support.isDataFlavorSupported(EQUIPMENT_ARRAY_FLAVOR))
	{
		EquipmentFacade[] equipmentArray = getEquipmentArray(support);
		if (equipmentArray == null)
		{
			return false;
		}
		for (EquipmentFacade equipmentFacade : equipmentArray)
		{
			equipSet.addEquipment(node, equipmentFacade, 1, beforeNode);
		}
	}
	return true;
}