From: Stephen C. <cr...@us...> - 2006-01-14 15:07:28
|
Update of /cvsroot/lexi/lexi/src/com/jmonkey/office/lexi/support/editors In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18901/src/com/jmonkey/office/lexi/support/editors Modified Files: OfficeDocumentEditor.java OfficeDocumentEditorKit.java OfficeStyleConstants.java Log Message: Implemented different units for layout measures; e.g. inches, points, cms, etc Index: OfficeDocumentEditorKit.java =================================================================== RCS file: /cvsroot/lexi/lexi/src/com/jmonkey/office/lexi/support/editors/OfficeDocumentEditorKit.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** OfficeDocumentEditorKit.java 19 Dec 2005 14:12:12 -0000 1.4 --- OfficeDocumentEditorKit.java 14 Jan 2006 15:07:17 -0000 1.5 *************** *** 70,74 **** private int m_height, m_width; - private int m_topMargin, m_bottomMargin, m_leftMargin, m_rightMargin; public PageView(Element elem) { --- 70,73 ---- *************** *** 81,85 **** public void changedUpdate(DocumentEvent changes, Shape a, ViewFactory f) { - System.err.println("changeUpdate"); AttributeSet attr = getAttributes(); if (attr != null) { --- 80,83 ---- *************** *** 91,110 **** private void updateFromAttributes(AttributeSet attr) { ! float height = OfficeStyleConstants.getPageHeight(attr); ! float width = OfficeStyleConstants.getPageWidth(attr); ! float leftMargin = OfficeStyleConstants.getPageLeftMargin(attr); ! float rightMargin = OfficeStyleConstants.getPageRightMargin(attr); ! float topMargin = OfficeStyleConstants.getPageTopMargin(attr); ! float bottomMargin = OfficeStyleConstants.getPageBottomMargin(attr); m_height = (int) height; m_width = (int) width; ! m_topMargin = (int) topMargin; ! m_bottomMargin = (int) bottomMargin; ! m_leftMargin = (int) leftMargin; ! m_rightMargin = (int) rightMargin; preferenceChanged(this, true, true); m_editor.setPageSize(new Dimension(m_width, m_height)); - System.err.println("Set page size to " + m_width + ", " + m_height); } --- 89,105 ---- private void updateFromAttributes(AttributeSet attr) { ! double height = OfficeStyleConstants.getPageHeight(attr); ! double width = OfficeStyleConstants.getPageWidth(attr); ! double leftMargin = OfficeStyleConstants.getPageLeftMargin(attr); ! double rightMargin = OfficeStyleConstants.getPageRightMargin(attr); ! double topMargin = OfficeStyleConstants.getPageTopMargin(attr); ! double bottomMargin = OfficeStyleConstants.getPageBottomMargin(attr); m_height = (int) height; m_width = (int) width; ! setInsets((short) topMargin, (short) leftMargin, ! (short) bottomMargin, (short) rightMargin); preferenceChanged(this, true, true); m_editor.setPageSize(new Dimension(m_width, m_height)); } *************** *** 136,170 **** Rectangle a = (Rectangle) allocation; m_border.paintBorder(null, g, a.x, a.y, a.width, a.height); ! Rectangle childAllocation = new Rectangle( ! a.x + m_leftMargin, ! a.y + m_topMargin, ! a.width - m_leftMargin - m_rightMargin, ! a.height - m_topMargin - m_bottomMargin); m_margins.paintBorder(null, g, childAllocation.x, childAllocation.y, childAllocation.width, childAllocation.height); layout(childAllocation.width, childAllocation.height); ! super.paint(g, childAllocation); } public Shape modelToView(int pos, Shape a, Bias b) throws BadLocationException { ! Rectangle bounds = a.getBounds(); ! Rectangle childBounds = ! new Rectangle(bounds.x + m_leftMargin, ! bounds.y + m_topMargin, ! bounds.width - m_leftMargin - m_rightMargin, ! bounds.height - m_topMargin - m_bottomMargin); ! return super.modelToView(pos, childBounds, b); } public int viewToModel(float x, float y, Shape a, Bias[] bias) { ! Rectangle bounds = a.getBounds(); ! Rectangle childBounds = ! new Rectangle(bounds.x + m_leftMargin, ! bounds.y + m_topMargin, ! bounds.width - m_leftMargin - m_rightMargin, ! bounds.height - m_topMargin - m_bottomMargin); ! if (childBounds.contains((int) x, (int) y)) { ! return super.viewToModel(x, y, childBounds, bias); } else { --- 131,149 ---- Rectangle a = (Rectangle) allocation; m_border.paintBorder(null, g, a.x, a.y, a.width, a.height); ! Rectangle childAllocation = getInsideAllocation(allocation); m_margins.paintBorder(null, g, childAllocation.x, childAllocation.y, childAllocation.width, childAllocation.height); layout(childAllocation.width, childAllocation.height); ! super.paint(g, allocation); } public Shape modelToView(int pos, Shape a, Bias b) throws BadLocationException { ! return super.modelToView(pos, a, b); } public int viewToModel(float x, float y, Shape a, Bias[] bias) { ! if (a.contains((int) x, (int) y)) { ! return super.viewToModel(x, y, a, bias); } else { *************** *** 249,260 **** throws IOException, BadLocationException { ! throw new UnsupportedOperationException("read(Reader, Document, int)"); } ! public void install(JEditorPane editor) ! { super.install(editor); m_viewFactory = new OfficeViewFactory(); - System.err.println("install: this is " + this + ", editor is " + editor); m_editor = (EditorTextPane) editor; } --- 228,240 ---- throws IOException, BadLocationException { ! int ch; ! while ((ch = reader.read()) != -1) { ! doc.insertString(pos++, Character.toString((char) ch), null); ! } } ! public void install(JEditorPane editor) { super.install(editor); m_viewFactory = new OfficeViewFactory(); m_editor = (EditorTextPane) editor; } *************** *** 262,266 **** public void deinstall(JEditorPane editor) { super.deinstall(editor); - System.err.println("deinstall: this is " + this); m_editor = null; } --- 242,245 ---- Index: OfficeDocumentEditor.java =================================================================== RCS file: /cvsroot/lexi/lexi/src/com/jmonkey/office/lexi/support/editors/OfficeDocumentEditor.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** OfficeDocumentEditor.java 19 Dec 2005 14:12:12 -0000 1.4 --- OfficeDocumentEditor.java 14 Jan 2006 15:07:17 -0000 1.5 *************** *** 102,106 **** public void setPageAttributes(AttributeSet attr, boolean replace) { - System.err.println("setPageAttributes " + attr); OfficeDocument doc = (OfficeDocument) m_editor.getStyledDocument(); doc.setPageAttributes(attr, replace); --- 102,105 ---- Index: OfficeStyleConstants.java =================================================================== RCS file: /cvsroot/lexi/lexi/src/com/jmonkey/office/lexi/support/editors/OfficeStyleConstants.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** OfficeStyleConstants.java 19 Dec 2005 14:12:12 -0000 1.1 --- OfficeStyleConstants.java 14 Jan 2006 15:07:17 -0000 1.2 *************** *** 84,158 **** } ! public static float getPageHeight(AttributeSet attrs) { ! Float v = (Float) attrs.getAttribute(PageHeight); if (v != null) { ! return v.floatValue(); } ! return (float) getPaperSize().getHeight(); } ! public static float getPageWidth(AttributeSet attrs) { ! Float v = (Float) attrs.getAttribute(PageWidth); if (v != null) { ! return v.floatValue(); } ! return (float) getPaperSize().getWidth(); } ! public static float getPageTopMargin(AttributeSet attrs) { ! Float v = (Float) attrs.getAttribute(PageTopMargin); if (v != null) { ! return v.floatValue(); } return 24; } ! public static float getPageBottomMargin(AttributeSet attrs) { ! Float v = (Float) attrs.getAttribute(PageBottomMargin); if (v != null) { ! return v.floatValue(); } return 24; } ! public static float getPageLeftMargin(AttributeSet attrs) { ! Float v = (Float) attrs.getAttribute(PageLeftMargin); if (v != null) { ! return v.floatValue(); } return 24; } ! public static float getPageRightMargin(AttributeSet attrs) { ! Float v = (Float) attrs.getAttribute(PageRightMargin); if (v != null) { ! return v.floatValue(); } return 24; } ! public static void setPageWidth(MutableAttributeSet attrs, float value) { ! attrs.addAttribute(PageWidth, new Float(value)); } ! public static void setPageHeight(MutableAttributeSet attrs, float value) { ! attrs.addAttribute(PageHeight, new Float(value)); } ! public static void setPageTopMargin(MutableAttributeSet attrs, float value) { ! attrs.addAttribute(PageTopMargin, new Float(value)); } ! public static void setPageBottomMargin(MutableAttributeSet attrs, float value) { ! attrs.addAttribute(PageBottomMargin, new Float(value)); } ! public static void setPageLeftMargin(MutableAttributeSet attrs, float value) { ! attrs.addAttribute(PageLeftMargin, new Float(value)); } ! public static void setPageRightMargin(MutableAttributeSet attrs, float value) { ! attrs.addAttribute(PageRightMargin, new Float(value)); } --- 84,158 ---- } ! public static double getPageHeight(AttributeSet attrs) { ! Double v = (Double) attrs.getAttribute(PageHeight); if (v != null) { ! return v.doubleValue(); } ! return getPaperSize().getHeight(); } ! public static double getPageWidth(AttributeSet attrs) { ! Double v = (Double) attrs.getAttribute(PageWidth); if (v != null) { ! return v.doubleValue(); } ! return getPaperSize().getWidth(); } ! public static double getPageTopMargin(AttributeSet attrs) { ! Double v = (Double) attrs.getAttribute(PageTopMargin); if (v != null) { ! return v.doubleValue(); } return 24; } ! public static double getPageBottomMargin(AttributeSet attrs) { ! Double v = (Double) attrs.getAttribute(PageBottomMargin); if (v != null) { ! return v.doubleValue(); } return 24; } ! public static double getPageLeftMargin(AttributeSet attrs) { ! Double v = (Double) attrs.getAttribute(PageLeftMargin); if (v != null) { ! return v.doubleValue(); } return 24; } ! public static double getPageRightMargin(AttributeSet attrs) { ! Double v = (Double) attrs.getAttribute(PageRightMargin); if (v != null) { ! return v.doubleValue(); } return 24; } ! public static void setPageWidth(MutableAttributeSet attrs, double value) { ! attrs.addAttribute(PageWidth, new Double(value)); } ! public static void setPageHeight(MutableAttributeSet attrs, double value) { ! attrs.addAttribute(PageHeight, new Double(value)); } ! public static void setPageTopMargin(MutableAttributeSet attrs, double value) { ! attrs.addAttribute(PageTopMargin, new Double(value)); } ! public static void setPageBottomMargin(MutableAttributeSet attrs, double value) { ! attrs.addAttribute(PageBottomMargin, new Double(value)); } ! public static void setPageLeftMargin(MutableAttributeSet attrs, double value) { ! attrs.addAttribute(PageLeftMargin, new Double(value)); } ! public static void setPageRightMargin(MutableAttributeSet attrs, double value) { ! attrs.addAttribute(PageRightMargin, new Double(value)); } *************** *** 164,168 **** String paper = Lexi.getRegistry().getString("MAIN", "paper.size"); LayoutUnits.PaperSize res = LayoutUnits.paperSize(paper); - System.err.println("paper size " + paper + " -> " + res); return res; } --- 164,167 ---- |