forked from FR-Global/plugin-event-manager
18 changed files with 600 additions and 166 deletions
@ -0,0 +1,52 @@
|
||||
package com.fr.plugin.event.manager.data; |
||||
|
||||
import com.fr.form.ui.Widget; |
||||
import com.fr.report.cell.CellElement; |
||||
|
||||
import javax.swing.Icon; |
||||
|
||||
/** |
||||
* @author Joe |
||||
* Created by Joe on 12/13/2020 |
||||
*/ |
||||
public class MyCellWidget extends MyWidget { |
||||
private CellElement cellElement; |
||||
private Widget widget; |
||||
// 来自普通还是条件属性
|
||||
private WidgetSource source; |
||||
|
||||
public MyCellWidget(CellElement cellElement, Widget widget) { |
||||
this(cellElement, widget, WidgetSource.NORMAL); |
||||
} |
||||
|
||||
public MyCellWidget(CellElement cellElement, Widget widget, WidgetSource source) { |
||||
super(widget); |
||||
this.cellElement = cellElement; |
||||
this.source = source; |
||||
} |
||||
|
||||
public Widget getWidget() { |
||||
return widget; |
||||
} |
||||
|
||||
public void setWidget(Widget widget) { |
||||
this.widget = widget; |
||||
} |
||||
|
||||
public WidgetSource getSource() { |
||||
return source; |
||||
} |
||||
|
||||
public void setSource(WidgetSource source) { |
||||
this.source = source; |
||||
} |
||||
|
||||
@Override |
||||
public String getNodeName() { |
||||
if (source == WidgetSource.NORMAL) { |
||||
return cellElement.getRow() + " - " + cellElement.getColumn(); |
||||
} else { |
||||
return cellElement.getRow() + " - " + cellElement.getColumn() + "Cond"; |
||||
} |
||||
} |
||||
} |
@ -1,37 +0,0 @@
|
||||
package com.fr.plugin.event.manager.data; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author Joe |
||||
* Created by Joe on 12/11/2020 |
||||
*/ |
||||
public class MyContainer { |
||||
private String blockName; |
||||
private List<MyWidget> widgets; |
||||
|
||||
public MyContainer() { |
||||
widgets = new ArrayList<>(); |
||||
} |
||||
|
||||
public String getBlockName() { |
||||
return blockName; |
||||
} |
||||
|
||||
public void setBlockName(String blockName) { |
||||
this.blockName = blockName; |
||||
} |
||||
|
||||
public void addWidget(MyWidget widget) { |
||||
this.widgets.add(widget); |
||||
} |
||||
|
||||
public void setWidgets(List<MyWidget> widgets) { |
||||
this.widgets = widgets; |
||||
} |
||||
|
||||
public List<MyWidget> getWidgets() { |
||||
return this.widgets; |
||||
} |
||||
} |
@ -1,11 +1,31 @@
|
||||
package com.fr.plugin.event.manager.data; |
||||
|
||||
import javax.swing.Icon; |
||||
|
||||
/** |
||||
* @author Joe |
||||
* Created by Joe on 12/14/2020 |
||||
*/ |
||||
public interface MyNode { |
||||
String getNodeName(); |
||||
public class MyNode { |
||||
protected String nodeName; |
||||
|
||||
public MyNode() { |
||||
|
||||
} |
||||
|
||||
public MyNode(String nodeName) { |
||||
this.nodeName = nodeName; |
||||
} |
||||
|
||||
public String getNodeName() { |
||||
return nodeName; |
||||
} |
||||
|
||||
public void setNodeName(String nodeName) { |
||||
this.nodeName = nodeName; |
||||
} |
||||
|
||||
String getIconPath(); |
||||
public Icon getIcon() { |
||||
return null; |
||||
} |
||||
} |
||||
|
@ -1,28 +0,0 @@
|
||||
package com.fr.plugin.event.manager.data; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author Joe |
||||
* Created by Joe on 12/11/2020 |
||||
*/ |
||||
public class MySheet { |
||||
private List<MyContainer> containers; |
||||
|
||||
public MySheet() { |
||||
containers = new ArrayList<>(); |
||||
} |
||||
|
||||
public void addContainer(MyContainer container) { |
||||
this.containers.add(container); |
||||
} |
||||
|
||||
public void setContainers(List<MyContainer> containers) { |
||||
this.containers = containers; |
||||
} |
||||
|
||||
public List<MyContainer> getContainers() { |
||||
return containers; |
||||
} |
||||
} |
@ -0,0 +1,137 @@
|
||||
package com.fr.plugin.event.manager.data; |
||||
|
||||
import java.util.LinkedList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author Joe |
||||
* Created by Joe on 12/14/2020 |
||||
*/ |
||||
public class MyTree { |
||||
/** |
||||
* 树节点 |
||||
*/ |
||||
private MyNode data; |
||||
|
||||
/** |
||||
* 父节点,根没有父节点 |
||||
*/ |
||||
private MyTree parent; |
||||
|
||||
/** |
||||
* 子节点,叶子节点没有子节点 |
||||
*/ |
||||
private List<MyTree> children; |
||||
|
||||
/** |
||||
* 保存了当前节点及其所有子节点,方便查询 |
||||
*/ |
||||
private List<MyTree> elementsIndex; |
||||
|
||||
private boolean visible; |
||||
|
||||
/** |
||||
* 构造函数 |
||||
* |
||||
* @param data |
||||
*/ |
||||
public MyTree(MyNode data) { |
||||
this.data = data; |
||||
this.children = new LinkedList<>(); |
||||
this.elementsIndex = new LinkedList<>(); |
||||
this.elementsIndex.add(this); |
||||
this.visible = true; |
||||
} |
||||
|
||||
public MyNode getData() { |
||||
return data; |
||||
} |
||||
|
||||
public void setVisible(boolean visible) { |
||||
this.visible = visible; |
||||
} |
||||
|
||||
public List<MyTree> getChildren() { |
||||
return children; |
||||
} |
||||
|
||||
public List<MyTree> getElementsIndex() { |
||||
return elementsIndex; |
||||
} |
||||
|
||||
/** |
||||
* 判断是否为根:根没有父节点 |
||||
* |
||||
* @return |
||||
*/ |
||||
public boolean isRoot() { |
||||
return parent == null; |
||||
} |
||||
|
||||
/** |
||||
* 判断是否为叶子节点:子节点没有子节点 |
||||
* |
||||
* @return |
||||
*/ |
||||
public boolean isLeaf() { |
||||
return children.size() == 0; |
||||
} |
||||
|
||||
/** |
||||
* 添加一个子节点 |
||||
* |
||||
* @param child |
||||
* @return |
||||
*/ |
||||
public MyTree addChild(MyNode child) { |
||||
MyTree childNode = new MyTree(child); |
||||
|
||||
childNode.parent = this; |
||||
|
||||
this.children.add(childNode); |
||||
|
||||
this.registerChildForSearch(childNode); |
||||
|
||||
return childNode; |
||||
} |
||||
|
||||
public void removeChild(MyTree child) { |
||||
// 如果是根的话,就保留
|
||||
if (child.parent != null) { |
||||
child.parent.children.remove(child); |
||||
child.parent = null; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 递归为当前节点以及当前节点的所有父节点增加新的节点 |
||||
* |
||||
* @param node |
||||
*/ |
||||
private void registerChildForSearch(MyTree node) { |
||||
elementsIndex.add(node); |
||||
if (parent != null) { |
||||
parent.registerChildForSearch(node); |
||||
} |
||||
} |
||||
|
||||
public MyTree findChild(int index) { |
||||
return children.get(index); |
||||
} |
||||
|
||||
public int getChildrenSize() { |
||||
return children.size(); |
||||
} |
||||
|
||||
public int getIndexOfChild(Object child) { |
||||
int count = getChildrenSize(); |
||||
for (int i = 0; i < count; i++) { |
||||
MyTree comp = findChild(i); |
||||
if (comp == child) { |
||||
return i; |
||||
} |
||||
} |
||||
return -1; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,55 @@
|
||||
package com.fr.plugin.event.manager.ui.tree; |
||||
|
||||
import com.fr.design.constants.UIConstants; |
||||
import com.fr.design.designer.creator.XCreator; |
||||
import com.fr.design.designer.creator.XCreatorUtils; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.plugin.event.manager.data.MyTree; |
||||
|
||||
import javax.swing.BorderFactory; |
||||
import javax.swing.Icon; |
||||
import javax.swing.JTree; |
||||
import javax.swing.tree.DefaultTreeCellRenderer; |
||||
import java.awt.Color; |
||||
import java.awt.Component; |
||||
|
||||
/** |
||||
* @author Joe |
||||
* Created by Joe on 12/14/2020 |
||||
*/ |
||||
public class MyComponentCellRenderer extends DefaultTreeCellRenderer { |
||||
public MyComponentCellRenderer() { |
||||
} |
||||
|
||||
@Override |
||||
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, |
||||
boolean leaf, int row, boolean hasFocus) { |
||||
super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus); |
||||
if (value instanceof MyTree) { |
||||
String name = ((MyTree) value).getData().getNodeName(); |
||||
setText(name); |
||||
Icon icon = ((MyTree) value).getData().getIcon(); |
||||
if (icon != null) { |
||||
setIcon(icon); |
||||
} |
||||
} |
||||
this.setBorder(BorderFactory.createEmptyBorder(1, 0, 1, 0)); |
||||
this.setBackgroundNonSelectionColor(new Color(255, 255, 255)); |
||||
return this; |
||||
} |
||||
|
||||
@Override |
||||
public Icon getClosedIcon() { |
||||
return getIcon(); |
||||
} |
||||
|
||||
@Override |
||||
public Icon getLeafIcon() { |
||||
return getIcon(); |
||||
} |
||||
|
||||
@Override |
||||
public Icon getOpenIcon() { |
||||
return getIcon(); |
||||
} |
||||
} |
@ -1,40 +1,45 @@
|
||||
package com.fr.plugin.event.manager.ui.tree; |
||||
|
||||
import com.fr.design.constants.UIConstants; |
||||
import com.fr.design.designer.treeview.ComponentTreeCellRenderer; |
||||
import com.fr.design.gui.itree.UITreeUI; |
||||
import com.fr.plugin.event.manager.data.MyContainer; |
||||
import com.fr.plugin.event.manager.data.MyTree; |
||||
import com.fr.plugin.event.manager.ui.EventConfigPane; |
||||
|
||||
import javax.swing.BorderFactory; |
||||
import javax.swing.JTree; |
||||
import javax.swing.tree.TreeSelectionModel; |
||||
import java.awt.Color; |
||||
|
||||
/** |
||||
* @author Joe |
||||
* Created by Joe on 12/14/2020 |
||||
*/ |
||||
public class ContainerRootTree extends JTree { |
||||
private MyContainer container; |
||||
private ContainerTreeModel model; |
||||
public class MyComponentTree extends JTree { |
||||
private EventConfigPane configPane; |
||||
private MyComponentTreeModel model; |
||||
private UITreeUI uiTreeUI = new UITreeUI(); |
||||
|
||||
private static final int PADDING_LEFT = 5; |
||||
private static final int PADDING_TOP = 5; |
||||
|
||||
public ContainerRootTree(MyContainer container) { |
||||
this.container = container; |
||||
model = new ContainerTreeModel(container); |
||||
public MyComponentTree(MyTree tree, EventConfigPane configPane, boolean rootVisible) { |
||||
this.configPane = configPane; |
||||
model = new MyComponentTreeModel(tree); |
||||
setModel(model); |
||||
this.setBackground(UIConstants.TREE_BACKGROUND); |
||||
// 根不可见
|
||||
setRootVisible(false); |
||||
setCellRenderer(new ComponentTreeCellRenderer()); |
||||
this.setBackground(new Color(255, 255, 255)); |
||||
// 根的可见性
|
||||
setRootVisible(rootVisible); |
||||
setCellRenderer(new MyComponentCellRenderer()); |
||||
getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); |
||||
this.setDragEnabled(false); |
||||
// initListeners();
|
||||
initListener(); |
||||
setEditable(false); |
||||
setUI(uiTreeUI); |
||||
setBorder(BorderFactory.createEmptyBorder(PADDING_TOP, PADDING_LEFT, 0, 0)); |
||||
} |
||||
|
||||
private void initListener() { |
||||
this.addTreeSelectionListener(configPane); |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue