View | Details | Raw Unified | Return to bug 10884
Collapse All | Expand All

(-)src/java/org/apache/poi/hssf/dev/BiffViewer.java (-1 / +12 lines)
Lines 609-615 Link Here
609
            case LegendRecord.sid:
609
            case LegendRecord.sid:
610
                retval = new LegendRecord(rectype, size, data);
610
                retval = new LegendRecord(rectype, size, data);
611
                break;
611
                break;
612
                
612
	    case LeftMarginRecord.sid:
613
	        retval = new LeftMarginRecord(rectype, size, data);
614
	        break;
615
	    case RightMarginRecord.sid:
616
	        retval = new RightMarginRecord(rectype, size, data);
617
	        break;
618
	    case TopMarginRecord.sid:
619
	        retval = new TopMarginRecord(rectype, size, data);
620
	        break;
621
	    case BottomMarginRecord.sid:
622
	        retval = new BottomMarginRecord(rectype, size, data);
623
	        break;
613
                
624
                
614
            default:
625
            default:
615
                retval = new UnknownRecord(rectype, size, data);
626
                retval = new UnknownRecord(rectype, size, data);
(-)src/java/org/apache/poi/hssf/model/Sheet.java (+87 lines)
Lines 92-97 Link Here
92
public class Sheet
92
public class Sheet
93
    extends java.lang.Object
93
    extends java.lang.Object
94
{
94
{
95
    public static final short LeftMargin = 0;
96
    public static final short RightMargin = 1;
97
    public static final short TopMargin = 2;
98
    public static final short BottomMargin = 3;
99
95
    protected ArrayList              records        = null;
100
    protected ArrayList              records        = null;
96
    int                              preoffset      =
101
    int                              preoffset      =
97
        0;      // offset of the sheet in a new file
102
        0;      // offset of the sheet in a new file
Lines 2031-2034 Link Here
2031
	printGridlines = newPrintGridlines;
2036
	printGridlines = newPrintGridlines;
2032
    }
2037
    }
2033
2038
2039
    /**
2040
     * Sets whether the sheet is selected
2041
     * @param sel True to select the sheet, false otherwise.
2042
     */
2043
    public void setSelected(boolean sel) {
2044
	WindowTwoRecord windowTwo = (WindowTwoRecord) findFirstRecordBySid(WindowTwoRecord.sid);
2045
	windowTwo.setSelected(sel);
2046
    }
2047
2048
    /**
2049
     * Gets the size of the margin in inches.
2050
     * @param margin which margin to get
2051
     * @return the size of the margin
2052
     */
2053
    public double getMargin(short margin) {
2054
	Margin m;
2055
	switch (margin) {
2056
	case LeftMargin : 
2057
	    m = (Margin)findFirstRecordBySid(LeftMarginRecord.sid);
2058
	    if (m == null) 
2059
		return .75;
2060
	    break;
2061
	case RightMargin : 
2062
	    m = (Margin)findFirstRecordBySid(RightMarginRecord.sid);
2063
	    if (m == null) 
2064
		return .75;
2065
	    break;
2066
	case TopMargin : 
2067
	    m = (Margin)findFirstRecordBySid(TopMarginRecord.sid);
2068
	    if (m == null) 
2069
		return 1.0;
2070
	    break;
2071
	case BottomMargin : 
2072
	    m = (Margin)findFirstRecordBySid(BottomMarginRecord.sid);
2073
	    if (m == null) 
2074
		return 1.0;
2075
	    break;
2076
	default : throw new RuntimeException("Unknown margin constant:  " + margin);
2077
	}
2078
	return m.getMargin();
2079
    }
2080
2081
    /**
2082
     * Sets the size of the margin in inches.
2083
     * @param margin which margin to get
2084
     * @param size the size of the margin
2085
     */
2086
    public void setMargin(short margin, double size) {
2087
	Margin m;
2088
	switch (margin) {
2089
	case LeftMargin : 
2090
	    m = (Margin)findFirstRecordBySid(LeftMarginRecord.sid);
2091
	    if (m == null) {
2092
		m = new LeftMarginRecord();
2093
		records.add(getDimsLoc() + 1, (Record)m);
2094
	    }
2095
	    break;
2096
	case RightMargin : 
2097
	    m = (Margin)findFirstRecordBySid(RightMarginRecord.sid);
2098
	    if (m == null) {
2099
		m = new RightMarginRecord();
2100
		records.add(getDimsLoc() + 1, (Record)m);
2101
	    }
2102
	    break;
2103
	case TopMargin : 
2104
	    m = (Margin)findFirstRecordBySid(TopMarginRecord.sid);
2105
	    if (m == null) {
2106
		m = new TopMarginRecord();
2107
		records.add(getDimsLoc() + 1, (Record)m);
2108
	    }
2109
	    break;
2110
	case BottomMargin : 
2111
	    m = (Margin)findFirstRecordBySid(BottomMarginRecord.sid);
2112
	    if (m == null) {
2113
		m = new BottomMarginRecord();
2114
		records.add(getDimsLoc() + 1, (Record)m);
2115
	    }
2116
	    break;
2117
	default : throw new RuntimeException("Unknown margin constant:  " + margin);
2118
	}
2119
	m.setMargin(size);
2120
    }
