コード例 #1
0
ファイル: WAxisSliderWidget.java プロジェクト: sebap/jwt
 private void init() {
   this.transform_ = this.createJSTransform();
   this.mouseWentDown()
       .addListener("function(o, e){var o=" + this.getSObjJsRef() + ";if(o){o.mouseDown(o, e);}}");
   this.mouseWentUp()
       .addListener("function(o, e){var o=" + this.getSObjJsRef() + ";if(o){o.mouseUp(o, e);}}");
   this.mouseDragged()
       .addListener("function(o, e){var o=" + this.getSObjJsRef() + ";if(o){o.mouseDrag(o, e);}}");
   this.mouseMoved()
       .addListener(
           "function(o, e){var o=" + this.getSObjJsRef() + ";if(o){o.mouseMoved(o, e);}}");
   this.touchStarted()
       .addListener(
           "function(o, e){var o=" + this.getSObjJsRef() + ";if(o){o.touchStarted(o, e);}}");
   this.touchEnded()
       .addListener(
           "function(o, e){var o=" + this.getSObjJsRef() + ";if(o){o.touchEnded(o, e);}}");
   this.touchMoved()
       .addListener(
           "function(o, e){var o=" + this.getSObjJsRef() + ";if(o){o.touchMoved(o, e);}}");
   this.setSelectionAreaPadding(0, EnumSet.of(Side.Top));
   this.setSelectionAreaPadding(20, EnumSet.of(Side.Left, Side.Right));
   this.setSelectionAreaPadding(30, EnumSet.of(Side.Bottom));
   if (this.chart_ != null) {
     this.chart_.addAxisSliderWidget(this);
   }
 }
コード例 #2
0
 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_);
 }
コード例 #3
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));
       }
     }
   }
 }
コード例 #4
0
ファイル: WAbstractMedia.java プロジェクト: clawplach/jwt
 /**
  * Consctructor for a media widget.
  *
  * <p>A freshly constructed media widget has no options set, no media sources, and has preload
  * mode set to PreloadAuto.
  */
 public WAbstractMedia(WContainerWidget parent) {
   super(parent);
   this.sources_ = new ArrayList<WAbstractMedia.Source>();
   this.sourcesRendered_ = 0;
   this.mediaId_ = "";
   this.flags_ = EnumSet.noneOf(WAbstractMedia.Options.class);
   this.preloadMode_ = WAbstractMedia.PreloadMode.PreloadAuto;
   this.alternative_ = null;
   this.flagsChanged_ = false;
   this.preloadChanged_ = false;
   this.sourcesChanged_ = false;
   this.playing_ = false;
   this.volume_ = -1;
   this.current_ = -1;
   this.duration_ = -1;
   this.ended_ = false;
   this.readyState_ = WAbstractMedia.ReadyState.HaveNothing;
   this.setInline(false);
   this.setFormObject(true);
   WApplication app = WApplication.getInstance();
   app.loadJavaScript("js/WAbstractMedia.js", wtjs1());
   this.setJavaScriptMember(
       " WAbstractMedia",
       "new Wt3_2_3.WAbstractMedia(" + app.getJavaScriptClass() + "," + this.getJsRef() + ");");
 }
コード例 #5
0
 void showDiagnostics(boolean showAll) {
   Set<JCDiagnostic.Kind> kinds = EnumSet.allOf(JCDiagnostic.Kind.class);
   if (!showAll) {
     // suppress errors, which are all presumed to be transient resolve errors
     kinds.remove(JCDiagnostic.Kind.ERROR);
   }
   log.reportDeferredDiagnostics(kinds);
 }
コード例 #6
0
ファイル: WGridLayout.java プロジェクト: kdeforche/jwt
 /**
  * Adds a nested layout item to the grid.
  *
  * <p>Calls {@link #addLayout(WLayout layout, int row, int column, int rowSpan, int columnSpan,
  * EnumSet alignment) addLayout(layout, row, column, rowSpan, columnSpan, EnumSet.of(alignmen,
  * alignment))}
  */
 public final void addLayout(
     WLayout layout,
     int row,
     int column,
     int rowSpan,
     int columnSpan,
     AlignmentFlag alignmen,
     AlignmentFlag... alignment) {
   addLayout(layout, row, column, rowSpan, columnSpan, EnumSet.of(alignmen, alignment));
 }
コード例 #7
0
 void repaintRow(WTableRow row) {
   if (row.getRowNum() >= (int) (this.getRowCount() - this.rowsAdded_)) {
     return;
   }
   if (!(this.rowsChanged_ != null)) {
     this.rowsChanged_ = new HashSet<WTableRow>();
   }
   this.rowsChanged_.add(row);
   this.repaint(EnumSet.of(RepaintFlag.RepaintInnerHtml));
 }
コード例 #8
0
 /** Delete a column and all its contents. */
 public void deleteColumn(int column) {
   for (int i = 0; i < this.getRowCount(); ++i) {
     this.rows_.get(i).deleteColumn(column);
   }
   if ((int) column <= this.columns_.size()) {;
     this.columns_.remove(0 + column);
   }
   this.flags_.set(BIT_GRID_CHANGED);
   this.repaint(EnumSet.of(RepaintFlag.RepaintInnerHtml));
 }
コード例 #9
0
ファイル: WGridLayout.java プロジェクト: kdeforche/jwt
 /**
  * Adds a layout item to the grid.
  *
  * <p>Calls {@link #addItem(WLayoutItem item, int row, int column, int rowSpan, int columnSpan,
  * EnumSet alignment) addItem(item, row, column, rowSpan, columnSpan, EnumSet.of(alignmen,
  * alignment))}
  */
 public final void addItem(
     WLayoutItem item,
     int row,
     int column,
     int rowSpan,
     int columnSpan,
     AlignmentFlag alignmen,
     AlignmentFlag... alignment) {
   addItem(item, row, column, rowSpan, columnSpan, EnumSet.of(alignmen, alignment));
 }
コード例 #10
0
ファイル: WGridLayout.java プロジェクト: kdeforche/jwt
 /**
  * Adds a widget to the grid.
  *
  * <p>Calls {@link #addWidget(WWidget widget, int row, int column, int rowSpan, int columnSpan,
  * EnumSet alignment) addWidget(widget, row, column, rowSpan, columnSpan, EnumSet.of(alignmen,
  * alignment))}
  */
 public final void addWidget(
     WWidget widget,
     int row,
     int column,
     int rowSpan,
     int columnSpan,
     AlignmentFlag alignmen,
     AlignmentFlag... alignment) {
   addWidget(widget, row, column, rowSpan, columnSpan, EnumSet.of(alignmen, alignment));
 }
コード例 #11
0
 /** Inserts an empty row. */
 public WTableRow insertRow(int row) {
   if (row >= this.getRowCount()) {
     return this.getRowAt(row);
   } else {
     WTableRow tableRow = new WTableRow(this, this.getColumnCount());
     this.rows_.add(0 + row, tableRow);
     this.flags_.set(BIT_GRID_CHANGED);
     this.repaint(EnumSet.of(RepaintFlag.RepaintInnerHtml));
     return tableRow;
   }
 }
コード例 #12
0
 private void generateGridItems(long newX, long newY) {
   WVirtualImage.Rect newNb =
       this.neighbourhood(newX, newY, this.viewPortWidth_, this.viewPortHeight_);
   long i1 = newNb.x1 / this.gridImageSize_;
   long j1 = newNb.y1 / this.gridImageSize_;
   long i2 = newNb.x2 / this.gridImageSize_ + 1;
   long j2 = newNb.y2 / this.gridImageSize_ + 1;
   for (int invisible = 0; invisible < 2; ++invisible) {
     for (long i = i1; i < i2; ++i) {
       for (long j = j1; j < j2; ++j) {
         long key = this.gridKey(i, j);
         WImage it = this.grid_.get(key);
         if (it == null) {
           boolean v = this.visible(i, j);
           if (v && !(invisible != 0) || !v && invisible != 0) {
             long brx = i * this.gridImageSize_ + this.gridImageSize_;
             long bry = j * this.gridImageSize_ + this.gridImageSize_;
             brx = Math.min(brx, this.imageWidth_);
             bry = Math.min(bry, this.imageHeight_);
             WImage img =
                 this.createImage(
                     i * this.gridImageSize_,
                     j * this.gridImageSize_,
                     (int) (brx - i * this.gridImageSize_),
                     (int) (bry - j * this.gridImageSize_));
             img.setAttributeValue("onmousedown", "return false;");
             this.contents_.addWidget(img);
             img.setPositionScheme(PositionScheme.Absolute);
             img.setOffsets(new WLength((double) i * this.gridImageSize_), EnumSet.of(Side.Left));
             img.setOffsets(new WLength((double) j * this.gridImageSize_), EnumSet.of(Side.Top));
             this.grid_.put(key, img);
           }
         }
       }
     }
   }
   this.currentX_ = newX;
   this.currentY_ = newY;
   this.cleanGrid();
 }
