Exemplo n.º 1
0
  /** Construct the JobQueue. This is private; use getJobQueue() to get the job queue instance. */
  private JobQueue() {
    // determine which compiler we should be using
    String compilertype = Config.getPropString("bluej.compiler.type");

    // even though it is specified to use internal, the preferred compiler for a
    // system running Java 6 or greater is the JavaCompiler API
    if (compilertype.equals("internal")) {
      if (Config.isJava16()) {
        try {
          Class<?> c = Class.forName("bluej.compiler.CompilerAPICompiler");
          compiler = (Compiler) c.newInstance();
        } catch (Throwable e) {
          Debug.message(
              "Could not instantiate the compiler API compiler implementation; defaulting to old compiler");
          compiler = new JavacCompilerInternal();
        }
      } else {
        compiler = new JavacCompilerInternal();
      }
    } else if (compilertype.equals("javac")) {
      compiler =
          new JavacCompiler(Config.getJDKExecutablePath("bluej.compiler.executable", "javac"));
    } else {
      Debug.message(Config.getString("compiler.invalidcompiler"));
    }

    thread = new CompilerThread();

    // Lower priority to improve GUI response time during compilation
    int priority = Thread.currentThread().getPriority() - 1;
    priority = Math.max(priority, Thread.MIN_PRIORITY);
    thread.setPriority(priority);

    thread.start();
  }
Exemplo n.º 2
0
  /**
   * Generates a source code skeleton for this class.
   *
   * @param template the name of the particular class template (just the base name without path and
   *     suffix)
   * @param pkg the package that the class target resides in
   * @param name the name of the class
   * @param sourceFile the name of the source file to be generated
   */
  public boolean generateSkeleton(String template, Package pkg, String name, String sourceFile) {
    Hashtable<String, String> translations = new Hashtable<String, String>();
    translations.put("CLASSNAME", name);

    if (pkg.isUnnamedPackage()) {
      translations.put("PKGLINE", "");
    } else {
      translations.put(
          "PKGLINE", "package " + pkg.getQualifiedName() + ";" + Config.nl + Config.nl);
    }

    try {
      // Check for existing file. Normally this won't happen (the check for duplicate
      // target occurs prior to this) but on Windows filenames are case insensitive.
      File dest = new File(sourceFile);
      if (dest.exists()) {
        pkg.showError("duplicate-name");
        return false;
      }
      BlueJFileReader.translateFile(
          Config.getClassTemplateFile(template),
          new File(sourceFile),
          translations,
          Charset.forName("UTF-8"),
          pkg.getProject().getProjectCharset());
      return true;
    } catch (IOException e) {
      pkg.showError("skeleton-error");
      Debug.reportError("The default skeleton for the class could not be generated");
      Debug.reportError("Exception: " + e);
      return false;
    }
  }
Exemplo n.º 3
0
    public void processKeyEvent(Component focusedComponent, KeyEvent e) {
      if (e.getID() != KeyEvent.KEY_PRESSED) return;

      int keyCode = e.getKeyCode();

      if (keyCode == KeyEvent.VK_CAPS_LOCK
          || // the keys we want to ignore...
          keyCode == KeyEvent.VK_SHIFT
          || keyCode == KeyEvent.VK_CONTROL
          || keyCode == KeyEvent.VK_META
          || keyCode == KeyEvent.VK_ALT
          || keyCode == KeyEvent.VK_ALT_GRAPH
          || keyCode == KeyEvent.VK_COMPOSE
          || keyCode == KeyEvent.VK_NUM_LOCK
          || keyCode == KeyEvent.VK_SCROLL_LOCK
          || keyCode == KeyEvent.VK_UNDEFINED) return;

      if (currentAction == null) Debug.message("FunctionDialog: currentAction is null...");
      else {
        KeyStroke key = KeyStroke.getKeyStrokeForEvent(e);
        if (isPrintable(key, e)) helpLabel.setText(getHelpText("cannot-redefine"));
        else {
          actions.addActionForKeyStroke(key, currentAction);
          handleFuncListSelect();
        }
      }
      e.consume();
      removeKeyListener();
    }
Exemplo n.º 4
0
  /**
   * Traverse the directory tree starting in dir and add all the encountered files to the Set
   * allFiles.
   */
  private void traverseDirsForFiles(Set allFiles, File dir, FileFilter filter) {
    if (!filter.accept(dir)) {
      return;
    }
    if (dir.isFile()) {
      allFiles.add(dir);
      return;
    }

    File[] files = dir.listFiles(filter);
    if (files == null) {
      return;
    }

    try {
      getLocallyDeletedFiles(allFiles, dir);
    } catch (IOException ioe) {
      Debug.message("CVS error determining locally deleted files: " + ioe.getLocalizedMessage());
      // TODO: should probably propagate and cause the command to fail.
    }
    for (int i = 0; i < files.length; i++) {
      if (files[i].isFile()) {
        allFiles.add(files[i]);
      } else {
        traverseDirsForFiles(allFiles, files[i], filter);
      }
    }
  }
