📄 sizesequence.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Frameset//EN""http://www.w3.org/TR/REC-html40/frameset.dtd"><!--NewPage--><HTML><HEAD><!-- Generated by javadoc on Thu Apr 27 23:39:53 PDT 2000 --><TITLE>Java 2 Platform SE v1.3: Class SizeSequence</TITLE><LINK REL ="stylesheet" TYPE="text/css" HREF="../../stylesheet.css" TITLE="Style"></HEAD><BODY BGCOLOR="white"><!-- ========== START OF NAVBAR ========== --><A NAME="navbar_top"><!-- --></A><TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0"><TR><TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1"><A NAME="navbar_top_firstrow"><!-- --></A><TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3"> <TR ALIGN="center" VALIGN="top"> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD> <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="class-use/SizeSequence.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../index-files/index-1.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD> </TR></TABLE></TD><TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM><b>Java<sup><font size=-2>TM</font></sup> 2 Platform<br>Std. Ed. v1.3</b></EM></TD></TR><TR><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> <A HREF="../../javax/swing/SizeRequirements.html"><B>PREV CLASS</B></A> <A HREF="../../javax/swing/SwingUtilities.html"><B>NEXT CLASS</B></A></FONT></TD><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> <A HREF="../../index.html" TARGET="_top"><B>FRAMES</B></A> <A HREF="SizeSequence.html" TARGET="_top"><B>NO FRAMES</B></A></FONT></TD></TR><TR><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> SUMMARY: INNER | FIELD | <A HREF="#constructor_summary">CONSTR</A> | <A HREF="#method_summary">METHOD</A></FONT></TD><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">DETAIL: FIELD | <A HREF="#constructor_detail">CONSTR</A> | <A HREF="#method_detail">METHOD</A></FONT></TD></TR></TABLE><!-- =========== END OF NAVBAR =========== --><HR><!-- ======== START OF CLASS DATA ======== --><H2><FONT SIZE="-1">javax.swing</FONT><BR>Class SizeSequence</H2><PRE><A HREF="../../java/lang/Object.html">java.lang.Object</A> | +--<B>javax.swing.SizeSequence</B></PRE><HR><DL><DT>public class <B>SizeSequence</B><DT>extends <A HREF="../../java/lang/Object.html">Object</A></DL><P>A <code>SizeSequence</code> object efficiently maintains an ordered list of sizes and corresponding positions. One situation for which <code>SizeSequence</code> might be appropriate is in a component that displays multiple rows of unequal size. In this case, a single <code>SizeSequence</code> object could be used to track the heights and Y positions of all rows. <p> Another example would be a multi-column component, such as a JTable, in which the column sizes are not all equal. The JTable might use a single <code>SizeSequence</code> object to store the widths and X positions of all the columns. The JTable could then use the <code>SizeSequence</code> object to find the column corresponding to a certain position. The JTable could update the <code>SizeSequence</code> object whenever one or more column sizes changed. <p> The following figure shows the relationship between size and position data for a multi-column component. <p> <center> <img src="doc-files/SizeSequence-1.gif" width=384 height = 100 alt="The first item begins at position 0, the second at the position equalto the size of the previous item, and so on."> </center> <p> In the figure, the first index (0) corresponds to the first column, the second index (1) to the second column, and so on. The first column's position starts at 0, and the column occupies <em>size<sub>0</sub></em> pixels, where <em>size<sub>0</sub></em> is the value returned by <code>getSize(0)</code>. Thus, the first column ends at <em>size<sub>0</sub></em> - 1. The second column then begins at the position <em>size<sub>0</sub></em> and occupies <em>size<sub>1</sub></em> (<code>getSize(1)</code>) pixels. <p> Note that a <code>SizeSequence</code> object simply represents intervals along an axis. In our examples, the intervals represent height or width in pixels. However, any other unit of measure (for example, time in days) could be just as valid. <p> <h4>Implementation Notes</h4> Normally when storing the size and position of entries, one would choose between storing the sizes or storing their positions instead. The two common operations that are needed during rendering are: <code>getIndex(position)</code> and <code>setSize(index, size)</code>. Whichever choice of internal format is made one of these operations is costly when the number of entries becomes large. If sizes are stored, finding the index of the entry that encloses a particular position is linear in the number of entries. If positions are stored instead, setting the size of an entry at a particular index requires updating the positions of the affected entries, which is also a linear calculation. <p> Like the above techniques this class holds an array of N integers internally but uses a hybrid encoding, which is halfway between the size-based and positional-based approaches. The result is a data structure that takes the same space to store the information but can perform most operations in Log(N) time instead of O(N), where N is the number of entries in the list. <p> Two operations that remain O(N) in the number of entries are the <code>insertEntries</code> and <code>removeEntries</code> methods, both of which are implemented by converting the internal array to a set of integer sizes, copying it into the new array, and then reforming the hybrid representation in place.<P><HR><P><!-- ======== INNER CLASS SUMMARY ======== --><!-- =========== FIELD SUMMARY =========== --><!-- ======== CONSTRUCTOR SUMMARY ======== --><A NAME="constructor_summary"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TD COLSPAN=2><FONT SIZE="+2"><B>Constructor Summary</B></FONT></TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><B><A HREF="../../javax/swing/SizeSequence.html#SizeSequence()">SizeSequence</A></B>()</CODE><BR> Creates a new <code>SizeSequence</code> object that contains no entries.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><B><A HREF="../../javax/swing/SizeSequence.html#SizeSequence(int)">SizeSequence</A></B>(int numEntries)</CODE><BR> Creates a new <code>SizeSequence</code> object that contains the specified number of entries, all initialized to have size 0.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><B><A HREF="../../javax/swing/SizeSequence.html#SizeSequence(int[])">SizeSequence</A></B>(int[] sizes)</CODE><BR> Creates a new <code>SizeSequence</code> object that contains the specified sizes.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><B><A HREF="../../javax/swing/SizeSequence.html#SizeSequence(int, int)">SizeSequence</A></B>(int numEntries, int value)</CODE><BR> Creates a new <code>SizeSequence</code> object that contains the specified number of entries, all initialized to have size <code>value</code>.</TD></TR></TABLE> <!-- ========== METHOD SUMMARY =========== --><A NAME="method_summary"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TD COLSPAN=2><FONT SIZE="+2"><B>Method Summary</B></FONT></TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> int</CODE></FONT></TD><TD><CODE><B><A HREF="../../javax/swing/SizeSequence.html#getIndex(int)">getIndex</A></B>(int position)</CODE><BR> Returns the index of the entry that corresponds to the specified position.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> int</CODE></FONT></TD><TD><CODE><B><A HREF="../../javax/swing/SizeSequence.html#getPosition(int)">getPosition</A></B>(int index)</CODE><BR> Returns the start position for the specified entry.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> int</CODE></FONT></TD><TD><CODE><B><A HREF="../../javax/swing/SizeSequence.html#getSize(int)">getSize</A></B>(int index)</CODE><BR> Returns the size of the specified entry.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> int[]</CODE></FONT></TD><TD><CODE><B><A HREF="../../javax/swing/SizeSequence.html#getSizes()">getSizes</A></B>()</CODE><BR> Returns the size of all entries.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> void</CODE></FONT></TD><TD><CODE><B><A HREF="../../javax/swing/SizeSequence.html#insertEntries(int, int, int)">insertEntries</A></B>(int start, int length, int value)</CODE><BR> Adds a contiguous group of entries to this <code>SizeSequence</code>.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> void</CODE></FONT></TD><TD><CODE><B><A HREF="../../javax/swing/SizeSequence.html#removeEntries(int, int)">removeEntries</A></B>(int start, int length)</CODE><BR> Removes a contiguous group of entries from this <code>SizeSequence</code>.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -