home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Extras / ODesign / SetupPSE.exe / data.z / BitMaps.java < prev    next >
Encoding:
Java Source  |  1997-05-08  |  35.3 KB  |  1,363 lines

  1. package COM.odi.demo.OSDraw;
  2.  
  3. /**
  4.  *      <H3>Copyright (C) Object Design Inc. 1996, 1997</H3>
  5.  */
  6.  
  7. import COM.odi.*;
  8.  
  9. import java.applet.Applet;
  10. import java.awt.*;
  11.  
  12. /* 
  13.  * The only purpose of BitMaps is to start applet and create MainFrame instance
  14.  */
  15.  
  16. public class BitMaps extends Applet {
  17.  
  18.   // Create and show the main window (MainFrame)
  19.  
  20.   public void init() {
  21.     MainFrame frame = new MainFrame(this);
  22.     frame.show();
  23.   }
  24. }
  25.  
  26. /*
  27.  * Subclass of java.awt.Frame
  28.  * User communicates to database through this window interface
  29.  * Handles menus and directs dialog boxes
  30.  * Handles all relevent events
  31.  */
  32.  
  33. class MainFrame extends Frame {
  34.  
  35.   private Applet parent;
  36.  
  37.   private Database db;        // Current database
  38.   private Transaction trans;    // Current transaction
  39.   private Thread initialized;    // Indicates if ObjectStore has been initialized
  40.  
  41.   // figure variable to indicate present figure and its constants
  42.   private int figure;
  43.   private CheckboxMenuGroup figureGroup;
  44.   private static final int LINE = 1;
  45.   private static final int RECTANGLE = 2;
  46.   private static final int OVAL = 3;
  47.   private static final int POLYGON = 4;
  48.   private static final int TEXT = 5;
  49.   private static final int IMAGE = 6;
  50.  
  51.   private boolean dragging;    // Indicates if mouse is being dragged
  52.  
  53.   // Coordinates used when the mouse is dragging
  54.   private int startX;
  55.   private int startY;
  56.   private int presentX;
  57.   private int presentY;
  58.  
  59.   // Used to record present polygon while it is drawn
  60.   private Polygon poly;
  61.  
  62.   // Settings for present text and its menu groups
  63.   private String presentString;
  64.   private TextSettings textSettings;
  65.   private CheckboxMenuGroup textNameGroup;
  66.   private CheckboxMenuGroup textStyleGroup;
  67.   private CheckboxMenuGroup textSizeGroup;
  68.  
  69.   // Settings for present image and its meny groups
  70.   private ImageSettings imageSettings;
  71.   private CheckboxMenuGroup XDirectionGroup;
  72.   private CheckboxMenuGroup YDirectionGroup;
  73.   private CheckboxMenuGroup XFactorGroup;
  74.   private CheckboxMenuGroup YFactorGroup;
  75.  
  76.   // Fill Status and its menu group
  77.   private boolean fillStatus;
  78.   private CheckboxMenuGroup fillGroup;
  79.  
  80.   // Present colors
  81.   private Color foreColor;
  82.   private Color backColor;
  83.   
  84.   // Menu group for colors and an array of color constants
  85.   private CheckboxMenuGroup colorGroup;
  86.   private static final Color colors[] = {
  87.     Color.white,
  88.     Color.lightGray,
  89.     Color.gray,
  90.     Color.darkGray,
  91.     Color.black,
  92.     Color.red,
  93.     Color.pink,
  94.     Color.orange,
  95.     Color.yellow,
  96.     Color.green,
  97.     Color.magenta,
  98.     Color.cyan,
  99.     Color.blue
  100.   };
  101.  
  102.   private BitMapObject root;    // Database root
  103.  
  104.   // Variable process used to lock app in a process, also its constants
  105.   private int process;
  106.   private static final int NO_PROCESS = 0;
  107.   private static final int DELIVER_MESSAGE = 1;
  108.   private static final int OPEN_DATABASE = 2;
  109.  
  110.   // Menu labels which lead to event-handling methods
  111.   private static final String newLabel = "New Database...";
  112.   private static final String openLabel = "Open Database...";
  113.   private static final String saveLabel = "Save Database";
  114.   private static final String closeLabel = "Close Database...";
  115.   private static final String repaintLabel = "Refresh Display";
  116.   private static final String destroyLastLabel = "Destroy Last Object";
  117.   private static final String clearLabel = "Clear Database";
  118.   private static final String setImageLabel = "Set Image...";
  119.   private static final String currentImageLabel = "Current Image...";
  120.   private static final String exitLabel = "Exit";
  121.  
  122.   private AppletIOSupport AIOS; // Control of I/O
  123.  
  124.   // Constructor to set default values
  125.  
  126.   public MainFrame(Applet parent) {
  127.     super("Empty");
  128.  
  129.     this.parent = parent;
  130.     
  131.     db = null;
  132.     trans = null;
  133.     initialized = null;
  134.  
  135.     figure = LINE;
  136.     figureGroup = new CheckboxMenuGroup();
  137.  
  138.     dragging = false;
  139.  
  140.     process = NO_PROCESS;
  141.  
  142.     poly = new Polygon();
  143.  
  144.     textSettings = new TextSettings();
  145.     textNameGroup = new CheckboxMenuGroup();
  146.     textStyleGroup = new CheckboxMenuGroup();
  147.     textSizeGroup = new CheckboxMenuGroup();
  148.  
  149.     imageSettings = new ImageSettings();
  150.     XDirectionGroup = new CheckboxMenuGroup();
  151.     YDirectionGroup = new CheckboxMenuGroup();
  152.     XFactorGroup = new CheckboxMenuGroup();
  153.     YFactorGroup = new CheckboxMenuGroup();
  154.  
  155.     fillStatus = false;
  156.     fillGroup = new CheckboxMenuGroup();
  157.  
  158.     foreColor = Color.black;
  159.     setForeground(foreColor);
  160.     colorGroup = new CheckboxMenuGroup();
  161.     
  162.     backColor = Color.cyan;
  163.     setBackground(backColor);
  164.  
  165.     setSize(600, 400);
  166.     setLocation(5, 150);
  167.     Font textFont = new Font("Arial", Font.PLAIN, 14);
  168.     setFont(textFont);
  169.  
  170.     AIOS = new AppletIOSupport();
  171.     AIOS.registerFontMetrics(getFontMetrics(textFont));
  172.     AIOS.initializeMessageBox(this, 25, 25);
  173.     AIOS.initializeMessageBox(this, 25, 25, true);
  174.  
  175.     buildMenuBar();
  176.   }
  177.  
  178.   // Long method to build the menu bar and its menus and nested menus
  179.  
  180.   private void buildMenuBar() {
  181.     MenuBar menuBar = new MenuBar();
  182.     setMenuBar(menuBar);
  183.  
  184.     Menu menu, sub;
  185.     CheckboxMenuItem checkItem;
  186.  
  187.     menu = new Menu("File");
  188.     menuBar.add(menu);
  189.     menu.add(new MenuItem(newLabel));
  190.     menu.add(new MenuItem(openLabel));
  191.     menu.add(new MenuItem(saveLabel));
  192.     menu.add(new MenuItem(closeLabel));
  193.     menu.addSeparator();
  194.     menu.add(new MenuItem(repaintLabel));
  195.     menu.addSeparator();
  196.     menu.add(new MenuItem(exitLabel));
  197.  
  198.     menu = new Menu("Edit");
  199.     menuBar.add(menu);
  200.     menu.add(new MenuItem(destroyLastLabel));
  201.     menu.add(new MenuItem(clearLabel));
  202.  
  203.     menu = new Menu("Settings");
  204.     menuBar.add(menu);
  205.     sub = new Menu("Shape");
  206.     checkItem = new CheckboxMenuItem("Line");
  207.     checkItem.setState(true);
  208.     sub.add(checkItem);
  209.     figureGroup.add(checkItem);
  210.     checkItem = new CheckboxMenuItem("Rectangle");
  211.     sub.add(checkItem);
  212.     figureGroup.add(checkItem);
  213.     checkItem = new CheckboxMenuItem("Oval");
  214.     sub.add(checkItem);
  215.     figureGroup.add(checkItem);
  216.     checkItem = new CheckboxMenuItem("Polygon");
  217.     sub.add(checkItem);
  218.     figureGroup.add(checkItem);
  219.     checkItem = new CheckboxMenuItem("Text");
  220.     sub.add(checkItem);
  221.     figureGroup.add(checkItem);
  222.     checkItem = new CheckboxMenuItem("Image");
  223.     sub.add(checkItem);
  224.     figureGroup.add(checkItem);
  225.     menu.add(sub);
  226.     sub = new Menu("Color");
  227.     checkItem = new CheckboxMenuItem("White");
  228.     sub.add(checkItem);
  229.     colorGroup.add(checkItem);
  230.     checkItem = new CheckboxMenuItem("Light Gray");
  231.     sub.add(checkItem);
  232.     colorGroup.add(checkItem);
  233.     checkItem = new CheckboxMenuItem("Gray");
  234.     sub.add(checkItem);
  235.     colorGroup.add(checkItem);
  236.     checkItem = new CheckboxMenuItem("Dark Gray");
  237.     sub.add(checkItem);
  238.     colorGroup.add(checkItem);
  239.     checkItem = new CheckboxMenuItem("Black");
  240.     checkItem.setState(true);
  241.     sub.add(checkItem);
  242.     colorGroup.add(checkItem);
  243.     checkItem = new CheckboxMenuItem("Red");
  244.     sub.add(checkItem);
  245.     colorGroup.add(checkItem);
  246.     checkItem = new CheckboxMenuItem("Pink");
  247.     sub.add(checkItem);
  248.     colorGroup.add(checkItem);
  249.     checkItem = new CheckboxMenuItem("Orange");
  250.     sub.add(checkItem);
  251.     colorGroup.add(checkItem);
  252.     checkItem = new CheckboxMenuItem("Yellow");
  253.     sub.add(checkItem);
  254.     colorGroup.add(checkItem);
  255.     checkItem = new CheckboxMenuItem("Green");
  256.     sub.add(checkItem);
  257.     colorGroup.add(checkItem);
  258.     checkItem = new CheckboxMenuItem("Magenta");
  259.     sub.add(checkItem);
  260.     colorGroup.add(checkItem);
  261.     checkItem = new CheckboxMenuItem("Cyan");
  262.     sub.add(checkItem);
  263.     colorGroup.add(checkItem);
  264.     checkItem = new CheckboxMenuItem("Blue");
  265.     sub.add(checkItem);
  266.     colorGroup.add(checkItem);
  267.     menu.add(sub);
  268.     menu.addSeparator();
  269.     sub = new Menu("Fill Status");
  270.     checkItem = new CheckboxMenuItem("On");
  271.     sub.add(checkItem);
  272.     fillGroup.add(checkItem);
  273.     checkItem = new CheckboxMenuItem("Off");
  274.     checkItem.setState(true);
  275.     sub.add(checkItem);
  276.     fillGroup.add(checkItem);
  277.     menu.add(sub);
  278.  
  279.     menu = new Menu("Text");
  280.     menuBar.add(menu);
  281.     sub = new Menu("Font Name");
  282.     for (int i = 0; i < textSettings.fontNames.length; i++) {
  283.       checkItem = new CheckboxMenuItem(textSettings.fontNames[i]);
  284.       sub.add(checkItem);
  285.       textNameGroup.add(checkItem);
  286.     }
  287.     textNameGroup.select(0);
  288.     menu.add(sub);
  289.     sub = new Menu("Font Style");
  290.     checkItem = new CheckboxMenuItem("Regular");
  291.     checkItem.setState(true);
  292.     sub.add(checkItem);
  293.     textStyleGroup.add(checkItem);
  294.     checkItem = new CheckboxMenuItem("Bold");
  295.     sub.add(checkItem);
  296.     textStyleGroup.add(checkItem);
  297.     checkItem = new CheckboxMenuItem("Italic");
  298.     sub.add(checkItem);
  299.     textStyleGroup.add(checkItem);
  300.     checkItem = new CheckboxMenuItem("Bold Italic");
  301.     sub.add(checkItem);
  302.     textStyleGroup.add(checkItem);
  303.     menu.add(sub);
  304.     sub = new Menu("Font Size");
  305.     for (int i = 0; i < 10; i++) {
  306.       checkItem = new CheckboxMenuItem(Integer.toString(getSizeFromIndex(i)));
  307.       sub.add(checkItem);
  308.       textSizeGroup.add(checkItem);
  309.     }
  310.     textSizeGroup.select(3);    // Selects font 16
  311.     menu.add(sub);
  312.     
  313.     menu = new Menu("Image");
  314.     menuBar.add(menu);
  315.     menu.add(new MenuItem(setImageLabel));
  316.     menu.addSeparator();
  317.     menu.add(new MenuItem(currentImageLabel));
  318.     menu.addSeparator();
  319.     sub = new Menu("X Direction");
  320.     checkItem = new CheckboxMenuItem("X enlarged");
  321.     sub.add(checkItem);
  322.     XDirectionGroup.add(checkItem);
  323.     checkItem = new CheckboxMenuItem("X reduced");
  324.     checkItem.setState(true);
  325.     sub.add(checkItem);
  326.     XDirectionGroup.add(checkItem);
  327.     menu.add(sub);
  328.     sub = new Menu("Y Direction");
  329.     checkItem = new CheckboxMenuItem("Y enlarged");
  330.     sub.add(checkItem);
  331.     YDirectionGroup.add(checkItem);
  332.     checkItem = new CheckboxMenuItem("Y reduced");
  333.     checkItem.setState(true);
  334.     sub.add(checkItem);
  335.     YDirectionGroup.add(checkItem);
  336.     menu.add(sub);
  337.     sub = new Menu("X Factor");
  338.     for (int i = 1; i <= 10; i++) {
  339.       checkItem = new CheckboxMenuItem(Integer.toString(i));
  340.       sub.add(checkItem);
  341.       XFactorGroup.add(checkItem);
  342.     }
  343.     XFactorGroup.select(0);
  344.     menu.add(sub);
  345.     sub = new Menu("Y Factor");
  346.     for (int i = 1; i <= 10; i++) {
  347.       checkItem = new CheckboxMenuItem(Integer.toString(i));
  348.       sub.add(checkItem);
  349.       YFactorGroup.add(checkItem);
  350.     }
  351.     YFactorGroup.select(0);
  352.     menu.add(sub);
  353.   }
  354.  
  355.   // Override java.awt.Component.show method to move the window
  356.  
  357.   public void setVisible(boolean b) {
  358.     super.setVisible(b);
  359.     setLocation(5, 150);
  360.   }
  361.  
  362.   // Override java.awt.Component.paint method to paint all database figures
  363.  
  364.   public void paint(Graphics g) {
  365.     if (initialized != null) {
  366.       ObjectStore.initialize(initialized);
  367.     }
  368.     super.paint(g);
  369.     if (db == null) {
  370.       return;
  371.     }
  372.     BitMapObject obj = root;
  373.     while (obj != null) {
  374.       if (obj instanceof OSImageFile) {
  375.     ((OSImageFile)obj).drawFigure(g, this);
  376.       }
  377.       else {
  378.     obj.drawFigure(g);
  379.       }
  380.       g.setColor(foreColor);
  381.       obj = obj.getNextObject();
  382.     }
  383.  
  384.     if (dragging) {
  385.       g.setColor(foreColor);
  386.       if (figure == LINE) {
  387.     g.drawLine(startX, startY, presentX, presentY);
  388.       }
  389.       if (figure == RECTANGLE) {
  390.     Point topLeft = getTopLeft(startX, startY, presentX, presentY);
  391.     Point bottomRight = getBottomRight(startX, startY, presentX, presentY);
  392.     g.drawRect(topLeft.x, topLeft.y, bottomRight.x - topLeft.x,
  393.            bottomRight.y - topLeft.y);
  394.       }
  395.       if (figure == OVAL) {
  396.     Point topLeft = getTopLeft(startX, startY, presentX, presentY);
  397.     Point bottomRight = getBottomRight(startX, startY, presentX, presentY);
  398.     g.drawOval(topLeft.x, topLeft.y, bottomRight.x - topLeft.x,
  399.            bottomRight.y - topLeft.y);
  400.       }
  401.       if (figure == POLYGON) {
  402.     g.drawPolygon(poly);
  403.       }
  404.       if (figure == TEXT) {
  405.     g.setFont(textSettings.getFont());
  406.     g.drawString(presentString, startX, startY);
  407.       }
  408.     }
  409.  
  410.     // Stop locking process in OPEN_DATABASE (if necessary)
  411.  
  412.     if (process == OPEN_DATABASE) {
  413.       process = NO_PROCESS;
  414.     }
  415.   }
  416.  
  417.   // Method to deal with user dragging the mouse
  418.  
  419.   public boolean mouseDrag(Event event, int x, int y) {
  420.     if (db == null) {
  421.       return true;
  422.     }
  423.  
  424.     // Make sure there is no process
  425.  
  426.     if (process != NO_PROCESS) {
  427.       return true;
  428.     }
  429.     if (figure == LINE || figure == RECTANGLE || figure == OVAL) {
  430.       if (!dragging) {
  431.     dragging = true;
  432.     startX = x;
  433.     startY = y;
  434.     return true;
  435.       }
  436.  
  437.       // Compute dimensions of largest rectangle
  438.       int largeX;
  439.       int largeY;
  440.       if (abs(presentX - startX) > abs(x - startX)) {
  441.     largeX = presentX;
  442.       }
  443.       else {
  444.     largeX = x;
  445.       }
  446.       if (abs(presentY - startY) > abs(y - startY)) {
  447.     largeY = presentY;
  448.       }
  449.       else {
  450.     largeY = y;
  451.       }
  452.       largeX += 10 * direction(largeX - startX);
  453.       largeY += 10 * direction(largeY - startY);
  454.       presentX = x;
  455.       presentY = y;
  456.       Point topLeft = getTopLeft(startX + 10 * direction(startX - largeX), 
  457.                  startY + 10 * direction(startY - largeY),
  458.                  largeX, largeY);
  459.       Point bottomRight = 
  460.       getBottomRight(startX + 10 * direction(startX - largeX), 
  461.              startY + 10 * direction(startY - largeY),
  462.              largeX, largeY);
  463.       repaint(topLeft.x, topLeft.y, bottomRight.x - topLeft.x,
  464.           bottomRight.y - topLeft.y);
  465.     }
  466.     return true;
  467.   }
  468.  
  469.   // Method to deal with user releasing mouse
  470.  
  471.   public boolean mouseUp(Event event, int x, int y) {
  472.     if (db == null) {
  473.       return true;
  474.     }
  475.  
  476.     // Make sure there is no process 
  477.  
  478.     if (process != NO_PROCESS) {
  479.       return true;
  480.     }
  481.     if (figure == POLYGON) {
  482.       dragging = true;
  483.       poly.addPoint(x, y);
  484.       Rectangle rect = getPolyRect(poly);
  485.       repaint(rect.x - 5, rect.y - 5, rect.width + 10, rect.height + 10);
  486.       return true;
  487.     }
  488.     if (figure == TEXT) {
  489.       dragging = true;
  490.       startX = x;
  491.       startY = y;
  492.       presentString = "";
  493.       return true; 
  494.     }
  495.     if (figure == IMAGE && imageSettings.getName() != null) {
  496.       addFigure(new OSImageFile(imageSettings.getName(), x, y));
  497.       repaint();
  498.       return true;
  499.     }
  500.     if (dragging) {
  501.       dragging = false;
  502.       if (startX == x && startY == y) {
  503.     return true;
  504.       }
  505.       if (figure == LINE) {
  506.     addFigure(new OSLine(startX, startY, x, y));
  507.       }
  508.       else if (figure == RECTANGLE) {
  509.     Point topLeft = getTopLeft(startX, startY, x, y);
  510.     Point bottomRight = getBottomRight(startX, startY, x, y);
  511.     addFigure(new OSRectangle(topLeft.x, topLeft.y,
  512.                   bottomRight.x, bottomRight.y));
  513.       }
  514.       else if (figure == OVAL) {
  515.     Point topLeft = getTopLeft(startX, startY, x, y);
  516.     Point bottomRight = getBottomRight(startX, startY, x, y);
  517.     addFigure(new OSOval(topLeft.x, topLeft.y, bottomRight.x - topLeft.x,
  518.                  bottomRight.y - topLeft.y));
  519.       }
  520.       repaint();
  521.     }
  522.     return true;
  523.   }
  524.  
  525.   // Method to handle keyboard event
  526.  
  527.   public boolean keyDown(Event event, int key) {
  528.  
  529.     // Make sure there is no process
  530.  
  531.     if (process != NO_PROCESS) {
  532.       return true;
  533.     }
  534.     if (figure == TEXT && dragging) {
  535.       if ((char)key == '\n') {
  536.     dragging = false;
  537.     addFigure(new OSText(presentString, startX, startY));
  538.       }
  539.       else if (key == 8) {
  540.     // Backspace key
  541.     if (presentString.length() > 0) {
  542.       FontMetrics metrics = getFontMetrics(textSettings.getFont());
  543.       int textWidth = metrics.stringWidth(presentString);
  544.       presentString = presentString.substring(0, presentString.length() - 1);
  545.       repaint(startX - 5, startY - metrics.getHeight(),
  546.           textWidth + 10, metrics.getHeight() + 10);
  547.     }
  548.     return true;
  549.       } else if (key == 27) {
  550.     // Esc key was pressed
  551.     dragging = false;
  552.       }
  553.       else {
  554.     presentString += (char)key;
  555.     FontMetrics metrics = getFontMetrics(textSettings.getFont());
  556.     repaint(startX - 5, startY - metrics.getHeight(),
  557.         metrics.stringWidth(presentString) + 10, 
  558.         metrics.getHeight() + 10);
  559.     return true;
  560.       } 
  561.       repaint();
  562.       return true;
  563.     }
  564.     if (figure == POLYGON && dragging) {
  565.       if ((char)key == '\n') {
  566.     finishPolygon();
  567.       }
  568.       else if (key == 27) {
  569.     // Esc key was pressed
  570.     dragging = false;
  571.     poly = new Polygon();
  572.     repaint();
  573.     return true;
  574.       }
  575.     }
  576.     return true;
  577.   }
  578.  
  579.   // Overloaded method addFigure to add each figure to the database
  580.     
  581.   private void addFigure(OSLine line) {
  582.     if (db == null) {
  583.       return;
  584.     }
  585.     if (root == null) {
  586.       root = line;
  587.       db.setRoot("Root", root);
  588.       ((OSLine)root).setColor(foreColor);
  589.       return;
  590.     }
  591.     BitMapObject node = root;
  592.     while (node.getNextObject() != null) {
  593.       node = node.getNextObject();
  594.     }
  595.     node.setNextObject(line);
  596.     line.setColor(foreColor);
  597.   }
  598.  
  599.   private void addFigure(OSRectangle rec) {
  600.     if (db == null) {
  601.       return;
  602.     }
  603.     if (root == null) {
  604.       root = rec;
  605.       db.setRoot("Root", root);
  606.       ((OSRectangle)root).setColor(foreColor);
  607.       ((OSRectangle)root).setFillStatus(fillStatus);
  608.       return;
  609.     }
  610.     BitMapObject node = root;
  611.     while (node.getNextObject() != null) {
  612.       node = node.getNextObject();
  613.     }
  614.     node.setNextObject(rec);
  615.     rec.setColor(foreColor);
  616.     rec.setFillStatus(fillStatus);
  617.   }
  618.  
  619.   public void addFigure(OSOval oval) {
  620.     if (db == null) {
  621.       return;
  622.     }
  623.     if (root == null) {
  624.       root = oval;
  625.       db.setRoot("Root", root);
  626.       ((OSOval)root).setColor(foreColor);
  627.       ((OSOval)root).setFillStatus(fillStatus);
  628.       return;
  629.     }
  630.     BitMapObject node = root;
  631.     while (node.getNextObject() != null) {
  632.       node = node.getNextObject();
  633.     }
  634.     node.setNextObject(oval);
  635.     oval.setColor(foreColor);
  636.     oval.setFillStatus(fillStatus);
  637.   }
  638.  
  639.   private void addFigure(OSPolygon pol) {
  640.     if (db == null) {
  641.       return;
  642.     }
  643.     if (root == null) {
  644.       root = pol;
  645.       db.setRoot("Root", root);
  646.       ((OSPolygon)root).setColor(foreColor);
  647.       ((OSPolygon)root).setFillStatus(fillStatus);
  648.       return;
  649.     }
  650.     BitMapObject node = root;
  651.     while (node.getNextObject() != null) {
  652.       node = node.getNextObject();
  653.     }
  654.     node.setNextObject(pol);
  655.     pol.setColor(foreColor);
  656.     pol.setFillStatus(fillStatus);
  657.   }
  658.  
  659.   private void addFigure(OSText text) {
  660.     if (db == null) {
  661.       return;
  662.     }
  663.     if (root == null) {
  664.       root = text;
  665.       db.setRoot("Root", root);
  666.       ((OSText)root).setColor(foreColor);
  667.       ((OSText)root).setFont(textSettings.getFont());
  668.       return;
  669.     }
  670.     BitMapObject node = root;
  671.     while (node.getNextObject() != null) {
  672.       node = node.getNextObject();
  673.     }
  674.     node.setNextObject(text);
  675.     text.setColor(foreColor);
  676.     text.setFont(textSettings.getFont());
  677.   }
  678.  
  679.   private void addFigure(OSImageFile imageFile) {
  680.     if (db == null) {
  681.       return;
  682.     }
  683.     if (root == null) {
  684.       root = imageFile;
  685.       db.setRoot("Root", root);
  686.       ((OSImageFile)root).setEnlargeX(imageSettings.getEnlargeX());
  687.       ((OSImageFile)root).setEnlargeY(imageSettings.getEnlargeY());
  688.       ((OSImageFile)root).setFactorX(imageSettings.getFactorX());
  689.       ((OSImageFile)root).setFactorY(imageSettings.getFactorY());
  690.       return;
  691.     }
  692.     BitMapObject node = root;
  693.     while (node.getNextObject() != null) {
  694.       node = node.getNextObject();
  695.     }
  696.     node.setNextObject(imageFile);
  697.     imageFile.setEnlargeX(imageSettings.getEnlargeX());
  698.     imageFile.setEnlargeY(imageSettings.getEnlargeY());
  699.     imageFile.setFactorX(imageSettings.getFactorX());
  700.     imageFile.setFactorY(imageSettings.getFactorY());
  701.   }
  702.  
  703.   // Methods to handle menu events
  704.  
  705.   private void newDatabase() {
  706.     if (db != null) {
  707.       showMessageBox("Database already open.");
  708.       return;
  709.     }
  710.     if (initialized == null) {
  711.       ObjectStore.initialize(null, null);
  712.       initialized = Thread.currentThread();
  713.     }
  714.     FileDialog dlg = new FileDialog(this, "New Database", FileDialog.SAVE);
  715.     dlg.setFile("*.odb");
  716.     dlg.setVisible(true);
  717.     if (dlg.getFile() == null) {
  718.       // Cancel button was pressed
  719.       return;
  720.     }
  721.     String fname = dlg.getFile();
  722.  
  723.     // Variable junk needed for Windows NT 4.0 beta
  724.     // For this release, extra junk is added to .odb file names
  725.  
  726.     boolean junk = true;
  727.     if (fname.length() > 4) {
  728.       int size = fname.length();
  729.       String extension = "";
  730.       char buf[] = fname.toCharArray();
  731.       for (int i = 0; i < 4; i++) {
  732.     extension += buf[size - 4 + i];
  733.       }
  734.       extension = extension.toLowerCase();
  735.       if (extension.equals(".odb")) {
  736.     junk = false;
  737.       }
  738.     }
  739.     if (junk) {
  740.       fname = dlg.getFile().substring(0, dlg.getFile().length() - 4);
  741.     }
  742.     String dbname = dlg.getDirectory() + fname;
  743.     setTitle(dbname);
  744.     try {
  745.       db = Database.create(dbname, 0664);
  746.     } catch (AccessViolationException e) {
  747.       setTitle("Empty");
  748.       showMessageBox("File system access violation.");
  749.       return;
  750.     } catch (DatabaseAlreadyExistsException e) {
  751.       setTitle("Empty");
  752.       showMessageBox("Database already exists.");
  753.       return;
  754.     } catch (DatabaseException e) {
  755.       setTitle("Empty");
  756.       showMessageBox("Invalid database: " + dbname);
  757.       return;
  758.     }
  759.  
  760.     // Create a database root and start transaction
  761.  
  762.     if (db != null) {
  763.       trans = Transaction.begin(ObjectStore.UPDATE);
  764.       db.createRoot("Root", null);
  765.       trans.commit();
  766.       trans = Transaction.begin(ObjectStore.UPDATE);
  767.       root = null;
  768.       poly = new Polygon();
  769.     }
  770.   }
  771.  
  772.   private void openDatabase() {
  773.     if (db != null) {
  774.       showMessageBox("Database already open.");
  775.       return;
  776.     }
  777.     if (initialized == null) {
  778.       ObjectStore.initialize(null, null);
  779.       initialized = Thread.currentThread();
  780.     }
  781.     FileDialog dlg = new FileDialog(this, "Open Database", FileDialog.LOAD);
  782.     dlg.setFile("*.odb");
  783.     dlg.setVisible(true);
  784.     if (dlg.getFile() == null) {
  785.       return;            // Cancel button was pressed
  786.     }
  787.     process = OPEN_DATABASE;    // No response to other events
  788.     String dbname = dlg.getDirectory() + dlg.getFile();
  789.     setTitle(dbname);
  790.     try {
  791.       db = Database.open(dbname, ObjectStore.OPEN_UPDATE);
  792.     } catch (DatabaseNotFoundException e) {
  793.       setTitle("Empty");
  794.       showMessageBox("Database not found.");
  795.       return;
  796.     } catch (AccessViolationException e) {
  797.       setTitle("Empty");
  798.       showMessageBox("File system access violation.");
  799.       return;
  800.     } catch (IncompatibleOpenTypeException e) {
  801.       setTitle("Empty");
  802.       showMessageBox("Database open with a different specification.");
  803.       return;
  804.     } catch (DatabaseException e) {
  805.       setTitle("Empty");
  806.       showMessageBox("Invalid database.");
  807.       return;
  808.     }
  809.     if (db != null) {
  810.       trans = Transaction.begin(ObjectStore.UPDATE);
  811.       root = (BitMapObject)db.getRoot("Root");
  812.       if (root != null) {
  813.     BitMapObject node = root;
  814.     while (node.getNextObject() != null) {
  815.       node = node.getNextObject();
  816.     }
  817.     if (node instanceof OSLine) {
  818.       figure = LINE;
  819.       figureGroup.select(0);
  820.       foreColor = ((OSLine)node).getColor();
  821.       colorGroup.select(getColorIndex(foreColor));
  822.     }
  823.     else if (node instanceof OSRectangle) {
  824.       figure = RECTANGLE;
  825.       figureGroup.select(1);
  826.       foreColor = ((OSRectangle)node).getColor();
  827.       colorGroup.select(getColorIndex(foreColor));
  828.       fillStatus = ((OSRectangle)node).getFillStatus();
  829.     }
  830.     else if (node instanceof OSOval) {
  831.       figure = OVAL;
  832.       figureGroup.select(2);
  833.       foreColor = ((OSOval)node).getColor();
  834.       colorGroup.select(getColorIndex(foreColor));
  835.       fillStatus = ((OSOval)node).getFillStatus();
  836.     }
  837.     else if (node instanceof OSPolygon) {
  838.       figure = POLYGON;
  839.       figureGroup.select(3);
  840.       foreColor = ((OSPolygon)node).getColor();
  841.       colorGroup.select(getColorIndex(foreColor));
  842.       fillStatus = ((OSPolygon)node).getFillStatus();
  843.     }
  844.     else if (node instanceof OSText) {
  845.       figure = TEXT;
  846.       figureGroup.select(4);
  847.       foreColor = ((OSText)node).getColor();
  848.       colorGroup.select(getColorIndex(foreColor));
  849.       Font font = ((OSText)node).getFont();
  850.       textSettings.setName(font.getName());
  851.       textNameGroup.select(textSettings.getNameIndex());
  852.       textSettings.setStyle(font.getStyle());
  853.       textStyleGroup.select(textSettings.getStyleIndex());
  854.       textSettings.setSize(font.getSize());
  855.       textSizeGroup.select(getIndexFromSize(font.getSize()));
  856.     }
  857.     else if (node instanceof OSImageFile) {
  858.       figure = IMAGE;
  859.       figureGroup.select(5);
  860.       foreColor = Color.black;
  861.       colorGroup.select(getColorIndex(foreColor));
  862.       imageSettings.setName(((OSImageFile)node).getFile());
  863.       imageSettings.setEnlargeX(((OSImageFile)node).getEnlargeX());
  864.       if (imageSettings.getEnlargeX()) {
  865.         XDirectionGroup.select(0);
  866.       }
  867.       else {
  868.         XDirectionGroup.select(1);
  869.       }
  870.       imageSettings.setEnlargeY(((OSImageFile)node).getEnlargeY());
  871.       if (imageSettings.getEnlargeY()) {
  872.         YDirectionGroup.select(0);
  873.       }
  874.       else {
  875.         YDirectionGroup.select(1);
  876.       }
  877.       imageSettings.setFactorX(((OSImageFile)node).getFactorX());
  878.       XFactorGroup.select(imageSettings.getFactorX() - 1);
  879.       imageSettings.setFactorY(((OSImageFile)node).getFactorY());
  880.       YFactorGroup.select(imageSettings.getFactorY() - 1); 
  881.     }
  882.     poly = new Polygon();
  883.       }
  884.       if (fillStatus) {
  885.     fillGroup.select(0);
  886.       }
  887.       else {
  888.     fillGroup.select(1);
  889.       }
  890.       dragging = false;
  891.       repaint();
  892.     }
  893.   }
  894.  
  895.   private void saveDatabase() {
  896.     if (db == null) {
  897.       showMessageBox("Database not open.");
  898.       return;
  899.     }
  900.     trans.commit();
  901.     trans = Transaction.begin(ObjectStore.UPDATE);
  902.     root = (BitMapObject)db.getRoot("Root");
  903.   }
  904.  
  905.   private void closeDatabase() {
  906.     if (db == null) {
  907.       showMessageBox("No database to close.");
  908.       return;
  909.     }
  910.     trans.abort();
  911.     db.close();
  912.     db = null;
  913.     setTitle("Empty");
  914.     repaint();
  915.   }
  916.  
  917.   private void exitApp() {
  918.     if (db != null) {
  919.       trans.abort();
  920.       db.close();
  921.       db = null;
  922.       repaint();
  923.     }
  924.     System.exit(0);
  925.   }
  926.  
  927.   private void destroyLast() {
  928.     if (db == null) {
  929.       showMessageBox("Database not open here.");
  930.       return;
  931.     }
  932.     if (root == null) {
  933.       showMessageBox("Empty database.");
  934.       return;
  935.     }
  936.     BitMapObject node = root;
  937.     BitMapObject temp = node.getNextObject();
  938.     if (temp == null) {
  939.       root = null;
  940.       db.setRoot("Root", root);
  941.       ObjectStore.destroy(node);
  942.       repaint();
  943.       return;
  944.     }
  945.     while (temp.getNextObject() != null) {
  946.       node = temp;
  947.       temp = temp.getNextObject();
  948.     }
  949.     node.setNextObject(null);
  950.     ObjectStore.destroy(temp);
  951.     repaint();
  952.   }
  953.  
  954.   private void clearDatabase() {
  955.     if (db == null) {
  956.       showMessageBox("Database not open.");
  957.       return;
  958.     }
  959.     if (root == null) {
  960.       showMessageBox("Empty database.");
  961.       return;
  962.     }
  963.     while (root != null) {
  964.       destroyNode(1);
  965.     }
  966.     repaint();
  967.     showMessageBox("Database is now empty.");
  968.   }
  969.  
  970.   private void destroyNode(int place) {
  971.     if (place == 1) {
  972.       BitMapObject temp = root;
  973.       root = root.getNextObject();
  974.       db.setRoot("Root", root);
  975.       ObjectStore.destroy(temp);
  976.       return;
  977.     }
  978.     BitMapObject node = root;
  979.     for (int i = 2; i < place; i++) {
  980.       node = node.getNextObject();
  981.     }
  982.     BitMapObject temp = node.getNextObject();
  983.     node.setNextObject(temp.getNextObject());
  984.     ObjectStore.destroy(temp);
  985.   }
  986.  
  987.   private void setImage() {
  988.     if (db == null) {
  989.       showMessageBox("Database not open.");
  990.       return;
  991.     }
  992.     FileDialog dlg = new FileDialog(this, "Set Image", FileDialog.LOAD);
  993.     dlg.setFile("*.gif");
  994.     dlg.setVisible(true);
  995.     if (dlg.getFile() == null) {
  996.       // Cancel button was pressed
  997.       return;
  998.     }
  999.     imageSettings.setName(dlg.getDirectory() + dlg.getFile());
  1000.   }
  1001.   
  1002.   private void currentImage() {
  1003.     if (db == null) {
  1004.       showMessageBox("Database not open.");
  1005.       return;
  1006.     }
  1007.     if (imageSettings.getName() == null) {
  1008.       showMessageBox("Please set image.");
  1009.       return;
  1010.     }
  1011.     AIOS.resetMessageBox();
  1012.     AIOS.addMessageBoxLabel("Image Name: " + imageSettings.getName(),
  1013.              Label.CENTER);
  1014.     if (imageSettings.getEnlargeX()) {
  1015.       AIOS.addMessageBoxLabel("X is enlarged by a factor of " +
  1016.                   Integer.toString(imageSettings.getFactorX()),
  1017.                   Label.CENTER);
  1018.     }
  1019.     else {
  1020.       AIOS.addMessageBoxLabel("X is reduced by a factor of " +
  1021.                   Integer.toString(imageSettings.getFactorX()),
  1022.                   Label.CENTER);
  1023.     }
  1024.     if (imageSettings.getEnlargeY()) {
  1025.       AIOS.addMessageBoxLabel("Y is enlarged by a factor of " +
  1026.                   Integer.toString(imageSettings.getFactorY()),
  1027.                   Label.CENTER);
  1028.     }
  1029.     else {
  1030.       AIOS.addMessageBoxLabel("Y is reduced by a factor of " +
  1031.                   Integer.toString(imageSettings.getFactorY()),
  1032.                   Label.CENTER);
  1033.     }
  1034.     showMessageBox();
  1035.   }
  1036.  
  1037.   // Methods to handle java.awt.CheckboxMenuItem events
  1038.  
  1039.   private void doFillGroup(int index) {
  1040.     fillStatus = (index == 0);
  1041.   }
  1042.  
  1043.   private void doColorGroup(int index) {
  1044.     foreColor = colors[index];
  1045.   }
  1046.  
  1047.   private void doFigureGroup(int index) {
  1048.     figure = index + 1;
  1049.   }
  1050.  
  1051.   private void doTextNameGroup(int index) {
  1052.     textSettings.setName(index);
  1053.   }
  1054.  
  1055.   private void doTextStyleGroup(int index) {
  1056.     textSettings.setStyle(index);
  1057.   }
  1058.  
  1059.   private void doTextSizeGroup(int index) {
  1060.     textSettings.setSize(getSizeFromIndex(index));
  1061.   }
  1062.   
  1063.   private void doXDirectionGroup(int index) {
  1064.     imageSettings.setEnlargeX(index == 0);
  1065.   }
  1066.  
  1067.   private void doYDirectionGroup(int index) {
  1068.     imageSettings.setEnlargeY(index == 0);
  1069.   }
  1070.  
  1071.   private void doXFactorGroup(int index) {
  1072.     imageSettings.setFactorX(index + 1);
  1073.   }
  1074.  
  1075.   private void doYFactorGroup(int index) {
  1076.     imageSettings.setFactorY(index + 1);
  1077.   }
  1078.  
  1079.   // Two useful methods to return a rectangle's top left and bottom right
  1080.  
  1081.   private Point getTopLeft(int x1, int y1, int x2, int y2) {
  1082.     if (x1 < x2 && y1 < y2) {
  1083.       return new Point(x1, y1);
  1084.     }
  1085.     if (x1 >= x2 && y1 < y2) {
  1086.       return new Point(x2, y1);
  1087.     }
  1088.     if (x1 < x2 && y1 >= y2) {
  1089.       return new Point(x1, y2);
  1090.     }
  1091.     return new Point(x2, y2);
  1092.   }
  1093.  
  1094.   private Point getBottomRight(int x1, int y1, int x2, int y2) {
  1095.     if (x1 < x2 && y1 < y2) {
  1096.       return new Point(x2, y2);
  1097.     }
  1098.     if (x1 >= x2 && y1 < y2) {
  1099.       return new Point(x1, y2);
  1100.     }
  1101.     if (x1 < x2 && y1 >= y2) {
  1102.       return new Point(x2, y1);
  1103.     }
  1104.     return new Point(x1, y1);
  1105.   }
  1106.  
  1107.   // Method used to save currently drawn polygon
  1108.  
  1109.   private void finishPolygon() {
  1110.     if (db == null) {
  1111.       return;
  1112.     }
  1113.     if (figure != POLYGON) {
  1114.       return;
  1115.     }
  1116.     if (!dragging) {
  1117.       return;
  1118.     }
  1119.     if (poly.npoints <= 2) {
  1120.       return;
  1121.     }
  1122.     dragging = false;
  1123.     OSPolygon addend = new OSPolygon();
  1124.     for (int i = 0; i < poly.npoints; i++) {
  1125.       addend.addPoint(poly.xpoints[i], poly.ypoints[i]);
  1126.     }
  1127.     addFigure(addend);
  1128.     poly = new Polygon();
  1129.     repaint();
  1130.   }
  1131.  
  1132.   // Method for finding ordinal value of a color in the colors array
  1133.  
  1134.   private int getColorIndex(Color color) {
  1135.     boolean found = false;
  1136.     int i = 0;
  1137.     while (!found && i < colors.length) {
  1138.       found = colors[i].equals(color);
  1139.       if (!found) {
  1140.     i++;
  1141.       }
  1142.     }
  1143.     if (found) {
  1144.       return i;
  1145.     }
  1146.     return -1;
  1147.   }
  1148.  
  1149.   // Two methods to understand formula for 10 font sizes
  1150.  
  1151.   // Method for getting proper font size from index
  1152.  
  1153.   private int getSizeFromIndex(int index) {
  1154.     if (index < 8) {
  1155.       return index * 2 + 10;
  1156.     }
  1157.     if (index == 8) {
  1158.       return 36;
  1159.     }
  1160.     return 48;
  1161.   }
  1162.  
  1163.   // Method for getting proper index from size
  1164.  
  1165.   private int getIndexFromSize(int size) {
  1166.     if (size < 36) {
  1167.       return (size - 10) / 2;
  1168.     }
  1169.     if (size == 36) {
  1170.       return 8;
  1171.     }
  1172.     return 9;
  1173.   }
  1174.  
  1175.   // Useful method for computing absolute value
  1176.  
  1177.   private int abs(int n) {
  1178.     if (n < 0) {
  1179.       return -1 * n;
  1180.     }
  1181.     return n;
  1182.   }
  1183.  
  1184.   // Useful method for computing direction of an integer (+ or -)
  1185.  
  1186.   private int direction(int n) {
  1187.     if (n < 0) {
  1188.       return -1;
  1189.     }
  1190.     return 1;
  1191.   }
  1192.  
  1193.   // getBoundingBox method of java.awt.Polygon does not work
  1194.   // Here is the replacement
  1195.  
  1196.   private Rectangle getPolyRect(Polygon pol) {
  1197.     Rectangle rect = new Rectangle(10000, 10000, 0, 0);
  1198.     for (int i = 0; i < pol.npoints; i++) {
  1199.       for (int j = i + 1; j < pol.npoints; j++) {
  1200.     if (abs(pol.xpoints[i] - pol.xpoints[j]) > rect.width) {
  1201.       rect.width = abs(pol.xpoints[i] - pol.xpoints[j]);
  1202.     }
  1203.     if (abs(pol.ypoints[i] - pol.ypoints[j]) > rect.height) {
  1204.       rect.height = abs(pol.ypoints[i] - pol.ypoints[j]);
  1205.     }
  1206.       }
  1207.       if (pol.xpoints[i] < rect.x) {
  1208.     rect.x = pol.xpoints[i];
  1209.       }
  1210.       if (pol.ypoints[i] < rect.y) {
  1211.     rect.y = pol.ypoints[i];
  1212.       }
  1213.     }
  1214.     if (rect.width < 2) {
  1215.       rect.width = 2;
  1216.     }
  1217.     if (rect.height < 2) {
  1218.       rect.height = 2;
  1219.     }
  1220.     return rect;
  1221.   }
  1222.   
  1223.   // Methods which prepare color settings before displaying a dialog box
  1224.  
  1225.   private void showMessageBox(String message) {
  1226.     setForeground(Color.black);
  1227.     setBackground(Color.lightGray);
  1228.     process = DELIVER_MESSAGE;
  1229.     AIOS.showMessageBox(message);
  1230.   }
  1231.  
  1232.   private void showMessageBox() {
  1233.     setForeground(Color.black);
  1234.     setBackground(Color.lightGray);
  1235.     process = DELIVER_MESSAGE;
  1236.     AIOS.showMessageBox();
  1237.   }
  1238.  
  1239.   // Override java.awt.Component.handleEvent method to close Window
  1240.  
  1241.   public boolean handleEvent(Event event) {
  1242.     if (event.id == Event.WINDOW_DESTROY) {
  1243.       exitApp();
  1244.       return true;
  1245.     }
  1246.     return super.handleEvent(event);
  1247.   }
  1248.  
  1249.   // Override java.awt.Component.action method to catch relevent events
  1250.  
  1251.   public boolean action(Event event, Object obj) {
  1252.     if (event.target instanceof MenuItem) {
  1253.       String label = ((MenuItem) event.target).getLabel();
  1254.       if (label.equals(newLabel)) {
  1255.     newDatabase();
  1256.     return true;
  1257.       }
  1258.       if (label.equals(openLabel)) {
  1259.     openDatabase();
  1260.     return true;
  1261.       }
  1262.       if (label.equals(saveLabel)) {
  1263.     saveDatabase();
  1264.     return true;
  1265.       }
  1266.       if (label.equals(closeLabel)) {
  1267.     closeDatabase();
  1268.     return true;
  1269.       }
  1270.       if (label.equals(repaintLabel)) {
  1271.     repaint();
  1272.     return true;
  1273.       }
  1274.       if (label.equals(destroyLastLabel)) {
  1275.     destroyLast();
  1276.     return true;
  1277.       }
  1278.       if (label.equals(clearLabel)) {
  1279.     clearDatabase();
  1280.     return true;
  1281.       }
  1282.       if (label.equals(setImageLabel)) {
  1283.     setImage();
  1284.     return true;
  1285.       }
  1286.       if (label.equals(currentImageLabel)) {
  1287.     currentImage();
  1288.     return true;
  1289.       }
  1290.       if (label.equals(exitLabel)) {
  1291.     exitApp();
  1292.     return true;
  1293.       }
  1294.     }
  1295.     if (event.target instanceof CheckboxMenuItem) {
  1296.       CheckboxMenuItem check = (CheckboxMenuItem)(event.target);
  1297.       int index;
  1298.       if ((index = fillGroup.select(check)) >= 0) {
  1299.     doFillGroup(index);
  1300.     return true;
  1301.       }
  1302.       if ((index = XDirectionGroup.select(check)) >= 0) {
  1303.     doXDirectionGroup(index);
  1304.     return true;
  1305.       }
  1306.       if ((index = YDirectionGroup.select(check)) >= 0) {
  1307.     doYDirectionGroup(index);
  1308.     return true;
  1309.       }
  1310.       if ((index = figureGroup.select(check)) >= 0) {
  1311.     doFigureGroup(index);
  1312.     return true;
  1313.       }
  1314.       if ((index = textNameGroup.select(check)) >= 0) {
  1315.     doTextNameGroup(index);
  1316.     return true;
  1317.       }
  1318.       if ((index = textStyleGroup.select(check)) >= 0) {
  1319.     doTextStyleGroup(index);
  1320.     return true;
  1321.       }
  1322.       if ((index = textSizeGroup.select(check)) >= 0) {
  1323.     doTextSizeGroup(index);
  1324.     return true;
  1325.       }
  1326.       if ((index = XFactorGroup.select(check)) >= 0) {
  1327.     doXFactorGroup(index);
  1328.     return true;
  1329.       }
  1330.       if ((index = YFactorGroup.select(check)) >= 0) {
  1331.     doYFactorGroup(index);
  1332.     return true;
  1333.       }
  1334.       if ((index = colorGroup.select(check)) >= 0) {
  1335.     doColorGroup(index);
  1336.     return true;
  1337.       }
  1338.     }
  1339.     if (event.target instanceof Button) {
  1340.       String label = (String)obj;
  1341.       if (label.equals("OK")) {
  1342.     if (process == DELIVER_MESSAGE) {
  1343.       AIOS.hideMessageBox();
  1344.     }
  1345.       }
  1346.       else if (label.equals("Cancel")) {
  1347.     process = NO_PROCESS;    // Unlock process
  1348.     AIOS.hideAll();
  1349.       }
  1350.       else {
  1351.     return false;
  1352.       }
  1353.       process = NO_PROCESS;    // Unlock process
  1354.       setForeground(foreColor);
  1355.       setBackground(backColor);
  1356.       repaint();
  1357.       return true;
  1358.     }
  1359.     return false;
  1360.   }
  1361. }
  1362.  
  1363.