@Override
 public void setSelection(final ISelection selection) {
   assert (selection != null && !selection.isEmpty());
   final Object firstElement = ((IStructuredSelection) selection).getFirstElement();
   /*
    * breadcrumbViewer.setInput is called every time an item is selected.
    * Because of this, it does not make sense for the content provider
    * associated with the breadcrumbViewer to register a listener on the model
    */
   breadcrumbViewer.setInput(firstElement);
   breadcrumbViewer.setSelection(selection, true);
   contentPanel.setSelection(firstElement);
   contentPanel.setFocus();
 }
Пример #2
0
 @Override
 public void setHeading(String text) {
   super.setHeading(text);
   if (ghost != null) {
     ghost.selectNode(".x-window-header-text").setInnerHtml(text);
   }
 }
Пример #3
0
 @Override
 protected void onDetach() {
   super.onDetach();
   if (eventPreview != null) {
     eventPreview.remove();
   }
 }
Пример #4
0
 @Override
 protected void onHide() {
   super.onHide();
   if (GXT.isAriaEnabled()) {
     Accessibility.setState(getElement(), "aria-hidden", "true");
   }
 }
Пример #5
0
 @Override
 protected void onFocus(ComponentEvent ce) {
   super.onFocus(ce);
   if (GXT.isFocusManagerEnabled()) {
     if (focusWidget != null) {
       El.fly(focusWidget.getElement()).focus();
     }
   }
 }
Пример #6
0
  @Override
  protected void onRender(Element parent, int pos) {
    super.onRender(parent, pos);

    el().makePositionable(true);

    if (manager == null) {
      manager = WindowManager.get();
    }

    if (plain) {
      addStyleName("x-window-plain");
    }

    eventPreview =
        new BaseEventPreview() {

          @Override
          protected boolean onAutoHide(PreviewEvent ce) {
            if (autoHide) {
              if (resizing) {
                return false;
              }
              hide();
              return true;
            }
            return false;
          }

          @Override
          protected void onPreviewKeyPress(PreviewEvent pe) {
            WindowEvent we = new WindowEvent(Window.this, pe.getEvent());
            onKeyPress(we);
          }
        };
    eventPreview.getIgnoreList().add(getElement());

    sinkEvents(Event.ONMOUSEDOWN | Event.ONKEYPRESS);

    el().setTabIndex(0);
    el().setElementAttribute("hideFocus", "true");

    if (GXT.isAriaEnabled()) {
      Accessibility.setRole(getElement(), "alertdialog");
      Accessibility.setState(getElement(), "aria-labelledby", head.getId() + "-label");
      Accessibility.setState(getElement(), "aria-hidden", "true");
    }

    if (modal || maximizable || constrain) {
      monitorWindowResize = true;
    }

    if (super.width == null) {
      setWidth(Math.max(initialWidth, minWidth));
    }
  }
Пример #7
0
 @Override
 public void setZIndex(int zIndex) {
   super.setZIndex(zIndex);
   if (ghost != null) {
     ghost.setZIndex(zIndex);
   }
   if (modalPanel != null && modalPanel.rendered) {
     modalPanel.el().setZIndex(zIndex - 9);
   }
 }
Пример #8
0
 void checkRunned() {
   if (runned) {
     list.selectAll(); // Add all clusters to Field again
     contentpanel.resetColors(); // Reset the colors
     PointCategory.resetIndex(); // Reset the point index
     field.reset(); // Reset the field
     updateContentPanel();
     empty.removeAll();
     empty.validate();
     runned = false;
   }
 }
Пример #9
0
  @Override
  public void onComponentEvent(ComponentEvent ce) {
    super.onComponentEvent(ce);
    if (ce.getEventTypeInt() == Event.ONMOUSEDOWN) {

      // dont bring to front on clicks where active is model as active window
      // may have just been opened from this click event
      Window active = manager.getActive();
      if (active != null && active != this && !active.isModal()) {
        manager.bringToFront(this);
      }
    }
  }
