Ejemplo n.º 1
1
    public synchronized Connection returnConnection() {
      Connection con = null;
      // 如果闲置小于最大连接,返回一个新连接
      if (freeConnections.size() < maxConn) {
        con = newConnection();
      }
      // 如果闲置大于最大连接,返回一个可用的旧连接
      else if (freeConnections.size() >= maxConn) {

        con = (Connection) freeConnections.firstElement();
        System.out.println(" [a 连接池可用连接数 ] : " + "[ " + freeConnections.size() + " ]");
        freeConnections.removeElementAt(0);
        System.out.println(" [b 连接池可用连接数 ] : " + "[ " + freeConnections.size() + " ]");
        try {
          if (con.isClosed()) {
            System.out.println("从连接池" + id + "删除一个无效连接");
            System.out.println("从连接池" + id + "删除一个无效连接");
            returnConnection();
          }
        } catch (SQLException e) {
          System.out.println("从连接池" + id + "删除一个无效连接时错误");
          System.out.println("从连接池" + id + "删除一个无效连接出错");
          returnConnection();
        }
      }
      return con;
    }
Ejemplo n.º 2
1
 public static String list(Context c, Vector<BaseObject> objs) {
   String ret = new String();
   if (objs.size() == 0) return ret;
   if (objs.size() == 1) {
     ret = objs.firstElement().getName();
     return ret;
   }
   if (objs.size() == 2) {
     ret =
         objs.get(0).getName()
             + " "
             + c.getString(R.string.stringhandler_and1)
             + " "
             + objs.get(1).getName();
     return ret;
   }
   for (int i = 0; i < objs.size() - 1; i++) {
     ret += objs.get(i).getName();
     if (i < objs.size() - 2) {
       ret += c.getString(R.string.stringhandler_comma);
       ret += " ";
     } else {
       ret += c.getString(R.string.stringhandler_and2);
       ret += " ";
     }
   }
   ret += objs.lastElement().getName();
   return ret;
 }
Ejemplo n.º 3
1
  public static InformalArgument_c[] getManyMSG_IAsOnR1013(
      MessageArgument_c[] targets, ClassQueryInterface_c test, boolean loadComponent) {

    if (targets == null || targets.length == 0 || targets[0] == null)
      return new InformalArgument_c[0];

    ModelRoot modelRoot = targets[0].getModelRoot();

    InstanceList instances = modelRoot.getInstanceList(InformalArgument_c.class);

    Vector matches = new Vector();
    for (int i = 0; i < targets.length; i++) {
      InformalArgument_c source =
          (InformalArgument_c) targets[i].backPointer_IsSubtypeInformalArgumentIsSubtype_R1013;
      if (source != null && (test == null || test.evaluate(source))) {
        matches.add(source);
      }
    }
    if (matches.size() > 0) {
      InformalArgument_c[] ret_set = new InformalArgument_c[matches.size()];
      matches.copyInto(ret_set);
      return ret_set;
    } else {
      return new InformalArgument_c[0];
    }
  }
Ejemplo n.º 4
1
  private void filterChange(final BamView bamView, final JComboBox flagCheck[]) {
    int nflags = SAMRecordFlagPredicate.FLAGS.length;
    int flagCombined = 0;
    Vector<SAMRecordPredicate> predicates = new Vector<SAMRecordPredicate>();

    for (int j = 0; j < nflags; j++) {
      String opt = (String) flagCheck[j].getSelectedItem();
      if (opt.equals("HIDE")) flagCombined = flagCombined | SAMRecordFlagPredicate.FLAGS[j];
      else if (opt.equals("SHOW"))
        predicates.add(new SAMRecordFlagPredicate(SAMRecordFlagPredicate.FLAGS[j], false));
    }

    if (flagCombined == 0 && predicates.size() == 0) bamView.setSamRecordFlagPredicate(null);
    else {
      final SAMRecordPredicate predicate;
      if (predicates.size() == 0) predicate = new SAMRecordFlagPredicate(flagCombined);
      else if (flagCombined == 0) {
        predicate =
            new SAMRecordFlagConjunctionPredicate(predicates, SAMRecordFlagConjunctionPredicate.OR);
      } else {
        SAMRecordFlagPredicate p1 = new SAMRecordFlagPredicate(flagCombined);
        SAMRecordFlagConjunctionPredicate p2 =
            new SAMRecordFlagConjunctionPredicate(predicates, SAMRecordFlagConjunctionPredicate.OR);

        predicate =
            new SAMRecordFlagConjunctionPredicate(p1, p2, SAMRecordFlagConjunctionPredicate.OR);
      }
      bamView.setSamRecordFlagPredicate(predicate);
    }
    bamView.repaint();
  }