コード例 #13
0
 /** Inserts an empty column. */
 public WTableColumn insertColumn(int column) {
   for (int i = 0; i < this.rows_.size(); ++i) {
     this.rows_.get(i).insertColumn(column);
   }
   WTableColumn tableColumn = null;
   if ((int) column <= this.columns_.size()) {
     tableColumn = new WTableColumn(this);
     this.columns_.add(0 + column, tableColumn);
   }
   this.flags_.set(BIT_GRID_CHANGED);
   this.repaint(EnumSet.of(RepaintFlag.RepaintInnerHtml));
   return tableColumn;
 }
コード例 #14
0
 /**
  * Move a table row from its original position to a new position.
  *
  * <p>The table expands automatically when the <code>to</code> row is beyond the current table
  * dimensions.
  *
  * <p>
  *
  * @see WTable#moveColumn(int from, int to)
  */
 public void moveRow(int from, int to) {
   if (from < 0 || from >= (int) this.rows_.size()) {
     logger.error(
         new StringWriter()
             .append("moveRow: the from index is not a valid row index.")
             .toString());
     return;
   }
   WTableRow from_tr = this.getRowAt(from);
   this.rows_.remove(from_tr);
   if (to > (int) this.rows_.size()) {
     this.getRowAt(to);
   }
   this.rows_.add(0 + to, from_tr);
   this.flags_.set(BIT_GRID_CHANGED);
   this.repaint(EnumSet.of(RepaintFlag.RepaintInnerHtml));
 }
コード例 #15
0
 /**
  * Deletes a row and all its contents.
  *
  * <p>Rows below the given row are shifted up.
  */
 public void deleteRow(int row) {
   if (this.rowsChanged_ != null) {
     this.rowsChanged_.remove(this.rows_.get(row));
     if (this.rowsChanged_.isEmpty()) {;
       this.rowsChanged_ = null;
     }
   }
   for (int i = 0; i < this.getColumnCount(); ++i) {
     WTableCell cell = this.rows_.get(row).cells_.get(i).cell;
     if (cell != null) cell.remove();
   }
   if (row >= (int) (this.getRowCount() - this.rowsAdded_)) {
     --this.rowsAdded_;
   } else {
     this.flags_.set(BIT_GRID_CHANGED);
     this.repaint(EnumSet.of(RepaintFlag.RepaintInnerHtml));
   }
   ;
   this.rows_.remove(0 + row);
 }
コード例 #16
0
ファイル: WGridLayout.java プロジェクト: kdeforche/jwt
 /**
  * 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);
 }
コード例 #17
0
 /**
  * Move a table column from its original position to a new position.
  *
  * <p>The table expands automatically when the <code>to</code> column is beyond the current table
  * dimensions.
  *
  * <p>
  *
  * @see WTable#moveRow(int from, int to)
  */
 public void moveColumn(int from, int to) {
   if (from < 0 || from >= (int) this.columns_.size()) {
     logger.error(
         new StringWriter()
             .append("moveColumn: the from index is not a valid column index.")
             .toString());
     return;
   }
   WTableColumn from_tc = this.getColumnAt(from);
   this.columns_.remove(from_tc);
   if (to > (int) this.columns_.size()) {
     this.getColumnAt(to);
   }
   this.columns_.add(0 + to, from_tc);
   for (int i = 0; i < this.rows_.size(); i++) {
     List<WTableRow.TableData> cells = this.rows_.get(i).cells_;
     WTableRow.TableData cell = cells.get(from);
     cells.remove(0 + from);
     cells.add(0 + to, cell);
   }
   this.flags_.set(BIT_GRID_CHANGED);
   this.repaint(EnumSet.of(RepaintFlag.RepaintInnerHtml));
 }
