TabbedPane and dockable component 2 : Dockable « Swing Components « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Class
8. Collections Data Structure
9. Data Type
10. Database SQL JDBC
11. Design Pattern
12. Development Class
13. EJB3
14. Email
15. Event
16. File Input Output
17. Game
18. Generics
19. GWT
20. Hibernate
21. I18N
22. J2EE
23. J2ME
24. JDK 6
25. JNDI LDAP
26. JPA
27. JSP
28. JSTL
29. Language Basics
30. Network Protocol
31. PDF RTF
32. Reflection
33. Regular Expressions
34. Scripting
35. Security
36. Servlets
37. Spring
38. Swing Components
39. Swing JFC
40. SWT JFace Eclipse
41. Threads
42. Tiny Application
43. Velocity
44. Web Services SOA
45. XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java » Swing Components » DockableScreenshots 
TabbedPane and dockable component 2
TabbedPane and dockable component 2

package net.eleritec.docking.demos;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Insets;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.border.LineBorder;

import net.eleritec.docking.Dockable;
import net.eleritec.docking.DockableAdapter;
import net.eleritec.docking.DockingManager;
import net.eleritec.docking.DockingPort;
import net.eleritec.docking.defaults.ComponentProviderAdapter;
import net.eleritec.docking.defaults.DefaultDockingPort;


public class TabbedPaneDemo extends JPanel {
  private JLabel titlebar;
  private Dockable dockableImpl;

  public TabbedPaneDemo(String title) {
    super();
    titlebar = createTitlebar(" " + title);
    add(titlebar);
    setBorder(new LineBorder(Color.black));
    dockableImpl = new DockableImpl();
  }

  private JLabel createTitlebar(String title) {
    JLabel lbl = new JLabel(title);
    lbl.setForeground(Color.white);
    lbl.setBackground(Color.blue);
    lbl.setOpaque(true);
    return lbl;
  }

  public void doLayout() {
    Insets in = getInsets();
    titlebar.setBounds(in.left, in.top, getWidth() - in.left - in.right, 25);
  }

  private TabbedPaneDemo getThis() {
    return this;
  }
  
  private Dockable getDockable() {
    return dockableImpl;
  }

  private class DockableImpl extends DockableAdapter {
    public Component getDockable() {
      return getThis();
    }
    
    public String getDockableDesc() {
      return titlebar.getText().trim();
    }

    public Component getInitiator() {
      // the titlebar will the the 'hot' component that initiates dragging
      return titlebar;
    }
  }




  private static JPanel createContentPane() {
    JPanel p = new JPanel(new BorderLayout(55));
    p.add(buildDockingPort("North"), BorderLayout.NORTH);
    p.add(buildDockingPort("South"), BorderLayout.SOUTH);
    p.add(buildDockingPort("East"), BorderLayout.EAST);
    p.add(buildDockingPort("West"), BorderLayout.WEST);
    p.add(createDockingPort("Center"), BorderLayout.CENTER);
    return p;
  }

  private static DefaultDockingPort buildDockingPort(String desc) {
    // create the DockingPort
    DefaultDockingPort port = createDockingPort(desc);

    // create the Dockable panel
    TabbedPaneDemo cd = new TabbedPaneDemo(desc);
    DockingManager.registerDockable(cd.getDockable());

    // dock the panel and return the DockingPort
    port.dock(cd.getDockable(), DockingPort.CENTER_REGION);
    return port;
  }

  private static int getTabPosition(String desc) {
    if ("North".equals(desc))
      return JTabbedPane.TOP;
    if ("South".equals(desc))
      return JTabbedPane.BOTTOM;
    if ("East".equals(desc))
      return JTabbedPane.RIGHT;
    if ("West".equals(desc))
      return JTabbedPane.LEFT;
    return JTabbedPane.TOP;
  }

  private static DefaultDockingPort createDockingPort(String desc) {
    DefaultDockingPort port = new DefaultDockingPort();
    port.setBackground(Color.gray);
    port.setPreferredSize(new Dimension(200100));
    port.setComponentProvider(new ComponentProvider(getTabPosition(desc)));
    return port;
  }

  public static void main(String[] args) {
    JFrame f = new JFrame("Custom Conatainers Docking Demo");
    f.setContentPane(createContentPane());
    f.setSize(600400);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
  }

  private static class ComponentProvider extends ComponentProviderAdapter {
    int tabPosition;

    private ComponentProvider(int tabs) {
      tabPosition = tabs;
    }

    public JTabbedPane createTabbedPane() {
      return new JTabbedPane(tabPosition);
    }
  }
  

}


           
       
dockingSrc-0.3.zip( 57 k)
Related examples in the same category
1. Swing dockable windowSwing dockable window
2. Simple demo for dockable windowsSimple demo for dockable windows
3. Compound dockable windowCompound dockable window
4. Cursor indication for dockable componentCursor indication for dockable component
5. SplitPane and dockable componentSplitPane and dockable component
6. Elegant Dockable frameworkElegant Dockable framework
7. Add border for dockable componentAdd border for dockable component
8. Swing dock framework
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.