Ejemplo n.º 5
1
  private static void testAdaBoost(int features) {
    Vector<IntegralImage> falseSet = new Vector<IntegralImage>();
    Vector<IntegralImage> trueSet = new Vector<IntegralImage>();
    {
      File noDirectory = new File("C:/Users/BOOBIES/Desktop/trainingData/no");
      File yesDirectory = new File("C:/Users/BOOBIES/Desktop/trainingData/yes");

      System.out.println("no directory = " + noDirectory);
      System.out.println("yes directory = " + yesDirectory);
      loadGifsAtDirectoryIntoVector(falseSet, noDirectory);
      loadGifsAtDirectoryIntoVector(trueSet, yesDirectory);
    }
    System.out.println("Gifs loaded!\t\t\ttrue:" + trueSet.size() + " false:" + falseSet.size());

    ViolaJones vj = new ViolaJones();
    Vector<HaarFeature> allFeatures = vj.getHaarFeatures();
    System.out.println("Generated all features!\t\tcount:" + allFeatures.size());

    AdaBoost boost = new AdaBoost();
    Vector<HaarFeature> bestFeatures =
        boost.startTraining(trueSet, falseSet, allFeatures, features);

    HaarFeatureChain chain = new HaarFeatureChain();
    chain.save(bestFeatures);

    System.out.println("dun learnin!! Wow!");
  }
Ejemplo n.º 6
1
  /**
   * Compute a logical, reasonably efficient join on the specified tables. See project description
   * for hints on how this should be implemented.
   *
   * @param stats Statistics for each table involved in the join, referenced by base table names,
   *     not alias
   * @param filterSelectivities Selectivities of the filter predicates on each table in the join,
   *     referenced by table alias (if no alias, the base table name)
   * @param explain Indicates whether your code should explain its query plan or simply execute it
   * @return A Vector<LogicalJoinNode> that stores joins in the left-deep order in which they should
   *     be executed.
   * @throws ParsingException when stats or filter selectivities is missing a table in the join, or
   *     or when another internal error occurs
   */
  public Vector<LogicalJoinNode> orderJoins(
      HashMap<String, TableStats> stats,
      HashMap<String, Double> filterSelectivities,
      boolean explain)
      throws ParsingException {

    // See the project writeup for some hints as to how this function
    // should work.

    // some code goes here
    PlanCache pc = new PlanCache();
    for (int i = 1; i <= joins.size(); i++) {
      Set<Set<LogicalJoinNode>> subsets = enumerateSubsets(joins, i);
      for (Set<LogicalJoinNode> subset : subsets) {
        CostCard best = new CostCard();
        best.cost = Double.MAX_VALUE;
        for (LogicalJoinNode node : subset) {
          CostCard subCard =
              computeCostAndCardOfSubplan(stats, filterSelectivities, node, subset, best.cost, pc);
          if (subCard != null) {
            if (subCard.cost < best.cost) best = subCard;
            pc.addPlan(subset, best.cost, best.card, best.plan);
          }
        }
      }
    }
    if (explain) printJoins(joins, pc, stats, filterSelectivities);
    HashSet<LogicalJoinNode> joinSet = new HashSet<LogicalJoinNode>();
    for (int i = 0; i < joins.size(); i++) {
      joinSet.add(joins.get(i));
    }
    Vector<LogicalJoinNode> order = pc.getOrder(joinSet);
    if (order != null) return order;
    return joins;
  }
