Example #1
0
  private void setupSwatchTab(TabPanel panel) {
    final ListView<FlatColor> colorList = new ListView<FlatColor>();
    colorList.setModel(manager.colorManager.getSwatchModel());
    colorList.setColumnWidth(20);
    colorList.setRowHeight(20);
    colorList.setOrientation(ListView.Orientation.HorizontalWrap);
    colorList.setRenderer(
        new ListView.ItemRenderer<FlatColor>() {
          public void draw(
              GFX gfx,
              ListView listView,
              FlatColor flatColor,
              int i,
              double x,
              double y,
              double w,
              double h) {
            gfx.setPaint(flatColor);
            gfx.fillRect(x, y, w, h);
          }
        });
    EventBus.getSystem()
        .addListener(
            colorList,
            SelectionEvent.Changed,
            new Callback<SelectionEvent>() {
              public void call(SelectionEvent e) throws Exception {
                int n = e.getView().getSelectedIndex();
                setSelectedFill(colorList.getModel().get(n));
                popup.setVisible(false);
              }
            });
    final PopupMenuButton switcher = new PopupMenuButton();
    final ArrayListModel<Palette> palettes = manager.colorManager.getPalettes();
    switcher.setModel(palettes);

    Button addButton = new Button("+");
    addButton.onClicked(
        new Callback<ActionEvent>() {
          public void call(ActionEvent actionEvent) throws Exception {
            if (!palettes.get(switcher.getSelectedIndex()).isEditable()) {
              return;
            }
            final Stage dialog = Stage.createStage();
            dialog.setTitle("Color");

            final ColorPickerPanel picker = new ColorPickerPanel();

            Callback<ActionEvent> okay =
                new Callback<ActionEvent>() {
                  public void call(ActionEvent event) {
                    FlatColor color = picker.getColor();
                    manager.colorManager.addSwatch(color);
                    dialog.hide();
                  }
                };
            Callback<ActionEvent> canceled =
                new Callback<ActionEvent>() {
                  public void call(ActionEvent event) {
                    dialog.hide();
                  }
                };
            dialog.setContent(
                new VFlexBox()
                    .add(picker)
                    .add(
                        new HFlexBox()
                            .add(new Button("okay").onClicked(okay))
                            .add(new Button("cancel").onClicked(canceled))));
            dialog.setWidth(400);
            dialog.setHeight(370);
            dialog.centerOnScreen();
          }
        });

    switcher.setTextRenderer(
        new ListView.TextRenderer() {
          public String toString(SelectableControl selectableControl, Object palette, int i) {
            if (palette instanceof Palette) {
              return ((Palette) palette).getName();
            } else {
              return "foo";
            }
          }
        });

    EventBus.getSystem()
        .addListener(
            switcher,
            SelectionEvent.Changed,
            new Callback<SelectionEvent>() {
              public void call(SelectionEvent selectionEvent) throws Exception {
                int n = selectionEvent.getView().getSelectedIndex();
                manager.colorManager.setCurrentPalette(palettes.get(n));
                colorList.setModel(manager.colorManager.getSwatchModel());
              }
            });

    VFlexBox vbox = new VFlexBox();
    vbox.setFill(FlatColor.GRAY);
    vbox.add(colorList, 1);
    vbox.add(new HFlexBox().add(addButton).add(switcher));
    vbox.setBoxAlign(FlexBox.Align.Stretch);
    panel.add("Swatches", vbox);
  }
Example #2
0
  private ListView<Paint> setupGradientTab(TabPanel panel) {
    double size = 40;
    // linears
    Paint gf1 =
        new LinearGradientFill()
            .setStartX(0)
            .setStartXSnapped(Snap.Start)
            .setEndX(size)
            .setEndXSnapped(Snap.End)
            .setStartY(size / 2)
            .setStartYSnapped(Snap.Middle)
            .setEndY(size / 2)
            .setEndYSnapped(Snap.Middle)
            .addStop(0, FlatColor.BLACK)
            .addStop(1, FlatColor.WHITE);

    Paint gf2 =
        new LinearGradientFill()
            .setStartX(size / 2)
            .setStartXSnapped(Snap.Middle)
            .setEndX(size / 2)
            .setEndXSnapped(Snap.Middle)
            .setStartY(0)
            .setStartYSnapped(Snap.Start)
            .setEndY(size)
            .setEndYSnapped(Snap.End)
            .addStop(0, FlatColor.BLACK)
            .addStop(1, FlatColor.WHITE);

    Paint gf3 =
        new LinearGradientFill()
            .setStartX(0)
            .setStartXSnapped(Snap.Start)
            .setEndX(size)
            .setEndXSnapped(Snap.End)
            .setStartY(0)
            .setStartYSnapped(Snap.Start)
            .setEndY(size)
            .setEndYSnapped(Snap.End)
            .addStop(0, FlatColor.BLACK)
            .addStop(1, FlatColor.WHITE);

    // linears 2
    Paint gf6 =
        new LinearGradientFill()
            .setStartX(0)
            .setStartXSnapped(Snap.Start)
            .setStartY(size / 2)
            .setStartYSnapped(Snap.Middle)
            .setEndX(size)
            .setEndXSnapped(Snap.End)
            .setEndY(size / 2)
            .setEndYSnapped(Snap.Middle)
            .addStop(0.0, FlatColor.BLACK)
            .addStop(0.5, FlatColor.WHITE)
            .addStop(1.0, FlatColor.BLACK);

    // radials
    Paint gf4 =
        new RadialGradientFill()
            .setCenterX(size / 2)
            .setCenterY(size / 2)
            .setRadius(size / 2)
            .addStop(0, FlatColor.BLACK)
            .addStop(1, FlatColor.WHITE);

    Paint gf5 =
        new RadialGradientFill()
            .setCenterX(size / 2)
            .setCenterY(size / 2)
            .setRadius(size / 2)
            .addStop(0.0, FlatColor.BLACK)
            .addStop(0.5, FlatColor.WHITE)
            .addStop(1.0, FlatColor.BLACK);

    ListModel<Paint> gradientModel = ListView.createModel(gf1, gf2, gf3, gf6, gf4, gf5);
    final ListView<Paint> gradientList =
        new ListView<Paint>()
            .setModel(gradientModel)
            .setColumnWidth(size)
            .setRowHeight(size)
            .setOrientation(ListView.Orientation.HorizontalWrap)
            .setRenderer(paintItemRenderer);
    panel.add("gradients", gradientList);
    EventBus.getSystem()
        .addListener(
            gradientList,
            SelectionEvent.Changed,
            new Callback<SelectionEvent>() {
              public void call(SelectionEvent e) throws Exception {
                int n = e.getView().getSelectedIndex();
                setSelectedFill(gradientList.getModel().get(n));
                popup.setVisible(false);
              }
            });

    return gradientList;
  }