Browse Source

componenttree后面还要修改

master
xiaoxia 8 years ago
parent
commit
0efb563d4c
  1. 182
      designer_form/src/com/fr/design/mainframe/ComponentTree.java

182
designer_form/src/com/fr/design/mainframe/ComponentTree.java

@ -40,7 +40,7 @@ public class ComponentTree extends JTree {
TreePath[] paths = getSelectedTreePath();
addTreeSelectionListener(designer);
setSelectionPaths(paths);
designer.addDesignerEditListener(new TreeDesignerEditAdapter());
this.addMouseListener(new MouseAdapter() {
@ -68,15 +68,19 @@ public class ComponentTree extends JTree {
setEditable(true);
}
public FormDesigner getDesigner() {
return designer;
}
/**
* 构造函数
*
*
* @param designer 设计界面组件
* @param model 构造JTree的model
*/
public ComponentTree(FormDesigner designer,ComponentTreeModel model) {
this(designer);
this.setModel(model);
this(designer);
this.setModel(model);
}
@ -96,17 +100,17 @@ public class ComponentTree extends JTree {
return super.isPathEditable(path);
}
/**
* 将值转换为文本
* @param value
* @param selected 是否选中
* @param expanded 扩展
* @param leaf 是否叶子
* @param row
* @param hasFocus 是否焦点
*
* @return 返回文本
*/
/**
* 将值转换为文本
* @param value
* @param selected 是否选中
* @param expanded 扩展
* @param leaf 是否叶子
* @param row
* @param hasFocus 是否焦点
*
* @return 返回文本
*/
@Override
public String convertValueToText(Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
if (value != null && value instanceof XCreator) {
@ -115,25 +119,25 @@ public class ComponentTree extends JTree {
return super.convertValueToText(value, selected, expanded, leaf, row, hasFocus);
}
}
public void setAndScrollSelectionPath(TreePath treepath) {
setSelectionPath(treepath);
scrollPathToVisible(treepath);
setSelectionPath(treepath);
scrollPathToVisible(treepath);
}
private void popupMenu(MouseEvent e) {
TreePath path = this.getSelectionPath();
if (path == null) {
return;
}
Component component = (Component) path.getLastPathComponent();
if (!(component instanceof XCreator)) {
return;
}
ComponentAdapter adapter = AdapterBus.getComponentAdapter(designer, (XCreator) component);
JPopupMenu menu = adapter.getContextPopupMenu(e);
menu.show(this, e.getX(), e.getY());
}
private void popupMenu(MouseEvent e) {
TreePath path = this.getSelectionPath();
if (path == null) {
return;
}
Component component = (Component) path.getLastPathComponent();
if (!(component instanceof XCreator)) {
return;
}
ComponentAdapter adapter = AdapterBus.getComponentAdapter(designer, (XCreator) component);
JPopupMenu menu = adapter.getContextPopupMenu(e);
menu.show(this, e.getX(), e.getY());
}
/**
* 刷新
@ -145,51 +149,51 @@ public class ComponentTree extends JTree {
public TreePath[] getSelectedTreePath() {
XCreator[] creators = designer.getSelectionModel().getSelection().getSelectedCreators();
TreePath[] paths = new TreePath[creators.length];
for (int i = 0; i < paths.length; i++) {
paths[i] = buildTreePath(creators[i]);
}
return paths;
}
private class TreeDesignerEditAdapter implements DesignerEditListener {
@Override
public void fireCreatorModified(DesignerEvent evt) {
if (evt.getCreatorEventID() == DesignerEvent.CREATOR_SELECTED) {
TreePath[] paths = getSelectedTreePath();
if (paths.length == 1) {
setAndScrollSelectionPath(paths[0]);
} else {
setSelectionPaths(paths);
}
} else if(evt.getCreatorEventID() == DesignerEvent.CREATOR_PASTED) {
ComponentTree.this.refreshUI();
TreePath[] paths = getSelectedTreePath();
if (paths.length == 1) {
setAndScrollSelectionPath(paths[0]);
} else {
setSelectionPaths(paths);
}
ComponentTree.this.repaint();
} else {
ComponentTree.this.refreshUI();
ComponentTree.this.repaint();
}
}
@Override
public boolean equals(Object o) {
return o.getClass() == this.getClass();
}
}
public TreePath[] getSelectedTreePath() {
XCreator[] creators = designer.getSelectionModel().getSelection().getSelectedCreators();
TreePath[] paths = new TreePath[creators.length];
for (int i = 0; i < paths.length; i++) {
paths[i] = buildTreePath(creators[i]);
}
return paths;
}
private class TreeDesignerEditAdapter implements DesignerEditListener {
@Override
public void fireCreatorModified(DesignerEvent evt) {
if (evt.getCreatorEventID() == DesignerEvent.CREATOR_SELECTED) {
TreePath[] paths = getSelectedTreePath();
if (paths.length == 1) {
setAndScrollSelectionPath(paths[0]);
} else {
setSelectionPaths(paths);
}
} else if(evt.getCreatorEventID() == DesignerEvent.CREATOR_PASTED) {
ComponentTree.this.refreshUI();
TreePath[] paths = getSelectedTreePath();
if (paths.length == 1) {
setAndScrollSelectionPath(paths[0]);
} else {
setSelectionPaths(paths);
}
ComponentTree.this.repaint();
} else {
ComponentTree.this.refreshUI();
ComponentTree.this.repaint();
}
}
@Override
public boolean equals(Object o) {
return o.getClass() == this.getClass();
}
}
/**
@ -211,11 +215,11 @@ public class ComponentTree extends JTree {
paths[i] = buildTreePath(searchList.get(i));
}
if(paths.length > 0) {
setAndScrollSelectionPath(paths[0]);
setAndScrollSelectionPath(paths[0]);
} else {
setSelectionPath();
setSelectionPath();
}
return paths;
return paths;
}
@ -248,7 +252,7 @@ public class ComponentTree extends JTree {
* 触发
*/
public void fireTreeChanged() {
designer.refreshDesignerUI();
designer.refreshDesignerUI();
}
/**
@ -267,14 +271,14 @@ public class ComponentTree extends JTree {
ArrayList<Component> path = new ArrayList<Component>();
Component parent = comp;
while (parent != null) {
XCreator creator = (XCreator) parent;
path.add(0, parent);
if (creator != comp ) {
creator.notShowInComponentTree(path);
}
parent = parent.getParent();
}
while (parent != null) {
XCreator creator = (XCreator) parent;
path.add(0, parent);
if (creator != comp ) {
creator.notShowInComponentTree(path);
}
parent = parent.getParent();
}
Object[] components = path.toArray();
return new TreePath(components);
}

Loading…
Cancel
Save