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

📄 flowview.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* FlowView.java -- A composite View   Copyright (C) 2005  Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING.  If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library.  Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule.  An independent module is a module which is not derived fromor based on this library.  If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so.  If you do not wish to do so, delete thisexception statement from your version. */package javax.swing.text;import java.awt.Container;import java.awt.Graphics;import java.awt.Rectangle;import java.awt.Shape;import java.util.Iterator;import java.util.Vector;import javax.swing.SwingConstants;import javax.swing.event.DocumentEvent;/** * A <code>View</code> that can flows it's children into it's layout space. * * The <code>FlowView</code> manages a set of logical views (that are * the children of the {@link #layoutPool} field). These are translated * at layout time into a set of physical views. These are the views that * are managed as the real child views. Each of these child views represents * a row and are laid out within a box using the superclasses behaviour. * The concrete implementation of the rows must be provided by subclasses. * * @author Roman Kennke (roman@kennke.org) */public abstract class FlowView extends BoxView{  /**   * A strategy for translating the logical views of a <code>FlowView</code>   * into the real views.   */  public static class FlowStrategy  {    /**     * Creates a new instance of <code>FlowStragegy</code>.     */    public FlowStrategy()    {      // Nothing to do here.    }    /**     * Receives notification from a <code>FlowView</code> that some content     * has been inserted into the document at a location that the     * <code>FlowView</code> is responsible for.     *     * The default implementation simply calls {@link #layout}.     *     * @param fv the flow view that sends the notification     * @param e the document event describing the change     * @param alloc the current allocation of the flow view     */    public void insertUpdate(FlowView fv, DocumentEvent e, Rectangle alloc)    {      layout(fv);    }    /**     * Receives notification from a <code>FlowView</code> that some content     * has been removed from the document at a location that the     * <code>FlowView</code> is responsible for.     *     * The default implementation simply calls {@link #layout}.     *     * @param fv the flow view that sends the notification     * @param e the document event describing the change     * @param alloc the current allocation of the flow view     */    public void removeUpdate(FlowView fv, DocumentEvent e, Rectangle alloc)    {      layout(fv);    }    /**     * Receives notification from a <code>FlowView</code> that some attributes     * have changed in the document at a location that the     * <code>FlowView</code> is responsible for.     *     * The default implementation simply calls {@link #layout}.     *     * @param fv the flow view that sends the notification     * @param e the document event describing the change     * @param alloc the current allocation of the flow view     */    public void changedUpdate(FlowView fv, DocumentEvent e, Rectangle alloc)    {      layout(fv);    }    /**     * Returns the logical view of the managed <code>FlowView</code>.     *     * @param fv the flow view for which to return the logical view     *     * @return the logical view of the managed <code>FlowView</code>     */    public View getLogicalView(FlowView fv)    {      return fv.layoutPool;    }    /**     * Performs the layout for the whole view. By default this rebuilds     * all the physical views from the logical views of the managed FlowView.     *     * This is called by {@link FlowView#layout} to update the layout of     * the view.     *     * @param fv the flow view for which we perform the layout     */    public void layout(FlowView fv)    {      fv.removeAll();      Element el = fv.getElement();      int rowStart = el.getStartOffset();      int end = el.getEndOffset();      int rowIndex = 0;      while (rowStart >= 0 && rowStart < end)        {          View row = fv.createRow();          fv.append(row);          rowStart = layoutRow(fv, rowIndex, rowStart);          rowIndex++;        }    }    /**     * Lays out one row of the flow view. This is called by {@link #layout}     * to fill one row with child views until the available span is exhausted.     *     * @param fv the flow view for which we perform the layout     * @param rowIndex the index of the row     * @param pos the start position for the row     *     * @return the start position of the next row     */    protected int layoutRow(FlowView fv, int rowIndex, int pos)    {      int spanLeft = fv.getFlowSpan(rowIndex);      if (spanLeft <= 0)        return -1;      int offset = pos;      View row = fv.getView(rowIndex);      int flowAxis = fv.getFlowAxis();      while (spanLeft > 0)        {          View child = createView(fv, offset, spanLeft, rowIndex);          if (child == null)            {              offset = -1;              break;            }          int span = (int) child.getPreferredSpan(flowAxis);          if (span > spanLeft)            {              offset = -1;              break;            }          row.append(child);          spanLeft -= span;          offset = child.getEndOffset();        }      return offset;    }    /**     * Creates physical views that form the rows of the flow view. This     * can be an entire view from the logical view (if it fits within the     * available span), a fragment of such a view (if it doesn't fit in the     * available span and can be broken down) or <code>null</code> (if it does     * not fit in the available span and also cannot be broken down).     *     * @param fv the flow view     * @param offset the start offset for the view to be created     * @param spanLeft the available span     * @param rowIndex the index of the row     *     * @return a view to fill the row with, or <code>null</code> if there     *         is no view or view fragment that fits in the available span     */    protected View createView(FlowView fv, int offset, int spanLeft,                              int rowIndex)    {      // Find the logical element for the given offset.      View logicalView = getLogicalView(fv);      int viewIndex = logicalView.getViewIndex(offset, Position.Bias.Forward);      if (viewIndex == -1)        return null;      View child = logicalView.getView(viewIndex);      int flowAxis = fv.getFlowAxis();      int span = (int) child.getPreferredSpan(flowAxis);      if (span <= spanLeft)        return child;      else if (child.getBreakWeight(flowAxis, offset, spanLeft)               > BadBreakWeight)        // FIXME: What to do with the pos parameter here?        return child.breakView(flowAxis, offset, 0, spanLeft);      else        return null;    }  }  /**   * This special subclass of <code>View</code> is used to represent   * the logical representation of this view. It does not support any   * visual representation, this is handled by the physical view implemented   * in the <code>FlowView</code>.   */  class LogicalView extends View  {    /**     * The child views of this logical view.     */    Vector children;    /**     * Creates a new LogicalView instance.     */    LogicalView(Element el)    {      super(el);      children = new Vector();    }    /**     * Returns the container that holds this view. The logical view returns     * the enclosing FlowView's container here.     *     * @return the container that holds this view     */    public Container getContainer()    {      return FlowView.this.getContainer();    }    /**     * Returns the number of child views of this logical view.     *     * @return the number of child views of this logical view     */    public int getViewCount()    {      return children.size();    }    /**     * Returns the child view at the specified index.     *     * @param index the index     *     * @return the child view at the specified index     */    public View getView(int index)    {      return (View) children.get(index);    }    /**     * Replaces some child views with other child views.     *     * @param offset the offset at which to replace child views     * @param length the number of children to remove     * @param views the views to be inserted     */    public void replace(int offset, int length, View[] views)    {      if (length > 0)        {          for (int count = 0; count < length; ++count)            children.remove(offset);        }      int endOffset = offset + views.length;      for (int i = offset; i < endOffset; ++i)        {          children.add(i, views[i - offset]);          // Set the parent of the child views to the flow view itself so          // it has something to resolve.          views[i - offset].setParent(FlowView.this);        }    }    /**     * Returns the index of the child view that contains the specified     * position in the document model.     *     * @param pos the position for which we are searching the child view     * @param b the bias     *     * @return the index of the child view that contains the specified     *         position in the document model     */    public int getViewIndex(int pos, Position.Bias b)

⌨️ 快捷键说明

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