home *** CD-ROM | disk | FTP | other *** search
/ Borland JBuilder 6 / jbuilder6.iso / IBM VisualAge for Java Enterprise v4.0 Retail / ivj40 / setup / IDE.Cab / F77577_BasicSmartGuideNotebookUI.class (.txt) < prev    next >
Encoding:
Java Class File  |  2000-04-25  |  7.3 KB  |  292 lines

  1. package com.ibm.ivb.sguides.basic;
  2.  
  3. import com.ibm.ivb.sguides.MultiLineEvent;
  4. import com.ibm.ivb.sguides.MultiLineLabel;
  5. import com.ibm.ivb.sguides.MultiLineListener;
  6. import com.ibm.ivb.sguides.SmartGuideNotebook;
  7. import com.ibm.ivb.sguides.SmartGuideNotebookUI;
  8. import com.ibm.ivb.sguides.SmartGuidePage;
  9. import java.awt.Color;
  10. import java.awt.Component;
  11. import java.awt.Container;
  12. import java.awt.Dimension;
  13. import java.awt.Font;
  14. import java.awt.Graphics;
  15. import java.awt.Insets;
  16. import java.awt.LayoutManager;
  17. import java.awt.Rectangle;
  18. import javax.swing.Icon;
  19. import javax.swing.JComponent;
  20. import javax.swing.JLabel;
  21. import javax.swing.SwingUtilities;
  22. import javax.swing.border.Border;
  23. import javax.swing.event.ChangeEvent;
  24. import javax.swing.plaf.ComponentUI;
  25.  
  26. public class BasicSmartGuideNotebookUI extends SmartGuideNotebookUI implements LayoutManager, MultiLineListener {
  27.    private static final String kCBIBMCopyright = "(c) Copyright IBM Corporation 1998";
  28.    protected boolean titleEnabled = true;
  29.    protected boolean descEnabled = true;
  30.    Border border;
  31.    protected SmartGuideNotebook sgbook;
  32.    protected JLabel title;
  33.    protected MultiLineLabel desc;
  34.    protected static Insets imageInsets = new Insets(30, 10, 10, 10);
  35.    protected static Insets cinsets = new Insets(10, 10, 10, 10);
  36.    protected static Dimension mcsize = new Dimension(400, 220);
  37.    protected static Font titleFont = new Font("SansSerif", 1, 16);
  38.    protected Icon icon;
  39.    protected SmartGuidePage prevPage;
  40.    protected SmartGuidePage currPage;
  41.  
  42.    public void addLayoutComponent(String var1, Component var2) {
  43.    }
  44.  
  45.    protected Dimension calculateSize() {
  46.       int var1 = 0;
  47.       int var2 = 0;
  48.  
  49.       for(int var3 = 0; var3 < this.sgbook.getPageCount(); ++var3) {
  50.          Dimension var4 = new Dimension(0, 0);
  51.          Dimension var5 = new Dimension(0, 0);
  52.          SmartGuidePage var6 = this.sgbook.getPageAt(var3);
  53.          Component var7 = var6.getClient();
  54.          if (var7 != null) {
  55.             var4 = var7.getPreferredSize();
  56.          }
  57.  
  58.          Icon var8 = var6.getIcon();
  59.          if (var8 != null && var6.getIconMode()) {
  60.             var5.width = var8.getIconWidth();
  61.             var5.height = var8.getIconHeight();
  62.          }
  63.  
  64.          int var9 = cinsets.left + var4.width + cinsets.right;
  65.          int var10 = cinsets.top + var4.height + cinsets.bottom;
  66.          int var11 = 0;
  67.          int var12 = 0;
  68.          if (this.titleEnabled) {
  69.             var11 = this.title.getPreferredSize().height;
  70.          }
  71.  
  72.          if (this.descEnabled) {
  73.             this.desc.setSize(var4.width, 0);
  74.             var12 = this.desc.getPreferredHeight(var4.width, var6.getDescription());
  75.          }
  76.  
  77.          int var13 = 0;
  78.          if (var8 != null && var6.getIconMode()) {
  79.             var13 = imageInsets.left + var5.width + imageInsets.right;
  80.          }
  81.  
  82.          var1 = Math.max(var9 + var13, var1);
  83.          var2 = Math.max(var10 + var11 + var12, var2);
  84.       }
  85.  
  86.       var1 = Math.max(var1, 600);
  87.       var2 = Math.max(var2, 400);
  88.       return new Dimension(var1, var2);
  89.    }
  90.  
  91.    public static ComponentUI createUI(JComponent var0) {
  92.       return new BasicSmartGuideNotebookUI();
  93.    }
  94.  
  95.    void flipPages(SmartGuidePage var1, SmartGuidePage var2) {
  96.       Component var3 = var1 != null ? var1.getClient() : null;
  97.       Component var4 = var2 != null ? var2.getClient() : null;
  98.       if (var1 != var2 || var3 != var4) {
  99.          if (var3 != null) {
  100.             this.sgbook.remove(var3);
  101.          }
  102.  
  103.          if (var4 != null) {
  104.             this.sgbook.add(var4);
  105.          }
  106.  
  107.          this.prevPage = var1;
  108.          this.currPage = var2;
  109.       }
  110.    }
  111.  
  112.    protected Font getTitleFont() {
  113.       return titleFont;
  114.    }
  115.  
  116.    public void installUI(JComponent var1) {
  117.       this.border = new ThickBorder();
  118.       var1.setBorder(this.border);
  119.       this.sgbook = (SmartGuideNotebook)var1;
  120.       ((Container)var1).setLayout(this);
  121.       if (this.titleEnabled) {
  122.          this.title = new JLabel();
  123.          Font var2 = this.getTitleFont();
  124.          if (var2 != null) {
  125.             this.title.setFont(var2);
  126.          }
  127.  
  128.          this.sgbook.add(this.title);
  129.       }
  130.  
  131.       if (this.descEnabled) {
  132.          this.desc = new MultiLineLabel();
  133.          this.sgbook.add(this.desc);
  134.          this.desc.addMultiLineListener(this);
  135.       }
  136.  
  137.       this.sgbook.addChangeListener(this);
  138.       this.sgbook.setDoubleBuffered(true);
  139.    }
  140.  
  141.    public void layoutContainer(Container var1) {
  142.       Dimension var2 = ((Component)var1).getSize();
  143.       Rectangle var3 = new Rectangle(var2);
  144.       Insets var4 = var1.getInsets();
  145.       var3.x += var4.left;
  146.       var3.y += var4.top;
  147.       var3.width -= var4.right + var3.x;
  148.       var3.height -= var4.bottom + var3.y;
  149.       boolean var5 = false;
  150.       int var6 = 0;
  151.       if (this.icon != null) {
  152.          var6 = imageInsets.left + this.icon.getIconWidth() + imageInsets.right;
  153.       }
  154.  
  155.       int var7 = var3.width - var6;
  156.       Component var8 = this.prevPage != null ? this.prevPage.getClient() : null;
  157.       Component var9 = this.currPage != null ? this.currPage.getClient() : null;
  158.       if (var8 != null && var8.getParent() == null && var9 != null && SwingUtilities.findFocusOwner(var8) != null) {
  159.          var5 = true;
  160.       }
  161.  
  162.       int var10 = var7 - cinsets.left - cinsets.right;
  163.       if (this.titleEnabled) {
  164.          this.title.setLocation(cinsets.left + var3.x, cinsets.top + var3.y);
  165.          this.title.setSize(var10, this.title.getPreferredSize().height);
  166.       }
  167.  
  168.       int var11 = 0;
  169.       if (this.descEnabled) {
  170.          this.desc.setSize(var10, this.desc.getPreferredHeight(var10));
  171.          var11 = cinsets.top + var3.y + this.title.getHeight();
  172.          this.desc.setLocation(cinsets.left + var3.x, var11);
  173.          var11 += this.desc.getSize().height;
  174.       } else {
  175.          var11 = var3.y + cinsets.top;
  176.       }
  177.  
  178.       if (var9 != null) {
  179.          var9.setLocation(var3.x + cinsets.left, var11 + cinsets.top);
  180.          var9.setSize(var3.width - var6 - cinsets.left - cinsets.right, var3.height - (var11 - var3.y) - cinsets.top - cinsets.bottom);
  181.          var9.setVisible(true);
  182.          var9.validate();
  183.          if (var5) {
  184.             this.transferFocusTo(var9);
  185.          }
  186.       }
  187.  
  188.    }
  189.  
  190.    public void linkStateChanged(MultiLineEvent var1) {
  191.       this.sgbook.fireHyperlinkChanged(var1);
  192.    }
  193.  
  194.    public Dimension minimumLayoutSize(Container var1) {
  195.       return this.calculateSize();
  196.    }
  197.  
  198.    public void pageAdded(SmartGuideNotebook var1, SmartGuidePage var2) {
  199.    }
  200.  
  201.    public void pageRemoved(SmartGuideNotebook var1, SmartGuidePage var2) {
  202.    }
  203.  
  204.    public void paint(Graphics var1, JComponent var2) {
  205.       Dimension var3 = ((Component)var2).getSize();
  206.       Rectangle var4 = new Rectangle(var3);
  207.       Insets var5 = var2.getInsets();
  208.       var4.x += var5.left;
  209.       var4.y += var5.top;
  210.       var4.width -= var5.right + var4.x;
  211.       var4.height -= var5.bottom + var4.y;
  212.       Color var6 = ((Component)var2).getBackground();
  213.       this.paintClientRectangle(var1, var4);
  214.       int var7 = 0;
  215.       if (this.icon != null) {
  216.          var7 = imageInsets.left + imageInsets.right;
  217.          var7 += this.icon.getIconWidth();
  218.       }
  219.  
  220.       int var8 = var4.x + var4.width - var7;
  221.       var1.setColor(var6.darker());
  222.       var1.fillRect(var8, var4.y, var7, var4.height);
  223.       if (this.icon != null) {
  224.          this.icon.paintIcon(var2, var1, var8 + imageInsets.left, var4.y + imageInsets.top);
  225.       }
  226.  
  227.    }
  228.  
  229.    protected void paintClientRectangle(Graphics var1, Rectangle var2) {
  230.    }
  231.  
  232.    public Dimension preferredLayoutSize(Container var1) {
  233.       return this.calculateSize();
  234.    }
  235.  
  236.    public void removeLayoutComponent(Component var1) {
  237.    }
  238.  
  239.    public void stateChanged(ChangeEvent var1) {
  240.       SmartGuidePage var2 = this.sgbook.getCurrentPage();
  241.       if (var2 != null) {
  242.          if (var2 != this.currPage) {
  243.             this.flipPages(this.currPage, var2);
  244.          }
  245.  
  246.          if (this.titleEnabled) {
  247.             this.updateTitle(var2);
  248.          }
  249.  
  250.          if (this.descEnabled) {
  251.             this.desc.setText(var2.getDescription());
  252.          }
  253.  
  254.          this.icon = var2.getIcon();
  255.          this.sgbook.invalidate();
  256.          this.sgbook.validate();
  257.          this.sgbook.repaint();
  258.       }
  259.    }
  260.  
  261.    protected void transferFocusTo(Component var1) {
  262.       boolean var2 = true;
  263.       if (var1.isFocusTraversable()) {
  264.          var1.requestFocus();
  265.          var2 = false;
  266.       } else if (var1 instanceof JComponent && ((JComponent)var1).requestDefaultFocus()) {
  267.          var2 = false;
  268.       }
  269.  
  270.       if (var2) {
  271.          this.sgbook.requestFocus();
  272.       }
  273.  
  274.    }
  275.  
  276.    public void uninstallUI(JComponent var1) {
  277.       if (var1.getBorder() == this.border) {
  278.          var1.setBorder((Border)null);
  279.       }
  280.  
  281.       ((Container)var1).setLayout((LayoutManager)null);
  282.       if (this.desc != null) {
  283.          this.desc.removeMultiLineListener(this);
  284.       }
  285.  
  286.    }
  287.  
  288.    protected void updateTitle(SmartGuidePage var1) {
  289.       this.title.setText(var1.getTitle());
  290.    }
  291. }
  292.