gpt4 book ai didi

java - 如何手动设置荣格可视化的缩放?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:23:04 26 4
gpt4 key购买 nike

我在 JPanel 中显示了一棵 jung 树。我的树的构造函数如下所示:

  Forest<String, Integer> graph = new DelegateForest<String, Integer>();
static GraphZoomScrollPane panel = null;
static DefaultModalGraphMouse graphMouse = null;
static JComboBox modeBox = null;
static ScalingControl scaler;

public PanelTree(List<Cluster> clist) {
setBounds(215, 10, 550, 550);
updateData(clist); // adds vertex and edges to graph

treeLayout = new TreeLayout<String, Integer>(graph);
vv = new VisualizationViewer<String, Integer>(treeLayout, new Dimension(500, 500));
vv.setBackground(Color.white);
vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.Line());
vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
// add a listener for ToolTips
vv.setVertexToolTipTransformer(new ToStringLabeller());
vv.getRenderContext()
.setArrowFillPaintTransformer(new ConstantTransformer(Color.lightGray));

panel = new GraphZoomScrollPane(vv);
add(panel);

graphMouse = new DefaultModalGraphMouse();

vv.setGraphMouse(graphMouse);

modeBox = graphMouse.getModeComboBox();
modeBox.addItemListener(graphMouse.getModeListener());
graphMouse.setMode(ModalGraphMouse.Mode.TRANSFORMING);

scaler = new CrossoverScalingControl();
}

但是这棵树很大。所以我想知道是否有一种方法可以自动缩小以使树适合窗口,否则只需设置小于默认缩放的默认缩放。我该怎么做?

最佳答案

ScalingControl scaler = new CrossoverScalingControl();

public void zoomIn() {
setZoom(1);
}

public void zoomOut() {
setZoom(-1);
}

private void setZoom(int amount) {
scaler.scale(vv, amount > 0 ? 1.1f : 1 / 1.1f, vv.getCenter());
}

要使图形适合窗口,您可以计算图形大小与面板大小之间的差异,并调用 setZoom() 方法传递差异因子。

关于java - 如何手动设置荣格可视化的缩放?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9761391/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com