Search in sources :

Example 1 with Section

use of sun.swing.SwingUtilities2.Section in project jdk8u_jdk by JetBrains.

the class JTable method dropLocationForPoint.

/**
     * Calculates a drop location in this component, representing where a
     * drop at the given point should insert data.
     *
     * @param p the point to calculate a drop location for
     * @return the drop location, or <code>null</code>
     */
DropLocation dropLocationForPoint(Point p) {
    DropLocation location = null;
    int row = rowAtPoint(p);
    int col = columnAtPoint(p);
    boolean outside = Boolean.TRUE == getClientProperty("Table.isFileList") && SwingUtilities2.pointOutsidePrefSize(this, row, col, p);
    Rectangle rect = getCellRect(row, col, true);
    Section xSection, ySection;
    boolean between = false;
    boolean ltr = getComponentOrientation().isLeftToRight();
    switch(dropMode) {
        case USE_SELECTION:
        case ON:
            if (row == -1 || col == -1 || outside) {
                location = new DropLocation(p, -1, -1, false, false);
            } else {
                location = new DropLocation(p, row, col, false, false);
            }
            break;
        case INSERT:
            if (row == -1 && col == -1) {
                location = new DropLocation(p, 0, 0, true, true);
                break;
            }
            xSection = SwingUtilities2.liesInHorizontal(rect, p, ltr, true);
            if (row == -1) {
                if (xSection == LEADING) {
                    location = new DropLocation(p, getRowCount(), col, true, true);
                } else if (xSection == TRAILING) {
                    location = new DropLocation(p, getRowCount(), col + 1, true, true);
                } else {
                    location = new DropLocation(p, getRowCount(), col, true, false);
                }
            } else if (xSection == LEADING || xSection == TRAILING) {
                ySection = SwingUtilities2.liesInVertical(rect, p, true);
                if (ySection == LEADING) {
                    between = true;
                } else if (ySection == TRAILING) {
                    row++;
                    between = true;
                }
                location = new DropLocation(p, row, xSection == TRAILING ? col + 1 : col, between, true);
            } else {
                if (SwingUtilities2.liesInVertical(rect, p, false) == TRAILING) {
                    row++;
                }
                location = new DropLocation(p, row, col, true, false);
            }
            break;
        case INSERT_ROWS:
            if (row == -1 && col == -1) {
                location = new DropLocation(p, -1, -1, false, false);
                break;
            }
            if (row == -1) {
                location = new DropLocation(p, getRowCount(), col, true, false);
                break;
            }
            if (SwingUtilities2.liesInVertical(rect, p, false) == TRAILING) {
                row++;
            }
            location = new DropLocation(p, row, col, true, false);
            break;
        case ON_OR_INSERT_ROWS:
            if (row == -1 && col == -1) {
                location = new DropLocation(p, -1, -1, false, false);
                break;
            }
            if (row == -1) {
                location = new DropLocation(p, getRowCount(), col, true, false);
                break;
            }
            ySection = SwingUtilities2.liesInVertical(rect, p, true);
            if (ySection == LEADING) {
                between = true;
            } else if (ySection == TRAILING) {
                row++;
                between = true;
            }
            location = new DropLocation(p, row, col, between, false);
            break;
        case INSERT_COLS:
            if (row == -1) {
                location = new DropLocation(p, -1, -1, false, false);
                break;
            }
            if (col == -1) {
                location = new DropLocation(p, getColumnCount(), col, false, true);
                break;
            }
            if (SwingUtilities2.liesInHorizontal(rect, p, ltr, false) == TRAILING) {
                col++;
            }
            location = new DropLocation(p, row, col, false, true);
            break;
        case ON_OR_INSERT_COLS:
            if (row == -1) {
                location = new DropLocation(p, -1, -1, false, false);
                break;
            }
            if (col == -1) {
                location = new DropLocation(p, row, getColumnCount(), false, true);
                break;
            }
            xSection = SwingUtilities2.liesInHorizontal(rect, p, ltr, true);
            if (xSection == LEADING) {
                between = true;
            } else if (xSection == TRAILING) {
                col++;
                between = true;
            }
            location = new DropLocation(p, row, col, false, between);
            break;
        case ON_OR_INSERT:
            if (row == -1 && col == -1) {
                location = new DropLocation(p, 0, 0, true, true);
                break;
            }
            xSection = SwingUtilities2.liesInHorizontal(rect, p, ltr, true);
            if (row == -1) {
                if (xSection == LEADING) {
                    location = new DropLocation(p, getRowCount(), col, true, true);
                } else if (xSection == TRAILING) {
                    location = new DropLocation(p, getRowCount(), col + 1, true, true);
                } else {
                    location = new DropLocation(p, getRowCount(), col, true, false);
                }
                break;
            }
            ySection = SwingUtilities2.liesInVertical(rect, p, true);
            if (ySection == LEADING) {
                between = true;
            } else if (ySection == TRAILING) {
                row++;
                between = true;
            }
            location = new DropLocation(p, row, xSection == TRAILING ? col + 1 : col, between, xSection != MIDDLE);
            break;
        default:
            assert false : "Unexpected drop mode";
    }
    return location;
}
Also used : Section(sun.swing.SwingUtilities2.Section) java.awt.print(java.awt.print)

Example 2 with Section

use of sun.swing.SwingUtilities2.Section in project jdk8u_jdk by JetBrains.

the class JTree method dropLocationForPoint.

/**
     * Calculates a drop location in this component, representing where a
     * drop at the given point should insert data.
     *
     * @param p the point to calculate a drop location for
     * @return the drop location, or <code>null</code>
     */
DropLocation dropLocationForPoint(Point p) {
    DropLocation location = null;
    int row = getClosestRowForLocation(p.x, p.y);
    Rectangle bounds = getRowBounds(row);
    TreeModel model = getModel();
    Object root = (model == null) ? null : model.getRoot();
    TreePath rootPath = (root == null) ? null : new TreePath(root);
    TreePath child;
    TreePath parent;
    boolean outside = row == -1 || p.y < bounds.y || p.y >= bounds.y + bounds.height;
    switch(dropMode) {
        case USE_SELECTION:
        case ON:
            if (outside) {
                location = new DropLocation(p, null, -1);
            } else {
                location = new DropLocation(p, getPathForRow(row), -1);
            }
            break;
        case INSERT:
        case ON_OR_INSERT:
            if (row == -1) {
                if (root != null && !model.isLeaf(root) && isExpanded(rootPath)) {
                    location = new DropLocation(p, rootPath, 0);
                } else {
                    location = new DropLocation(p, null, -1);
                }
                break;
            }
            boolean checkOn = dropMode == DropMode.ON_OR_INSERT || !model.isLeaf(getPathForRow(row).getLastPathComponent());
            Section section = SwingUtilities2.liesInVertical(bounds, p, checkOn);
            if (section == LEADING) {
                child = getPathForRow(row);
                parent = child.getParentPath();
            } else if (section == TRAILING) {
                int index = row + 1;
                if (index >= getRowCount()) {
                    if (model.isLeaf(root) || !isExpanded(rootPath)) {
                        location = new DropLocation(p, null, -1);
                    } else {
                        parent = rootPath;
                        index = model.getChildCount(root);
                        location = new DropLocation(p, parent, index);
                    }
                    break;
                }
                child = getPathForRow(index);
                parent = child.getParentPath();
            } else {
                assert checkOn;
                location = new DropLocation(p, getPathForRow(row), -1);
                break;
            }
            if (parent != null) {
                location = new DropLocation(p, parent, model.getIndexOfChild(parent.getLastPathComponent(), child.getLastPathComponent()));
            } else if (checkOn || !model.isLeaf(root)) {
                location = new DropLocation(p, rootPath, -1);
            } else {
                location = new DropLocation(p, null, -1);
            }
            break;
        default:
            assert false : "Unexpected drop mode";
    }
    if (outside || row != expandRow) {
        cancelDropTimer();
    }
    if (!outside && row != expandRow) {
        if (isCollapsed(row)) {
            expandRow = row;
            startDropTimer();
        }
    }
    return location;
}
Also used : Section(sun.swing.SwingUtilities2.Section)

Example 3 with Section

use of sun.swing.SwingUtilities2.Section in project jdk8u_jdk by JetBrains.

the class JList method dropLocationForPoint.

/**
     * Calculates a drop location in this component, representing where a
     * drop at the given point should insert data.
     *
     * @param p the point to calculate a drop location for
     * @return the drop location, or <code>null</code>
     */
DropLocation dropLocationForPoint(Point p) {
    DropLocation location = null;
    Rectangle rect = null;
    int index = locationToIndex(p);
    if (index != -1) {
        rect = getCellBounds(index, index);
    }
    switch(dropMode) {
        case USE_SELECTION:
        case ON:
            location = new DropLocation(p, (rect != null && rect.contains(p)) ? index : -1, false);
            break;
        case INSERT:
            if (index == -1) {
                location = new DropLocation(p, getModel().getSize(), true);
                break;
            }
            if (layoutOrientation == HORIZONTAL_WRAP) {
                boolean ltr = getComponentOrientation().isLeftToRight();
                if (SwingUtilities2.liesInHorizontal(rect, p, ltr, false) == TRAILING) {
                    index++;
                // special case for below all cells
                } else if (index == getModel().getSize() - 1 && p.y >= rect.y + rect.height) {
                    index++;
                }
            } else {
                if (SwingUtilities2.liesInVertical(rect, p, false) == TRAILING) {
                    index++;
                }
            }
            location = new DropLocation(p, index, true);
            break;
        case ON_OR_INSERT:
            if (index == -1) {
                location = new DropLocation(p, getModel().getSize(), true);
                break;
            }
            boolean between = false;
            if (layoutOrientation == HORIZONTAL_WRAP) {
                boolean ltr = getComponentOrientation().isLeftToRight();
                Section section = SwingUtilities2.liesInHorizontal(rect, p, ltr, true);
                if (section == TRAILING) {
                    index++;
                    between = true;
                // special case for below all cells
                } else if (index == getModel().getSize() - 1 && p.y >= rect.y + rect.height) {
                    index++;
                    between = true;
                } else if (section == LEADING) {
                    between = true;
                }
            } else {
                Section section = SwingUtilities2.liesInVertical(rect, p, true);
                if (section == LEADING) {
                    between = true;
                } else if (section == TRAILING) {
                    index++;
                    between = true;
                }
            }
            location = new DropLocation(p, index, between);
            break;
        default:
            assert false : "Unexpected drop mode";
    }
    return location;
}
Also used : Section(sun.swing.SwingUtilities2.Section)

Aggregations

Section (sun.swing.SwingUtilities2.Section)3 java.awt.print (java.awt.print)1