コード例 #18
0
ファイル: WAbstractMedia.java プロジェクト: clawplach/jwt
 /**
  * Set the media element options.
  *
  * <p>Calls {@link #setOptions(EnumSet flags) setOptions(EnumSet.of(flag, flags))}
  */
 public final void setOptions(WAbstractMedia.Options flag, WAbstractMedia.Options... flags) {
   setOptions(EnumSet.of(flag, flags));
 }
コード例 #19
0
ファイル: WAbstractMedia.java プロジェクト: clawplach/jwt
 /**
  * Set the media element options.
  *
  * <p>
  *
  * @see WAbstractMedia.Options
  */
 public void setOptions(EnumSet<WAbstractMedia.Options> flags) {
   this.flags_ = EnumSet.copyOf(flags);
   this.flagsChanged_ = true;
   this.repaint(EnumSet.of(RepaintFlag.RepaintPropertyAttribute));
 }
コード例 #20
0
  public List<Revision> filter(Collection<Revision> list, EnumSet<Library.Phase> phases) {
    List<Revision> filtered = new ArrayList<Library.Revision>();
    for (Revision r : list) if (phases.contains(r.phase)) filtered.add(r);

    return filtered;
  }
コード例 #21
0
ファイル: WAxisSliderWidget.java プロジェクト: sebap/jwt
 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;
 }
コード例 #22
0
ファイル: WAxisSliderWidget.java プロジェクト: sebap/jwt
 /**
  * Sets an internal margin for the selection area.
  *
  * <p>Calls {@link #setSelectionAreaPadding(int padding, EnumSet sides)
  * setSelectionAreaPadding(padding, EnumSet.of(side, sides))}
  */
 public final void setSelectionAreaPadding(int padding, Side side, Side... sides) {
   setSelectionAreaPadding(padding, EnumSet.of(side, sides));
 }
コード例 #23
0
ファイル: RestXqFunction.java プロジェクト: jolau/basex-api
/**
 * This class represents a single RESTXQ function.
 *
 * @author BaseX Team 2005-12, BSD License
 * @author Christian Gruen
 */
final class RestXqFunction implements Comparable<RestXqFunction> {
  /** Pattern for a single template. */
  private static final Pattern TEMPLATE = Pattern.compile("\\s*\\{\\s*\\$(.+?)\\s*\\}\\s*");

  /** Supported methods. */
  EnumSet<HTTPMethod> methods = EnumSet.allOf(HTTPMethod.class);
  /** Serialization parameters. */
  final SerializerProp output = new SerializerProp();
  /** Associated function. */
  final StaticUserFunc function;
  /** Associated module. */
  final RestXqModule module;
  /** Path. */
  RestXqPath path;

  /** Query parameters. */
  final ArrayList<RestXqParam> queryParams = new ArrayList<RestXqParam>();
  /** Form parameters. */
  final ArrayList<RestXqParam> formParams = new ArrayList<RestXqParam>();
  /** Header parameters. */
  final ArrayList<RestXqParam> headerParams = new ArrayList<RestXqParam>();
  /** Cookie parameters. */
  final ArrayList<RestXqParam> cookieParams = new ArrayList<RestXqParam>();

  /** Query context. */
  private final QueryContext context;
  /** Consumed media types. */
  private final StringList consumes = new StringList();
  /** Returned media types. */
  private final StringList produces = new StringList();
  /** Post/Put variable. */
  private QNm requestBody;

  /**
   * Constructor.
   *
   * @param uf associated user function
   * @param qc query context
   * @param m associated module
   */
  RestXqFunction(final StaticUserFunc uf, final QueryContext qc, final RestXqModule m) {
    function = uf;
    context = qc;
    module = m;
  }