Ejemplo n.º 7
1
    /** 从连接池获得一个可用连接.如没有空闲的连接且当前连接数小于最大连接 数限制,则创建新连接.如原来登记为可用的连接不再有效,则从向量删除之, 然后递归调用自己以尝试新的可用连接. */
    public synchronized Connection getConnection() {
      Connection con = null;
      if (freeConnections.size() > 0) {
        // 获取向量中第一个可用连接
        con = (Connection) freeConnections.firstElement();
        freeConnections.removeElementAt(0);
        try {
          if (con.isClosed()) {
            System.out.println("从连接池" + id + "删除一个无效连接");
            System.out.println("从连接池" + id + "删除一个无效连接");
            // 递归调用自己,尝试再次获取可用连接
            con = getConnection();
          }
        } catch (SQLException e) {
          System.out.println("从连接池" + id + "删除一个无效连接时错误");
          System.out.println("从连接池" + id + "删除一个无效连接出错");
          // 递归调用自己,尝试再次获取可用连接
          con = getConnection();
        }
        if (freeConnections.size() > maxConn) {
          System.out.println(" 删除一个溢出连接 ");
          releaseOne();
        }
      } else if ((maxConn == 0) || (freeConnections.size() < maxConn)) {
        con = newConnection();
      }

      return con;
    }
Ejemplo n.º 8
1
  public Vector obterLinhas(String nome, String status) {
    Vector linhas = new Vector();
    try {
      if (status.equals("Ativo")) {
        usuariosAtivos = usuarioDao.obterUsuarios(nome, status);
        for (int i = 0; i < usuariosAtivos.size(); i++) {
          Usuario usuario = usuariosAtivos.get(i);
          linhas.addElement(this.criarLinhaUsuario(usuario));
        }
      } else {
        usuariosInativos = usuarioDao.obterUsuarios(nome, status);
        for (int i = 0; i < usuariosInativos.size(); i++) {
          Usuario usuario = usuariosInativos.get(i);
          linhas.addElement(this.criarLinhaUsuario(usuario));
        }
      }
    } catch (SQLException ex) {
      ex.printStackTrace();
      JOptionPane.showMessageDialog(
          null,
          "Erro ao acesso o banco de dados,\n" + "por favor contate o Suporte",
          "Erro",
          JOptionPane.ERROR_MESSAGE);
    }

    return linhas;
  }
Ejemplo n.º 9
1
        public void handle(PeerMessage event) {
          PeerAddress oldFriend;
          PeerAddress sender = event.getMSPeerSource();
          PeerAddress newFriend = event.getNewFriend();

          // add the sender address to the list of friends
          if (!friends.contains(sender)) {
            if (friends.size() == viewSize) {
              oldFriend = friends.get(rand.nextInt(viewSize));
              friends.remove(oldFriend);
              fdUnregister(oldFriend);
              Snapshot.removeFriend(serverPeerAddress, oldFriend);
            }

            friends.addElement(sender);
            fdRegister(sender);
            Snapshot.addFriend(serverPeerAddress, sender);
          }

          // add the received new friend from the sender to the list of friends
          if (!friends.contains(newFriend) && !serverPeerAddress.equals(newFriend)) {
            if (friends.size() == viewSize) {
              oldFriend = friends.get(rand.nextInt(viewSize));
              friends.remove(oldFriend);
              fdUnregister(oldFriend);
              Snapshot.removeFriend(serverPeerAddress, oldFriend);
            }

            friends.addElement(newFriend);
            fdRegister(newFriend);
            Snapshot.addFriend(serverPeerAddress, newFriend);
          }
        }
Ejemplo n.º 10
1
 private void fillItems(String[] sArray) {
   int index;
   for (int i = 0, k = subCategories.size(); i < items.size(); i++) {
     index = ((Integer) items.elementAt(i)).intValue();
     sArray[k + i] = ((Item) itemsIndex.elementAt(index)).title;
   }
 }
Ejemplo n.º 11
0
  /** Layout the GUI components of this Folder. */
  private void layoutComponents() {

    // clear the box
    box.removeAll();

    // add the heading if one has been specified
    if (heading != null) {
      if (LOG.isDebugEnabled()) {
        LOG.debug(Messages.getString(BUNDLE_NAME, "Folder.0")); // $NON-NLS-1$
      }
      JLabel p1 = new JLabel(heading);
      box.add(p1);
    }

    // add the tabbed pane if there is more than 1 tab
    if (dataItems.size() > 1) {
      box.add(tabbedPane);

    } else if (dataItems.size() == 1) {
      // otherwise add the single tab as the main component
      DataItem item = (DataItem) dataItems.elementAt(0);
      box.add(item);
    }

    validate();

    repaint();
  }
Ejemplo n.º 12
0
  /** Called when a key is pressed. */
  protected void keyPressed(int keyCode) {
    if ((keyCode == KEY_NUM2) || (keyCode == -1)) se--;
    if ((keyCode == KEY_NUM8) || (keyCode == -2)) se++;
    if (se < 0) se = myTools.size() - 1;
    if (se >= myTools.size()) se = 0;

    if ((keyCode == -5) || (keyCode == KEY_NUM5)) {
      JustPaint.c.brush = (((Integer) myTools.elementAt(se)).intValue());
      JustPaint.display.setCurrent(JustPaint.c);
    }

    // if (keyCode==KEY_NUM0) JustPaint.display.setCurrent(JustPaint.nf);
    if (keyCode == -6) {
      JustPaint.display.setCurrent(JustPaint.nmt);
    }

    if (keyCode == -7) {
      JustPaint.display.setCurrent(JustPaint.mm);
    }

    if (keyCode == -8) {
      myTools.removeElementAt(se);
      if (se >= myTools.size()) se--;
      if (se < 0) se = 0;
    }

    repaint();
  }
Ejemplo n.º 13
0
  private void runScript(File script) {
    FileReader fr;
    try {
      fr = new FileReader(script);
    } catch (FileNotFoundException e) {
      HF.showErrorMessage(i18n.getMessage("FileNotFound!"));
      return;
    }

    BufferedReader br = new BufferedReader(fr);

    try {
      String s = br.readLine();
      while (s != null) {
        getLSConsoleModel().setCommandLineText(s);
        getLSConsoleModel().execCommand();
        s = br.readLine();
      }
    } catch (Exception e) {
      HF.showErrorMessage(e);
      return;
    }

    if (!cbmiLSConsoleShown.isSelected()) cbmiLSConsoleShown.doClick(0);

    String s = script.getAbsolutePath();
    recentScripts.remove(s);
    recentScripts.insertElementAt(s, 0);

    while (recentScripts.size() > ClassicPrefs.getRecentScriptsSize()) {
      recentScripts.removeElementAt(recentScripts.size() - 1);
    }

    updateRecentScriptsMenu();
  }
Ejemplo n.º 14
0
  public void fillMenuOptions(Menu menu, int instance) {
    boolean haveContext = false;
    boolean hasMiniMenu = false;

    if ((instance == Menu.INSTANCE_CONTEXT) || (pushMiniMenu)) {
      for (int i = 0; i < m_MiniMenuItems.size(); ++i) {
        MenuItem item = (MenuItem) m_MiniMenuItems.elementAt(i);
        if (item != null) {
          menu.add(item);
          hasMiniMenu = true;
        }
      }
    }

    if (!hasMiniMenu) {
      for (int i = 0; i < m_contextMenuItems.size(); ++i) {
        MenuItem item = (MenuItem) m_contextMenuItems.elementAt(i);
        if (item != null) {
          menu.add(item);
          haveContext = true;
        }
      }
    }

    if (((!haveContext) && (!hasMiniMenu))) {
      for (int i = 0; i < m_menuItems.size(); ++i) {
        menu.add((MenuItem) m_menuItems.elementAt(i));
      }
    }
  }
Ejemplo n.º 15
0
 public Buffer getVertices() {
   float v[] = new float[points.size()];
   for (int i = 0; i < points.size(); i++) {
     v[i] = (points.elementAt(i)).floatValue();
   }
   return FloatBuffer.wrap(v);
 }