2034
}
2121
}
(-)src/java/org/apache/poi/hssf/record/RecordFactory.java (-2 / +5 lines)
Lines 107-113 Link Here
107
                LabelRecord.class, BlankRecord.class, ColumnInfoRecord.class,
107
                LabelRecord.class, BlankRecord.class, ColumnInfoRecord.class,
108
                MulRKRecord.class, MulBlankRecord.class, MergeCellsRecord.class,
108
                MulRKRecord.class, MulBlankRecord.class, MergeCellsRecord.class,
109
                FormulaRecord.class, BoolErrRecord.class, ExternSheetRecord.class,
109
                FormulaRecord.class, BoolErrRecord.class, ExternSheetRecord.class,
110
		NameRecord.class
110
		NameRecord.class, LeftMarginRecord.class, RightMarginRecord.class, 
111
		TopMarginRecord.class, BottomMarginRecord.class
111
            };
112
            };
112
        } else {
113
        } else {
113
            records = new Class[]
114
            records = new Class[]
Lines 135-141 Link Here
135
                WindowTwoRecord.class, SelectionRecord.class, ContinueRecord.class,
136
                WindowTwoRecord.class, SelectionRecord.class, ContinueRecord.class,
136
                LabelRecord.class, BlankRecord.class, ColumnInfoRecord.class,
137
                LabelRecord.class, BlankRecord.class, ColumnInfoRecord.class,
137
                MulRKRecord.class, MulBlankRecord.class, MergeCellsRecord.class,
138
                MulRKRecord.class, MulBlankRecord.class, MergeCellsRecord.class,
138
                BoolErrRecord.class, ExternSheetRecord.class, NameRecord.class
139
                BoolErrRecord.class, ExternSheetRecord.class, NameRecord.class,
140
		LeftMarginRecord.class, RightMarginRecord.class, 
141
		TopMarginRecord.class, BottomMarginRecord.class
139
            };
142
            };
140
            
143
            
141
        }
144
        }
(-)src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java (+33 lines)
Lines 65-70 Link Here
65
import org.apache.poi.hssf.record.Record;
65
import org.apache.poi.hssf.record.Record;
66
import org.apache.poi.hssf.record.RowRecord;
66
import org.apache.poi.hssf.record.RowRecord;
67
import org.apache.poi.hssf.record.VCenterRecord;
67
import org.apache.poi.hssf.record.VCenterRecord;
68
import org.apache.poi.hssf.record.WindowTwoRecord;
68
import org.apache.poi.hssf.record.WSBoolRecord;
69
import org.apache.poi.hssf.record.WSBoolRecord;
69
import org.apache.poi.hssf.util.Region;
70
import org.apache.poi.hssf.util.Region;
70
import org.apache.poi.util.POILogFactory;
71
import org.apache.poi.util.POILogFactory;
Lines 85-90 Link Here
85
{
86
{
86
    private static final int DEBUG = POILogger.DEBUG;
87
    private static final int DEBUG = POILogger.DEBUG;
87
88
89
    /* Constants for margins */
90
    public static final short LeftMargin = Sheet.LeftMargin;
91
    public static final short RightMargin = Sheet.RightMargin;
92
    public static final short TopMargin = Sheet.TopMargin;
93
    public static final short BottomMargin = Sheet.BottomMargin;
94
88
    /**
95
    /**
89
     * Used for compile-time optimization.  This is the initial size for the collection of
96
     * Used for compile-time optimization.  This is the initial size for the collection of
90
     * rows.  It is currently set to 20.  If you generate larger sheets you may benefit
97
     * rows.  It is currently set to 20.  If you generate larger sheets you may benefit
Lines 784-788 Link Here
784
     */
791
     */
785
    public HSSFFooter getFooter() {
792
    public HSSFFooter getFooter() {
786
        return new HSSFFooter(getSheet().getFooter());
793
        return new HSSFFooter(getSheet().getFooter());
794
     }
795
     /**
796
      * Sets whether sheet is selected.
797
      * @param sel Whether to select the sheet or deselect the sheet.
798
      */
799
     public void setSelected(boolean sel) {
800
       getSheet().setSelected(sel); 
801
802
     }
803
804
    /**
805
     * Gets the size of the margin in inches.
806
     * @param margin which margin to get
807
     * @return the size of the margin
808
     */
809
    public double getMargin(short margin) {
810
	return getSheet().getMargin(margin);
811
    }
812
813
    /**
814
     * Sets the size of the margin in inches.
815
     * @param margin which margin to get
816
     * @param size the size of the margin
817
     */
818
    public void setMargin(short margin, double size) {
819
	getSheet().setMargin(margin, size);
787
    }
820
    }
788
}
821
}

Return to bug 10884