Пример #10
0
  /** Class constructor - make the JFrame ready */
  public TestProgram() {
    // Set screen size
    Toolkit tk = Toolkit.getDefaultToolkit();
    int x = (int) tk.getScreenSize().getWidth() - 150;
    int y = (int) tk.getScreenSize().getHeight() - 100;
    this.setSize(x, y);

    // Some settings
    this.setTitle("Friends With Benefits - Test program");
    field = new Field();
    random = new Random(System.currentTimeMillis());

    // Set the panel
    c = this.getContentPane();
    c.setLayout(new BorderLayout());

    contentpanel = new ContentPanel();
    contentpanel.setField(field);
    c.add(contentpanel, BorderLayout.CENTER);

    // Menupanel
    menupanel = new JPanel();
    layout = new GroupLayout(menupanel);
    menupanel.setLayout(layout);
    c.add(menupanel, BorderLayout.EAST);

    progress = new JProgressBar(0, 99);
    progress.setValue(99);

    open = new JButton("Open");
    open.setFocusPainted(false);
    save = new JButton("Save");
    save.setFocusPainted(false);
    open.addActionListener(this);
    save.addActionListener(this);

    everywhere = new JRadioButton("Everywhere");
    everywhere.setFocusPainted(false);
    inRectangle = new JRadioButton("In bounding rectangle");
    inRectangle.setFocusPainted(false);
    inRectangle.setSelected(true);

    placeOfCluster = new ButtonGroup();
    placeOfCluster.add(everywhere);
    placeOfCluster.add(inRectangle);

    addnoise = new JButton("Add noise");
    addnoise.setFocusPainted(false);
    addnoise.addActionListener(this);

    circle = new JRadioButton("Circle");
    circle.setFocusPainted(false);
    square = new JRadioButton("Square");
    square.setFocusPainted(false);
    circle.setSelected(true);

    squarecircle = new ButtonGroup();
    squarecircle.add(circle);
    squarecircle.add(square);

    fillFactor = new JSlider();
    fillFactor.setMajorTickSpacing(20);
    fillFactor.setMinorTickSpacing(5);
    fillFactor.setPaintTicks(true);

    addacluster = new JButton("Add simple cluster");
    addacluster.setFocusPainted(false);
    addacluster.addActionListener(this);

    clear = new JButton("Clear field");
    clear.addActionListener(this);
    clear.setFocusPainted(false);

    center = new JButton("Center field");
    center.addActionListener(this);
    center.setFocusPainted(false);

    minAlgo = new JTextField();
    minAlgo.setText("0");
    maxAlgo = new JTextField();
    maxAlgo.setText("10");
    run = new JButton("Run algo");
    run.addActionListener(this);
    run.setFocusPainted(false);

    empty = new JPanel();
    empty.setLayout(new BorderLayout());

    JSeparator sep1 = new JSeparator();
    JSeparator sep2 = new JSeparator();
    JSeparator sep3 = new JSeparator();
    JSeparator sep4 = new JSeparator();
    JLabel runalgo = new JLabel("Run algorithm"), addcluster = new JLabel("Add simple cluster");
    JLabel addNoise = new JLabel("Add noise"), fillf = new JLabel("Fill factor:");
    JLabel minalgo = new JLabel("Min:"), maxalgo = new JLabel("Max:");
    addcluster.setFont(f);
    addNoise.setFont(f);
    runalgo.setFont(f);

    fillFactor.setPreferredSize(
        new Dimension(
            menupanel.getPreferredSize().width / 2, fillFactor.getPreferredSize().height));

    layout.setHorizontalGroup(
        layout
            .createParallelGroup(GroupLayout.Alignment.CENTER)
            .addGroup(
                layout.createSequentialGroup().addComponent(open).addGap(2).addComponent(save))
            .addComponent(sep1)
            .addComponent(addNoise)
            .addGroup(
                layout
                    .createParallelGroup(GroupLayout.Alignment.LEADING)
                    .addComponent(everywhere)
                    .addComponent(inRectangle))
            .addComponent(addnoise)
            .addComponent(sep2)
            .addComponent(addcluster)
            .addGroup(
                layout
                    .createParallelGroup(GroupLayout.Alignment.LEADING)
                    .addComponent(circle)
                    .addComponent(square))
            .addComponent(fillf)
            .addComponent(fillFactor)
            .addComponent(addacluster)
            .addComponent(sep3)
            .addComponent(center)
            .addComponent(clear)
            .addComponent(sep4)
            .addComponent(runalgo)
            .addGroup(
                layout
                    .createSequentialGroup()
                    .addComponent(minalgo)
                    .addGap(2)
                    .addComponent(minAlgo)
                    .addGap(10)
                    .addComponent(maxalgo)
                    .addGap(2)
                    .addComponent(maxAlgo))
            .addComponent(run)
            .addComponent(empty)
            .addComponent(progress));
    layout.setVerticalGroup(
        layout
            .createSequentialGroup()
            .addGroup(
                layout
                    .createParallelGroup(GroupLayout.Alignment.BASELINE)
                    .addComponent(open)
                    .addComponent(save))
            .addGap(5)
            .addComponent(sep1)
            .addGap(5)
            .addComponent(addNoise)
            .addComponent(everywhere)
            .addComponent(inRectangle)
            .addGap(3)
            .addComponent(addnoise)
            .addGap(5)
            .addComponent(sep2)
            .addGap(5)
            .addComponent(addcluster)
            .addComponent(circle)
            .addComponent(square)
            .addGap(3)
            .addComponent(fillf)
            .addGap(3)
            .addComponent(fillFactor)
            .addGap(3)
            .addComponent(addacluster)
            .addGap(5)
            .addComponent(sep3)
            .addGap(5)
            .addComponent(center)
            .addGap(3)
            .addComponent(clear)
            .addGap(5)
            .addComponent(sep4)
            .addGap(5)
            .addComponent(runalgo)
            .addGap(3)
            .addGroup(
                layout
                    .createParallelGroup(GroupLayout.Alignment.BASELINE)
                    .addComponent(minalgo)
                    .addComponent(minAlgo)
                    .addComponent(maxalgo)
                    .addComponent(maxAlgo))
            .addComponent(run)
            .addComponent(empty)
            .addComponent(progress));

    int width = menupanel.getPreferredSize().width;

    setSize(addNoise, width - 10);
    setSize(everywhere, width - 20);
    setSize(inRectangle, width - 20);
    setSize(addnoise, width);

    setSize(addcluster, width - 10);
    setSize(circle, width - 20);
    setSize(square, width - 20);
    setSize(addacluster, width);

    setSize(center, width);
    setSize(clear, width);

    setSize(runalgo, width - 10);
    setSize(minalgo, (int) Math.floor(width / 4) - 20);
    setMaxSize(minAlgo, (int) Math.ceil(width / 4));
    setSize(maxalgo, (int) Math.floor(width / 4) - 20);
    setMaxSize(maxAlgo, (int) Math.ceil(width / 4));
    setSize(run, width);

    empty.setPreferredSize(new Dimension(width, 1000));

    menupanel.setBorder(
        BorderFactory.createTitledBorder(
            BorderFactory.createLineBorder(Color.BLACK),
            "Menu",
            TitledBorder.CENTER,
            TitledBorder.DEFAULT_POSITION,
            f));
  }
Пример #11
0
  @Override
  public void actionPerformed(ActionEvent e) {
    if (e.getSource() == open) {
      if (isInProgress()) {
        systemIsBusy();
        return;
      }

      checkRunned();

      chooser = new JFileChooser();
      chooser.setAcceptAllFileFilterUsed(false);
      chooser.setFileFilter(new InputFileFilter(false));
      if (loadedFile != null) chooser.setSelectedFile(loadedFile);
      int returnValue = chooser.showOpenDialog(this);
      if (returnValue == JFileChooser.APPROVE_OPTION) {
        boolean approved =
            ((InputFileFilter) chooser.getFileFilter()).isFileApproved(chooser.getSelectedFile());
        if (approved) {
          startProgress();
          new MultiThread(
                  new Runnable() {
                    public void run() {
                      try {

                        loadedFile = chooser.getSelectedFile();
                        FileInputStream fis = new FileInputStream(loadedFile);
                        InputParser ip = new InputParser(fis);
                        if (ip.parseInput()) {
                          field = new Field(new ArrayList<Point>(Arrays.asList(ip.getPoints())));
                          minAlgo.setText(String.valueOf(ip.minimumClusters));
                          maxAlgo.setText(String.valueOf(ip.maximumClusters));
                        }
                      } catch (FileNotFoundException e1) {
                      }
                      contentpanel.center();
                      stopProgress();
                    }
                  })
              .start();
        }
      }
    } else if (e.getSource() == center) {
      if (isInProgress()) {
        systemIsBusy();
        return;
      }

      startProgress();
      new MultiThread(
              new Runnable() {
                public void run() {
                  contentpanel.removeMouseWheelListener(contentpanel);
                  contentpanel.center();
                  contentpanel.addMouseWheelListener(contentpanel);
                  stopProgressRepaint();
                }
              })
          .start();
    } else if (e.getSource() == save) {
      if (isInProgress()) {
        systemIsBusy();
        return;
      }

      checkRunned();

      chooser = new JFileChooser();
      chooser.setAcceptAllFileFilterUsed(false);
      chooser.setFileFilter(new InputFileFilter(true));
      if (loadedFile != null) chooser.setSelectedFile(loadedFile);
      int returnValue = chooser.showSaveDialog(this);
      if (returnValue == JFileChooser.APPROVE_OPTION) {
        boolean approved =
            ((InputFileFilter) chooser.getFileFilter()).isFileApproved(chooser.getSelectedFile());
        if (approved) {
          loadedFile = chooser.getSelectedFile();
          boolean halt = loadedFile.exists();
          if (halt) {
            int i =
                JOptionPane.showInternalConfirmDialog(
                    c,
                    "Are you sure you want to override this file?",
                    "Warning",
                    JOptionPane.YES_NO_OPTION,
                    JOptionPane.WARNING_MESSAGE);
            if (i == JOptionPane.YES_OPTION) {
              halt = false;
            }
          }

          if (!halt) {
            try {
              PrintWriter pw = new PrintWriter(new FileWriter(loadedFile));
              pw.println("find " + field.getNumberOfClusters() + " clusters");
              pw.println(field.size() + " points");
              Object[] obj = field.toArray();
              for (int i = 0; i < obj.length; i++) {
                Point p = (Point) obj[i];
                pw.println(p.getX() + " " + p.getY());
              }
              pw.close();
            } catch (IOException e1) {
            }
          }
        }
      }
    } else if (e.getSource() == clear) {
      if (isInProgress()) {
        systemIsBusy();
        return;
      }

      int i =
          JOptionPane.showInternalConfirmDialog(
              c,
              "Are you sure you want to clear the field?",
              "Warning",
              JOptionPane.YES_NO_OPTION,
              JOptionPane.WARNING_MESSAGE);

      checkRunned();
      if (i == JOptionPane.YES_OPTION) {
        field = new Field();
        updateContentPanel();
      }
    } else if (e.getSource() == circle) {
      contentpanel.setSelectionMode(ContentPanel.SELECT_CIRCLE);
    } else if (e.getSource() == square) {
      contentpanel.setSelectionMode(ContentPanel.SELECT_SQUARE);
    } else if (e.getSource() == addacluster) {
      if (isInProgress()) {
        systemIsBusy();
        return;
      }

      checkRunned();

      contentpanel.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
    } else if (e.getSource() == addnoise) {
      if (isInProgress()) {
        systemIsBusy();
        return;
      }

      checkRunned();
      final String s =
          JOptionPane.showInternalInputDialog(
              c, "How many points?", "Add noise", JOptionPane.QUESTION_MESSAGE);

      startProgress();
      new MultiThread(
              new Runnable() {
                public void run() {
                  if (s != null) {
                    int number;
                    try {
                      number = Integer.parseInt(s);
                    } catch (Exception ex) {
                      number = 0;
                    }

                    int tillX = 1000000000;
                    int tillY = 1000000000;
                    int addX = 0;
                    int addY = 0;
                    if (inRectangle.isSelected()) {
                      Rectangle r = field.getBoundingRectangle();
                      if (!(r.x1 == 0 && r.y1 == 0 && r.x2 == 0 && r.y2 == 0)) {
                        tillX = r.x2 - r.x1;
                        addX = r.x1;
                        tillY = r.y2 - r.y1;
                        addY = r.y1;
                      } else {
                        tillX = 500000000;
                        tillY = 500000000;
                      }
                    }

                    for (int i = 0; i < number; i++) {
                      int x = random.nextInt(tillX);
                      x += addX;
                      int y;

                      boolean busy = true;
                      while (busy) {
                        y = random.nextInt(tillY);
                        y += addY;
                        boolean inside = false;
                        Object[] array = field.toArray();
                        for (int j = 0; j < field.size(); j++) {
                          if (((Point) array[j]).compareTo(x, y)) {
                            inside = true;
                            break;
                          }
                        }

                        if (!inside) {
                          field.add(new Point(x, y));
                          busy = false;
                        }
                      }
                    }
                  }
                  stopProgress();
                }
              })
          .start();
    } else if (e.getSource() == run) {
      if (isInProgress()) {
        systemIsBusy();
        return;
      }

      checkRunned();

      startProgress();

      runAlgo();
    }
  }
