|
GridPeer |
|
/* ** Luxor - XML User Interface Language (XUL) Toolkit ** Copyright (c) 2001, 2002 by Gerald Bauer ** ** This program is free software. ** ** You may redistribute it and/or modify it under the terms of the GNU ** General Public License as published by the Free Software Foundation. ** Version 2 of the license should be included with this distribution in ** the file LICENSE, as well as License.html. If the license is not ** included with this distribution, you may find a copy at the FSF web ** site at 'www.gnu.org' or 'www.fsf.org', or you may write to the ** Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139 USA. ** ** THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND, ** NOT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY. THE AUTHOR ** OF THIS SOFTWARE, ASSUMES _NO_ RESPONSIBILITY FOR ANY ** CONSEQUENCE RESULTING FROM THE USE, MODIFICATION, OR ** REDISTRIBUTION OF THIS SOFTWARE. ** */ package luxor.swing; import java.awt.Component; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.util.*; import javax.swing.*; import luxor.core.*; import luxor.core.grid.*; import luxor.spi.*; import luxor.status.*; public class GridPeer extends AbstractContainer { static Logger T = Logger.getLogger( GridPeer.class ); private JPanel _panel; public GridPeer( GridDef def, JComponentResolver resolver ) { super( def ); _panel = new JPanel(); _panel.setLayout( new GridBagLayout() ); // fix: use flex attributes List rows = def.getRowsDef().getRowDefs(); List columns = def.getColumnsDef().getColumnDefs(); int columnCount = columns.size(); int rowCount = rows.size(); for( int row = 0; row < rowCount; row++ ) { RowDef rowDef = ( RowDef ) rows.get( row ); Iterator colIt = rowDef.getColumns().iterator(); for( int col = 0; col < columnCount; col++ ) { GridBagConstraints con = new GridBagConstraints(); int horz = Xul.Align.LEFT; int vert = Xul.Align.MIDDLE; con.gridx = col; con.gridy = row; con.weightx = 0; con.weighty = 0; con.gridwidth = 1; con.gridheight = 1; con.fill = GridBagConstraints.NONE; if( horz == Xul.Align.LEFT && vert == Xul.Align.MIDDLE ) { con.anchor = GridBagConstraints.WEST; } if( colIt.hasNext() ) { NComponentFactory f = ( NComponentFactory ) colIt.next(); NComponent comp = f.createNComponent( resolver ); _panel.add( comp.getJComponent(), con ); addComponent( comp ); } else { // add empty cell _panel.add( new JLabel( "" ), con ); } } } resolveReferences(); } public JComponent getJComponent() { return _panel; } public boolean useMinHeight() { return false; } public boolean useMinWidth() { return false; } }
|
GridPeer |
|