示例#1
0
  public void load() {

    Document doc = null;
    String fileName =
        Constants.getConfigFile(Constants.VDCT_SETTINGS_FILE_NAME, Constants.VDCT_SETTINGS_FILE);

    try {

      // If file does not exists, load default file.
      if (!(new File(fileName).exists())) {
        Console.getInstance().println("o) No settings file found. Using defaults...");

        URL url =
            getClass().getResource("/" + Constants.CONFIG_DIR + Constants.VDCT_SETTINGS_FILE_NAME);
        if (url == null) {
          throw new FileNotFoundException();
        }
        fileName = url.getFile();
      }

      /* Sometimes fileName is in a format with backslashes and sometimes slashes.
       * TASK:SLASH: replace this hack with a general rule on how the file names should be passed.
       */
      if (fileName.indexOf('\\') >= 0) {
        try {
          fileName = (new File(fileName).toURI()).toURL().getFile();
        } catch (MalformedURLException exception) {
          // nothing
        }
      }
      doc = XMLManager.readResourceDocument(fileName);
    } catch (FileNotFoundException e) {
      Console.getInstance().println("Settings file '" + fileName + "' not found.");
      return;
    } catch (Exception e) {
      Console.getInstance().println("An error occured while loading settings!");
      Console.getInstance().println(e);
      return;
    }

    if (doc == null) {
      Console.getInstance().println("Failed to read settings file '" + fileName + "'.");
      return;
    }

    loadRdbSettings(doc);
  }
示例#2
0
  public void save() {
    Document doc = XMLManager.newDocument();

    Element root = (Element) doc.createElement("vdct");

    doc.appendChild(root);
    saveRdbSettings(doc, root);
    root.normalize();

    String fileName = System.getProperty(Constants.VDCT_SETTINGS_FILE);
    if (fileName == null) {
      fileName = System.getProperty("user.home") + "/" + Constants.VDCT_SETTINGS_FILE_NAME;
    }

    try {
      XMLManager.writeDocument(fileName, doc, null, null, null);

    } catch (IOException e) {
      Console.getInstance().println("Error while saving settings file!");
      Console.getInstance().println(e);
    }
  }
示例#3
0
public class TextButton extends Colleague {
  private String nome;
  private boolean active = false;
  private int positionX = 1;
  private int positionY = 1;

  private Console c = Console.getInstance();

  public TextButton(String s, int y) {
    nome = s;
    positionY = y;
  }

  public TextButton(String s, int y, int x) {
    nome = s;
    positionY = y;
    positionX = x;
  }

  public void activate() {
    active = true;
    show();
  }

  public void deactivate() {
    active = false;
    show();
  }

  public void show() {
    if (active) c.bold();
    else c.normal();

    c.position(positionY, positionX);
    System.out.print("[" + nome + "]");
  }
}