DividerLayout is layout that divides two components with the column of actions : Custom Layout « Swing « Java Tutorial

Java Tutorial
1. Language
2. Data Type
3. Operators
4. Statement Control
5. Class Definition
6. Development
7. Reflection
8. Regular Expressions
9. Collections
10. Thread
11. File
12. Generics
13. I18N
14. Swing
15. Swing Event
16. 2D Graphics
17. SWT
18. SWT 2D Graphics
19. Network
20. Database
21. Hibernate
22. JPA
23. JSP
24. JSTL
25. Servlet
26. Web Services SOA
27. EJB3
28. Spring
29. PDF
30. Email
31. J2ME
32. J2EE Application
33. XML
34. Design Pattern
35. Log
36. Security
37. Apache Common
38. Ant
39. JUnit
Java
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 Tutorial » Swing » Custom Layout 
14. 97. 13. DividerLayout is layout that divides two components with the column of actions
/*
 * $Id: DividerLayout.java,v 1.1.1.1 2005/04/07 18:36:20 pocho Exp $
 */
// Revised from javautils swing;

import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Insets;
import java.awt.LayoutManager2;
import java.awt.Rectangle;

/**
 * <p>
 * <code>DividerLayout</code> is layout that divides two components with the
 * column of actions. It is especially usefull for components that contains
 * two lists of elements and buttons for transfering elements between these
 * two lists.
 * </p>
 * <p>
 *   Components are indicated as {@link #WEST}{@link #EAST} and {@link #CENTER}.
 * </p>
 
 @version $Name:  $ - $Revision: 1.1.1.1 $ - $Date: 2005/04/07 18:36:20 $
 * TODO Test
 */
public class DividerLayout implements LayoutManager2 {
  
  /**
   * Indicates west component
   */
  public final static String WEST = "WEST";
  /**
   * indicates east component
   */
  public final static String EAST = "EAST";
  /**
   * indicates center component
   */
  public final static String CENTER = "CENTER";

  /**
   * west component
   */
  protected Component westComponent;
  
  /**
   * center component
   */
  protected Component centerComponent;
  
  /**
   * east component
   */
  protected Component eastComponent;
  
