private WVirtualImage.Rect neighbourhood(long x, long y, int marginX, int marginY) {
   long x1 = x - marginX;
   if (this.imageWidth_ != Infinite) {
     x1 = Math.max((long) 0, x1);
   }
   long y1 = Math.max((long) 0, y - marginY);
   long x2 = x + this.viewPortWidth_ + marginX;
   if (this.imageWidth_ != Infinite) {
     x2 = Math.min(this.imageWidth_, x2);
   }
   long y2 = Math.min(this.imageHeight_, y + this.viewPortHeight_ + marginY);
   return new WVirtualImage.Rect(x1, y1, x2, y2);
 }
 private void internalScrollTo(long newX, long newY, boolean moveViewPort) {
   if (this.imageWidth_ != Infinite) {
     newX = Math.min(this.imageWidth_ - this.viewPortWidth_, Math.max((long) 0, newX));
   }
   if (this.imageHeight_ != Infinite) {
     newY = Math.min(this.imageHeight_ - this.viewPortHeight_, Math.max((long) 0, newY));
   }
   if (moveViewPort) {
     this.contents_.setOffsets(new WLength((double) -newX), EnumSet.of(Side.Left));
     this.contents_.setOffsets(new WLength((double) -newY), EnumSet.of(Side.Top));
   }
   this.generateGridItems(newX, newY);
   this.viewPortChanged_.trigger(this.currentX_, this.currentY_);
 }
Exemplo n.º 3
0
  /*
  	Show context number lines of string before and after target line.
  	Add HTML formatting to bold the target line.
  */
  String showScriptContextHTML(String s, int lineNo, int context) {
    StringBuffer sb = new StringBuffer();
    BufferedReader br = new BufferedReader(new StringReader(s));

    int beginLine = Math.max(1, lineNo - context);
    int endLine = lineNo + context;
    for (int i = 1; i <= lineNo + context + 1; i++) {
      if (i < beginLine) {
        try {
          br.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e.toString());
        }
        continue;
      }
      if (i > endLine) break;

      String line;
      try {
        line = br.readLine();
      } catch (IOException e) {
        throw new RuntimeException(e.toString());
      }

      if (line == null) break;
      if (i == lineNo) sb.append("<font color=\"red\">" + i + ": " + line + "</font><br/>");
      else sb.append(i + ": " + line + "<br/>");
    }

    return sb.toString();
  }
Exemplo n.º 4
0
 void expand(int row, int column, int rowSpan, int columnSpan) {
   int newNumRows = row + rowSpan;
   int curNumColumns = this.getColumnCount();
   int newNumColumns = Math.max(curNumColumns, column + columnSpan);
   if (newNumRows > this.getRowCount() || newNumColumns > curNumColumns) {
     if (newNumColumns == curNumColumns && this.getRowCount() >= this.headerRowCount_) {
       this.rowsAdded_ += newNumRows - this.getRowCount();
     } else {
       this.flags_.set(BIT_GRID_CHANGED);
     }
     this.repaint(EnumSet.of(RepaintFlag.RepaintInnerHtml));
     for (int r = this.getRowCount(); r < newNumRows; ++r) {
       this.rows_.add(new WTableRow(this, newNumColumns));
     }
     if (newNumColumns > curNumColumns) {
       for (int r = 0; r < this.getRowCount(); ++r) {
         WTableRow tr = this.rows_.get(r);
         tr.expand(newNumColumns);
       }
       for (int c = curNumColumns; c <= column; ++c) {
         this.columns_.add(new WTableColumn(this));
       }
     }
   }
 }