  /**
   * Processes the HTTP request. Parses new modules and discards obsolete ones.
   *
   * @param http HTTP context
   * @throws Exception exception
   */
  void process(final HTTPContext http) throws Exception {
    try {
      module.process(http, this);
    } catch (final QueryException ex) {
      if (ex.file() == null) ex.info(function.info);
      throw ex;
    }
  }

  /**
   * Checks a function for RESTFful annotations.
   *
   * @return {@code true} if module contains relevant annotations
   * @throws QueryException query exception
   */
  boolean analyze() throws QueryException {
    // parse all annotations
    final EnumSet<HTTPMethod> mth = EnumSet.noneOf(HTTPMethod.class);
    final boolean[] declared = new boolean[function.args.length];
    boolean found = false;
    final int as = function.ann.size();
    for (int a = 0; a < as; a++) {
      final QNm name = function.ann.names[a];
      final Value value = function.ann.values[a];
      final byte[] local = name.local();
      final byte[] uri = name.uri();
      final boolean rexq = eq(uri, QueryText.RESTXQURI);
      if (rexq) {
        if (eq(PATH, local)) {
          // annotation "path"
          if (path != null) error(ANN_TWICE, "%", name.string());
          path = new RestXqPath(toString(value, name));
          for (final String s : path) {
            if (s.trim().startsWith("{")) checkVariable(s, AtomType.AAT, declared);
          }
        } else if (eq(CONSUMES, local)) {
          // annotation "consumes"
          strings(value, name, consumes);
        } else if (eq(PRODUCES, local)) {
          // annotation "produces"
          strings(value, name, produces);
        } else if (eq(QUERY_PARAM, local)) {
          // annotation "query-param"
          queryParams.add(param(value, name, declared));
        } else if (eq(FORM_PARAM, local)) {
          // annotation "form-param"
          formParams.add(param(value, name, declared));
        } else if (eq(HEADER_PARAM, local)) {
          // annotation "header-param"
          headerParams.add(param(value, name, declared));
        } else if (eq(COOKIE_PARAM, local)) {
          // annotation "cookie-param"
          cookieParams.add(param(value, name, declared));
        } else {
          // method annotations
          final HTTPMethod m = HTTPMethod.get(string(local));
          if (m == null) error(ANN_UNKNOWN, "%", name.string());
          if (!value.isEmpty()) {
            // remember post/put variable
            if (requestBody != null) error(ANN_TWICE, "%", name.string());
            if (m != POST && m != PUT) error(METHOD_VALUE, m);
            requestBody = checkVariable(toString(value, name), declared);
          }
          if (mth.contains(m)) error(ANN_TWICE, "%", name.string());
          mth.add(m);
        }
      } else if (eq(uri, QueryText.OUTPUTURI)) {
        // serialization parameters
        final String key = string(local);
        final String val = toString(value, name);
        if (output.get(key) == null) error(UNKNOWN_SER, key);
        output.set(key, val);
      }
      found |= rexq;
    }
    if (!mth.isEmpty()) methods = mth;

    if (found) {
      if (path == null) error(ANN_MISSING, PATH);
      for (int i = 0; i < declared.length; i++)
        if (!declared[i]) error(VAR_UNDEFINED, function.args[i].name.string());
    }
    return found;
  }

  /**
   * Checks if an HTTP request matches this function and its constraints.
   *
   * @param http http context
   * @return result of check
   */
  boolean matches(final HTTPContext http) {
    // check method, path, consumed and produced media type
    return methods.contains(http.method) && pathMatches(http) && consumes(http) && produces(http);
  }

  /**
   * Binds the annotated variables.
   *
   * @param http http context
   * @param arg argument array
   * @throws QueryException query exception
   * @throws IOException I/O exception
   */
  void bind(final HTTPContext http, final Expr[] arg) throws QueryException, IOException {
    // bind variables from segments
    for (int s = 0; s < path.size; s++) {
      final Matcher m = TEMPLATE.matcher(path.segment[s]);
      if (!m.find()) continue;
      final QNm qnm = new QNm(token(m.group(1)), context);
      bind(qnm, arg, new Atm(http.segment(s)));
    }

    // cache request body
    final String ct = http.contentType();
    IOContent body = null;

    if (requestBody != null) {
      body = cache(http, null);
      try {
        // bind request body in the correct format
        body.name(http.method + IO.XMLSUFFIX);
        bind(requestBody, arg, Parser.item(body, context.context.prop, ct));
      } catch (final IOException ex) {
        error(INPUT_CONV, ex);
      }
    }

    // bind query parameters
    final Map<String, String[]> params = http.params();
    for (final RestXqParam rxp : queryParams) bind(rxp, arg, params.get(rxp.key));

    // bind form parameters
    if (!formParams.isEmpty()) {
      if (MimeTypes.APP_FORM.equals(ct)) {
        // convert parameters encoded in a form
        body = cache(http, body);
        addParams(body.toString(), params);
      }
      for (final RestXqParam rxp : formParams) bind(rxp, arg, params.get(rxp.key));
    }

    // bind header parameters
    for (final RestXqParam rxp : headerParams) {
      final StringList sl = new StringList();
      final Enumeration<?> en = http.req.getHeaders(rxp.key);
      while (en.hasMoreElements()) {
        for (final String s : en.nextElement().toString().split(", *")) sl.add(s);
      }
      bind(rxp, arg, sl.toArray());
    }

    // bind cookie parameters
    final Cookie[] ck = http.req.getCookies();
    for (final RestXqParam rxp : cookieParams) {
      String v = null;
      if (ck != null) {
        for (final Cookie c : ck) {
          if (rxp.key.equals(c.getName())) v = c.getValue();
        }
      }
      if (v == null) bind(rxp, arg);
      else bind(rxp, arg, v);
    }
  }

  /**
   * Creates an exception with the specified message.
   *
   * @param msg message
   * @param ext error extension
   * @return exception
   * @throws QueryException query exception
   */
  QueryException error(final String msg, final Object... ext) throws QueryException {
    throw new QueryException(function.info, Err.BASX_RESTXQ, Util.info(msg, ext));
  }

  @Override
  public int compareTo(final RestXqFunction rxf) {
    return path.compareTo(rxf.path);
  }

  // PRIVATE METHODS ====================================================================

  /**
   * Checks the specified template and adds a variable.
   *
   * @param tmp template string
   * @param declared variable declaration flags
   * @return resulting variable
   * @throws QueryException query exception
   */
  private QNm checkVariable(final String tmp, final boolean[] declared) throws QueryException {
    return checkVariable(tmp, AtomType.ITEM, declared);
  }

  /**
   * Checks the specified template and adds a variable.
   *
   * @param tmp template string
   * @param type allowed type
   * @param declared variable declaration flags
   * @return resulting variable
   * @throws QueryException query exception
   */
  private QNm checkVariable(final String tmp, final Type type, final boolean[] declared)
      throws QueryException {
    final Var[] args = function.args;
    final Matcher m = TEMPLATE.matcher(tmp);
    if (!m.find()) error(INV_TEMPLATE, tmp);
    final byte[] vn = token(m.group(1));
    if (!XMLToken.isQName(vn)) error(INV_VARNAME, vn);
    final QNm qnm = new QNm(vn, context);
    int r = -1;
    while (++r < args.length && !args[r].name.eq(qnm)) ;
    if (r == args.length) error(UNKNOWN_VAR, vn);
    if (declared[r]) error(VAR_ASSIGNED, vn);
    final SeqType st = args[r].declaredType();
    if (args[r].checksType() && !st.type.instanceOf(type)) error(INV_VARTYPE, vn, type);
    declared[r] = true;
    return qnm;
  }

  /**
   * Checks if the path matches the HTTP request.
   *
   * @param http http context
   * @return result of check
   */
  private boolean pathMatches(final HTTPContext http) {
    return path.matches(http);
  }

  /**
   * Checks if the consumed content type matches.
   *
   * @param http http context
   * @return result of check
   */
  private boolean consumes(final HTTPContext http) {
    // return true if no type is given
    if (consumes.isEmpty()) return true;
    // return true if no content type is specified by the user
    final String ct = http.contentType();
    if (ct == null) return true;
    // check if any combination matches
    for (final String c : consumes) {
      if (MimeTypes.matches(c, ct)) return true;
    }
    return false;
  }

