Exemplo n.º 1
0
  /** Paint it. */
  public void paint(Graphics g) {
    Dimension d = getSize();
    if (!inited || buff == null || d.width != buffSize.width || d.height != buffSize.height) {
      buffSize.width = d.width;
      buffSize.height = d.height;
      buff = createImage(d.width + 4, d.height + 4);
      if (buff == null) return;
      buffG = buff.getGraphics();
      inited = true;
    }

    buffG.setColor(Color.lightGray);
    buffG.fillRect(0, 0, prefSize.width, prefSize.height);
    PressedRect(buffG, 0, 0, prefSize.width - 2, prefSize.height - 2);

    buffG.setColor(Color.lightGray);
    buffG.fillRect(0, 0, prefSize.width + 2, prefSize.height + 2);
    if (!gameover) if ((gameover = is_game_over())) end_game();
    for (int i = 0; i < rows; i++) {
      for (int j = 0; j < cols; j++) {
        drawBlock(buffG, i, j, status(i, j));
      }
    }
    // PressedRect(buffG,0,0,prefSize.width + 2,prefSize.height + 2);
    if (buff != null) g.drawImage(buff, 0, 0, null);
  }
Exemplo n.º 2
0
  /** Is called when the applet wants to be resized. */
  @Override
  public void appletResize(int width, int height) {
    currentAppletSize.width = width;
    currentAppletSize.height = height;
    final Dimension currentSize = new Dimension(currentAppletSize.width, currentAppletSize.height);

    if (loader != null) {
      AppContext appCtxt = loader.getAppContext();
      if (appCtxt != null) appEvtQ = (java.awt.EventQueue) appCtxt.get(AppContext.EVENT_QUEUE_KEY);
    }

    final AppletPanel ap = this;
    if (appEvtQ != null) {
      appEvtQ.postEvent(
          new InvocationEvent(
              Toolkit.getDefaultToolkit(),
              new Runnable() {
                @Override
                public void run() {
                  if (ap != null) {
                    ap.dispatchAppletEvent(APPLET_RESIZE, currentSize);
                  }
                }
              }));
    }
  }
Exemplo n.º 3
0
 public void restart(int rows, int cols, int nummines) {
   this.rows = rows;
   this.cols = cols;
   this.nummines = nummines;
   prefSize.width = cols * wt;
   prefSize.height = rows * ht;
   minerowlist = new int[nummines];
   minecollist = new int[nummines];
   restart();
 }
Exemplo n.º 4
0
 /**
  * Prepare a buffer for the image, return if the canvas is ready Only need to call this when the
  * size of the canvas is changed, Since we automatically detect the size change in paint() only
  * call this on start
  */
 public boolean newImgBuf() {
   Dimension sz = getSize();
   if (sz.width == 0 || sz.height == 0) return false;
   // quit if the current image already has the right size
   if (img != null && imgG != null && sz.equals(imgSize)) return true;
   img = createImage(sz.width, sz.height);
   if (imgG != null) imgG.dispose();
   imgG = img.getGraphics();
   imgSize = sz;
   return true;
 }
Exemplo n.º 5
0
 public void sizeToText() {
   Dimension d = new Dimension(0, 0);
   Dimension di;
   for (int i = 0; i < nLists; i++) {
     fm = getFontMetrics(list[i].getFont());
     di = list[i].preferredSize();
     d.height += di.height;
     for (int j = 0; j < list[i].countItems(); j++) {
       d.width = Math.max(d.width, fm.stringWidth(list[i].getItem(j) + "  "));
     }
   }
   for (int i = 0; i < nLists; i++) {
     list[i].resize(d.width + hSpace / 3, list[i].preferredSize().height);
   }
   panel.resize(d.width + hSpace / 3, list[1].preferredSize().height);
   this.resize(d.width + hSpace, d.height + vSpace);
   panel.invalidate();
   validate();
 }