Ejemplo n.º 16
0
  /**
   * Executa o c�lculo da fun��o
   *
   * @return valor do c�lculo
   * @param oper nome da fun��o
   * @param params parametros da fun��o
   * @throws java.lang.Exception erro
   */
  public String Calculate(String oper, Vector params) throws Exception {
    if (params.size() == 0) return Calculate0(oper);
    if (params.size() == 1) return Calculate1(oper, (String) params.get(0));
    if (params.size() == 2) return Calculate2(oper, (String) params.get(0), (String) params.get(1));

    throw new Exception("ERRO fun��o parametros errados [" + oper + "] " + params.toString());
  }
Ejemplo n.º 17
0
  public static Vector filterDistinct(Vector tupels, String key) {
    Vector res = new Vector();
    key = key.toLowerCase();

    for (int i = 0; i < tupels.size(); i++) {
      DB_Tupel tupel = (DB_Tupel) tupels.get(i);
      Object o = tupel.get(key);

      if (o instanceof String) {
        String s = (String) o;
        boolean found = false;
        for (int j = 0; j < res.size(); j++) {
          String t = (String) res.get(j);
          if (s.equalsIgnoreCase(t)) {
            found = true;
            break;
          }
        }
        if (!found) res.add(s);
      } else {
        if (!res.contains(o)) res.add(o);
      }
    }

    return res;
  }
Ejemplo n.º 18
0
  /**
   * calculates the TP, FP, FN and the first Part for the Performance
   *
   * @param idsWithHull
   * @param GOsWithHull
   */
  private void calcPosNegs(Vector<String> idsWithHull, Vector<String> GOsWithHull) {

    int TP = 0;
    int FP = 0;
    int FN = 0;

    Vector<String> toRemove = new Vector<String>();

    for (String a : idsWithHull) {
      if (GOsWithHull.contains(a)) {
        TP++;
        toRemove.add(a);
      }
    }

    for (String tr : toRemove) {
      idsWithHull.remove(tr);
      GOsWithHull.remove(tr);
    }

    FP = GOsWithHull.size();
    FN = idsWithHull.size();

    calcPerformanceI(TP, FP, FN);
  }
Ejemplo n.º 19
0
 public Buffer getUV() {
   float v[] = new float[uv.size()];
   for (int i = 0; i < uv.size(); i++) {
     v[i] = (uv.elementAt(i)).floatValue();
   }
   return FloatBuffer.wrap(v);
 }
Ejemplo n.º 20
0
  public static DataTypeInPackage_c[] getManyS_DIPsOnR39(
      DataTypePackage_c target, ClassQueryInterface_c test, boolean loadComponent) {
    if (target == null) return new DataTypeInPackage_c[0];

    ModelRoot modelRoot = target.getModelRoot();
    Vector matches = new Vector();
    synchronized (target.backPointer_ContainsDataTypeInPackageContains_R39) {
      for (int i = 0; i < target.backPointer_ContainsDataTypeInPackageContains_R39.size(); ++i) {
        DataTypeInPackage_c source =
            (DataTypeInPackage_c) target.backPointer_ContainsDataTypeInPackageContains_R39.get(i);
        if (source != null && (test == null || test.evaluate(source))) {

          matches.add(source);
        }
      }
    }

    if (matches.size() > 0) {
      DataTypeInPackage_c[] ret_set = new DataTypeInPackage_c[matches.size()];
      matches.copyInto(ret_set);
      return ret_set;
    } else {
      return new DataTypeInPackage_c[0];
    }
  }
