2

JGraph(T)ライブラリの使用に問題があります。デフォルトの選択ビューを変更する必要があります。例:デフォルトの背景はオレンジ色です。頂点が選択され、次に緑色の境界線が追加された場合、この視覚化戦略を変更して、選択した要素の背景をColor.BLUEに変更できますか。次のコードを実行してみます:

 GraphSelectionModel graphSelectionModel = new DefaultGraphSelectionModel(jGraph);
    graphSelectionModel.setSelectionMode(GraphSelectionModel.MULTIPLE_GRAPH_SELECTION);
    graphSelectionModel.addGraphSelectionListener(new GraphSelectionListener()
    {
        HashMap oldestCellsAndAttrs = new HashMap();
        @Override
        public void valueChanged(GraphSelectionEvent e)
        {
            jGraph.getModel().beginUpdate();
            m_jgAdapter.edit(oldestCellsAndAttrs, null, null, null);
            oldestCellsAndAttrs.clear();
            Map cellAndAttrs = new HashMap();
            for (Object obj : e.getCells())
            {
                DefaultGraphCell cell = (DefaultGraphCell) obj;
                oldestCellsAndAttrs.put(cell, JGraphModelAdapter.createDefaultVertexAttributes());
                Map attrs = cell.getAttributes();
                GraphConstants.setBackground(attrs, Color.BLUE);
                cellAndAttrs.put(cell, attrs);
            }
            m_jgAdapter.edit(cellAndAttrs, null, null, null);
            jGraph.getModel().endUpdate();
        }
    });
    fillGraph(tree, g);
    layout(g, m_jgAdapter, jGraph);
    setSize(3 * width / 4, height);
    jGraph.setSelectionModel(graphSelectionModel);

これにより、同じ選択されたオブジェクトのbkgが変更されますが、選択されていない場合は返されません。この問題のデフォルトの解決策は存在しますか?

4

1 に答える 1

3

私は次のコードで問題を解決します:

            @Override
        public void valueChanged(GraphSelectionEvent e)
        {
           Object[] cells = e.getCells();
            HashMap<DefaultGraphCell, AttributeMap> cellsAndAttrs = new HashMap<DefaultGraphCell, AttributeMap>();
            for (Object c : cells)
            {
                DefaultGraphCell cell = (DefaultGraphCell) c;
                AttributeMap cellAttrs = cell.getAttributes();
                if (jGraph.isCellSelected(cell))
                    GraphConstants.setBackground(cellAttrs, SELECTED_COLOR);
                else
                    GraphConstants.setBackground(cellAttrs, NON_SELECTED_COLOR);
                cellsAndAttrs.put(cell, cellAttrs);
            }
            m_jgAdapter.edit(cellsAndAttrs, null, null, null);
        }
于 2012-02-23T11:45:26.750 に答える