Exemplo n.º 5
0
  @Override
  public void keyTyped(KeyEvent event) {
    // We handle most things we are interested in here. The InputMap filters out
    // most other unwanted actions (but allows copy/paste).

    char ch = event.getKeyChar();

    if ((!isMacOs) && handleFontsizeKeys(event, ch)) {
      // Note: On Mac OS with Java 7+, we don't see command+= / command+- as a
      // key-typed event and so we handle it in keyReleased instead.
      return;
    }

    if ((event.getModifiers() & Event.META_MASK) != 0) {
      return; // return without consuming the event
    }
    if (isActive) {
      switch (ch) {
        case 4: // CTRL-D (unix/Mac EOF)
        case 26: // CTRL-Z (DOS/Windows EOF)
          buffer.signalEOF();
          writeToTerminal("\n");
          event.consume();
          break;

        case '\b': // backspace
          if (buffer.backSpace()) {
            try {
              int length = text.getDocument().getLength();
              text.replaceRange("", length - 1, length);
            } catch (Exception exc) {
              Debug.reportError("bad location " + exc);
            }
          }
          event.consume();
          break;

        case '\r': // carriage return
        case '\n': // newline
          if (buffer.putChar('\n')) {
            writeToTerminal(String.valueOf(ch));
            buffer.notifyReaders();
          }
          event.consume();
          break;

        default:
          if (ch >= 32) {
            if (buffer.putChar(ch)) {
              writeToTerminal(String.valueOf(ch));
            }
            event.consume();
          }
          break;
      }
    }
  }
Exemplo n.º 6
0
  /**
   * Create the connection, open it and associate it with the client.
   *
   * @throws AuthenticationException
   * @throws CommandAbortedException
   * @throws AuthenticationException
   * @throws CommandAbortedException
   * @throws InvalidCvsRootException
   */
  void setupConnection(Client client) throws CommandAbortedException, AuthenticationException {
    Connection connection = getConnection(cvsroot);

    if (connection != null) {
      connection.open();
      client.setConnection(connection);
    } else {
      Debug.message("Repository.setupConnection: connection is null");
    }
  }
Exemplo n.º 7
0
  /**
   * Create the menu items for the given members (constructors or methods).
   *
   * @return true if any items were created
   */
  public static boolean createMenuItems(
      JPopupMenu menu,
      CallableView[] members,
      ViewFilter filter,
      int first,
      int last,
      String prefix,
      InvokeListener il) {
    // Debug.message("Inside ClassTarget.createMenuItems\n first = " + first
    // + " last = " + last);
    boolean hasEntries = false;
    JMenuItem item;

    for (int i = first; i < last; i++) {
      try {
        CallableView m = members[last - i - 1];
        if (!filter.accept(m)) continue;
        // Debug.message("createSubMenu - creating MenuItem");

        Action callAction = null;
        if (m instanceof MethodView)
          callAction = new InvokeAction((MethodView) m, il, prefix + m.getLongDesc());
        else if (m instanceof ConstructorView)
          callAction = new ConstructAction((ConstructorView) m, il, prefix + m.getLongDesc());

        if (callAction != null) {
          item = menu.add(callAction);
          item.setFont(PrefMgr.getPopupMenuFont());
          hasEntries = true;
        }
      } catch (Exception e) {
        Debug.reportError("Exception accessing methods: " + e);
        e.printStackTrace();
      }
    }
    return hasEntries;
  }
Exemplo n.º 8
0
  public static void setClassImage(ClassView classView, ImageClassRole gclassRole, File imageFile) {
    GClass gclass = classView.getGClass();
    File projImagesDir = gclass.getPackage().getProject().getImageDir();
    if (imageFile != null) {
      if (!imageFile.getParentFile().getAbsoluteFile().equals(projImagesDir)) {
        // An image was selected from an external dir. We need
        // to copy it into the project images directory first.
        File destFile = new File(projImagesDir, imageFile.getName());
        try {
          FileUtility.copyFile(imageFile, destFile);
          imageFile = destFile;
        } catch (IOException e) {
          Debug.reportError("Error when copying file: " + imageFile + " to: " + destFile, e);
        }
      }

      gclass.setClassProperty("image", imageFile.getName());
    } else {
      imageFile = null;
      gclass.setClassProperty("image", null);
    }
    gclassRole.changeImage();
    gclass.getPackage().getProject().getProjectProperties().save();
  }