Exemplo n.º 5
0
 private void expand(int row, int column, int rowSpan, int columnSpan) {
   int newRowCount = Math.max(this.getRowCount(), row + rowSpan);
   int newColumnCount = Math.max(this.getColumnCount(), column + columnSpan);
   int extraRows = newRowCount - this.getRowCount();
   int extraColumns = newColumnCount - this.getColumnCount();
   if (extraColumns > 0) {
     for (int a_row = 0; a_row < this.getRowCount(); ++a_row) {
       {
         int insertPos = this.grid_.items_.get(a_row).size();
         for (int ii = 0; ii < (extraColumns); ++ii)
           this.grid_.items_.get(a_row).add(insertPos + ii, new Grid.Item());
       }
       ;
     }
     {
       int insertPos = this.grid_.columns_.size();
       for (int ii = 0; ii < (extraColumns); ++ii)
         this.grid_.columns_.add(insertPos + ii, new Grid.Section());
     }
     ;
   }
   if (extraRows > 0) {
     {
       int insertPos = this.grid_.items_.size();
       for (int ii = 0; ii < (extraRows); ++ii)
         this.grid_.items_.add(insertPos + ii, new ArrayList<Grid.Item>());
     }
     ;
     for (int i = 0; i < extraRows; ++i) {
       final List<Grid.Item> items =
           this.grid_.items_.get(this.grid_.items_.size() - extraRows + i);
       {
         int insertPos = items.size();
         for (int ii = 0; ii < (newColumnCount); ++ii) items.add(insertPos + ii, new Grid.Item());
       }
       ;
     }
     {
       int insertPos = this.grid_.rows_.size();
       for (int ii = 0; ii < (extraRows); ++ii)
         this.grid_.rows_.add(insertPos + ii, new Grid.Section());
     }
     ;
   }
 }
Exemplo n.º 6
0
 /**
  * Adds a layout item to the grid.
  *
  * <p>Adds the <i>item</i> at (<i>row</i>, <code>column</code>). If an item was already added to
  * that location, it is replaced (but not deleted).
  *
  * <p>An item may span several more rows or columns, which is controlled by <i>rowSpan</i> and
  * <code>columnSpan</code>.
  *
  * <p>The <code>alignment</code> specifies the vertical and horizontal alignment of the item. The
  * default value 0 indicates that the item is stretched to fill the entire grid cell. The
  * alignment can be specified as a logical combination of a horizontal alignment ( {@link
  * AlignmentFlag#AlignLeft}, {@link AlignmentFlag#AlignCenter}, or {@link
  * AlignmentFlag#AlignRight}) and a vertical alignment ( {@link AlignmentFlag#AlignTop}, {@link
  * AlignmentFlag#AlignMiddle}, or {@link AlignmentFlag#AlignBottom}).
  *
  * <p>
  *
  * @see WGridLayout#addLayout(WLayout layout, int row, int column, EnumSet alignment)
  * @see WGridLayout#addWidget(WWidget widget, int row, int column, EnumSet alignment)
  */
 public void addItem(
     WLayoutItem item,
     int row,
     int column,
     int rowSpan,
     int columnSpan,
     EnumSet<AlignmentFlag> alignment) {
   columnSpan = Math.max(1, columnSpan);
   rowSpan = Math.max(1, rowSpan);
   this.expand(row, column, rowSpan, columnSpan);
   final Grid.Item gridItem = this.grid_.items_.get(row).get(column);
   if (gridItem.item_ != null) {
     WLayoutItem oldItem = gridItem.item_;
     gridItem.item_ = null;
     this.updateRemoveItem(oldItem);
   }
   gridItem.item_ = item;
   gridItem.rowSpan_ = rowSpan;
   gridItem.colSpan_ = columnSpan;
   gridItem.alignment_ = EnumSet.copyOf(alignment);
   this.updateAddItem(item);
 }
Exemplo n.º 7
0
  private static int getBackupVersion(String dirName, String fileName) {
    int maxN = 0;
    File dir = new File(dirName);
    if (!dir.exists()) return -1;

    String[] files = dir.list();
    if (null == files) return -1;

    for (String name : files) {
      if (name.indexOf(fileName) < 0) continue;
      int pos = name.indexOf('~');
      if (pos < 0) continue;
      String ver = name.substring(pos + 1);
      int n = 0;
      try {
        n = Integer.parseInt(ver);
      } catch (NumberFormatException e) {
        log.error("Format Integer error on backup filename= " + ver);
      }
      maxN = Math.max(n, maxN);
    }
    return maxN + 1;
  }
  protected ModelAndView handleRequestInternal(
      HttpServletRequest request, HttpServletResponse response) throws Exception {

    Map<String, Object> map = new HashMap<String, Object>();

    //	String id = request.getParameter("id");
    //  MediaFile mediaFile = mediaFileService.getMediaFile(path);

    int listOffset = DEFAULT_LIST_OFFSET;
    int listSize = DEFAULT_LIST_SIZE;
    String listType = DEFAULT_LIST_TYPE;

    User user = securityService.getCurrentUser(request);
    String username = user.getUsername();
    UserSettings userSettings = settingsService.getUserSettings(username);
    int userGroupId = securityService.getCurrentUserGroupId(request);

    if (request.getParameter("listOffset") != null) {
      listOffset =
          Math.max(
              0, Math.min(Integer.parseInt(request.getParameter("listOffset")), MAX_LIST_OFFSET));
    }

    if (request.getParameter("listSize") != null) {
      listSize =
          Math.max(0, Math.min(Integer.parseInt(request.getParameter("listSize")), MAX_LIST_SIZE));
    }

    if (request.getParameter("listType") != null) {
      listType = String.valueOf(request.getParameter("listType"));
    }
    List<MediaFile> songs;
    if ("topplayed".equals(listType)) {
      songs = mediaFileDao.getTopPlayedCountForUser(listOffset, listSize, username);
    } else if ("otheruser".equals(listType)) {
      songs = mediaFileDao.getLastPlayedCountForAllUser(listOffset, listSize, userGroupId);
    } else if ("overall".equals(listType)) {
      songs = mediaFileDao.getTopPlayedCountForAllUser(listOffset, listSize, userGroupId);
    } else if ("lastplayed".equals(listType)) {
      songs = mediaFileDao.getLastPlayedCountForUser(listOffset, listSize, username);
    } else {
      songs = mediaFileDao.getLastPlayedCountForAllUser(0, 1, userGroupId);
    }

    mediaFileService.populateStarredDate(songs, username);
    map.put("user", user);
    map.put("songs", songs);

    map.put("partyModeEnabled", userSettings.isPartyModeEnabled());
    map.put("player", playerService.getPlayer(request, response));

    map.put("listOffset", listOffset);
    map.put("listSize", listSize);
    map.put("listType", listType);

    //  map.put("starred", mediaFileService.getMediaFileStarredDate(dir.getId(), username) != null);

    ModelAndView result = super.handleRequestInternal(request, response);
    result.addObject("model", map);
    return result;
  }
Exemplo n.º 9
0
 protected void paintEvent(WPaintDevice paintDevice) {
   if (!(this.chart_ != null) || !this.chart_.cObjCreated_) {
     return;
   }
   if (this.chart_.getSeries(this.seriesColumn_).getType() != SeriesType.LineSeries
       && this.chart_.getSeries(this.seriesColumn_).getType() != SeriesType.CurveSeries) {
     if (this.getMethod() == WPaintedWidget.Method.HtmlCanvas) {
       StringBuilder ss = new StringBuilder();
       ss.append("jQuery.removeData(").append(this.getJsRef()).append(",'sobj');");
       ss.append("\nif (")
           .append(this.getObjJsRef())
           .append(") {")
           .append(this.getObjJsRef())
           .append(".canvas.style.cursor = 'auto';")
           .append("setTimeout(")
           .append(this.getObjJsRef())
           .append(".repaint,0);}\n");
       this.doJavaScript(ss.toString());
     }
     logger.error(
         new StringWriter()
             .append("WAxisSliderWidget is not associated with a line or curve series.")
             .toString());
     return;
   }
   WPainter painter = new WPainter(paintDevice);
   boolean horizontal = this.chart_.getOrientation() == Orientation.Vertical;
   double w = horizontal ? this.getWidth().getValue() : this.getHeight().getValue();
   double h = horizontal ? this.getHeight().getValue() : this.getWidth().getValue();
   boolean autoPadding = this.autoPadding_;
   if (autoPadding
       && EnumUtils.mask(paintDevice.getFeatures(), WPaintDevice.FeatureFlag.HasFontMetrics)
           .equals(0)
       && this.labelsEnabled_) {
     logger.error(
         new StringWriter()
             .append(
                 "setAutoLayout(): device does not have font metrics (not even server-side font metrics).")
             .toString());
     autoPadding = false;
   }
   if (autoPadding) {
     if (horizontal) {
       if (this.labelsEnabled_) {
         this.setSelectionAreaPadding(0, EnumSet.of(Side.Top));
         this.setSelectionAreaPadding(
             (int)
                 (this.chart_
                         .getAxis(Axis.XAxis)
                         .calcMaxTickLabelSize(paintDevice, Orientation.Vertical)
                     + 10),
             EnumSet.of(Side.Bottom));
         this.setSelectionAreaPadding(
             (int)
                 Math.max(
                     this.chart_
                             .getAxis(Axis.XAxis)
                             .calcMaxTickLabelSize(paintDevice, Orientation.Horizontal)
                         / 2,
                     10.0),
             EnumSet.of(Side.Left, Side.Right));
       } else {
         this.setSelectionAreaPadding(0, EnumSet.of(Side.Top));
         this.setSelectionAreaPadding(5, EnumSet.of(Side.Left, Side.Right, Side.Bottom));
       }
     } else {
       if (this.labelsEnabled_) {
         this.setSelectionAreaPadding(0, EnumSet.of(Side.Right));
         this.setSelectionAreaPadding(
             (int)
                 Math.max(
                     this.chart_
                             .getAxis(Axis.XAxis)
                             .calcMaxTickLabelSize(paintDevice, Orientation.Vertical)
                         / 2,
                     10.0),
             EnumSet.of(Side.Top, Side.Bottom));
         this.setSelectionAreaPadding(
             (int)
                 (this.chart_
                         .getAxis(Axis.XAxis)
                         .calcMaxTickLabelSize(paintDevice, Orientation.Horizontal)
                     + 10),
             EnumSet.of(Side.Left));
       } else {
         this.setSelectionAreaPadding(0, EnumSet.of(Side.Right));
         this.setSelectionAreaPadding(5, EnumSet.of(Side.Top, Side.Bottom, Side.Left));
       }
     }
   }
   double left =
       horizontal
           ? this.getSelectionAreaPadding(Side.Left)
           : this.getSelectionAreaPadding(Side.Top);
   double right =
       horizontal
           ? this.getSelectionAreaPadding(Side.Right)
           : this.getSelectionAreaPadding(Side.Bottom);
   double top =
       horizontal
           ? this.getSelectionAreaPadding(Side.Top)
           : this.getSelectionAreaPadding(Side.Right);
   double bottom =
       horizontal
           ? this.getSelectionAreaPadding(Side.Bottom)
           : this.getSelectionAreaPadding(Side.Left);
   double maxW = w - left - right;
   WRectF drawArea = new WRectF(left, 0, maxW, h);
   List<WAxis.Segment> segmentsBak =
       new ArrayList<WAxis.Segment>(this.chart_.getAxis(Axis.XAxis).segments_);
   double renderIntervalBak = this.chart_.getAxis(Axis.XAxis).renderInterval_;
   this.chart_
       .getAxis(Axis.XAxis)
       .prepareRender(
           horizontal ? Orientation.Horizontal : Orientation.Vertical, drawArea.getWidth());
   final WRectF chartArea = this.chart_.chartArea_;
   WRectF selectionRect = null;
   {
     double u =
         -this.chart_.xTransformHandle_.getValue().getDx()
             / (chartArea.getWidth() * this.chart_.xTransformHandle_.getValue().getM11());
     selectionRect = new WRectF(0, top, maxW, h - (top + bottom));
     this.transform_.setValue(
         new WTransform(
             1 / this.chart_.xTransformHandle_.getValue().getM11(), 0, 0, 1, u * maxW, 0));
   }
   WRectF seriesArea = new WRectF(left, top + 5, maxW, h - (top + bottom + 5));
   WTransform selectionTransform =
       this.hv(new WTransform(1, 0, 0, 1, left, 0).multiply(this.transform_.getValue()));
   WRectF rect = selectionTransform.map(this.hv(selectionRect));
   painter.fillRect(this.hv(new WRectF(left, top, maxW, h - top - bottom)), this.background_);
   painter.fillRect(rect, this.selectedAreaBrush_);
   final double TICK_LENGTH = 5;
   final double ANGLE1 = 15;
   final double ANGLE2 = 80;
   double tickStart = 0.0;
   double tickEnd = 0.0;
   double labelPos = 0.0;
   AlignmentFlag labelHFlag = AlignmentFlag.AlignCenter;
   AlignmentFlag labelVFlag = AlignmentFlag.AlignMiddle;
   final WAxis axis = this.chart_.getAxis(Axis.XAxis);
   if (horizontal) {
     tickStart = 0;
     tickEnd = TICK_LENGTH;
     labelPos = TICK_LENGTH;
     labelVFlag = AlignmentFlag.AlignTop;
   } else {
     tickStart = -TICK_LENGTH;
     tickEnd = 0;
     labelPos = -TICK_LENGTH;
     labelHFlag = AlignmentFlag.AlignRight;
   }
   if (horizontal) {
     if (axis.getLabelAngle() > ANGLE1) {
       labelHFlag = AlignmentFlag.AlignRight;
       if (axis.getLabelAngle() > ANGLE2) {
         labelVFlag = AlignmentFlag.AlignMiddle;
       }
     } else {
       if (axis.getLabelAngle() < -ANGLE1) {
         labelHFlag = AlignmentFlag.AlignLeft;
         if (axis.getLabelAngle() < -ANGLE2) {
           labelVFlag = AlignmentFlag.AlignMiddle;
         }
       }
     }
   } else {
     if (axis.getLabelAngle() > ANGLE1) {
       labelVFlag = AlignmentFlag.AlignBottom;
       if (axis.getLabelAngle() > ANGLE2) {
         labelHFlag = AlignmentFlag.AlignCenter;
       }
     } else {
       if (axis.getLabelAngle() < -ANGLE1) {
         labelVFlag = AlignmentFlag.AlignTop;
         if (axis.getLabelAngle() < -ANGLE2) {
           labelHFlag = AlignmentFlag.AlignCenter;
         }
       }
     }
   }
   EnumSet<AxisProperty> axisProperties = EnumSet.of(AxisProperty.Line);
   if (this.labelsEnabled_) {
     axisProperties.add(AxisProperty.Labels);
   }
   if (horizontal) {
     axis.render(
         painter,
         axisProperties,
         new WPointF(drawArea.getLeft(), h - bottom),
         new WPointF(drawArea.getRight(), h - bottom),
         tickStart,
         tickEnd,
         labelPos,
         EnumSet.of(labelHFlag, labelVFlag));
     WPainterPath line = new WPainterPath();
     line.moveTo(drawArea.getLeft() + 0.5, h - (bottom - 0.5));
     line.lineTo(drawArea.getRight(), h - (bottom - 0.5));
     painter.strokePath(line, this.chart_.getAxis(Axis.XAxis).getPen());
   } else {
     axis.render(
         painter,
         axisProperties,
         new WPointF(this.getSelectionAreaPadding(Side.Left) - 1, drawArea.getLeft()),
         new WPointF(this.getSelectionAreaPadding(Side.Left) - 1, drawArea.getRight()),
         tickStart,
         tickEnd,
         labelPos,
         EnumSet.of(labelHFlag, labelVFlag));
     WPainterPath line = new WPainterPath();
     line.moveTo(this.getSelectionAreaPadding(Side.Left) - 0.5, drawArea.getLeft() + 0.5);
     line.lineTo(this.getSelectionAreaPadding(Side.Left) - 0.5, drawArea.getRight());
     painter.strokePath(line, this.chart_.getAxis(Axis.XAxis).getPen());
   }
   WPainterPath curve = new WPainterPath();
   {
     WTransform t =
         new WTransform(1, 0, 0, 1, seriesArea.getLeft(), seriesArea.getTop())
             .multiply(
                 new WTransform(
                     seriesArea.getWidth() / chartArea.getWidth(),
                     0,
                     0,
                     seriesArea.getHeight() / chartArea.getHeight(),
                     0,
                     0))
             .multiply(new WTransform(1, 0, 0, 1, -chartArea.getLeft(), -chartArea.getTop()));
     if (!horizontal) {
       t.assign(
           new WTransform(
                   0,
                   1,
                   1,
                   0,
                   this.getSelectionAreaPadding(Side.Left)
                       - this.getSelectionAreaPadding(Side.Right)
                       - 5,
                   0)
               .multiply(t)
               .multiply(new WTransform(0, 1, 1, 0, 0, 0)));
     }
     curve.assign(t.map(this.chart_.pathForSeries(this.seriesColumn_)));
   }
   {
     WRectF leftHandle = this.hv(new WRectF(-5, top, 5, h - top - bottom));
     WTransform t =
         new WTransform(1, 0, 0, 1, left, -top)
             .multiply(
                 new WTransform()
                     .translate(this.transform_.getValue().map(selectionRect.getTopLeft())));
     painter.fillRect(this.hv(t).map(leftHandle), this.handleBrush_);
   }
   {
     WRectF rightHandle = this.hv(new WRectF(0, top, 5, h - top - bottom));
     WTransform t =
         new WTransform(1, 0, 0, 1, left, -top)
             .multiply(
                 new WTransform()
                     .translate(this.transform_.getValue().map(selectionRect.getTopRight())));
     painter.fillRect(this.hv(t).map(rightHandle), this.handleBrush_);
   }
   if (this.selectedSeriesPen_ != this.seriesPen_
       && !this.selectedSeriesPen_.equals(this.seriesPen_)) {
     WPainterPath clipPath = new WPainterPath();
     clipPath.addRect(this.hv(selectionRect));
     painter.setClipPath(selectionTransform.map(clipPath));
     painter.setClipping(true);
     painter.setPen(this.getSelectedSeriesPen());
     painter.drawPath(curve);
     WPainterPath leftClipPath = new WPainterPath();
     leftClipPath.addRect(
         this.hv(new WTransform(1, 0, 0, 1, -selectionRect.getWidth(), 0).map(selectionRect)));
     painter.setClipPath(
         this.hv(
                 new WTransform(1, 0, 0, 1, left, -top)
                     .multiply(
                         new WTransform()
                             .translate(
                                 this.transform_.getValue().map(selectionRect.getTopLeft()))))
             .map(leftClipPath));
     painter.setPen(this.getSeriesPen());
     painter.drawPath(curve);
     WPainterPath rightClipPath = new WPainterPath();
     rightClipPath.addRect(
         this.hv(new WTransform(1, 0, 0, 1, selectionRect.getWidth(), 0).map(selectionRect)));
     painter.setClipPath(
         this.hv(
                 new WTransform(1, 0, 0, 1, left - selectionRect.getRight(), -top)
                     .multiply(
                         new WTransform()
                             .translate(
                                 this.transform_.getValue().map(selectionRect.getTopRight()))))
             .map(rightClipPath));
     painter.drawPath(curve);
     painter.setClipping(false);
   } else {
     painter.setPen(this.getSeriesPen());
     painter.drawPath(curve);
   }
   if (this.getMethod() == WPaintedWidget.Method.HtmlCanvas) {
     WApplication app = WApplication.getInstance();
     StringBuilder ss = new StringBuilder();
     ss.append("new Wt3_3_5.WAxisSliderWidget(")
         .append(app.getJavaScriptClass())
         .append(",")
         .append(this.getJsRef())
         .append(",")
         .append(this.getObjJsRef())
         .append(",")
         .append("{chart:")
         .append(this.chart_.getCObjJsRef())
         .append(",transform:")
         .append(this.transform_.getJsRef())
         .append(",rect:function(){return ")
         .append(rect.getJsRef())
         .append("},drawArea:")
         .append(drawArea.getJsRef())
         .append(",series:")
         .append(this.seriesColumn_)
         .append("});");
     this.doJavaScript(ss.toString());
   }
   Utils.copyList(segmentsBak, this.chart_.getAxis(Axis.XAxis).segments_);
   this.chart_.getAxis(Axis.XAxis).renderInterval_ = renderIntervalBak;
 }
Exemplo n.º 10
0
 long _getScopeTime() {
   long last = 0;
   for (File f : _initFlies) if (f.exists()) last = Math.max(last, f.lastModified());
   return last;
 }