Esempio n. 1
0
  public AndItem(boolean preview, Window w) {
    super(preview);
    this.w = w;
    FlowLayout fl = new FlowLayout(FlowLayout.CENTER, 1, 1);
    this.setLayout(fl);
    lefthand = new ParameterSlot(Parameter.Condition, "lefthand", preview, w);
    this.add(lefthand);
    JLabel la = new JLabel(" AND ");
    this.add(la);
    righthand = new ParameterSlot(Parameter.Condition, "righthand", preview, w);
    this.add(righthand);
    ToolTipItem tti = new ToolTipItem();
    tti.setToolTipText(
        "<html>This is an if item, if the specified condition <br> is fulfilled, the following block will be executed</html>");
    this.add(tti);
    this.setBackground(new Color(108, 45, 199));
    this.setBorder(BorderFactory.createLineBorder(Color.black));
    if (preview) {
      DragSource ds = new DragSource();
      ParameterDragGestureListener pdgl = new ParameterDragGestureListener();
      ds.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_COPY, pdgl);
      ds.addDragSourceMotionListener(pdgl);
      ds.addDragSourceListener(
          new DragSourceListener() {
            @Override
            public void dropActionChanged(DragSourceDragEvent dsde) {}

            @Override
            public void dragOver(DragSourceDragEvent dsde) {}

            @Override
            public void dragExit(DragSourceEvent dse) {}

            @Override
            public void dragEnter(DragSourceDragEvent dsde) {}

            @Override
            public void dragDropEnd(DragSourceDropEvent dsde) {
              ImageMover.stop();
            }
          });
    }
  }
  public VariablePanel(String variableName, boolean preview, Window w) {
    super(preview);
    this.w = w;
    if (preview) {
      w.spellItems.put(variableName, this);
    }
    this.s = variableName;
    JLabel jl = new JLabel(variableName);
    this.setLayout(new BorderLayout());
    this.add(jl, BorderLayout.CENTER);
    this.setBorder(BorderFactory.createLineBorder(Color.black));
    this.setBackground(Color.lightGray);
    DragSource ds = new DragSource();
    VariableDragGestureListener pdgl = new VariableDragGestureListener();
    ds.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_COPY, pdgl);
    ds.addDragSourceMotionListener(pdgl);
    ds.addDragSourceListener(
        new DragSourceListener() {
          @Override
          public void dropActionChanged(DragSourceDragEvent dsde) {}

          @Override
          public void dragOver(DragSourceDragEvent dsde) {}

          @Override
          public void dragExit(DragSourceEvent dse) {}

          @Override
          public void dragEnter(DragSourceDragEvent dsde) {}

          @Override
          public void dragDropEnd(DragSourceDropEvent dsde) {
            ImageMover.stop();
          }
        });
  }
  @SuppressWarnings("serial")
  public JTableRenderer(final Object cell, final GraphComponent graphContainer) {
    this.cell = cell;
    this.graphContainer = graphContainer;
    this.graph = graphContainer.getGraph();
    setLayout(new BorderLayout());
    setBorder(
        BorderFactory.createCompoundBorder(
            ShadowBorder.getSharedInstance(), BorderFactory.createBevelBorder(BevelBorder.RAISED)));

    JPanel title = new JPanel();
    title.setBackground(new Color(149, 173, 239));
    title.setOpaque(true);
    title.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 1));
    title.setLayout(new BorderLayout());

    JLabel icon =
        new JLabel(new ImageIcon(JTableRenderer.class.getResource(IMAGE_PATH + "preferences.gif")));
    icon.setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 1));
    title.add(icon, BorderLayout.WEST);

    JLabel label = new JLabel(String.valueOf(graph.getLabel(cell)));
    label.setForeground(Color.WHITE);
    label.setFont(title.getFont().deriveFont(Font.BOLD, 11));
    label.setBorder(BorderFactory.createEmptyBorder(0, 1, 0, 2));
    title.add(label, BorderLayout.CENTER);

    JPanel toolBar2 = new JPanel();
    toolBar2.setLayout(new FlowLayout(FlowLayout.LEFT, 1, 2));
    toolBar2.setOpaque(false);
    JButton button =
        new JButton(
            new AbstractAction(
                "", new ImageIcon(JTableRenderer.class.getResource(IMAGE_PATH + "minimize.gif"))) {

              public void actionPerformed(ActionEvent e) {
                graph.foldCells(graph.isCellCollapsed(cell), false, new Object[] {cell});
                ((JButton) e.getSource())
                    .setIcon(
                        new ImageIcon(
                            JTableRenderer.class.getResource(
                                IMAGE_PATH
                                    + ((graph.isCellCollapsed(cell))
                                        ? "maximize.gif"
                                        : "minimize.gif"))));
              }
            });
    button.setPreferredSize(new Dimension(16, 16));
    button.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
    button.setToolTipText("Collapse/Expand");
    button.setOpaque(false);
    toolBar2.add(button);

    title.add(toolBar2, BorderLayout.EAST);
    add(title, BorderLayout.NORTH);

    // CellStyle style =
    // graph.getStylesheet().getCellStyle(graph.getModel(),
    // cell);
    // if (style.getStyleClass() == null) {
    table = new MyTable();
    JScrollPane scrollPane = new JScrollPane(table);
    scrollPane.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));

    if (graph.getModel().getChildCount(cell) == 0) {
      scrollPane.getViewport().setBackground(Color.WHITE);
      setOpaque(true);
      add(scrollPane, BorderLayout.CENTER);
    }

    scrollPane
        .getVerticalScrollBar()
        .addAdjustmentListener(
            new AdjustmentListener() {

              public void adjustmentValueChanged(AdjustmentEvent e) {
                graphContainer.refresh();
              }
            });

    label = new JLabel(new ImageIcon(JTableRenderer.class.getResource(IMAGE_PATH + "resize.gif")));
    label.setCursor(new Cursor(Cursor.NW_RESIZE_CURSOR));

    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());
    panel.add(label, BorderLayout.EAST);

    add(panel, BorderLayout.SOUTH);

    ResizeHandler resizeHandler = new ResizeHandler();
    label.addMouseListener(resizeHandler);
    label.addMouseMotionListener(resizeHandler);

    setMinimumSize(new Dimension(20, 30));
  }