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

📄 portletbeangrid.java

📁 java 写的一个新闻发布系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package org.jahia.layout;/** * Title:        2D grid of PortletBean object, used to map notably on HTML * tables * Description:  This object offers 2D layout of portlets, allowing them to * be added to the grid, as well as interactively moved. * Copyright:    Copyright (c) 2002 * Company:      Jahia Ltd * @author Serge Huber * @version 1.0 * @todo Currently this is not optimized, we go through enumerations a lot, * we might want to add a real grid to speed up operations */import java.util.Enumeration;import org.jahia.utils.JahiaConsole;import org.jahia.exceptions.JahiaException;public class PortletBeanGrid extends PortletBeanSet {    protected int columnCount = 0;    protected int rowCount = 0;    public PortletBeanGrid() {    }    /**     * Copy constructor     * @param sourceSet original set to copy from     */    public PortletBeanGrid(PortletBeanSet sourceSet) {        Enumeration sourceElements = sourceSet.elements();        while (sourceElements.hasMoreElements()) {            PortletBean portlet = (PortletBean) sourceElements.nextElement();            this.add(portlet);        }    }    /**     * Retrieves the PortletBean at the specified position in the grid.     * @param rowID the number of the row (0-based)     * @param columnID the number of the column (0-based)     * @returns the portlet bean at the specified position, and if there is none,     * returns null     */    public PortletBean getPosPortlet(int rowID, int columnID) {        Enumeration portletList = this.elements();        while (portletList.hasMoreElements()) {            PortletBean curPortlet = (PortletBean) portletList.nextElement();            if ( (curPortlet.getPortletRow() == rowID) &&                 (curPortlet.getPortletColumn() == columnID) ) {                return curPortlet;            }        }        return null; // no portlet at that position ! Might be better to return        // an exception here !    }    /**     * Retrieves all the portlets on a given row     * @param rowID the number of the row to retrieve (0-based)     * @returns a PortletBeanSet object containing a set of the PortletBean objects     * available on that row. This set might be empty if the row doesn't exist. The     * result list is sorted according to the column position     */    public PortletBeanSet getRowPortlets(int rowID) {        Enumeration portletList = this.elements();        PortletBeanSet resultList = new PortletBeanSet();        while (portletList.hasMoreElements()) {            PortletBean curPortlet = (PortletBean) portletList.nextElement();            if (curPortlet.getPortletRow() == rowID) {                resultList.add(curPortlet);            }        }        // let's sort inside the row by column        // FIXME : this could be much faster with better sorting algorithms        PortletBeanSet sortedResultList = new PortletBeanSet();        for (int i = 0; i < resultList.size(); i++) {            for (int j = 0; j < resultList.size(); j++) {                PortletBean curPortlet = (PortletBean) resultList.elementAt(j);                if (curPortlet.getPortletColumn() == i)                    sortedResultList.add(curPortlet);            }        }        return sortedResultList;    }    /**     * Retrieves all the portlets on a given column     * @param columnID the number of the column to retrieve (0-based)     * @returns a PortletBeanSet object containing a set of the PortletBean objects     * available on that column. This set might be empty if the column doesn't exist.     */    public PortletBeanSet getColumnPortlets(int columnID) {        Enumeration portletList = this.elements();        PortletBeanSet resultList = new PortletBeanSet();        while (portletList.hasMoreElements()) {            PortletBean curPortlet = (PortletBean) portletList.nextElement();            if (curPortlet.getPortletColumn() == columnID) {                resultList.add(curPortlet);            }        }        // let's sort inside the column by row        // FIXME : this could be much faster with better sorting algorithms        PortletBeanSet sortedResultList = new PortletBeanSet();        for (int i = 0; i < resultList.size(); i++) {            for (int j = 0; j < resultList.size(); j++) {                PortletBean curPortlet = (PortletBean) resultList.elementAt(j);                if (curPortlet.getPortletRow() == i)                    sortedResultList.add(curPortlet);            }        }        return sortedResultList;    }    /**     * Move the portlet up by one row in the grid. If the row is already the top     * one no movement is down. Otherwise the movement is simply done by swapping     * positions with the portlet above the one we want to move.     * @param portletID the identifier of the portlet to move     * @throws JahiaException if the portlet corresponding to the identifier     * cannot be found.     */    public void movePortletUp(int portletID)    throws JahiaException {        PortletBean targetPortlet = findPortlet(portletID);        if (targetPortlet.getPortletRow() == 0) {            /** @todo for the moment we just do nothing, but we could also             *  decide to move everything down and insert a new first row with             *  our portlet alone on it             */        } else {            PortletBean portletToSwap = getPosPortlet(targetPortlet.getPortletRow() - 1,                                                      targetPortlet.getPortletColumn());            if (portletToSwap != null) {                portletToSwap.setPortletRow(targetPortlet.getPortletRow());            }            targetPortlet.setPortletRow(targetPortlet.getPortletRow() - 1);        }    }    /**     * Moves the portlet down one row, creating a new row if it doesn't exist     * @param portletID identifier of the portlet to be moved     * @throws JahiaException if the portlet cannot be found.     */    public void movePortletDown(int portletID)    throws JahiaException {        PortletBean targetPortlet = findPortlet(portletID);        if (targetPortlet.getPortletRow() == getRowCount()-1) {            rowCount++;        } else {            PortletBean portletToSwap = getPosPortlet(targetPortlet.getPortletRow() + 1 ,                                                      targetPortlet.getPortletColumn());            if (portletToSwap != null) {                portletToSwap.setPortletRow(targetPortlet.getPortletRow());            }        }        targetPortlet.setPortletRow(targetPortlet.getPortletRow() + 1);    }    /**     * Moves the specified portlet one column to the left. If the portlet is     * already in the leftmost column, this method does nothing.     * @param portletID identifier of the portlet to be moved     * @throws JahiaException if the portlet corresponding to the identifier     * cannot be found     */    public void movePortletLeft(int portletID)    throws JahiaException {        PortletBean targetPortlet = findPortlet(portletID);        int oldRow = targetPortlet.getPortletRow();        int oldColumn = targetPortlet.getPortletColumn();        if (targetPortlet.getPortletColumn() == 0) {            /** @todo for the moment we just do nothing, but we could also             *  decide to move everything down and insert a new first row with             *  our portlet alone on it             */        } else {            /* Let's move all the portlets in the current column up one row */            for (int i = oldRow +1; i <= getRowCount(oldColumn); i++) {                PortletBean curPortlet = getPosPortlet(i, oldColumn);                if (curPortlet != null) {                    curPortlet.setPortletRow(i-1);                }            }            /* Let's move all the portlets in the new column down to insert the portlet */            for (int i = getRowCount(oldColumn - 1) - 1; i >= oldRow; i--) {                PortletBean curPortlet = getPosPortlet(i, oldColumn - 1);                if (curPortlet != null) {                    curPortlet.setPortletRow(i+1);                }            }            /* Let's check if we are inserting in a column that is smaller than

⌨️ 快捷键说明

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