当前位置: 首页>>代码示例>>Java>>正文


Java JTree.DropLocation方法代码示例

本文整理汇总了Java中javax.swing.JTree.DropLocation方法的典型用法代码示例。如果您正苦于以下问题:Java JTree.DropLocation方法的具体用法?Java JTree.DropLocation怎么用?Java JTree.DropLocation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.JTree的用法示例。


在下文中一共展示了JTree.DropLocation方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: repaintDropLocation

import javax.swing.JTree; //导入方法依赖的package包/类
private void repaintDropLocation(JTree.DropLocation loc) {
    if (loc == null) {
        return;
    }

    Rectangle r;

    if (isDropLine(loc)) {
        r = getDropLineRect(loc);
    } else {
        r = tree.getPathBounds(loc.getPath());
        if (r != null) {
            r.x = 0;
            r.width = tree.getWidth();
        }
    }

    if (r != null) {
        tree.repaint(r);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:22,代码来源:SynthTreeUI.java

示例2: importData

import javax.swing.JTree; //导入方法依赖的package包/类
@Override
public boolean importData(TransferSupport support) {

	try {

		// check if transferable can be imported
		if (!canImport(support)) {
			return false;
		}

		// fetch the drop location
		JTree.DropLocation dropLocation = (javax.swing.JTree.DropLocation) support.getDropLocation();
		TreePath path = dropLocation.getPath();
		int childIndex = dropLocation.getChildIndex();
		support.setShowDropLocation(true);

		if (support.isDataFlavorSupported(RangeAxisConfigTreeNode.RANGE_AXIS_CONFIG_FLAVOR)) {
			rangeAxisConfigDrop(support, path, childIndex);
		} else if (support.isDataFlavorSupported(ValueSourceTreeNode.VALUE_SOURCE_FLAVOR)) {
			ValueSourceTreeNode valueSourceTreeNode = (ValueSourceTreeNode) support.getTransferable().getTransferData(
					ValueSourceTreeNode.VALUE_SOURCE_FLAVOR);
			valueSourceDrop(valueSourceTreeNode, path, childIndex, false);
		} else if (support.isDataFlavorSupported(DataTableColumnCollection.DATATABLE_COLUMN_COLLECTION_FLAVOR)) {
			dataTableColumnDrop(support, path, childIndex);
		} else {
			return false;
		}

		return true;
	} catch (Exception e) {
		e.printStackTrace();
		return false;
	}
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:35,代码来源:PlotConfigurationTreeTransferHandler.java

示例3: canImport

import javax.swing.JTree; //导入方法依赖的package包/类
@Override
public boolean canImport(TransferHandler.TransferSupport info) {

    final JTree.DropLocation dl = (JTree.DropLocation) info.getDropLocation();
    final TreePath tp = dl.getPath();
    final DefaultMutableTreeNode parent = (DefaultMutableTreeNode) tp
        .getLastPathComponent();
    return parent.getParent().getParent() == null;
}
 
开发者ID:bcgov,项目名称:sbc-qsystem,代码行数:10,代码来源:PComplexService.java

示例4: importData

import javax.swing.JTree; //导入方法依赖的package包/类
public boolean importData(TransferHandler.TransferSupport support) {
    if(!canImport(support)) {
        return false;
    }
    // Extract transfer data.
    DefaultMutableTreeNode[] nodes = null;
    try {
        Transferable t = support.getTransferable();
        nodes = (DefaultMutableTreeNode[])t.getTransferData(nodesFlavor);
    } catch(UnsupportedFlavorException ufe) {
        System.out.println("UnsupportedFlavor: " + ufe.getMessage());
    } catch(java.io.IOException ioe) {
        System.out.println("I/O error: " + ioe.getMessage());
    }
    // Get drop location info.
    JTree.DropLocation dl =
            (JTree.DropLocation)support.getDropLocation();
    int childIndex = dl.getChildIndex();
    TreePath dest = dl.getPath();
    DefaultMutableTreeNode parent =
        (DefaultMutableTreeNode)dest.getLastPathComponent();
    JTree tree = (JTree)support.getComponent();
    DefaultTreeModel model = (DefaultTreeModel)tree.getModel();
    // Configure for drop mode.
    int index = childIndex;    // DropMode.INSERT
    if(childIndex == -1) {     // DropMode.ON
        index = parent.getChildCount();
    }
    // Add data to model.
    for(int i = 0; i < nodes.length; i++) {
        model.insertNodeInto(nodes[i], parent, index++);
    }
    return true;
}
 
开发者ID:Panzer1119,项目名称:JAddOn,代码行数:35,代码来源:TreeTransferHandler.java

示例5: importData

import javax.swing.JTree; //导入方法依赖的package包/类
@Override
public boolean importData(TransferHandler.TransferSupport support) {
    if (!canImport(support)) {
        return false;
    }
    // Extract transfer data.
    DefaultMutableTreeNode[] nodes = null;
    try {
        Transferable t = support.getTransferable();
        nodes = (DefaultMutableTreeNode[]) t.getTransferData(nodesFlavor);
    } catch (UnsupportedFlavorException ufe) {
        System.out.println("UnsupportedFlavor: " + ufe.getMessage());
    } catch (java.io.IOException ioe) {
        System.out.println("I/O error: " + ioe.getMessage());
    }
    // Get drop location info.
    JTree.DropLocation dl = (JTree.DropLocation) support.getDropLocation();
    int childIndex = dl.getChildIndex();
    TreePath dest = dl.getPath();
    DefaultMutableTreeNode parent = (DefaultMutableTreeNode)
            dest.getLastPathComponent();
    JTree tree = (JTree) support.getComponent();
    DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
    // Configure for drop mode.
    int index = childIndex;    // DropMode.INSERT
    if (childIndex == -1) {     // DropMode.ON
        index = parent.getChildCount();
    }
    // Add data to model.
    for (DefaultMutableTreeNode node : nodes) {
        model.insertNodeInto(node, parent, index++);
    }
    return true;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:35,代码来源:LastNodeLowerHalfDrop.java

示例6: paintRow

import javax.swing.JTree; //导入方法依赖的package包/类
private void paintRow(TreeCellRenderer renderer,
           DefaultTreeCellRenderer dtcr, SynthContext treeContext,
           SynthContext cellContext, Graphics g, Rectangle clipBounds,
           Insets insets, Rectangle bounds, Rectangle rowBounds,
           TreePath path, int row, boolean isExpanded,
           boolean hasBeenExpanded, boolean isLeaf) {
    // Don't paint the renderer if editing this row.
    boolean selected = tree.isRowSelected(row);

    JTree.DropLocation dropLocation = tree.getDropLocation();
    boolean isDrop = dropLocation != null
                     && dropLocation.getChildIndex() == -1
                     && path == dropLocation.getPath();

    int state = ENABLED;
    if (selected || isDrop) {
        state |= SELECTED;
    }

    if (tree.isFocusOwner() && row == getLeadSelectionRow()) {
        state |= FOCUSED;
    }

    cellContext.setComponentState(state);

    if (dtcr != null && (dtcr.getBorderSelectionColor() instanceof
                         UIResource)) {
        dtcr.setBorderSelectionColor(style.getColor(
                                         cellContext, ColorType.FOCUS));
    }
    SynthLookAndFeel.updateSubregion(cellContext, g, rowBounds);
    cellContext.getPainter().paintTreeCellBackground(cellContext, g,
                rowBounds.x, rowBounds.y, rowBounds.width,
                rowBounds.height);
    cellContext.getPainter().paintTreeCellBorder(cellContext, g,
                rowBounds.x, rowBounds.y, rowBounds.width,
                rowBounds.height);
    if (editingComponent != null && editingRow == row) {
        return;
    }

    int leadIndex;

    if (tree.hasFocus()) {
        leadIndex = getLeadSelectionRow();
    }
    else {
        leadIndex = -1;
    }

    Component component = renderer.getTreeCellRendererComponent(
                     tree, path.getLastPathComponent(),
                     selected, isExpanded, isLeaf, row,
                     (leadIndex == row));

    rendererPane.paintComponent(g, component, tree, bounds.x, bounds.y,
                                bounds.width, bounds.height, true);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:59,代码来源:SynthTreeUI.java

示例7: canImport

import javax.swing.JTree; //导入方法依赖的package包/类
@Override
public boolean canImport(TransferHandler.TransferSupport support) {
    if (!support.isDrop()) {
        return false;
    }
    support.setShowDropLocation(true);
    if (!support.isDataFlavorSupported(nodesFlavor)) {
        return false;
    }
    // Do not allow a drop on the drag source selections.
    JTree.DropLocation dl = (JTree.DropLocation) support.getDropLocation();
    JTree tree = (JTree) support.getComponent();
    int dropRow = tree.getRowForPath(dl.getPath());
    int[] selRows = tree.getSelectionRows();
    for (int i = 0; i < selRows.length; i++) {
        if (selRows[i] == dropRow) {
            return false;
        }
    }
    // Do not allow MOVE-action drops if a non-leaf node is
    // selected unless all of its children are also selected.
    int action = support.getDropAction();
    if (action == MOVE) {
        return haveCompleteNode(tree);
    }
    // Do not allow a non-leaf node to be copied to a level
    // which is less than its source level.
    TreePath dest = dl.getPath();
    DefaultMutableTreeNode target = (DefaultMutableTreeNode)
            dest.getLastPathComponent();
    TreePath path = tree.getPathForRow(selRows[0]);
    DefaultMutableTreeNode firstNode = (DefaultMutableTreeNode)
            path.getLastPathComponent();
    if (firstNode.getChildCount() > 0
            && target.getLevel() < firstNode.getLevel()) {
        return false;
    }
    return true;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:40,代码来源:LastNodeLowerHalfDrop.java

示例8: paintDropLine

import javax.swing.JTree; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
protected void paintDropLine(Graphics g) {
    JTree.DropLocation loc = tree.getDropLocation();
    if (!isDropLine(loc)) {
        return;
    }

    Color c = (Color)style.get(paintContext, "Tree.dropLineColor");
    if (c != null) {
        g.setColor(c);
        Rectangle rect = getDropLineRect(loc);
        g.fillRect(rect.x, rect.y, rect.width, rect.height);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:18,代码来源:SynthTreeUI.java

示例9: propertyChange

import javax.swing.JTree; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void propertyChange(PropertyChangeEvent event) {
    if (SynthLookAndFeel.shouldUpdateStyle(event)) {
        updateStyle((JTree)event.getSource());
    }

    if ("dropLocation" == event.getPropertyName()) {
        JTree.DropLocation oldValue = (JTree.DropLocation)event.getOldValue();
        repaintDropLocation(oldValue);
        repaintDropLocation(tree.getDropLocation());
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:16,代码来源:SynthTreeUI.java

示例10: adaptContainerStyle

import javax.swing.JTree; //导入方法依赖的package包/类
private void adaptContainerStyle(JTree tree, Object node, boolean selected, boolean expanded, boolean leaf, int row,
		boolean hasFocus, boolean dragging, boolean setForeground) {
	SwingTools.setEnabledRecursive(this, tree.isEnabled());

	Color fg = null;
	Color bg = null;

	boolean highlightingEnabled = RapidMinerGUI.getDragHighlighteMode().equals(DragHighlightMode.FULL);

	JTree.DropLocation dropLocation = tree.getDropLocation();
	if (dropLocation != null && dropLocation.getChildIndex() == -1
			&& tree.getRowForPath(dropLocation.getPath()) == row) {
		fg = TEXT_SELECTED_COLOR;
		bg = SELECTED_COLOR;
	} else if (selected && !dragging) {
		fg = TEXT_SELECTED_COLOR;
		bg = SELECTED_COLOR;
	} else {
		fg = TEXT_NON_SELECTED_COLOR;
		if (highlightingEnabled && dragging) {
			bg = ProcessDrawer.INNER_DRAG_COLOR;
		} else {
			bg = NOT_SELECTED_COLOR;
		}
	}

	if (setForeground) {
		nameLabel.setForeground(fg);
		attributeLabel.setForeground(fg);
	}
	this.setBackground(bg);

	if (hasFocus) {
		this.setBorder(focusBorder);
	} else {
		if (highlightingEnabled && dragging) {
			this.setBorder(draggingNotFocusedBorder);
		} else {
			this.setBorder(nonFocusBorder);
		}
	}
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:43,代码来源:PlotConfigurationTreeCellRenderer.java

示例11: canImport

import javax.swing.JTree; //导入方法依赖的package包/类
@Override
public boolean canImport(TransferSupport support) {

	// only support drops
	if (!support.isDrop()) {
		updateDropDeniedTooltip((JComponent) support.getComponent(), null);
		return false;
	}

	if (!doesSupportFlavor(support)) {
		updateDropDeniedTooltip((JComponent) support.getComponent(), null);
		return false;
	}

	// fetch the drop location
	JTree.DropLocation dropLocation = (javax.swing.JTree.DropLocation) support.getDropLocation();

	// get path, if path is null importing is not possible
	TreePath path = dropLocation.getPath();
	if (path == null) {
		updateDropDeniedTooltip((JComponent) support.getComponent(), null);
		return false;
	}

	Object lastPathComponent = path.getLastPathComponent();

	// make drop location and transferable dependent decision
	int childIndex = dropLocation.getChildIndex();
	Transferable transferable = support.getTransferable();

	// check if drop on tree component is possible
	String actionDescription = isDropOnTreeComponentPossible(support.getComponent(), (TreeNode) lastPathComponent,
			transferable, childIndex);
	if (actionDescription == null) {
		return false;
	}

	// check if the source actions (a bitwise-OR of supported actions)
	// contains the COPY action
	boolean copySupported = (COPY & support.getSourceDropActions()) == (COPY);
	if (copySupported) {
		support.setDropAction(COPY);
		updateDropDeniedTooltip((JComponent) support.getComponent(), actionDescription);
		return true;
	}
	boolean moveSupported = (MOVE & support.getSourceDropActions()) == (MOVE);
	if (moveSupported) {
		support.setDropAction(MOVE);
		updateDropDeniedTooltip((JComponent) support.getComponent(), actionDescription);
		return true;
	}

	updateDropDeniedTooltip((JComponent) support.getComponent(), null);
	// reject the transfer if copy or move is not supported
	return false;

}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:58,代码来源:PlotConfigurationTreeTransferHandler.java

示例12: getTreeCellRendererComponent

import javax.swing.JTree; //导入方法依赖的package包/类
/**
  * Configures the renderer based on the passed in components.
  * The value is set from messaging the tree with
  * <code>convertValueToText</code>, which ultimately invokes
  * <code>toString</code> on <code>value</code>.
  * The foreground color is set based on the selection and the icon
  * is set based on the <code>leaf</code> and <code>expanded</code>
  * parameters.
  */
public Component getTreeCellRendererComponent(JTree tree, Object value,
                                              boolean sel,
                                              boolean expanded,
                                              boolean leaf, int row,
                                              boolean hasFocus) {
    String         stringValue = tree.convertValueToText(value, sel,
                                      expanded, leaf, row, hasFocus);

    this.tree = tree;
    this.hasFocus = hasFocus;
    setText(stringValue);

    Color fg = null;
    isDropCell = false;

    JTree.DropLocation dropLocation = tree.getDropLocation();
    if (dropLocation != null
            && dropLocation.getChildIndex() == -1
            && tree.getRowForPath(dropLocation.getPath()) == row) {

        Color col = DefaultLookup.getColor(this, ui, "Tree.dropCellForeground");
        if (col != null) {
            fg = col;
        } else {
            fg = getTextSelectionColor();
        }

        isDropCell = true;
    } else if (sel) {
        fg = getTextSelectionColor();
    } else {
        fg = getTextNonSelectionColor();
    }

    setForeground(fg);

    Icon icon = null;
    if (leaf) {
        icon = getLeafIcon();
    } else if (expanded) {
        icon = getOpenIcon();
    } else {
        icon = getClosedIcon();
    }

    if (!tree.isEnabled()) {
        setEnabled(false);
        LookAndFeel laf = UIManager.getLookAndFeel();
        Icon disabledIcon = laf.getDisabledIcon(tree, icon);
        if (disabledIcon != null) icon = disabledIcon;
        setDisabledIcon(icon);
    } else {
        setEnabled(true);
        setIcon(icon);
    }
    setComponentOrientation(tree.getComponentOrientation());

    selected = sel;

    return this;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:71,代码来源:DefaultTreeCellRenderer.java


注:本文中的javax.swing.JTree.DropLocation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。