  /**
   * Checks if the produced content type matches.
   *
   * @param http http context
   * @return result of check
   */
  private boolean produces(final HTTPContext http) {
    // return true if no type is given
    if (produces.isEmpty()) return true;
    // check if any combination matches
    for (final String pr : http.produces()) {
      for (final String p : produces) {
        if (MimeTypes.matches(p, pr)) return true;
      }
    }
    return false;
  }

  /**
   * Binds the specified parameter to a variable.
   *
   * @param rxp parameter
   * @param args argument array
   * @param values values to be bound; the parameter's default value is assigned if the argument is
   *     {@code null} or empty
   * @throws QueryException query exception
   */
  private void bind(final RestXqParam rxp, final Expr[] args, final String... values)
      throws QueryException {
    final Value val;
    if (values == null || values.length == 0) {
      val = rxp.value;
    } else {
      final ValueBuilder vb = new ValueBuilder();
      for (final String s : values) vb.add(new Atm(s));
      val = vb.value();
    }
    bind(rxp.name, args, val);
  }

  /**
   * Binds the specified value to a variable.
   *
   * @param name variable name
   * @param args argument array
   * @param value value to be bound
   * @throws QueryException query exception
   */
  private void bind(final QNm name, final Expr[] args, final Value value) throws QueryException {
    // skip nulled values
    if (value == null) return;

    for (int i = 0; i < function.args.length; i++) {
      final Var var = function.args[i];
      if (!var.name.eq(name)) continue;
      // casts and binds the value
      args[i] = var.checkType(value, context, null);
      break;
    }
  }

  /**
   * Returns the specified value as an atomic string.
   *
   * @param value value
   * @param name name
   * @return string
   * @throws QueryException HTTP exception
   */
  private String toString(final Value value, final QNm name) throws QueryException {
    if (!(value instanceof Str)) error(ANN_STRING, "%", name.string(), value);
    return ((Str) value).toJava();
  }

  /**
   * Adds items to the specified list.
   *
   * @param value value
   * @param name name
   * @param list list to add values to
   * @throws QueryException HTTP exception
   */
  private void strings(final Value value, final QNm name, final StringList list)
      throws QueryException {

    final long vs = value.size();
    for (int v = 0; v < vs; v++) list.add(toString(value.itemAt(v), name));
  }

  /**
   * Returns a parameter.
   *
   * @param value value
   * @param name name
   * @param declared variable declaration flags
   * @return parameter
   * @throws QueryException HTTP exception
   */
  private RestXqParam param(final Value value, final QNm name, final boolean[] declared)
      throws QueryException {
    // [CG] RESTXQ: allow identical field names?
    final long vs = value.size();
    if (vs < 2) error(ANN_PARAMS, "%", name.string(), 2);
    // name of parameter
    final String key = toString(value.itemAt(0), name);
    // variable template
    final QNm qnm = checkVariable(toString(value.itemAt(1), name), declared);
    // default value
    final ValueBuilder vb = new ValueBuilder();
    for (int v = 2; v < vs; v++) vb.add(value.itemAt(v));
    return new RestXqParam(qnm, key, vb.value());
  }

  // PRIVATE STATIC METHODS =============================================================

  /**
   * Caches the request body, if not done yet.
   *
   * @param http http context
   * @param cache cache existing cache reference
   * @return cache
   * @throws IOException I/O exception
   */
  private static IOContent cache(final HTTPContext http, final IOContent cache) throws IOException {

    if (cache != null) return cache;
    final BufferInput bi = new BufferInput(http.req.getInputStream());
    final IOContent io = new IOContent(bi.content());
    io.name(http.method + IO.XMLSUFFIX);
    return io;
  }

