gt:             if (!tabSelected) {
context: // $Id: DetailsPane.java 127 2010-09-25 22:23:13Z marcusvnac $
  // Copyright (c) 1996-2008 The Regents of the University of California. All
  // Rights Reserved. Permission to use, copy, modify, and distribute this
  // software and its documentation without fee, and without a written
  // agreement is hereby granted, provided that the above copyright notice
  // and this paragraph appear in all copies.  This software program and
  // documentation are copyrighted by The Regents of the University of
  // California. The software program and documentation are supplied "AS
  // IS", without any accompanying services from The Regents. The Regents
  // does not warrant that the operation of the program will be
  // uninterrupted or error-free. The end-user understands that the program
  // was developed for research purposes and is advised not to rely
  // exclusively on the program for any reason.  IN NO EVENT SHALL THE
  // UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
  // SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
  // ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
  // THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
  // SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
  // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
  // PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
  // CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
  // UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  
  package org.argouml.ui;
  
  import java.awt.BorderLayout;
  import java.awt.Component;
  import java.awt.Dimension;
  import java.awt.Font;
  import java.awt.Rectangle;
  import java.awt.event.MouseEvent;
  import java.awt.event.MouseListener;
  import java.util.ArrayList;
  import java.util.Iterator;
  import java.util.List;
  
  import javax.swing.Icon;
  import javax.swing.JPanel;
  import javax.swing.JTabbedPane;
  import javax.swing.event.ChangeEvent;
  import javax.swing.event.ChangeListener;
  import javax.swing.event.EventListenerList;
  
  //#if defined(LOGGING)
  //@#$LPS-LOGGING:GranularityType:Import
  import org.apache.log4j.Logger;
  //#endif
  import org.argouml.application.api.AbstractArgoJPanel;
  import org.argouml.i18n.Translator;
  import org.argouml.model.Model;
  import org.argouml.swingext.LeftArrowIcon;
  import org.argouml.swingext.UpArrowIcon;
  import org.argouml.ui.ProjectBrowser.Position;
  import org.argouml.ui.targetmanager.TargetEvent;
  import org.argouml.ui.targetmanager.TargetListener;
  import org.argouml.ui.targetmanager.TargetManager;
  import org.argouml.uml.ui.PropPanel;
  import org.argouml.uml.ui.TabProps;
  import org.tigris.swidgets.Orientable;
  import org.tigris.swidgets.Orientation;
  
  /**
   * The lower-right pane of the main ArgoUML window, which shows
   * the details of a selected model element. <p>
   *
   * This panel has several tabs that show details of the selected
   * ToDoItem, or the selected model element in the Explorer (NavigatorPane),
   * or the MultiEditorPane. <p>
   *
   * There are requests to have the cursor automatically
   * be set to the primary field.
   */
  public class DetailsPane
      extends JPanel
      implements ChangeListener, MouseListener,
  	       Orientable,
  	       TargetListener {
      //#if defined(LOGGING)
      //@#$LPS-LOGGING:GranularityType:Field
      /**
       * Logger.
       */
      private static final Logger LOG = Logger.getLogger(DetailsPane.class);
      //#endif
      /**
       * The top level pane, which is a tabbed pane.
       */
      private JTabbedPane topLevelTabbedPane = new JTabbedPane();
  
      /**
       * The current target.
       */
      private Object currentTarget;
  
      
      /**
       * The list of all the tabs, which are JPanels, in the JTabbedPane tabs.
       */
      private List<JPanel> tabPanelList = new ArrayList<JPanel>();
  
      /**
       * index of the selected tab in the JTabbedPane.
       */
      private int lastNonNullTab = -1;
  
      /**
       * The list with targetlisteners, this are the property panels
       * managed by TabProps It should only contain one listener at a
       * time.
       */
      private EventListenerList listenerList = new EventListenerList();
      
      private Orientation orientation;
      
      private boolean hasTabs = false;
  
      /**
       * Adds a listener.
       * @param listener the listener to add
       */
      private void addTargetListener(TargetListener listener) {
          listenerList.add(TargetListener.class, listener);
      }
  
      /**
       * Removes a target listener.
       * @param listener the listener to remove
       */
      private void removeTargetListener(TargetListener listener) {
          listenerList.remove(TargetListener.class, listener);
      }
  
      /**
       * Gets all of the tabPanels from the ConfigLoader, then
       * adds them to the JTabbedPane.<p>
       *
       * Sets the target to null.<p>
       *
       * Registers listeners.<p>
       *
       * @param compassPoint the position for which to build the pane
       * @param theOrientation is the orientation.
       */
      public DetailsPane(String compassPoint, Orientation theOrientation) {
          //#if defined(LOGGING)
          //@#$LPS-LOGGING:GranularityType:Statement
          //@#$LPS-LOGGING:Localization:StartMethod
          LOG.info("making DetailsPane(" + compassPoint + ")");
          //#endif
          orientation = theOrientation;
  
          loadTabs(compassPoint, theOrientation);
          
          setOrientation(orientation);
          
          setLayout(new BorderLayout());
          setFont(new Font("Dialog", Font.PLAIN, 10));
          add(topLevelTabbedPane, BorderLayout.CENTER);
  
          setTarget(null, true);
          topLevelTabbedPane.addMouseListener(this);
          topLevelTabbedPane.addChangeListener(this);
      }
  
      /* TODO: Some parts of ArgoUML have preliminary support for multiple
       * details panels, but we currently only support 
       * the default South (bottom) panel
       */
      private void loadTabs(String direction, Orientation theOrientation) {
          if (Position.South.toString().equalsIgnoreCase(direction)
                  // Special case for backward compatibility
                  || "detail".equalsIgnoreCase(direction)) {
              /* The south panel always has tabs - but they are 
               * added (later) elsewhere.
               */
              hasTabs = true;
          } 
      }
      
      boolean hasTabs() {
          return hasTabs;
      }
  
      /**
       * Returns the JTabbedPane that contains all details panels.
       * @return the JTabbedPane.
       */
      JTabbedPane getTabs() {
          return topLevelTabbedPane;
      }
  
      /**
       * @param p the panel to be added 
       * @param atEnd true = add the panel at the end, 
       *                  false = at the beginning
       */
      public void addTab(AbstractArgoJPanel p, boolean atEnd) {
          Icon icon = p.getIcon();
          String title = Translator.localize(p.getTitle());
          if (atEnd) {
              topLevelTabbedPane.addTab(title, icon, p); 
              tabPanelList.add(p);
          } else { 
              topLevelTabbedPane.insertTab(title, icon, p, null, 0);
              tabPanelList.add(0, p);
          }
  
      }
  
      /**
       * Selects the to do tab, and sets the target of that tab.
       * 
       * @param item the selected todo item
       * @return true if todo tab is really selected.
       * @deprecated for 0.25.5 by tfmorris. Send an event that TabToDoTargets
       *             listen to.
       */
      @Deprecated
      public boolean setToDoItem(Object item) {
          enableTabs(item);
          for (JPanel t : tabPanelList) {
              if (t instanceof TabToDoTarget) {
                  ((TabToDoTarget) t).setTarget(item);
                  topLevelTabbedPane.setSelectedComponent(t);
                  return true;
              }
          }
          return false;
      }
  
      /**
       * Selects the prop tab if it is appropriate for the target.
       *
       * @param target
       *            the target object
       * @return true if props tab is really selected
       */
      private boolean selectPropsTab(Object target) {
          if (getTabProps().shouldBeEnabled(target)) {
              int indexOfPropPanel = topLevelTabbedPane
                      .indexOfComponent(getTabProps());
              topLevelTabbedPane.setSelectedIndex(indexOfPropPanel);
              lastNonNullTab = indexOfPropPanel;
              return true;
          }
          return false;
      }
  
      /**
       * Sets the target of the Details pane to either be a
       * selected model element or
       * the owner(model element) of a selected fig.<p>
       *
       * Decides which panels to enable.
       *
       * @param target the target object
       */
      private void setTarget(Object target, boolean defaultToProperties) {
          enableTabs(target);
          if (target != null) {
              boolean tabSelected = false;
  
              // Always select properties panel if defaultToProperties is true,
              // and if properties panel is appropriate for selected perspective
              if (defaultToProperties || lastNonNullTab < 0) {
                  tabSelected = selectPropsTab(target);
              } else {
                  // Select prop panel if current panel is not appropriate
                  // for selected target
                  Component selectedTab = topLevelTabbedPane
                          .getComponentAt(lastNonNullTab);
                  if (selectedTab instanceof TabTarget) {
                      if (((TabTarget) selectedTab).shouldBeEnabled(target)) {
                          topLevelTabbedPane.setSelectedIndex(lastNonNullTab);
                          tabSelected = true;
                      } else {
                          tabSelected = selectPropsTab(target);
                      }
                  }
              }
              if (!tabSelected) {
                  for (int i = lastNonNullTab + 1;
  		     i < topLevelTabbedPane.getTabCount();
  		     i++) {
                      Component tab = topLevelTabbedPane.getComponentAt(i);
                      if (tab instanceof TabTarget) {
                          if (((TabTarget) tab).shouldBeEnabled(target)) {
                              topLevelTabbedPane.setSelectedIndex(i);
                              ((TabTarget) tab).setTarget(target);
                              lastNonNullTab = i;
                              tabSelected = true;
                              break;
                          }
                      }
                  }
              }
              // default tab todo
  