diff --git a/designer_form/src/com/fr/design/mainframe/ComponentTree.java b/designer_form/src/com/fr/design/mainframe/ComponentTree.java
index fb0586a693..0a268610ec 100644
--- a/designer_form/src/com/fr/design/mainframe/ComponentTree.java
+++ b/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
Description: 树形结构而来的DefaultListCellRenderer
+ */ + class UITreeComboBoxRenderer extends DefaultListCellRenderer { + public Component getListCellRendererComponent(JList list, Object value, + int index, boolean isSelected, boolean cellHasFocus){ + if(value != null){ + TreePath path = (TreePath)value; + Object node = path.getLastPathComponent(); + value = node; + TreeCellRenderer r = tree.getCellRenderer(); + JLabel lb = (JLabel)r.getTreeCellRendererComponent( + tree, value, isSelected, false, false, index, + cellHasFocus); + return lb; + } + return super.getListCellRendererComponent(list, value, index, + isSelected, cellHasFocus); + } + } + + + private class TreeComboBoxDesignerEditAdapter implements DesignerEditListener { + + @Override + public void fireCreatorModified(DesignerEvent evt) { + if (evt.getCreatorEventID() == DesignerEvent.CREATOR_SELECTED || evt.getCreatorEventID() == DesignerEvent.CREATOR_PASTED) { + TreePath[] paths = tree.getSelectedTreePath(); + + if (paths.length == 1) { + tree.setAndScrollSelectionPath(paths[0]); + } else { + tree.setSelectionPaths(paths); + } + setSelectedItem(paths[0]); + MenuSelectionManager.defaultManager().clearSelectedPath(); + } else { + return; + } + + } + + @Override + public boolean equals(Object o) { + return o.getClass() == this.getClass(); + } + } + + /** + * 测试 + */ +// public static void main(String args[]){ +// JFrame frame = new JFrame("UITreeComboBox"); +// final UITreeComboBox box = new UITreeComboBox(new ComponentTree(new FormDesigner())); +// box.setPreferredSize(new Dimension(300, 28)); +// frame.getContentPane().add(box); +// frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); +// frame.pack(); +// frame.setVisible(true); +// } +} + +/** + *Title: UITreeComboBox
+ *Description: TreePopup
+ */ +class TreePopup extends JPopupMenu implements ComboPopup{ + protected UITreeComboBox comboBox; + protected JScrollPane scrollPane; + + protected MouseMotionListener mouseMotionListener; + protected MouseListener mouseListener; + + + public void popupMenu(MouseEvent e) { + TreePath path = comboBox.getTree().getSelectionPath(); + if (path == null) { + return; + } + Component component = (Component) path.getLastPathComponent(); + if (!(component instanceof XCreator)) { + return; + } + com.fr.design.designer.beans.ComponentAdapter adapter = AdapterBus.getComponentAdapter(comboBox.getTree().getDesigner(), (XCreator) component); + JPopupMenu menu = adapter.getContextPopupMenu(e); + menu.show(comboBox, e.getX(), e.getY()); + } + + public TreePopup(JComboBox comboBox){ + this.comboBox = (UITreeComboBox)comboBox; + setBorder(BorderFactory.createLineBorder(Color.black)); + setLayout(new BorderLayout()); + setLightWeightPopupEnabled(comboBox.isLightWeightPopupEnabled()); + JTree tree = this.comboBox.getTree(); + if(tree != null){ + scrollPane = new JScrollPane(tree); + scrollPane.setBorder(null); + add(scrollPane, BorderLayout.CENTER); + } + } + + public void show(){ + updatePopup(); + show(comboBox, 0, comboBox.getHeight()); + comboBox.getTree().requestFocus(); + } + + public void hide(){ + setVisible(false); + comboBox.firePropertyChange("popupVisible", true, false); + } + + protected JList list = new JList(); + public JList getList(){ + return list; + } + + public MouseMotionListener getMouseMotionListener(){ + if(mouseMotionListener == null){ + mouseMotionListener = new MouseMotionAdapter(){}; + } + return mouseMotionListener; + } + + public KeyListener getKeyListener(){ + return null; + } + + public void uninstallingUI(){} + + /** + * Implementation of ComboPopup.getMouseListener(). + * + * @return aMouseListener
or null
+ * @see ComboPopup#getMouseListener
+ */
+ public MouseListener getMouseListener(){
+ if(mouseListener == null){
+ mouseListener = new InvocationMouseHandler();
+ }
+ return mouseListener;
+ }
+
+ protected void togglePopup(){
+ if(isVisible()){
+ hide();
+ } else{
+ show();
+ }
+ }
+ protected void updatePopup(){
+ setPreferredSize(new Dimension(comboBox.getSize().width, 200));
+ Object selectedObj = comboBox.getSelectedItem();
+ if(selectedObj != null){
+ TreePath tp = (TreePath)selectedObj;
+ ((UITreeComboBox)comboBox).getTree().setSelectionPath(tp);
+ }
+ }
+
+ protected class InvocationMouseHandler extends MouseAdapter{
+ public void mousePressed(MouseEvent e){
+ if(!SwingUtilities.isLeftMouseButton(e) || !comboBox.isEnabled()){
+ return;
+ }
+ if(comboBox.isEditable()){
+ Component comp = comboBox.getEditor().getEditorComponent();
+ if((!(comp instanceof JComponent)) ||
+ ((JComponent)comp).isRequestFocusEnabled()){
+ comp.requestFocus();
+ }
+ } else if(comboBox.isRequestFocusEnabled()){
+ comboBox.requestFocus();
+ }
+ togglePopup();
+ }
+
+ public void mouseClicked (MouseEvent e){
+ if (e.isMetaDown()) {
+ popupMenu(e);
+ } else {
+ return;
+ }
+ }
+ }
+
+
+
+}