  /**
   * Adds parameters from the passed on request body.
   *
   * @param body request body
   * @param params map parameters
   */
  private static void addParams(final String body, final Map<String, String[]> params) {
    for (final String nv : body.split("&")) {
      final String[] parts = nv.split("=", 2);
      if (parts.length < 2) continue;
      try {
        params.put(parts[0], new String[] {URLDecoder.decode(parts[1], Token.UTF8)});
      } catch (final Exception ex) {
        Util.notexpected(ex);
      }
    }
  }
}
コード例 #24
0
ファイル: WAbstractMedia.java プロジェクト: clawplach/jwt
 /**
  * Add a media source.
  *
  * <p>This method specifies a media source (which may be a URL or dynamic resource). You may add
  * as many media sources as you want. The browser will select the appropriate media stream to
  * display to the user.
  *
  * <p>This method specifies a media source using the URL, the mime type, and the media attribute.
  * HTML allows for empty type and media attributes.
  */
 public void addSource(WLink link, String type, String media) {
   this.sources_.add(new WAbstractMedia.Source(this, link, type, media));
   this.sourcesChanged_ = true;
   this.repaint(EnumSet.of(RepaintFlag.RepaintPropertyAttribute));
 }
コード例 #25
0
ファイル: WGridLayout.java プロジェクト: kdeforche/jwt
 /**
  * Adds a nested layout item to the grid.
  *
  * <p>Calls {@link #addLayout(WLayout layout, int row, int column, int rowSpan, int columnSpan,
  * EnumSet alignment) addLayout(layout, row, column, rowSpan, columnSpan,
  * EnumSet.noneOf(AlignmentFlag.class))}
  */
 public final void addLayout(WLayout layout, int row, int column, int rowSpan, int columnSpan) {
   addLayout(layout, row, column, rowSpan, columnSpan, EnumSet.noneOf(AlignmentFlag.class));
 }
コード例 #26
0
ファイル: WAbstractMedia.java プロジェクト: clawplach/jwt
 /** Set the preload mode. */
 public void setPreloadMode(WAbstractMedia.PreloadMode mode) {
   this.preloadMode_ = mode;
   this.preloadChanged_ = true;
   this.repaint(EnumSet.of(RepaintFlag.RepaintPropertyAttribute));
 }
コード例 #27
0
ファイル: WAbstractMedia.java プロジェクト: clawplach/jwt
 /**
  * Removes all source elements.
  *
  * <p>This method can be used to remove all media sources. Afterward, you may add new media
  * sources with calls to {@link WAbstractMedia#addSource(WLink link, String type, String media)
  * addSource()}.
  *
  * <p>Use this to reuse a {@link WAbstractMedia} instantiation to play something else.
  */
 public void clearSources() {
   for (int i = 0; i < this.sources_.size(); ++i) {;
   }
   this.sources_.clear();
   this.repaint(EnumSet.of(RepaintFlag.RepaintPropertyAttribute));
 }
コード例 #28
0
ファイル: WGridLayout.java プロジェクト: kdeforche/jwt
 /**
  * Adds a layout item to the grid.
  *
  * <p>Calls {@link #addItem(WLayoutItem item, int row, int column, int rowSpan, int columnSpan,
  * EnumSet alignment) addItem(item, row, column, rowSpan, columnSpan,
  * EnumSet.noneOf(AlignmentFlag.class))}
  */
 public final void addItem(WLayoutItem item, int row, int column, int rowSpan, int columnSpan) {
   addItem(item, row, column, rowSpan, columnSpan, EnumSet.noneOf(AlignmentFlag.class));
 }
コード例 #29
0
ファイル: WAbstractMedia.java プロジェクト: clawplach/jwt
 public void resourceChanged() {
   this.parent.sourcesChanged_ = true;
   this.parent.repaint(EnumSet.of(RepaintFlag.RepaintPropertyAttribute));
 }
コード例 #30
0
ファイル: WGridLayout.java プロジェクト: kdeforche/jwt
 /**
  * Adds a widget to the grid.
  *
  * <p>Calls {@link #addWidget(WWidget widget, int row, int column, int rowSpan, int columnSpan,
  * EnumSet alignment) addWidget(widget, row, column, rowSpan, columnSpan,
  * EnumSet.noneOf(AlignmentFlag.class))}
  */
 public final void addWidget(WWidget widget, int row, int column, int rowSpan, int columnSpan) {
   addWidget(widget, row, column, rowSpan, columnSpan, EnumSet.noneOf(AlignmentFlag.class));
 }