//
// OptionPane.java
//

/*
VisBio application for visualization of multidimensional
biological image data. Copyright (C) 2002-2004 Curtis Rueden.

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
*/

package loci.visbio.state;

import java.awt.Component;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import loci.visbio.util.DialogPane;

/** OptionPane provides a dialog box for adjusting VisBio's options. */
public class OptionPane extends DialogPane {

  // -- Fields --

  /** Options manager. */
  private OptionManager om;

  /** Tabbed pane. */
  private JTabbedPane tabs;


  // -- Constructor --

  /** Creates a new options pane. */
  public OptionPane(OptionManager om) {
    super("VisBio Options");
    this.om = om;
    tabs = new JTabbedPane();
    add(tabs);
  }


  // -- OptionPane API methods --

  /** Adds an option with a boolean value to the specified tab. */
  public void addOption(String tab, BioOption option) {
    JPanel tabPanel = getTab(tab);
    Component c = option.getComponent();
    if (c instanceof JComponent) {
      JComponent jc = (JComponent) c;
      jc.setAlignmentX(JComponent.LEFT_ALIGNMENT);
    }
    tabPanel.add(c);
  }

  /** Initializes a tab with the given name. */
  public void addTab(String tab) { getTab(tab); }


  // -- DialogPane API methods --

  /** Resets the dialog pane's components to their default states. */
  public void resetComponents() { tabs.setSelectedIndex(0); }


  // -- Helper methods --

  /** Gets the tab with the given name, initializing it if necessary. */
  protected JPanel getTab(String tab) {
    int ndx = tabs.indexOfTab(tab);
    if (ndx < 0) {
      JPanel p = new JPanel();
      p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
      p.setBorder(new EmptyBorder(5, 5, 5, 5));
      tabs.addTab(tab, p);
      ndx = tabs.getTabCount() - 1;
    }
    return (JPanel) tabs.getComponentAt(ndx);
  }
}

@@ -1093,16 +1093,162 @@
 Pane %7B%0A%0A
+  // -- Constants --%0A%0A  /** Flag indicating options should be divided into separate tabs. */%0A  protected static final boolean USE_TABS = false;%0A%0A%0A
   // -- 
@@ -1288,21 +1288,23 @@
  */%0A  pr
-iva
+otec
 te
+d
  OptionM
@@ -1345,13 +1345,15 @@
   pr
-ivate
+otected
  JTa
@@ -1368,16 +1368,70 @@
  tabs;%0A%0A
+  /** Non-tabbed pane. */%0A  protected JPanel noTabs;%0A%0A
 %0A  // --
@@ -1571,16 +1571,38 @@
 m = om;%0A
+    if (USE_TABS) %7B%0A  
     tabs
@@ -1627,16 +1627,18 @@
 ();%0A    
+  
 add(tabs
@@ -1640,16 +1640,152 @@
 (tabs);%0A
+    %7D%0A    else %7B%0A      noTabs = new JPanel();%0A      noTabs.setLayout(new BoxLayout(noTabs, BoxLayout.Y_AXIS));%0A      add(noTabs);%0A    %7D%0A
   %7D%0A%0A%0A  
@@ -1961,16 +1961,27 @@
 bPanel =
+ USE_TABS ?
  getTab(
@@ -1980,24 +1980,33 @@
  getTab(tab)
+ : noTabs
 ;%0A    Compon
@@ -2274,16 +2274,30 @@
 g tab) %7B
+ if (USE_TABS)
  getTab(
@@ -2444,16 +2444,30 @@
 ents() %7B
+ if (USE_TABS)
  tabs.se

Add flag for mashing all options into a single tab for now (not enough options for it to make sense to divide them into tabs).