Example #1
0
 public void inventory() {
   txtTranscript.insert("You are carrying:\n", txtTranscript.getText().length());
   for (String item : inventory) {
     txtTranscript.insert(item + "\n", txtTranscript.getText().length());
   }
   if (inventory.isEmpty()) {
     txtTranscript.insert("No items.\n", txtTranscript.getText().length());
   }
 }
Example #2
0
 public void autoinventory() {
   inv.setText("");
   inv.insert("You are carrying:\n", inv.getText().length());
   for (String item : inventory) {
     inv.insert(item + "\n", inv.getText().length());
   }
   if (inventory.isEmpty()) {
     inv.insert("No items.\n", inv.getText().length());
   }
 }
Example #3
0
  public void take(String takable) {
    String takeItem = null;
    int[] mapKey = null;
    int[] pair = {row, col};

    for (int[] key : myMap.items.keySet()) {
      if (Arrays.equals(pair, key)) {
        mapKey = key;
      }
    }
    if (mapKey != null) {
      ArrayList<String> loot = myMap.items.get(mapKey);
      for (String item : loot) {
        if (item.toUpperCase().equals(takable.toUpperCase())) {
          takeItem = item;
        }
      }
      if (takeItem != null) {
        inventory.add(takeItem);
        loot.remove(takeItem);
        txtTranscript.insert(
            "You picked up a " + takeItem + "\n", txtTranscript.getText().length());
        if (takeItem.equals("BLASTER")) {
          txtTranscript.insert(
              "You roll your eyes\nSo uncivilized...\n", txtTranscript.getText().length());
        } else if (takeItem.toUpperCase().equals("LIGHT SABER")) {
          txtTranscript.insert(
              "Now we're talking!\nA key weapon in defeating Vader.\n",
              txtTranscript.getText().length());
        } else if (takeItem.toUpperCase().equals("BAG OF YODA SNACKS")) {
          txtTranscript.insert(
              "You roll your eyes\nSo uncivilized..\n", txtTranscript.getText().length());
        } else if (takeItem.equals("HAIR BRUSH")) {
          txtTranscript.insert(
              "Perhaps these will help convince Yoda to train you.\n",
              txtTranscript.getText().length());
        } else if (takeItem.equals("STORM TROOPER HELMET")) {
          txtTranscript.insert(
              "A disguise to sneek up on Vader?\n", txtTranscript.getText().length());
        } else if (takeItem.equals("GLOWING HULK MASK")) {
          txtTranscript.insert(
              "Maybe you could scare Vader to death?\n", txtTranscript.getText().length());
        } else if (takeItem.equals("MIDICHLORIANS")) {
          txtTranscript.insert(
              "You feel the power of the force surging through you.\n",
              txtTranscript.getText().length());
        }
      }
    }
    if (mapKey == null || takeItem == null) {
      txtTranscript.insert(
          "You can't find \"" + takable + "\" to pick up.\n", txtTranscript.getText().length());
    }
    autoinventory();
  }
  public DistributedTextEditor() {
    area1.setFont(new Font("Monospaced", Font.PLAIN, 12));

    area2.setFont(new Font("Monospaced", Font.PLAIN, 12));
    ((AbstractDocument) area1.getDocument()).setDocumentFilter(dec);
    area2.setEditable(false);

    Container content = getContentPane();
    content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS));

    JScrollPane scroll1 =
        new JScrollPane(
            area1, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    content.add(scroll1, BorderLayout.CENTER);

    JScrollPane scroll2 =
        new JScrollPane(
            area2, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    content.add(scroll2, BorderLayout.CENTER);

    content.add(ipaddress, BorderLayout.CENTER);
    content.add(portNumber, BorderLayout.CENTER);

    JMenuBar JMB = new JMenuBar();
    setJMenuBar(JMB);
    JMenu file = new JMenu("File");
    JMenu edit = new JMenu("Edit");
    JMB.add(file);
    JMB.add(edit);

    file.add(Listen);
    file.add(Connect);
    file.add(Disconnect);
    file.addSeparator();
    file.add(Save);
    file.add(SaveAs);
    file.add(Quit);

    edit.add(Copy);
    edit.add(Paste);
    edit.getItem(0).setText("Copy");
    edit.getItem(1).setText("Paste");

    Save.setEnabled(false);
    SaveAs.setEnabled(false);
    Disconnect.setEnabled(false);

    setDefaultCloseOperation(EXIT_ON_CLOSE);
    pack();
    area1.addKeyListener(k1);
    area1.addMouseListener(m1);
    setTitle("Disconnected");
    setVisible(true);
    area1.insert("Welcome to Hjortehandlerne's distributed text editor. \n", 0);

    this.addWindowListener(w1);
  }
Example #5
0
  public void go(String[] userInput) {
    if (userInput.length == 0) {
      txtTranscript.insert("You did not specify a direction.\n", txtTranscript.getText().length());
    } else {
      char direction = Character.toLowerCase(userInput[0].charAt(0));

      if (direction == 'n') {
        if (row > MINROW) {
          txtTranscript.insert("Moving north . . .\n", txtTranscript.getText().length());
          row--;
        } else {
          txtTranscript.insert("North is out of bounds..\n", txtTranscript.getText().length());
        }
      } else if (direction == 'e') {
        if (col < MAXCOL) {
          txtTranscript.insert("Moving east . . .\n", txtTranscript.getText().length());
          col++;
        } else {
          txtTranscript.insert("East is out of bounds..\n", txtTranscript.getText().length());
        }
      } else if (direction == 's') {
        if (row < MAXROW) {
          txtTranscript.insert("Moving south . . .\n", txtTranscript.getText().length());
          row++;
        } else {
          txtTranscript.insert("South is out of bounds..\n", txtTranscript.getText().length());
        }
      } else if (direction == 'w') {
        if (col > MINCOL) {
          txtTranscript.insert("Moving west . . .\n", txtTranscript.getText().length());
          col--;
        } else {
          txtTranscript.insert("West is out of bounds.\n", txtTranscript.getText().length());
        }
      } else {
        txtTranscript.insert(
            "Which direction did you want to go?\n", txtTranscript.getText().length());
      }
      printLocation();
    }
  }
Example #6
0
  public void drop(String dropped) {
    int[] pair = {row, col};
    String takeItem = null;

    for (String item : inventory) {
      if (item.equals(dropped)) {
        takeItem = item;
      }
    }

    if (takeItem != null) {
      inventory.remove(takeItem);
      myMap.addItems(pair, takeItem);
      txtTranscript.insert(
          "You dropped a \"" + takeItem + "\".\n", txtTranscript.getText().length());
    } else {
      txtTranscript.insert(
          "You aren't carrying a \"" + dropped + "\" to drop.\n", txtTranscript.getText().length());
    }
    autoinventory();
  }
Example #7
0
 public void printLocation() {
   txtTranscript.insert(
       "You are at location "
           + row
           + ","
           + col
           + " in terrain: "
           + myMap.terrainTypes.get(Character.toString(myMap.terrain(row, col)))
           + "\n",
       txtTranscript.getText().length());
   if (myMap.terrain(row, col) == '*') {
     Dragon found = new Dragon();
     found.Dragon();
   }
 }
Example #8
0
 void insertMatchButton_actionPerformed(ActionEvent e) {
   String key = (String) matchComboBox.getSelectedItem();
   String format = (String) matchesKeys.get(key);
   if (key.equals(STRING_LITERAL)) {
     format =
         escapeReservedChars(
             (String)
                 JOptionPane.showInputDialog(
                     this,
                     "Enter the string you wish to match",
                     "String Literal Input",
                     JOptionPane.OK_CANCEL_OPTION));
     if (StringUtil.isNullString(format)) {
       return;
     }
   }
   if (selectedPane == 0) {
     insertText(format, PLAIN_ATTR, editorPane.getSelectionStart());
   } else {
     // add the combobox data value to the edit box
     int pos = formatTextArea.getCaretPosition();
     formatTextArea.insert(format, pos);
   }
 }
Example #9
0
  void insertButton_actionPerformed(ActionEvent e) {
    Object selected = paramComboBox.getSelectedItem();
    ConfigParamDescr descr;
    String key;
    int type = 0;
    String format = "";
    if (selected instanceof ConfigParamDescr) {
      descr = (ConfigParamDescr) selected;
      key = descr.getKey();
      type = descr.getType();
      switch (type) {
        case ConfigParamDescr.TYPE_STRING:
        case ConfigParamDescr.TYPE_URL:
        case ConfigParamDescr.TYPE_BOOLEAN:
          format = "%s";
          break;
        case ConfigParamDescr.TYPE_INT:
        case ConfigParamDescr.TYPE_LONG:
        case ConfigParamDescr.TYPE_POS_INT:
          NumericPaddingDialog dialog = new NumericPaddingDialog();
          Point pos = this.getLocationOnScreen();
          dialog.setLocation(pos.x, pos.y);
          dialog.pack();
          dialog.setVisible(true);
          StringBuilder fbuf = new StringBuilder("%");
          int width = dialog.getPaddingSize();
          boolean is_zero = dialog.useZero();
          if (width > 0) {
            fbuf.append(".");
            if (is_zero) {
              fbuf.append(0);
            }
            fbuf.append(width);
          }
          if (type == ConfigParamDescr.TYPE_LONG) {
            fbuf.append("ld");
          } else {
            fbuf.append("d");
          }
          format = fbuf.toString();
          break;
        case ConfigParamDescr.TYPE_YEAR:
          if (key.startsWith(DefinableArchivalUnit.PREFIX_AU_SHORT_YEAR)) {
            format = "%02d";
          } else {
            format = "%d";
          }
          break;
        case ConfigParamDescr.TYPE_RANGE:
        case ConfigParamDescr.TYPE_NUM_RANGE:
        case ConfigParamDescr.TYPE_SET:
          format = "%s";
          break;
      }
      if (selectedPane == 0) {
        insertParameter(descr, format, editorPane.getSelectionStart());
      } else if (selectedPane == 1) {
        // add the combobox data value to the edit box
        int pos = formatTextArea.getCaretPosition();
        formatTextArea.insert(format, pos);

        pos = parameterTextArea.getCaretPosition();
        parameterTextArea.insert(", " + key, pos);
      }
    } else {
      key = selected.toString();
      format =
          escapePrintfChars(
              (String)
                  JOptionPane.showInputDialog(
                      this,
                      "Enter the string you wish to input",
                      "String Literal Input",
                      JOptionPane.OK_CANCEL_OPTION));
      if (StringUtil.isNullString(format)) {
        return;
      }
      if (selectedPane == 0) {
        insertText(format, PLAIN_ATTR, editorPane.getSelectionStart());
      } else if (selectedPane == 1) {
        // add the combobox data value to the edit box
        formatTextArea.insert(format, formatTextArea.getCaretPosition());
      }
    }
  }