Exemplo n.º 6
0
 public static void openFrame(Object frame) {
   boolean packFrame = false;
   if (packFrame) {
     ((JFrame) frame).pack();
   } else {
     ((JFrame) frame).validate();
   }
   // Center the window
   Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
   Dimension frameSize = ((JFrame) frame).getSize();
   if (frameSize.height > screenSize.height) {
     frameSize.height = screenSize.height;
   }
   if (frameSize.width > screenSize.width) {
     frameSize.width = screenSize.width;
   }
   ((JFrame) frame)
       .setLocation(
           (screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
   ((JFrame) frame).setVisible(true);
 }
Exemplo n.º 7
0
  /** Construct an applet viewer and start the applet. */
  public void init() {
    try {
      // Get the width (if any)
      defaultAppletSize.width = getWidth();
      currentAppletSize.width = defaultAppletSize.width;

      // Get the height (if any)
      defaultAppletSize.height = getHeight();
      currentAppletSize.height = defaultAppletSize.height;

    } catch (NumberFormatException e) {
      // Turn on the error flag and let TagAppletPanel
      // do the right thing.
      status = APPLET_ERROR;
      showAppletStatus("badattribute.exception");
      showAppletLog("badattribute.exception");
      showAppletException(e);
    }

    setLayout(new BorderLayout());

    createAppletThread();
  }
  /**
   * Method declaration
   *
   * @param ev
   */
  public void actionPerformed(ActionEvent ev) {

    String s = ev.getActionCommand();

    if (s == null) {
      if (ev.getSource() instanceof MenuItem) {
        MenuItem i;

        s = ((MenuItem) ev.getSource()).getLabel();
      }
    }

    if (s.equals("Execute")) {
      execute();
    } else if (s.equals("Exit")) {
      windowClosing(null);
    } else if (s.equals("Transfer")) {
      Transfer.work(null);
    } else if (s.equals("Dump")) {
      Transfer.work(new String[] {"-d"});

      /* NB - 26052002 Restore is not implemented yet in the transfer tool */
      /*
              } else if (s.equals("Restore")) {
                  Transfer.work(new String[]{"-r"});
      */
    } else if (s.equals("Logging on")) {
      jdbcSystem.setLogToSystem(true);
    } else if (s.equals("Logging off")) {
      jdbcSystem.setLogToSystem(false);
    } else if (s.equals("Refresh Tree")) {
      refreshTree();
    } else if (s.startsWith("#")) {
      int i = Integer.parseInt(s.substring(1));

      txtCommand.setText(sRecent[i]);
    } else if (s.equals("Connect...")) {
      connect(ConnectionDialog.createConnection(fMain, "Connect"));
      refreshTree();
    } else if (s.equals("Results in Grid")) {
      iResult = 0;

      pResult.removeAll();
      pResult.add("Center", gResult);
      pResult.doLayout();
    } else if (s.equals("Open Script...")) {
      FileDialog f = new FileDialog(fMain, "Open Script", FileDialog.LOAD);

      // (ulrivo): set default directory if set from command line
      if (defDirectory != null) {
        f.setDirectory(defDirectory);
      }

      f.show();

      String file = f.getFile();

      if (file != null) {
        txtCommand.setText(DatabaseManagerCommon.readFile(f.getDirectory() + file));
      }
    } else if (s.equals("Save Script...")) {
      FileDialog f = new FileDialog(fMain, "Save Script", FileDialog.SAVE);

      // (ulrivo): set default directory if set from command line
      if (defDirectory != null) {
        f.setDirectory(defDirectory);
      }

      f.show();

      String file = f.getFile();

      if (file != null) {
        DatabaseManagerCommon.writeFile(f.getDirectory() + file, txtCommand.getText());
      }
    } else if (s.equals("Save Result...")) {
      FileDialog f = new FileDialog(fMain, "Save Result", FileDialog.SAVE);

      // (ulrivo): set default directory if set from command line
      if (defDirectory != null) {
        f.setDirectory(defDirectory);
      }

      f.show();

      String file = f.getFile();

      if (file != null) {
        showResultInText();
        DatabaseManagerCommon.writeFile(f.getDirectory() + file, txtResult.getText());
      }
    } else if (s.equals("Results in Text")) {
      iResult = 1;

      pResult.removeAll();
      pResult.add("Center", txtResult);
      pResult.doLayout();
      showResultInText();
    } else if (s.equals("AutoCommit on")) {
      try {
        cConn.setAutoCommit(true);
      } catch (SQLException e) {
      }
    } else if (s.equals("AutoCommit off")) {
      try {
        cConn.setAutoCommit(false);
      } catch (SQLException e) {
      }
    } else if (s.equals("Enlarge Tree")) {
      Dimension d = tTree.getMinimumSize();

      d.width += 20;

      tTree.setMinimumSize(d);
      fMain.pack();
    } else if (s.equals("Shrink Tree")) {
      Dimension d = tTree.getMinimumSize();

      d.width -= 20;

      if (d.width >= 0) {
        tTree.setMinimumSize(d);
      }

      fMain.pack();
    } else if (s.equals("Enlarge Command")) {
      txtCommand.setRows(txtCommand.getRows() + 1);
      fMain.pack();
    } else if (s.equals("Shrink Command")) {
      int i = txtCommand.getRows() - 1;

      txtCommand.setRows(i < 1 ? 1 : i);
      fMain.pack();
    } else if (s.equals("Commit")) {
      try {
        cConn.commit();
      } catch (SQLException e) {
      }
    } else if (s.equals("Insert test data")) {
      insertTestData();
    } else if (s.equals("Rollback")) {
      try {
        cConn.rollback();
      } catch (SQLException e) {
      }
    } else if (s.equals("Disable MaxRows")) {
      try {
        sStatement.setMaxRows(0);
      } catch (SQLException e) {
      }
    } else if (s.equals("Set MaxRows to 100")) {
      try {
        sStatement.setMaxRows(100);
      } catch (SQLException e) {
      }
    } else if (s.equals("SELECT")) {
      showHelp(DatabaseManagerCommon.selectHelp);
    } else if (s.equals("INSERT")) {
      showHelp(DatabaseManagerCommon.insertHelp);
    } else if (s.equals("UPDATE")) {
      showHelp(DatabaseManagerCommon.updateHelp);
    } else if (s.equals("DELETE")) {
      showHelp(DatabaseManagerCommon.deleteHelp);
    } else if (s.equals("CREATE TABLE")) {
      showHelp(DatabaseManagerCommon.createTableHelp);
    } else if (s.equals("DROP TABLE")) {
      showHelp(DatabaseManagerCommon.dropTableHelp);
    } else if (s.equals("CREATE INDEX")) {
      showHelp(DatabaseManagerCommon.createIndexHelp);
    } else if (s.equals("DROP INDEX")) {
      showHelp(DatabaseManagerCommon.dropIndexHelp);
    } else if (s.equals("CHECKPOINT")) {
      showHelp(DatabaseManagerCommon.checkpointHelp);
    } else if (s.equals("SCRIPT")) {
      showHelp(DatabaseManagerCommon.scriptHelp);
    } else if (s.equals("SHUTDOWN")) {
      showHelp(DatabaseManagerCommon.shutdownHelp);
    } else if (s.equals("SET")) {
      showHelp(DatabaseManagerCommon.setHelp);
    } else if (s.equals("Test Script")) {
      showHelp(DatabaseManagerCommon.testHelp);
    }
  }
Exemplo n.º 9
0
 public Dimension getPreferredSize() {
   prefSize.width = 4 + cols * ht;
   prefSize.height = 4 + rows * ht;
   return prefSize;
 }
Exemplo n.º 10
0
 @Override
 public void setBounds(int x, int y, int width, int height) {
   super.setBounds(x, y, width, height);
   currentAppletSize.width = width;
   currentAppletSize.height = height;
 }