  /**
   * Adds a component to specified position.
   */
  public void addLayoutComponent(Component comp, Object constraints) {
    if (WEST.equalsIgnoreCase((Stringconstraints)) {
      westComponent = comp;
    }
    else if (CENTER.equalsIgnoreCase((Stringconstraints)) {
      centerComponent = comp;
    }
    else if (EAST.equalsIgnoreCase((Stringconstraints)) {
      eastComponent = comp;
    }
  }

  /**
   @see java.awt.LayoutManager2#maximumLayoutSize(java.awt.Container)
   */
  public Dimension maximumLayoutSize(Container target) {
    Dimension size;
    int width = 0;
    int height = 0;
    if ((westComponent != null&& (westComponent.isVisible())) {
      size = westComponent.getMaximumSize();
      width = Math.max(width, size.width);
      height = Math.max(height, size.height);
    }
    if ((eastComponent != null&& (eastComponent.isVisible())) {
      size = eastComponent.getMaximumSize();
      width = Math.max(width, size.width);
      height = Math.max(height, size.height);
    }
    width *= 2;
    if ((centerComponent != null&& (centerComponent.isVisible())) {
      size = centerComponent.getPreferredSize();
      width += size.width;
      height = Math.max(height, size.height);
    }
    return new Dimension(width, height);
  }

  /**
   @see java.awt.LayoutManager2#getLayoutAlignmentX(java.awt.Container)
   */
  public float getLayoutAlignmentX(Container target) {
    return 0.0f;
  }

  /**
   @see java.awt.LayoutManager2#getLayoutAlignmentY(java.awt.Container)
   */
  public float getLayoutAlignmentY(Container target) {
    return 0.0f;
  }

  /**
   @see java.awt.LayoutManager2#invalidateLayout(java.awt.Container)
   */
  public void invalidateLayout(Container target) {}

  /**
   @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
   */
  public void addLayoutComponent(String name, Component comp) {
    addLayoutComponent(comp, name);
  }

  /**
   @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
   */
  public void removeLayoutComponent(Component comp) {
    if (comp == westComponent) {
      westComponent = null;
    }
    else if (comp == centerComponent) {
      centerComponent = null;
    }
    else if (comp == eastComponent) {
      centerComponent = null;
    }
  }
  
  /**
   @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
   */
  public Dimension preferredLayoutSize(Container parent) {
    Dimension size;
    int width = 0;
    int height = 0;
    if ((westComponent != null&& (westComponent.isVisible())) {
      size = westComponent.getPreferredSize();
      width = Math.max(width, size.width);
      height = Math.max(height, size.height);
    }
    if ((eastComponent != null&& (eastComponent.isVisible())) {
      size = eastComponent.getPreferredSize();
      width = Math.max(width, size.width);
      height = Math.max(height, size.height);
    }
    width *= 2;
    if ((centerComponent != null&& (centerComponent.isVisible())) {
      size = centerComponent.getPreferredSize();
      width += size.width;
      height = Math.max(height, size.height);
    }
    return new Dimension(width, height);
  }


  /**
   @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
   */
  public Dimension minimumLayoutSize(Container parent) {
    Dimension size;
    int width = 0;
    int height = 0;
    if ((westComponent != null&& (westComponent.isVisible())) {
      size = westComponent.getMinimumSize();
      width = Math.max(width, size.width);
      height = Math.max(height, size.height);
    }
    if ((eastComponent != null&& (eastComponent.isVisible())) {
      size = eastComponent.getMinimumSize();
      width = Math.max(width, size.width);
      height = Math.max(height, size.height);
    }
    width *= 2;
    if ((centerComponent != null&& (centerComponent.isVisible())) {
      size = centerComponent.getPreferredSize();
      width += size.width;
      height += Math.max(height, size.height);
    }
    return new Dimension(width, height);
  }

  /**
   @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
   */
  public void layoutContainer(Container container) {
   Insets insets = container.getInsets();
   Dimension westSize = new Dimension(00);
   Dimension centerSize = new Dimension(00);
   Dimension eastSize = new Dimension(00);
   Rectangle centerBounds = new Rectangle(0000);
   Dimension containerSize = container.getSize();
   int centerX = containerSize.width / 2;
   int centerY = containerSize.height / 2;
   if ((centerComponent != null&&
       (centerComponent.isVisible())) {
     centerSize = centerComponent.getPreferredSize();
     centerSize.width = Math.min(centerSize.width,
         containerSize.width - insets.left -
         insets.right);
     centerSize.height = Math.min(centerSize.height,
         containerSize.height - insets.top -
         insets.bottom);
     centerComponent.setBounds(centerX -
         (centerSize.width / 2),
         centerY - (centerSize.height / 2),
         centerSize.width, centerSize.height);
     centerBounds = centerComponent.getBounds();
   }
   if ((westComponent != null&& (westComponent.isVisible())) {
     westSize = westComponent.getPreferredSize();
   }
   if ((eastComponent != null&& (eastComponent.isVisible())) {
     eastSize = eastComponent.getPreferredSize();
   }
  /* int maxWidth = Math.min(westSize.width, eastSize.width);
   maxWidth = Math.min(maxWidth, (containerSize.width -
       centerBounds.width - insets.left -
       insets.right) / 2);*/
  int maxWidth = (containerSize.width -
       centerBounds.width - insets.left -
       insets.right2;

  /* int maxHeight = Math.min(westSize.height, eastSize.height);
    maxHeight = Math.max(maxHeight, containerSize.height -
       insets.top - insets.bottom);*/
  int maxHeight=containerSize.height - insets.top - insets.bottom;
   if (westComponent != null) {
     westComponent.setBounds(centerBounds.x - maxWidth,
         centerY - (maxHeight / 2),
         maxWidth, maxHeight);
   }
   if (eastComponent != null) {
     eastComponent.setBounds(centerBounds.x +
         centerBounds.width,
         centerY - (maxHeight / 2),
         maxWidth, maxHeight);
   }
 }


}
14. 97. Custom Layout
14. 97. 1. Custom Layout: DiagonalLayoutCustom Layout: DiagonalLayout
14. 97. 2. GraphPaperLayout implements LayoutManager2
14. 97. 3. Circle Layout
14. 97. 4. This LayoutManager arranges the components into a column. Components are always given their preferred size
14. 97. 5. Compents are laid out in a circle.
14. 97. 6. Specialised layout manager for a grid of components.
14. 97. 7. Stack Layout, uses an orientation to determine if the contents should be arranged horizontally or vertically.
14. 97. 8. A layout manager that displays a single component in the center of its container.
14. 97. 9. A simple layoutmanager to overlay all components of a parent.
14. 97. 10. A layout manager that lays out components along a central axis
14. 97. 11. Wrapper Layout
14. 97. 12. Center Layout
14. 97. 13. DividerLayout is layout that divides two components with the column of actions
14. 97. 14. X Y Layout
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.