⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jgrouppanel.java

📁 JGraph扩展应用。自定义Renderer,自定义视图View实现自定义工作流控件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    }
	
	public void insertGroup(String name){
		
	}

    /**
     * 插入一个组
     * @param p JPanel 目标面板
     * @param index int 顺序号
     * @param name String 组名


         /**
      * 插入一个组
      * @param p JPanel 目标面板
      * @param index int 顺序号
      * @param name String 组名
      * @return JGroupContainer
      */
     private JGroupContainer insertGroup(JPanel p, int index, String name,
                                         Color bg) {
         JGroupContainer group = new JGroupContainer(name, bg);
         p.add(group);
         return group;
     }

    /**
     * 删除一个组
     * @param index int 顺序号
     */
    public void removeGroup(int index) {
        JGroupContainer c = (JGroupContainer) groupList.get(index);
        c.getParent().remove(c);
        c.getTitleButton().removeActionListener(al);
		groupList.remove(index);
    }
	

    /**
     * 删除一个组
     * @param name String 组名
     */
    public void removeGroup(String name) {
		/*
        for (int i = getGroupCount() - 1; i >= 0; i--) {
            if (getGroupName(i).equals(name)) {
                this.removeGroup(i);
            }
        }
        */
		int index = getGroupIndex(name);
		if(index >= 0)
			removeGroup(index);
    }

    /**
     * 设置组名
     * @param index int 顺序号
     * @param name String 组名
     */
    public void setGroupName(int index, String name) {
        this.getGroup(index).setName(name);
    }

    /**
     * 取得组名
     * @param groupIndex int 顺序号
     * @return String 组名
     */
    public String getGroupName(int groupIndex) {
        return getGroup(groupIndex).getName();
    }

    /**
     * 取得全部组名
     * @return String[]
     */
    public String[] getGroupNames() {
        String sResult[] = new String[getGroupCount()];
        for (int i = 0; i < getGroupCount(); i++) {
            sResult[i] = getGroupName(i);
        }
        return sResult;
    }

    /**
     * 取得当前组的总数
     * @return int
     */
    public int getGroupCount() {
        return groupList.size();
    }

    /**
     * 往组中添加成员组件
     * @param groupIndex int 组的顺序号
     * @param member Component 成员组件
     */
    public int addMember(int groupIndex, Component member) {
		int i = getGroup(groupIndex).getMemberCount();
        getGroup(groupIndex).addMember(getGroup(groupIndex).getMemberCount(),
                                       member);
		return i;
    }
	
	public void addMember(String groupName, Component member){
		int index = getGroupIndex(groupName);
		if(index >= 0){
			addMember(index, member);
		}
	}
	
	public void addUserObject(int groupIndex, Object obj){
		getGroup(groupIndex).addUserObject(obj);
	}
	
	public void addUserObject(String name, Object obj){
		int index = getGroupIndex(name);
		if(index >= 0)
			getGroup(index).addUserObject(obj);
	}
	
	public Object getUserObject(String name){
		//System.out.println("name="+name);
		int index = getGroupIndex(name);
		if(index >= 0){
			//System.out.println("0==========");
			return getGroup(index).getUserObject();
		}
		//System.out.println("1==========");
		return null;
	}
	
	public Object getUserObject(int groupIndex){
		return getGroup(groupIndex).getUserObject();
	}

    /**
     * 往组中插入成员组件
     * @param groupIndex int 组的顺序号
     * @param memberIndex int 插入的顺序号
     * @param member Component 成员组件
     */
    public void insertMember(int groupIndex, int memberIndex, Component member) {
        getGroup(groupIndex).addMember(memberIndex, member);
    }

    /**
     * 从组中移除成员组件
     * @param groupIndex int
     * @param memberIndex int
     */
    public void removeMember(int groupIndex, int memberIndex) {
        getGroup(groupIndex).removeMember(memberIndex);
    }

	public int getGroupIndex(String name){
        for (int i = getGroupCount() - 1; i >= 0; i--) {
			//System.out.println("groupName"+i+"="+getGroupName(i)+",name="+name);
            if (getGroupName(i).equals(name)) {
				return i;
            }
        }
		return -1;
	}
		
	public void removeMember(String groupName, String memberName){
		int index = getGroupIndex(groupName);
		//System.out.println("1---------"+index);
		if(index >= 0){
			//System.out.println("2---------"+index);
			for(int i=0;i<getMemberCount(index);i++){
				SelectButton sb = (SelectButton)getMember(index, i);
				if(sb.getActionCommand().equals(memberName)){
					removeMember(index, i);
				}
			}
		}
	}
    /**
     * 取得成员组件
     * @param groupIndex int 组的顺序号
     * @param memberIndex int 成员组件的顺序号
     * @return Component 成员组件
     */
    public Component getMember(int groupIndex, int memberIndex) {
        return getGroup(groupIndex).getMember(memberIndex);
    }

    /**
     * 取得全部成员组件
     * @param groupIndex int 组的顺序号
     * @return Component[] 全部成员组件
     */
    public Component[] getMembers(int groupIndex) {
        return getGroup(groupIndex).getMembers();
    }

    /**
     * 取得成员组件的总数
     * @param groupIndex int 组的顺序号
     * @return int 总数
     */
    public int getMemberCount(int groupIndex) {
        return getGroup(groupIndex).getMemberCount();
    }

    /**
     * 取得组
     * @param index int 组的顺序号
     * @return JGroupContainer 组
     */
    public JGroupContainer getGroup(int index) {
        return (JGroupContainer) groupList.get(index);
    }

    public JGroupContainer getGroup(String name) {
		int index = getGroupIndex(name);
        return (JGroupContainer) groupList.get(index);
    }

    /**
     * 覆写的addImpl方法,禁止再向JGroupPane中添加组件
     * @param comp Component
     * @param constraints Object
     * @param index int
     */
    protected void addImpl(Component comp, Object constraints, int index) {
        if (forbidFlag) {
            if (! (comp instanceof JGroupContainer)) {
                throw new UnsupportedOperationException(
                    "JGroupPane can't add component!");
            }
        }
        else {
            super.addImpl(comp, constraints, index);
        }
    }

    /**
     * <p>Title: OpenSwing</p>
     * <p>Description: 组面板布局管理器</p>
     * <p>Copyright: Copyright (c) 2004</p>
     * <p>Company: </p>
     * @author <a href="mailto:sunkingxie@hotmail.com">SunKing</a>
     * @version 1.0
     */


    /**
         /**
      * 测试程序
      * @param args String[]
      */
     public static void main(String[] args){
		 System.out.println(Color.LIGHT_GRAY);
         JFrame frame = new JFrame("JGroupPanel Demo");
		 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         frame.getContentPane().setLayout(new BorderLayout());
		 JGroupPanel group = new JGroupPanel();
		 		 
		 group.createDefaultGroup();
		 
		 
         frame.getContentPane().add(group, BorderLayout.CENTER);
         frame.setSize(150, 600);
         Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
         frame.setLocation(d.width - frame.getSize().width - 10, 10);
         frame.setVisible(true);
     }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -