// --------------------------------------- // Restricted Focus Viewer (RFV) Program // Version 2.1 // Language: Java 2 // October, 2000 // Copyright (C) 2000 Anthony R. Jansen // --------------------------------------- // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // --------------------------------------- // RFV_Display_Column.java // // Class for specifying display elements // to be set out in a vertical column. // --------------------------------------- import java.util.*; import java.awt.Graphics; public class RFV_Display_Column extends RFV_Display_Element { // Variables for column elements // ----------------------------- private LinkedList column_elements; private int num_flexible_spaces; private boolean calculated; // Constructor // ----------- public RFV_Display_Column() { super(false, false); calculated = false; num_flexible_spaces = 0; column_elements = new LinkedList(); } // Add an element to the column // ---------------------------- public void addElement(RFV_Display_Element element) { column_elements.add(element); element.setParent(this); if (element.isFlexibleSpace()) num_flexible_spaces++; } // Returns the number of elements // ------------------------------ public int getNumberOfElements() { return column_elements.size(); } // Returns the indexed element // --------------------------- public RFV_Display_Element getElement(int index) { RFV_Display_Element element = null; try { element = (RFV_Display_Element) column_elements.get(index); } catch(IndexOutOfBoundsException e) { RFV_Error.die(49); } return element; } // Adds flexible space to ends of the column // if it is needed, otherwise does nothing // ----------------------------------------- public void addFlexibleSpace() { if (num_flexible_spaces == 0) { column_elements.add(new RFV_V_Space()); column_elements.addFirst(new RFV_V_Space()); num_flexible_spaces = 2; } } // Draws column // ------------ public void draw(Graphics g) { for (int i = 0; i < getNumberOfElements(); i++) getElement(i).draw(g); } // Calculates the column dimensions if not previously done // ------------------------------------------------------- public void calculateDimensions() { RFV_Display_Element element; int maximum_width = 0; if (calculated) return; height = 0; for (int i = 0; i < getNumberOfElements(); i++) { element = getElement(i); if (!element.isSingleElement()) ((RFV_Display_Row) element).calculateDimensions(); if (element.getWidth() > maximum_width) maximum_width = element.getWidth(); height += element.getHeight(); } width = maximum_width; calculated = true; } // Allocates extra height to the flexible spaces // so that the column has the new specified height // ----------------------------------------------- public void extendHeightTo(int h) { RFV_Display_Element element; int modulus; int division; if (!calculated) return; addFlexibleSpace(); modulus = (h - height) % num_flexible_spaces; division = (h - height - modulus) / num_flexible_spaces; for (int i = 0; i < getNumberOfElements(); i++) { element = getElement(i); if (element.isFlexibleSpace()) { if (modulus > 0) { ((RFV_V_Space) element).setHeight(division + 1); modulus--; } else ((RFV_V_Space) element).setHeight(division); } else if (!element.isSingleElement()) ((RFV_Display_Row) element).extendWidthTo(width); } height = h; } // Calculates the top left co-ordinates (x_offset, y_offset) // of all of the elements in the column // --------------------------------------------------------- public void calculateOffsets() { RFV_Display_Element element; int x_loc; int y_loc; if (!calculated) return; y_loc = y_offset; for (int i = 0; i < getNumberOfElements(); i++) { element = getElement(i); x_loc = ((width - element.getWidth()) / 2) + x_offset; element.setLocation(x_loc, y_loc); if (!element.isSingleElement()) ((RFV_Display_Row) element).calculateOffsets(); y_loc += element.getHeight(); } } }