home *** CD-ROM | disk | FTP | other *** search
- package com.ibm.ivb.sguides.basic;
-
- import com.ibm.ivb.sguides.MultiLineEvent;
- import com.ibm.ivb.sguides.MultiLineLabel;
- import com.ibm.ivb.sguides.MultiLineListener;
- import com.ibm.ivb.sguides.SmartGuideNotebook;
- import com.ibm.ivb.sguides.SmartGuideNotebookUI;
- import com.ibm.ivb.sguides.SmartGuidePage;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Dimension;
- import java.awt.Font;
- import java.awt.Graphics;
- import java.awt.Insets;
- import java.awt.LayoutManager;
- import java.awt.Rectangle;
- import javax.swing.Icon;
- import javax.swing.JComponent;
- import javax.swing.JLabel;
- import javax.swing.SwingUtilities;
- import javax.swing.border.Border;
- import javax.swing.event.ChangeEvent;
- import javax.swing.plaf.ComponentUI;
-
- public class BasicSmartGuideNotebookUI extends SmartGuideNotebookUI implements LayoutManager, MultiLineListener {
- private static final String kCBIBMCopyright = "(c) Copyright IBM Corporation 1998";
- protected boolean titleEnabled = true;
- protected boolean descEnabled = true;
- Border border;
- protected SmartGuideNotebook sgbook;
- protected JLabel title;
- protected MultiLineLabel desc;
- protected static Insets imageInsets = new Insets(30, 10, 10, 10);
- protected static Insets cinsets = new Insets(10, 10, 10, 10);
- protected static Dimension mcsize = new Dimension(400, 220);
- protected static Font titleFont = new Font("SansSerif", 1, 16);
- protected Icon icon;
- protected SmartGuidePage prevPage;
- protected SmartGuidePage currPage;
-
- public void addLayoutComponent(String var1, Component var2) {
- }
-
- protected Dimension calculateSize() {
- int var1 = 0;
- int var2 = 0;
-
- for(int var3 = 0; var3 < this.sgbook.getPageCount(); ++var3) {
- Dimension var4 = new Dimension(0, 0);
- Dimension var5 = new Dimension(0, 0);
- SmartGuidePage var6 = this.sgbook.getPageAt(var3);
- Component var7 = var6.getClient();
- if (var7 != null) {
- var4 = var7.getPreferredSize();
- }
-
- Icon var8 = var6.getIcon();
- if (var8 != null && var6.getIconMode()) {
- var5.width = var8.getIconWidth();
- var5.height = var8.getIconHeight();
- }
-
- int var9 = cinsets.left + var4.width + cinsets.right;
- int var10 = cinsets.top + var4.height + cinsets.bottom;
- int var11 = 0;
- int var12 = 0;
- if (this.titleEnabled) {
- var11 = this.title.getPreferredSize().height;
- }
-
- if (this.descEnabled) {
- this.desc.setSize(var4.width, 0);
- var12 = this.desc.getPreferredHeight(var4.width, var6.getDescription());
- }
-
- int var13 = 0;
- if (var8 != null && var6.getIconMode()) {
- var13 = imageInsets.left + var5.width + imageInsets.right;
- }
-
- var1 = Math.max(var9 + var13, var1);
- var2 = Math.max(var10 + var11 + var12, var2);
- }
-
- var1 = Math.max(var1, 600);
- var2 = Math.max(var2, 400);
- return new Dimension(var1, var2);
- }
-
- public static ComponentUI createUI(JComponent var0) {
- return new BasicSmartGuideNotebookUI();
- }
-
- void flipPages(SmartGuidePage var1, SmartGuidePage var2) {
- Component var3 = var1 != null ? var1.getClient() : null;
- Component var4 = var2 != null ? var2.getClient() : null;
- if (var1 != var2 || var3 != var4) {
- if (var3 != null) {
- this.sgbook.remove(var3);
- }
-
- if (var4 != null) {
- this.sgbook.add(var4);
- }
-
- this.prevPage = var1;
- this.currPage = var2;
- }
- }
-
- protected Font getTitleFont() {
- return titleFont;
- }
-
- public void installUI(JComponent var1) {
- this.border = new ThickBorder();
- var1.setBorder(this.border);
- this.sgbook = (SmartGuideNotebook)var1;
- ((Container)var1).setLayout(this);
- if (this.titleEnabled) {
- this.title = new JLabel();
- Font var2 = this.getTitleFont();
- if (var2 != null) {
- this.title.setFont(var2);
- }
-
- this.sgbook.add(this.title);
- }
-
- if (this.descEnabled) {
- this.desc = new MultiLineLabel();
- this.sgbook.add(this.desc);
- this.desc.addMultiLineListener(this);
- }
-
- this.sgbook.addChangeListener(this);
- this.sgbook.setDoubleBuffered(true);
- }
-
- public void layoutContainer(Container var1) {
- Dimension var2 = ((Component)var1).getSize();
- Rectangle var3 = new Rectangle(var2);
- Insets var4 = var1.getInsets();
- var3.x += var4.left;
- var3.y += var4.top;
- var3.width -= var4.right + var3.x;
- var3.height -= var4.bottom + var3.y;
- boolean var5 = false;
- int var6 = 0;
- if (this.icon != null) {
- var6 = imageInsets.left + this.icon.getIconWidth() + imageInsets.right;
- }
-
- int var7 = var3.width - var6;
- Component var8 = this.prevPage != null ? this.prevPage.getClient() : null;
- Component var9 = this.currPage != null ? this.currPage.getClient() : null;
- if (var8 != null && var8.getParent() == null && var9 != null && SwingUtilities.findFocusOwner(var8) != null) {
- var5 = true;
- }
-
- int var10 = var7 - cinsets.left - cinsets.right;
- if (this.titleEnabled) {
- this.title.setLocation(cinsets.left + var3.x, cinsets.top + var3.y);
- this.title.setSize(var10, this.title.getPreferredSize().height);
- }
-
- int var11 = 0;
- if (this.descEnabled) {
- this.desc.setSize(var10, this.desc.getPreferredHeight(var10));
- var11 = cinsets.top + var3.y + this.title.getHeight();
- this.desc.setLocation(cinsets.left + var3.x, var11);
- var11 += this.desc.getSize().height;
- } else {
- var11 = var3.y + cinsets.top;
- }
-
- if (var9 != null) {
- var9.setLocation(var3.x + cinsets.left, var11 + cinsets.top);
- var9.setSize(var3.width - var6 - cinsets.left - cinsets.right, var3.height - (var11 - var3.y) - cinsets.top - cinsets.bottom);
- var9.setVisible(true);
- var9.validate();
- if (var5) {
- this.transferFocusTo(var9);
- }
- }
-
- }
-
- public void linkStateChanged(MultiLineEvent var1) {
- this.sgbook.fireHyperlinkChanged(var1);
- }
-
- public Dimension minimumLayoutSize(Container var1) {
- return this.calculateSize();
- }
-
- public void pageAdded(SmartGuideNotebook var1, SmartGuidePage var2) {
- }
-
- public void pageRemoved(SmartGuideNotebook var1, SmartGuidePage var2) {
- }
-
- public void paint(Graphics var1, JComponent var2) {
- Dimension var3 = ((Component)var2).getSize();
- Rectangle var4 = new Rectangle(var3);
- Insets var5 = var2.getInsets();
- var4.x += var5.left;
- var4.y += var5.top;
- var4.width -= var5.right + var4.x;
- var4.height -= var5.bottom + var4.y;
- Color var6 = ((Component)var2).getBackground();
- this.paintClientRectangle(var1, var4);
- int var7 = 0;
- if (this.icon != null) {
- var7 = imageInsets.left + imageInsets.right;
- var7 += this.icon.getIconWidth();
- }
-
- int var8 = var4.x + var4.width - var7;
- var1.setColor(var6.darker());
- var1.fillRect(var8, var4.y, var7, var4.height);
- if (this.icon != null) {
- this.icon.paintIcon(var2, var1, var8 + imageInsets.left, var4.y + imageInsets.top);
- }
-
- }
-
- protected void paintClientRectangle(Graphics var1, Rectangle var2) {
- }
-
- public Dimension preferredLayoutSize(Container var1) {
- return this.calculateSize();
- }
-
- public void removeLayoutComponent(Component var1) {
- }
-
- public void stateChanged(ChangeEvent var1) {
- SmartGuidePage var2 = this.sgbook.getCurrentPage();
- if (var2 != null) {
- if (var2 != this.currPage) {
- this.flipPages(this.currPage, var2);
- }
-
- if (this.titleEnabled) {
- this.updateTitle(var2);
- }
-
- if (this.descEnabled) {
- this.desc.setText(var2.getDescription());
- }
-
- this.icon = var2.getIcon();
- this.sgbook.invalidate();
- this.sgbook.validate();
- this.sgbook.repaint();
- }
- }
-
- protected void transferFocusTo(Component var1) {
- boolean var2 = true;
- if (var1.isFocusTraversable()) {
- var1.requestFocus();
- var2 = false;
- } else if (var1 instanceof JComponent && ((JComponent)var1).requestDefaultFocus()) {
- var2 = false;
- }
-
- if (var2) {
- this.sgbook.requestFocus();
- }
-
- }
-
- public void uninstallUI(JComponent var1) {
- if (var1.getBorder() == this.border) {
- var1.setBorder((Border)null);
- }
-
- ((Container)var1).setLayout((LayoutManager)null);
- if (this.desc != null) {
- this.desc.removeMultiLineListener(this);
- }
-
- }
-
- protected void updateTitle(SmartGuidePage var1) {
- this.title.setText(var1.getTitle());
- }
- }
-