示例#1
0
 public void setSelectedFill(Paint paint) {
   this.selectedFill = paint;
   if (!locked) {
     if (paint instanceof FlatColor) {
       freerangeColorPickerPopup.setSelectedColor((FlatColor) paint);
       rgbhsvpicker.setSelectedColor((FlatColor) paint);
     }
   }
   EventBus.getSystem().publish(new ChangedEvent(ChangedEvent.ObjectChanged, selectedFill, this));
   setDrawingDirty();
 }
示例#2
0
  private void setupColorTab(TabPanel panel) {
    freerangeColorPickerPopup = new FreerangeColorPickerPopup(null, 300, 170, false);
    freerangeColorPickerPopup.setOutsideColorProvider(
        new FreerangeColorPickerPopup.OutsideColorProvider() {
          @Override
          public FlatColor getColorAt(MouseEvent event) {
            if (context == null) return super.getColorAt(event);
            Point2D pt = event.getPointInNodeCoords(context.getSketchCanvas());
            pt = context.getSketchCanvas().transformToCanvas(pt.getX(), pt.getY());
            java.util.List<SNode> underCursor = new ArrayList<SNode>();
            for (SNode node : context.getDocument().getCurrentPage().getNodes()) {
              if (node.getTransformedBounds().contains(pt)) {
                underCursor.add(node);
              }
            }
            if (underCursor.isEmpty()) {
            } else {
              SNode node = underCursor.get(underCursor.size() - 1);
              if (node instanceof SShape) {
                SShape shape = ((SShape) node);
                if (shape.getFillPaint() instanceof FlatColor) {
                  return (FlatColor) shape.getFillPaint();
                }
              }
            }

            return super.getColorAt(
                event); // To change body of overridden methods use File | Settings | File
            // Templates.
          }
        });
    EventBus.getSystem()
        .addListener(
            freerangeColorPickerPopup,
            ChangedEvent.ColorChanged,
            new Callback<ChangedEvent>() {
              public void call(ChangedEvent event) throws Exception {
                locked = true;
                setSelectedFill((FlatColor) event.getValue());
                locked = false;
                if (!event.isAdjusting()) {
                  popup.setVisible(false);
                }
              }
            });
    panel.add("Color", freerangeColorPickerPopup);
  }