Ejemplo n.º 21
0
  public static DataTypeInPackage_c[] getManyS_DIPsOnR39(
      DataType_c[] targets, ClassQueryInterface_c test, boolean loadComponent) {

    if (targets == null || targets.length == 0 || targets[0] == null)
      return new DataTypeInPackage_c[0];

    ModelRoot modelRoot = targets[0].getModelRoot();

    InstanceList instances = modelRoot.getInstanceList(DataTypeInPackage_c.class);

    Vector matches = new Vector();
    for (int i = 0; i < targets.length; i++) {
      synchronized (targets[i].backPointer_IsContainedInDataTypeInPackageIsContainedIn_R39) {
        for (int j = 0;
            j < targets[i].backPointer_IsContainedInDataTypeInPackageIsContainedIn_R39.size();
            ++j) {
          DataTypeInPackage_c source =
              (DataTypeInPackage_c)
                  targets[i].backPointer_IsContainedInDataTypeInPackageIsContainedIn_R39.get(j);
          if (source != null && (test == null || test.evaluate(source))) {
            matches.add(source);
          }
        }
      }
    }
    if (matches.size() > 0) {
      DataTypeInPackage_c[] ret_set = new DataTypeInPackage_c[matches.size()];
      matches.copyInto(ret_set);
      return ret_set;
    } else {
      return new DataTypeInPackage_c[0];
    }
  }
Ejemplo n.º 22
0
  @Override
  public boolean tick(Tickable ticking, int tickID) {
    if (!super.tick(ticking, tickID)) return false;

    if (affected == null) return false;
    if (!(affected instanceof MOB)) return false;
    final MOB mob = (MOB) affected;
    if (mob.location().numInhabitants() == 1) return true;
    final Vector choices = new Vector();
    for (final Enumeration<Ability> a = mob.effects(); a.hasMoreElements(); ) {
      final Ability A = a.nextElement();
      if ((A != null)
          && (A.canBeUninvoked())
          && (!A.ID().equals(ID()))
          && (A.abstractQuality() == Ability.QUALITY_MALICIOUS)
          && (((A.classificationCode() & Ability.ALL_ACODES) == Ability.ACODE_SPELL)
              || ((A.classificationCode() & Ability.ALL_ACODES) == Ability.ACODE_PRAYER))
          && (!A.isAutoInvoked())) choices.addElement(A);
    }
    if (choices.size() == 0) return true;
    final MOB target = mob.location().fetchRandomInhabitant();
    final Ability thisOne = (Ability) choices.elementAt(CMLib.dice().roll(1, choices.size(), -1));
    if ((target == null) || (thisOne == null) || (target.fetchEffect(ID()) != null)) return true;
    if (CMLib.dice().rollPercentage() > (target.charStats().getSave(CharStats.STAT_SAVE_DISEASE))) {
      ((Ability) this.copyOf()).invoke(target, target, true, 0);
      if (target.fetchEffect(ID()) != null)
        ((Ability) thisOne.copyOf()).invoke(target, target, true, 0);
    } else spreadImmunity(target);
    return true;
  }
Ejemplo n.º 23
0
  public void showCategory(int selectedCategory) {
    if (selectedCategory == PARENT_CATEGORY_ROOT_FILE) {
      level = ROOT_FILE;
      selectedCategory = PARENT_CATEGORY_TOP;
    }
    if (level == ROOT_FILE) {
      setRootContent();
      displayedCategory = (Category) categoriesIndex.elementAt(0);
      level = NON_ROOT_FILE;
      lastSelectedCategoryIndex = PARENT_CATEGORY_TOP;
    } else if (level == NON_ROOT_FILE) {
      createContentObjectAndInitCategory(selectedCategory);
      level = IN_NON_ROOT_FILE;
      lastSelectedCategoryIndex = PARENT_CATEGORY_TOP;
    } else if (level == IN_NON_ROOT_FILE) {
      displayedCategory = (Category) categoriesIndex.elementAt(selectedCategory);
      lastSelectedCategoryIndex = selectedCategory;
    }
    subCategories = displayedCategory.subcategories;
    items = displayedCategory.items;

    String[] sArray = new String[subCategories.size() + items.size()];
    fillCategories(sArray);
    fillItems(sArray);
    List tmpList = showList(tr.t("CATEGORIES"), sArray);
    tmpList.setSelectedIndex(displayedCategory.lastSelectedPosition, true);

    display.setCurrent(tmpList);
  }
Ejemplo n.º 24
0
 public Buffer getNormals() {
   float v[] = new float[normals.size()];
   for (int i = 0; i < normals.size(); i++) {
     v[i] = (normals.elementAt(i)).floatValue();
   }
   return FloatBuffer.wrap(v);
 }
Ejemplo n.º 25
0
  @Override
  protected Void doInBackground(Long... params) {
    long movieId = params[0];

    WebService webService = new WebService();
    List<Trailer> trailers = webService.getMovieTrailers(movieId);

    Vector<ContentValues> cVVector = new Vector<ContentValues>(trailers.size());
    for (int i = 0; i < trailers.size(); i++) {
      Trailer trailer = trailers.get(i);
      ContentValues values = trailer.asContentValues();
      values.put(MovieContract.TrailerEntry.COLUMN_MOVIE_ID, movieId);
      cVVector.add(values);
    }

    // add to database
    int inserted = 0;
    if (cVVector.size() > 0) {
      ContentValues[] contentValues = new ContentValues[cVVector.size()];
      cVVector.toArray(contentValues);
      inserted =
          mContext
              .getContentResolver()
              .bulkInsert(MovieContract.TrailerEntry.CONTENT_URI, contentValues);
    }
    Log.d(TAG, "FetchTrailersTask Complete. " + inserted + " Inserted");

    return null;
  }
Ejemplo n.º 26
0
  // {{{ createMacrosMenu() method
  private void createMacrosMenu(JMenu menu, Vector vector, int start) {
    Vector<JMenuItem> menuItems = new Vector<JMenuItem>();
    int maxItems = jEdit.getIntegerProperty("menu.spillover", 20);
    JMenu subMenu = null;
    for (int i = start; i < vector.size(); i++) {
      if (i != start && i % maxItems == 0) {
        subMenu = new JMenu(jEdit.getProperty("common.more"));
        createMacrosMenu(subMenu, vector, i);
        break;
      }
      Object obj = vector.elementAt(i);
      if (obj instanceof String) {
        menuItems.add(
            new EnhancedMenuItem(
                jEdit.getProperty(obj + ".label"), (String) obj, jEdit.getActionContext()));
      } else if (obj instanceof Vector) {
        Vector subvector = (Vector) obj;
        String name = (String) subvector.elementAt(0);
        JMenu submenu = new JMenu(jEdit.getProperty("macros.folder." + name + ".label", name));
        createMacrosMenu(submenu, subvector, 1);
        if (submenu.getMenuComponentCount() != 0) menuItems.add(submenu);
      }
    }

    Collections.sort(menuItems, new MenuItemTextComparator());

    if (subMenu != null) menuItems.add(subMenu);

    for (int i = 0; i < menuItems.size(); i++) {
      menu.add(menuItems.get(i));
    }
  } // }}}
Ejemplo n.º 27
0
 public DVector parseLootPolicyFor(MOB mob) {
   if (mob == null) return new DVector(3);
   Vector lootPolicy =
       (!mob.isMonster())
           ? new Vector()
           : CMParms.parseCommas(CMProps.getVar(CMProps.SYSTEM_ITEMLOOTPOLICY), true);
   DVector policies = new DVector(3);
   for (int p = 0; p < lootPolicy.size(); p++) {
     String s = ((String) lootPolicy.elementAt(p)).toUpperCase().trim();
     if (s.length() == 0) continue;
     Vector compiledMask = null;
     int maskDex = s.indexOf("MASK=");
     if (maskDex >= 0) {
       s = s.substring(0, maskDex).trim();
       compiledMask =
           CMLib.masking()
               .maskCompile(((String) lootPolicy.elementAt(p)).substring(maskDex + 5).trim());
     } else compiledMask = new Vector();
     Vector parsed = CMParms.parse(s);
     int pct = 100;
     for (int x = 0; x < parsed.size(); x++)
       if (CMath.isInteger((String) parsed.elementAt(x)))
         pct = CMath.s_int((String) parsed.elementAt(x));
       else if (CMath.isPct((String) parsed.elementAt(x)))
         pct = (int) Math.round(CMath.s_pct((String) parsed.elementAt(x)) * 100.0);
     int flags = 0;
     if (parsed.contains("RUIN")) flags |= CMMiscUtils.LOOTFLAG_RUIN;
     else if (parsed.contains("LOSS")) flags |= CMMiscUtils.LOOTFLAG_LOSS;
     if (flags == 0) flags |= CMMiscUtils.LOOTFLAG_LOSS;
     if (parsed.contains("WORN")) flags |= CMMiscUtils.LOOTFLAG_WORN;
     else if (parsed.contains("UNWORN")) flags |= CMMiscUtils.LOOTFLAG_UNWORN;
     policies.addElement(Integer.valueOf(pct), Integer.valueOf(flags), compiledMask);
   }
   return policies;
 }
Ejemplo n.º 28
0
 /**
  * Returns a matrix containing the line dimensions of this text element. The rows in this matrix
  * represent the lines, the two columns represent respectively the width and the height of the
  * corresponding line.
  *
  * @return line dimension matrix
  */
 public float[][] getLineDimensions() {
   float lineDimensions[][] = new float[0][0];
   if (getTaintMode() == TAINTED) {
     int lines = 1;
     if (tspanVector.size() > 0) lines = tspanVector.lastElement().getLine() + 1;
     lineDimensions = new float[lines][2];
     lineDimensions[0][0] = 0.0f;
     lineDimensions[0][1] = 0.0f;
     for (int i = 0; i < lines; i++) {
       float h = 0.0f;
       float w = 0.0f;
       for (int x = 0; x < tspanVector.size(); x++) {
         if (tspanVector.elementAt(x).getLine() == i) {
           h = Math.max(h, tspanVector.elementAt(x).getHeight());
           w += tspanVector.elementAt(x).getWidth();
         }
         lineDimensions[i][0] = w;
         lineDimensions[i][1] = 0.5f * h; // bug in batik?!
       }
     }
     cachedLineDimensions = lineDimensions;
   }
   if (getTaintMode() == UNTAINTED) lineDimensions = cachedLineDimensions;
   return lineDimensions;
 }
Ejemplo n.º 29
0
 public static void WriteLog(String log, int nbLines) {
   if (nbLines == -1) {
     WriteFile("log.txt", getDateTime() + " >> " + log + "\n", true);
   } else {
     try {
       FileInputStream fstream = new FileInputStream("log.txt");
       DataInputStream in = new DataInputStream(fstream);
       BufferedReader br = new BufferedReader(new InputStreamReader(in));
       String strLine;
       Vector<String> totalLines = new Vector<String>();
       while ((strLine = br.readLine()) != null) {
         totalLines.add(strLine);
       }
       if (totalLines.size() > nbLines) {
         String content = "";
         for (int i = totalLines.size() - nbLines; i <= totalLines.size() - 1; i++) {
           content += totalLines.get(i) + "\n";
         }
         WriteFile("log.txt", content, false);
       }
       in.close();
     } catch (Exception e) {
       Utilities.WriteLogTrace(e);
     }
     WriteLog(log);
   }
 }
Ejemplo n.º 30
0
  private void evaluateTriggerables(Vector tv, TreeReference anchorRef) {
    // add all cascaded triggerables to queue
    for (int i = 0; i < tv.size(); i++) {
      Triggerable t = (Triggerable) tv.elementAt(i);
      if (t.canCascade()) {
        for (int j = 0; j < t.getTargets().size(); j++) {
          TreeReference target = (TreeReference) t.getTargets().elementAt(j);
          Vector triggered = (Vector) triggerIndex.get(target);
          if (triggered != null) {
            for (int k = 0; k < triggered.size(); k++) {
              Triggerable u = (Triggerable) triggered.elementAt(k);
              if (!tv.contains(u)) tv.addElement(u);
            }
          }
        }
      }
    }

    // 'triggerables' is topologically-ordered by dependencies, so evaluate the triggerables in 'tv'
    // in the order they appear in 'triggerables'
    for (int i = 0; i < triggerables.size(); i++) {
      Triggerable t = (Triggerable) triggerables.elementAt(i);
      if (tv.contains(t)) {
        evaluateTriggerable(t, anchorRef);
      }
    }
  }