001 /* 002 * Copyright (C) 2003 Adam Olsen 003 * This program is free software; you can redistribute it and/or modify 004 * it under the terms of the GNU General Public License as published by 005 * the Free Software Foundation; either version 1, or (at your option) 006 * any later version. 007 * This program is distributed in the hope that it will be useful, 008 * but WITHOUT ANY WARRANTY; without even the implied warranty of 009 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 010 * GNU General Public License for more details. 011 * You should have received a copy of the GNU General Public License 012 * along with this program; if not, write to the Free Software 013 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 014 */ 015 package com.valhalla.jbother; 016 017 import com.valhalla.gui.*; 018 import java.util.*; 019 import java.awt.*; 020 import javax.swing.*; 021 import com.valhalla.jbother.*; 022 import com.valhalla.settings.Settings; 023 024 public class AbstractOptionPanel extends JPanel 025 { 026 private GridBagLayout grid = new GridBagLayout(); 027 private GridBagConstraints c = new GridBagConstraints(); 028 029 public AbstractOptionPanel() 030 { 031 c.gridx = 0; 032 c.gridy = 0; 033 c.insets = new Insets( 1, 1, 1, 1 ); 034 c.ipadx = 1; 035 c.ipady = 1; 036 setBorder( BorderFactory.createEmptyBorder( 5, 5, 5, 5 ) ); 037 setLayout( grid ); 038 } 039 040 public void addComponent( String text, JComponent component ) 041 { 042 c.anchor = GridBagConstraints.WEST; 043 JLabel label = new JLabel( text + ": " ); 044 045 c.weightx = 0; 046 grid.setConstraints( label, c ); 047 add( label ); 048 c.gridx++; 049 grid.setConstraints( component, c ); 050 add( component ); 051 c.gridy++; 052 c.gridx = 0; 053 } 054 055 public void addComponent( JComponent component, int gridx, int anchor ) 056 { 057 c.anchor = anchor; 058 c.gridx = gridx; 059 c.fill = GridBagConstraints.VERTICAL; 060 grid.setConstraints( component, c ); 061 add( component ); 062 c.gridx = 0; 063 c.gridy++; 064 } 065 066 public void end() 067 { 068 c.weightx = .9; 069 c.weighty = .9; 070 c.gridwidth = 2; 071 JLabel label = new JLabel(); 072 grid.setConstraints( label, c ); 073 add( label ); 074 } 075 }