Пример #12
0
 protected synchronized void stopProgressRepaint() {
   progressWorks = false;
   progress.setIndeterminate(false);
   contentpanel.repaint();
 }
Пример #13
0
 @Override
 public void setPagePosition(int x, int y) {
   super.setPagePosition(x, y);
   positioned = true;
 }
Пример #14
0
 synchronized void updateContentPanel() {
   contentpanel.setField(field);
 }
Пример #15
0
 @Override
 public void setPosition(int left, int top) {
   super.setPosition(left, top);
   positioned = true;
 }
Пример #16
0
 synchronized void repaintContentPanel() {
   contentpanel.repaint();
 }
Пример #17
0
  protected void initTools() {
    super.initTools();

    if (GXT.isAriaEnabled()) {
      moveBtn = new ToolButton("x-tool-move");
      moveBtn.getAriaSupport().setLabel(GXT.MESSAGES.window_ariaMove());
      moveBtn.getAriaSupport().setDescription(GXT.MESSAGES.window_ariaMoveDescription());
      head.addTool(moveBtn);

      resizeBtn = new ToolButton("x-tool-resize");
      resizeBtn.getAriaSupport().setLabel(GXT.MESSAGES.window_ariaResize());
      resizeBtn.getAriaSupport().setDescription(GXT.MESSAGES.window_ariaResizeDescription());
      head.addTool(resizeBtn);
    }

    if (minimizable) {
      minBtn = new ToolButton("x-tool-minimize");
      minBtn.addSelectionListener(
          new SelectionListener<IconButtonEvent>() {
            public void componentSelected(IconButtonEvent ce) {
              minimize();
            }
          });
      head.addTool(minBtn);
    }

    if (maximizable) {
      maxBtn = new ToolButton("x-tool-maximize");
      maxBtn.addSelectionListener(
          new SelectionListener<IconButtonEvent>() {
            public void componentSelected(IconButtonEvent ce) {
              maximize();
            }
          });
      head.addTool(maxBtn);

      restoreBtn = new ToolButton("x-tool-restore");
      restoreBtn.setVisible(false);
      restoreBtn.addSelectionListener(
          new SelectionListener<IconButtonEvent>() {
            public void componentSelected(IconButtonEvent ce) {
              restore();
            }
          });
      head.addTool(restoreBtn);
    }

    if (closable) {
      closeBtn = new ToolButton("x-tool-close");
      if (GXT.isAriaEnabled()) {
        closeBtn.setTitle(GXT.MESSAGES.messageBox_close());
      }
      closeBtn.addListener(
          Events.Select,
          new Listener<ComponentEvent>() {
            public void handleEvent(ComponentEvent ce) {
              hide();
            }
          });
      head.addTool(closeBtn);
    }
  }