All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.alantea.swing.panels.MainContent Maven / Gradle / Ivy

The newest version!
package net.alantea.swing.panels;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.JTabbedPane;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import net.alantea.swing.Application;
import net.alantea.swing.misc.ResourceManager;
import net.alantea.swing.ribbon.Ribbon;
import net.alantea.swing.tab.TabbedPane;
import net.alantea.viewml.annotations.VElement;

/**
 * The Class MainContent.
 */
@VElement("mainContent")
@SuppressWarnings("serial")
public class MainContent extends JPanel
{
   
   /** The ribbon. */
   private Ribbon ribbon;
   
   /** The tab folder. */
   private JTabbedPane tabFolder;
   
   /** The vertical tab folder. */
   private VerticalTabFolder verticalTabFolder;
   
   /** The info folder. */
   private JTabbedPane infoFolder;

	/**
	 * Create the composite.
	 */
	public MainContent()
	{
		super();
      setLayout(new BorderLayout());
      
      ribbon = createRibbon();
       if (ribbon != null)
      {
         ribbon.setMinimumSize(new Dimension(300,50));
      add(ribbon, BorderLayout.PAGE_START);
      }
      
      verticalTabFolder = new VerticalTabFolder();

      tabFolder = new TabbedPane();
      tabFolder.addChangeListener(new ChangeListener()
      {
         public void stateChanged(ChangeEvent e)
         {
            tabFolder.getSelectedComponent().revalidate();
            tabFolder.getSelectedComponent().repaint();
         }
     });      
      infoFolder = new TabbedPane();
      tabFolder.addChangeListener(new ChangeListener()
      {
         public void stateChanged(ChangeEvent e)
         {
            if (infoFolder.getSelectedComponent() != null)
            {
               infoFolder.getSelectedComponent().revalidate();
               infoFolder.getSelectedComponent().repaint();
            }
         }
     });      
      
      JSplitPane rightSashForm = new JSplitPane(JSplitPane.VERTICAL_SPLIT, tabFolder, infoFolder);
      rightSashForm.setOrientation(JSplitPane.VERTICAL_SPLIT);
      rightSashForm.setDividerLocation(750);
      rightSashForm.setDividerSize(5);
      
      JSplitPane sashForm = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, verticalTabFolder, rightSashForm);
      sashForm.setDividerSize(5);
      add(sashForm, BorderLayout.CENTER);
      sashForm.setDividerLocation(200);
            
      Application.setMainContent(this);
	}

   
   /**
    * Adds the navigation tab.
    *
    * @param control the control
    * @param imageName the image name
    * @param tooltip the tooltip
    */
   public void addNavigationTab(JComponent control, String imageName, String tooltip)
   {
      verticalTabFolder.addFolder(control, ResourceManager.getImage(imageName), tooltip);
      verticalTabFolder.select(0);
   }
   
   /**
    * Creates the ribbon.
    *
    * @return the ribbon
    */
   protected Ribbon createRibbon()
   {
      return new Ribbon();
   }
   
   /**
    * Gets the ribbon.
    *
    * @return the ribbon
    */
   public Ribbon getRibbon()
   {
      return ribbon;
   }
   
   /**
    * Gets the navigation folder.
    *
    * @return the navigation folder
    */
   public VerticalTabFolder getNavigationFolder()
   {
      return verticalTabFolder;
   }
   
   /**
    * Gets the navigation folder container.
    *
    * @return the navigation folder container
    */
   public JPanel getNavigationFolderContainer()
   {
      return verticalTabFolder.getFolderComposite();
   }
   
   /**
    * Gets the tab folder.
    *
    * @return the tab folder
    */
   public JTabbedPane getTabFolder()
   {
      return tabFolder;
   }
   
   /**
    * Gets the info folder.
    *
    * @return the info folder
    */
   public JTabbedPane getInfoFolder()
   {
      return infoFolder;
   }

   /**
    * Adds the to tab folder.
    *
    * @param panel the panel
    * @param name the name
    * @return the int
    */
   public int addToTabFolder(final JPanel panel, String name)
   {
      tabFolder.add(panel);
      JPanel titlePanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
      titlePanel.setOpaque(false);
      JLabel titleLbl = new JLabel(name);
      titleLbl.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5));
      titlePanel.add(titleLbl);
      JLabel closeButton = new JLabel("  x");

      closeButton.addMouseListener(new MouseAdapter()
      {
         @Override
         public void mouseClicked(MouseEvent e)
         {
            tabFolder.remove(panel);
         }
      });
      titlePanel.add(closeButton);
      tabFolder.setTabComponentAt(tabFolder.indexOfComponent(panel), titlePanel);
      return tabFolder.indexOfComponent(panel);
   }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy