Пример #1
0
 /**
  * set / update the text of the displayLabels. these are the Week column headers above the days on
  * the Calendar part of the <code>CDateTime</code>.
  */
 private void updateDaysOfWeek() {
   if (dayPanel != null) {
     Calendar tmpcal = cdt.getCalendarInstance();
     tmpcal.set(Calendar.DAY_OF_WEEK, tmpcal.getFirstDayOfWeek());
     Locale locale = cdt.getLocale();
     boolean ltr =
         (ComponentOrientation.getOrientation(locale).isLeftToRight()
             && !locale.getLanguage().equals("zh")); // $NON-NLS-1$
     BreakIterator iterator = BreakIterator.getCharacterInstance(locale);
     for (int x = 0; x < dayLabels.length; x++) {
       String str = getFormattedDate("E", tmpcal.getTime()); // $NON-NLS-1$
       if (dayLabels[x].getData(CDT.Key.Compact, Boolean.class)) {
         iterator.setText(str);
         int start, end;
         if (ltr) {
           start = iterator.first();
           end = iterator.next();
         } else {
           end = iterator.last();
           start = iterator.previous();
         }
         dayLabels[x].setText(str.substring(start, end));
       } else {
         dayLabels[x].setText(str);
       }
       tmpcal.add(Calendar.DAY_OF_WEEK, 1);
     }
   }
 }
Пример #2
0
  public void check(String name, String in, String[] out, BreakIterator bi, TestHarness harness) {
    harness.checkPoint(name);
    bi.setText(in);

    int index = 0;
    int from = bi.current();
    harness.check(from, 0);

    while (true) {
      int to = bi.next();
      if (to == BreakIterator.DONE) break;
      harness.check(in.substring(from, to), out[index]);
      ++index;
      from = to;
    }

    harness.check(index, out.length);

    harness.checkPoint("backwards " + name);
    bi.last();
    index = out.length - 1;
    from = bi.current();
    harness.check(from, in.length());

    while (true) {
      int to = bi.previous();
      if (to == BreakIterator.DONE) break;
      harness.check(in.substring(to, from), out[index]);
      --index;
      from = to;
    }

    harness.check(index, -1);
  }
Пример #3
0
 // offsets on any line will go from start,true to end,false
 // excluding start,false and end,true
 public Selection point2Offset(Point p, Selection o) {
   if (p.y < yInset) {
     o.caret = 0;
     o.clickAfter = true;
     return o;
   }
   int line = (p.y - yInset) / lineHeight;
   if (line >= lineCount) {
     o.caret = contents.length();
     o.clickAfter = false;
     return o;
   }
   int target = p.x - xInset;
   if (target <= 0) {
     o.caret = lineStarts[line];
     o.clickAfter = true;
     return o;
   }
   int lowGuess = lineStarts[line];
   int lowWidth = 0;
   int highGuess = lineStarts[line + 1];
   int highWidth = fm.stringWidth(contents.substring(lineStarts[line], highGuess));
   if (target >= highWidth) {
     o.caret = lineStarts[line + 1];
     o.clickAfter = false;
     return o;
   }
   while (lowGuess < highGuess - 1) {
     int guess = (lowGuess + highGuess) / 2;
     int width = fm.stringWidth(contents.substring(lineStarts[line], guess));
     if (width <= target) {
       lowGuess = guess;
       lowWidth = width;
       if (width == target) break;
     } else {
       highGuess = guess;
       highWidth = width;
     }
   }
   // at end, either lowWidth < target < width(low+1), or lowWidth = target
   int highBound = charBreaker.following(lowGuess);
   int lowBound = charBreaker.previous();
   // we are now at character boundaries
   if (lowBound != lowGuess)
     lowWidth = fm.stringWidth(contents.substring(lineStarts[line], lowBound));
   if (highBound != highGuess)
     highWidth = fm.stringWidth(contents.substring(lineStarts[line], highBound));
   // we now have the right widths
   if (target - lowWidth < highWidth - target) {
     o.caret = lowBound;
     o.clickAfter = true;
   } else {
     o.caret = highBound;
     o.clickAfter = false;
   }
   // we now have the closest!
   return o;
 }