home *** CD-ROM | disk | FTP | other *** search
- import corel.af.util.BToolPix;
- import java.awt.Choice;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Dimension;
- import java.awt.Event;
- import java.awt.FlowLayout;
- import java.awt.Graphics;
- import java.awt.Image;
- import java.awt.MediaTracker;
- import java.awt.Panel;
- import java.awt.Point;
- import java.awt.Rectangle;
- import java.awt.TextField;
- import java.awt.image.CropImageFilter;
- import java.awt.image.FilteredImageSource;
- import java.awt.image.MemoryImageSource;
- import java.net.MalformedURLException;
- import java.net.URL;
-
- public class VToolbar extends Panel {
- private VDoc m_Document;
- private Barista m_Applet;
- private Image m_ToolBarImg;
- private String ToolBarGifName = "tools.gif";
- private ToolBarBtn CorelButton;
- private ToolBarBtn FirstPgButton;
- private ToolBarBtn PrevPgButton;
- private ToolBarBtn NextPgButton;
- private ToolBarBtn LastPgButton;
- private ToolBarBtn PViewButton;
- private ToolBarBtn StartTButton;
- private ToolBarBtn StopTButton;
- private ToolBarBtn MinimizeButton;
- private Choice m_cChoice;
- private Rectangle m_cChoiceRect;
- private BToolTip TextLabel;
- private int m_nNumOfPages;
- private int m_ToolBarLoc;
- static int TOOLBAR_LOCATION_TOP = 1;
- static int TOOLBAR_LOCATION_BOT = 2;
- public static final Dimension DEFAULT_BUTTON_SIZE = new Dimension(22, 22);
- public static final Dimension DEFAULT_BUTTON_IMAGE_SIZE = new Dimension(20, 20);
- static Dimension NumDefaultButtons = new Dimension(4, 4);
- static String[][] m_DefaultButtonMap;
- public ToolBarBtn PrevButton;
- public ToolBarBtn NextButton;
- public static final String IdCorel = "Corel";
- public static final String IdTransition = "Transition";
- public static final String IdStop = "TransitionStop";
- public static final String IdStart = "TransitionStart";
- public static final String IdBarHelp = "CorelBaristaHelp";
- public static final String IdBarAbout = "AboutCorelBarista";
- public static final String IdPView = "previousview";
- public static final String IdFirstPage = "Gotothefirstpage";
- public static final String IdLastPage = "Gotothelastpage";
- public static final String IdPrevPage = "Previous Page";
- public static final String IdNextPage = "Next Page";
- public static final String IdFind = "Findtext";
- public static final String IdMinimize = "MinimizeToolBar";
- public static final String IdCopy = "Copy";
- public static final String IdPrint = "Print...";
-
- public boolean init(VDoc var1, int var2) {
- this.m_ToolBarLoc = var2;
- this.m_Document = var1;
- this.m_Applet = this.m_Document.m_Applet;
- this.m_nNumOfPages = this.m_Document.m_nNumOfPages;
- this.m_ToolBarImg = this.loadImage(this.ToolBarGifName);
- if (this.m_ToolBarImg == null) {
- this.m_ToolBarImg = this.loadToolbarBitmapClass();
- }
-
- if (this.m_ToolBarImg == null) {
- return false;
- } else {
- initDefaultButtonMap();
- ((Component)this).setBackground(Color.lightGray);
- ((Container)this).setLayout(new FlowLayout(0, 2, 2));
- if (this.m_ToolBarLoc == TOOLBAR_LOCATION_TOP) {
- this.CorelButton = this.CreateNewButton("Corel", this.m_Applet.m_BaristaLoc.IdCorelTip);
- if (this.m_Document.m_bIsMultiPage) {
- this.FirstPgButton = this.CreateNewButton("Gotothefirstpage", this.m_Applet.m_BaristaLoc.IdFirstPageTip);
- this.PrevPgButton = this.CreateNewButton("Previous Page", this.m_Applet.m_BaristaLoc.IdPrevPageTip);
- this.NextPgButton = this.CreateNewButton("Next Page", this.m_Applet.m_BaristaLoc.IdNextPageTip);
- this.LastPgButton = this.CreateNewButton("Gotothelastpage", this.m_Applet.m_BaristaLoc.IdLastPageTip);
- this.PViewButton = this.CreateNewButton("previousview", this.m_Applet.m_BaristaLoc.IdPViewTip);
- this.m_cChoice = this.CreatePageChoice();
- if (this.m_Document.AutoScrollEnabled()) {
- this.StartTButton = this.CreateNewButton("TransitionStart", this.m_Applet.m_BaristaLoc.IdStartTip);
- this.StopTButton = this.CreateNewButton("TransitionStop", this.m_Applet.m_BaristaLoc.IdStopTip);
- }
- }
-
- this.MinimizeButton = this.CreateNewButton("MinimizeToolBar", this.m_Applet.m_BaristaLoc.IdMinimizeTip);
- } else {
- this.FirstPgButton = this.CreateNewButton("Gotothefirstpage", this.m_Applet.m_BaristaLoc.IdFirstPageTip);
- this.PrevPgButton = this.CreateNewButton("Previous Page", this.m_Applet.m_BaristaLoc.IdPrevPageTip);
- this.NextPgButton = this.CreateNewButton("Next Page", this.m_Applet.m_BaristaLoc.IdNextPageTip);
- this.LastPgButton = this.CreateNewButton("Gotothelastpage", this.m_Applet.m_BaristaLoc.IdLastPageTip);
- this.m_cChoice = this.CreatePageChoice();
- }
-
- this.TextLabel = this.CreateTipWindow();
- if (this.m_Document.m_bIsMultiPage) {
- this.UpdateButtons(this.m_Document.m_iCurrPage);
- }
-
- return true;
- }
- }
-
- public ToolBarBtn CreateNewButton(String var1, String var2) {
- ToolBarBtn var3 = new ToolBarBtn();
- var3.init(var1, var2, this);
- ((Container)this).add(var3);
- return var3;
- }
-
- public Choice CreatePageChoice() {
- Choice var1 = new Choice();
-
- for(int var2 = 1; var2 <= this.m_nNumOfPages; ++var2) {
- var1.addItem(var2 + " of " + this.m_nNumOfPages);
- }
-
- var1.select(this.m_Document.m_iCurrPage - 1);
- ((Component)var1).setBackground(Color.lightGray);
- ((Container)this).add(var1);
- return var1;
- }
-
- public BToolTip CreateTipWindow() {
- Dimension var1 = this.m_Applet.size();
- Dimension var2 = ((Container)this).minimumSize();
- BToolTip var3 = new BToolTip();
- var3.init("");
- ((Component)var3).resize(5, 22);
- ((Container)this).add(var3);
- return var3;
- }
-
- private Image loadToolbarBitmapClass() {
- BToolPix var1 = new BToolPix();
- MemoryImageSource var2 = new MemoryImageSource(var1.width, var1.height, var1.PixArray, 0, var1.width);
- return this.m_Applet.createImage(var2);
- }
-
- public void clearTip(String var1) {
- this.TextLabel.clearText(var1);
- }
-
- public void setTip(String var1) {
- this.TextLabel.setText(var1);
- }
-
- public boolean mouseExit(Event var1, int var2, int var3) {
- this.setTip(" ");
- return true;
- }
-
- public void paint(Graphics var1) {
- Dimension var2 = ((Component)this).size();
- if (this.m_cChoiceRect == null) {
- Dimension var3 = ((Container)this).minimumSize();
- int var4 = var2.width - var3.width;
- this.TextLabel.resize(var4 + 4, 22);
- if (this.m_cChoice != null) {
- this.m_cChoiceRect = this.m_cChoice.bounds();
- } else {
- this.m_cChoiceRect = new Rectangle();
- }
- }
-
- this.drawFrame(var1, var2.width, var2.height, false);
- }
-
- void drawFrame(Graphics var1, int var2, int var3, boolean var4) {
- if (var4) {
- var1.setColor(Color.darkGray);
- } else {
- var1.setColor(Color.white);
- }
-
- var1.drawLine(0, 0, var2 - 1, 0);
- var1.drawLine(0, 0, 0, var3 - 1);
- if (var4) {
- var1.setColor(Color.white);
- } else {
- var1.setColor(Color.darkGray);
- }
-
- var1.drawLine(0, var3 - 1, var2, var3 - 1);
- var1.drawLine(var2 - 1, 0, var2 - 1, var3);
- }
-
- void UpdateButtons(int var1) {
- if (this.m_ToolBarLoc == TOOLBAR_LOCATION_TOP && this.m_Document.AutoScrollEnabled()) {
- if (this.m_Document.AutoScrollStatus(1)) {
- this.StartTButton.enable();
- this.StopTButton.disable();
- } else {
- this.StartTButton.disable();
- this.StopTButton.enable();
- }
- }
-
- if (var1 > 1) {
- this.PrevPgButton.enable();
- if (this.FirstPgButton != null) {
- this.FirstPgButton.enable();
- }
- } else {
- this.PrevPgButton.disable();
- if (this.FirstPgButton != null) {
- this.FirstPgButton.disable();
- }
- }
-
- if (var1 < this.m_nNumOfPages) {
- this.NextPgButton.enable();
- if (this.LastPgButton != null) {
- this.LastPgButton.enable();
- }
- } else {
- this.NextPgButton.disable();
- if (this.LastPgButton != null) {
- this.LastPgButton.disable();
- }
- }
-
- this.m_cChoice.select(var1 - 1);
- this.m_cChoice.hide();
- this.m_cChoice.show();
- }
-
- private static void initDefaultButtonMap() {
- if (NumDefaultButtons.width != 0 && NumDefaultButtons.height != 0) {
- m_DefaultButtonMap = new String[NumDefaultButtons.width][NumDefaultButtons.height];
- m_DefaultButtonMap[0][0] = "CorelBaristaHelp";
- m_DefaultButtonMap[0][1] = "AboutCorelBarista";
- m_DefaultButtonMap[0][2] = "Corel";
- m_DefaultButtonMap[0][3] = "previousview";
- m_DefaultButtonMap[1][0] = "Previous Page";
- m_DefaultButtonMap[1][1] = "Next Page";
- m_DefaultButtonMap[1][2] = "Gotothefirstpage";
- m_DefaultButtonMap[1][3] = "Gotothelastpage";
- m_DefaultButtonMap[2][0] = "MinimizeToolBar";
- m_DefaultButtonMap[2][1] = "Transition";
- m_DefaultButtonMap[2][2] = "TransitionStop";
- m_DefaultButtonMap[2][3] = "TransitionStart";
- m_DefaultButtonMap[3][0] = "Findtext";
- m_DefaultButtonMap[3][1] = "Copy";
- m_DefaultButtonMap[3][2] = "Print...";
- m_DefaultButtonMap[3][3] = "";
- }
- }
-
- public Image getButtonImage(String var1) {
- Point var2 = getDefaultButtonImageIndex(var1);
- return var2 != null && this.m_ToolBarImg != null ? this.getSubImage(var2.y * DEFAULT_BUTTON_IMAGE_SIZE.width, var2.x * DEFAULT_BUTTON_IMAGE_SIZE.height, DEFAULT_BUTTON_IMAGE_SIZE.width, DEFAULT_BUTTON_IMAGE_SIZE.height) : null;
- }
-
- private static Point getDefaultButtonImageIndex(String var0) {
- for(int var2 = 0; var2 < NumDefaultButtons.width; ++var2) {
- for(int var3 = 0; var3 < NumDefaultButtons.height; ++var3) {
- String var1 = m_DefaultButtonMap[var2][var3];
- if (var1 == null) {
- break;
- }
-
- if (var1.equals(var0)) {
- return new Point(var2, var3);
- }
- }
- }
-
- return null;
- }
-
- public final Image getSubImage(int var1, int var2, int var3, int var4) {
- Image var6 = null;
- if (var3 == this.m_ToolBarImg.getWidth(this) && var4 == this.m_ToolBarImg.getHeight(this)) {
- return this.m_ToolBarImg;
- } else {
- CropImageFilter var5 = new CropImageFilter(var1, var2, var3, var4);
-
- try {
- var6 = ((Component)this).createImage(new FilteredImageSource(this.m_ToolBarImg.getSource(), var5));
- ((Component)this).prepareImage(var6, this);
- } catch (Exception var7) {
- }
-
- return var6;
- }
- }
-
- public final Image loadImage(String var1) {
- MediaTracker var2 = new MediaTracker(this);
- Object var3 = null;
-
- try {
- var7 = this.m_Applet.getImage(this.m_Applet.getDocumentBase(), var1);
- } catch (Exception var6) {
- System.out.println("Unable to load image : " + var6);
- return null;
- }
-
- if (var7 == null) {
- return null;
- } else {
- var2.addImage(var7, 0);
-
- try {
- var2.waitForID(0);
- } catch (InterruptedException var5) {
- System.out.println("tracker.addImage(image, 0);" + var5);
- }
-
- if ((var2.statusID(0, true) & 4) != 0) {
- var7.flush();
- var7 = null;
- }
-
- return var7;
- }
- }
-
- public synchronized boolean handleEvent(Event var1) {
- boolean var2 = false;
- if (var1.target instanceof TextField) {
- return false;
- } else {
- switch (var1.id) {
- case 1001:
- if (var1.target == this.m_cChoice) {
- int var3 = this.m_cChoice.getSelectedIndex();
- this.m_Document.GoToPage(var3 + 1);
- var2 = true;
- } else if (var1.target == this.PrevPgButton) {
- this.m_Document.PrevPage();
- var2 = true;
- } else if (var1.target == this.NextPgButton) {
- this.m_Document.NextPage();
- var2 = true;
- }
- default:
- if (!var2) {
- if (var1.id == 201) {
- var2 = this.OnClose();
- }
-
- if (!var2) {
- var2 = super.handleEvent(var1);
- }
- }
-
- return var2;
- }
- }
- }
-
- public boolean action(Event var1, Object var2) {
- boolean var3 = false;
- String var4 = (String)var2;
- if (var4.equals("Corel")) {
- try {
- URL var5 = new URL("http://www.corel.com/internet/barista.htm");
- this.m_Applet.getAppletContext().showDocument(var5);
- } catch (MalformedURLException var6) {
- }
-
- var3 = true;
- } else if (var4.equals("Print...")) {
- var3 = this.OnPrint();
- } else if (var4.equals("AboutCorelBarista")) {
- var3 = this.OnAbout();
- } else if (var4.equals("Gotothefirstpage")) {
- var3 = this.OnFirstPage();
- } else if (var4.equals("Previous Page")) {
- var3 = this.OnPrevPage();
- } else if (var4.equals("Next Page")) {
- var3 = this.OnNextPage();
- } else if (var4.equals("Gotothelastpage")) {
- var3 = this.OnLastPage();
- } else if (var4.equals("previousview")) {
- var3 = this.OnPView();
- } else if (var4.equals("TransitionStop")) {
- var3 = this.OnStartStopTransition(false);
- } else if (var4.equals("TransitionStart")) {
- var3 = this.OnStartStopTransition(true);
- } else if (var4.equals("MinimizeToolBar")) {
- var3 = this.OnMinimize();
- }
-
- return var3;
- }
-
- public boolean OnMinimize() {
- Event var1 = new Event(this, 1001, "DoMinimize");
- ((Component)this).postEvent(var1);
- return true;
- }
-
- public boolean OnPrint() {
- return true;
- }
-
- private boolean OnFirstPage() {
- if (this.m_Applet.m_Document.m_iCurrPage != 1) {
- this.m_Applet.m_Document.PrevView(this.m_Applet.m_Document.m_iCurrPage);
- this.m_Applet.m_Document.GoToPage(1);
- }
-
- return true;
- }
-
- private boolean OnLastPage() {
- if (this.m_Applet.m_Document.m_iCurrPage != this.m_Applet.m_Document.m_nNumOfPages) {
- this.m_Applet.m_Document.PrevView(this.m_Applet.m_Document.m_iCurrPage);
- this.m_Applet.m_Document.GoToPage(this.m_Applet.m_Document.m_nNumOfPages);
- }
-
- return true;
- }
-
- private boolean OnNextPage() {
- this.m_Applet.m_Document.NextPage();
- return true;
- }
-
- private boolean OnPrevPage() {
- this.m_Applet.m_Document.PrevPage();
- return true;
- }
-
- private boolean OnPView() {
- int var1 = this.m_Applet.m_Document.m_iCurrPage;
- this.m_Applet.m_Document.GoToPage(this.m_Applet.m_Document.m_nPrevPage);
- this.m_Applet.m_Document.PrevView(var1);
- return true;
- }
-
- private boolean OnAbout() {
- try {
- URL var1 = new URL("http://missionimprobable.com/barista/all.html");
- this.m_Applet.getAppletContext().showDocument(var1);
- } catch (MalformedURLException var2) {
- }
-
- return true;
- }
-
- public boolean OnClose() {
- ((Component)this).hide();
- ((Container)this).removeAll();
- System.exit(0);
- return true;
- }
-
- private final boolean OnStartStopTransition(boolean var1) {
- boolean var2 = this.m_Applet.GetDocument().AutoScrollStatus(1);
- if (var1) {
- if (!var2) {
- return true;
- }
- } else if (var2) {
- return true;
- }
-
- this.m_Applet.GetDocument().StartAutoScroll(false, true, true, true);
- return true;
- }
- }
-