/** This method initializes main controls of the main window */
  private void initControlsArea(
      final Composite controlsArea,
      final Combo feederSelectionCombo,
      final Button startStopButton,
      final StartStopScanningAction startStopScanningAction,
      final ToolsActions.Preferences preferencesListener,
      final ToolsActions.ChooseFetchers chooseFetchersListsner) {
    controlsArea.setLayoutData(
        LayoutHelper.formData(
            new FormAttachment(feederArea),
            new FormAttachment(100),
            new FormAttachment(0),
            new FormAttachment(feederArea, 0, SWT.BOTTOM)));
    controlsArea.setLayout(LayoutHelper.formLayout(7, 3, 3));

    // steal the height from the second child of the FeederGUI - this must be the first edit box.
    // this results in better visual alignment with FeederGUIs
    Control secondControl = feederRegistry.current().getChildren()[1];
    // initialize global standard button height
    buttonHeight = secondControl.getSize().y + 2;

    // feeder selection combobox
    this.feederSelectionCombo = feederSelectionCombo;
    feederSelectionCombo.pack();
    IPFeederSelectionListener feederSelectionListener = new IPFeederSelectionListener();
    feederSelectionCombo.addSelectionListener(feederSelectionListener);
    // initialize the selected feeder GUI
    feederSelectionCombo.select(guiConfig.activeFeeder);
    feederSelectionCombo.setToolTipText(Labels.getLabel("combobox.feeder.tooltip"));

    // start/stop button
    this.startStopButton = startStopButton;
    shell.setDefaultButton(startStopButton);
    startStopButton.addSelectionListener(startStopScanningAction);

    // traverse the button before the combo (and don't traverse other buttons at all)
    controlsArea.setTabList(new Control[] {startStopButton, feederSelectionCombo});

    prefsButton = new ToolBar(controlsArea, SWT.FLAT);
    prefsButton.setCursor(prefsButton.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
    ToolItem item = new ToolItem(prefsButton, SWT.PUSH);
    item.setImage(new Image(null, Labels.getInstance().getImageAsStream("button.preferences.img")));
    item.setToolTipText(Labels.getLabel("title.preferences"));
    item.addListener(SWT.Selection, preferencesListener);

    fetchersButton = new ToolBar(controlsArea, SWT.FLAT);
    fetchersButton.setCursor(fetchersButton.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
    item = new ToolItem(fetchersButton, SWT.PUSH);
    item.setImage(new Image(null, Labels.getInstance().getImageAsStream("button.fetchers.img")));
    item.setToolTipText(Labels.getLabel("title.fetchers.select"));
    item.addListener(SWT.Selection, chooseFetchersListsner);

    feederSelectionListener.widgetSelected(null);
  }
 /**
  * Computes the common width hint (the largest width) and set it as {@link GridData#widthHint} for
  * all combos, if the combo has a {@link GridData} as {@link LayoutData}.
  */
 protected void adjustComboWidth(List<Combo> combos) {
   int withHint = SWT.DEFAULT;
   for (Combo comboBox : combos) {
     comboBox.pack(true);
     Point computeSize = comboBox.computeSize(SWT.DEFAULT, SWT.DEFAULT);
     int pixels = computeSize.x;
     if (pixels > withHint) {
       withHint = pixels;
     }
   }
   for (Combo comboBox : combos) {
     Object ld = comboBox.getLayoutData();
     if (ld instanceof GridData) {
       GridData layoutData = (GridData) ld;
       layoutData.widthHint = withHint;
     }
   }
 }
Example #3
0
    public parseGroup(Composite parent) {
      super(parent, SWT.NONE);
      Group group = new Group(this, SWT.SHADOW_ETCHED_IN);
      group.setText("Set predicates");

      GridLayout layout = new GridLayout();
      layout.numColumns = 3;
      group.setLayout(layout);

      final Combo predCombo = new Combo(group, SWT.NONE);
      final Combo placeCombo = new Combo(group, SWT.NONE);
      // predCombo.setLocation(5,15);
      predCombo.pack();

      final Combo opCombo = new Combo(group, SWT.NONE);
      opCombo.add(">");
      opCombo.add(">=");
      opCombo.add("=");
      opCombo.add("!=");
      opCombo.add("<=");
      opCombo.add("<");
      // opCombo.setLocation(30,15);
      opCombo.pack();

      final Spinner nSpinner = new Spinner(group, SWT.NONE);
      // nSpinner.setLocation(55,15);
      nSpinner.setDigits(0);
      nSpinner.pack();

      Label label = new Label(group, SWT.NONE);
      label.setText("Text\nText\nqwertyuiopiuytrdsadfghjk");
      // label.setAlignment(SWT.CENTER);
      // label.setLocation(5, 60);
      label.pack();

      final Button addButton = new Button(group, SWT.PUSH);
      addButton.setText("Add predicate");
      addButton.addSelectionListener(
          new SelectionListener() {
            public void widgetSelected(SelectionEvent e) {
              if (predCombo.getSelectionIndex() >= 0 && opCombo.getSelectionIndex() >= 0) {

                predicates.add(
                    new AtomicPredicate( // TODO
                        predCombo.getItem(predCombo.getSelectionIndex())));
              }

              //
            }

            public void widgetDefaultSelected(SelectionEvent e) {
              widgetSelected(e);
            }
          }); // addBuuton action

      final Button cButton = new Button(group, SWT.PUSH);
      cButton.setText("Check formula");
      cButton.setEnabled(false);

      Button pButton = new Button(group, SWT.PUSH);
      pButton.setText("Parse formula");
      // button1.setLocation(20, 45);

      pButton.addSelectionListener(
          new SelectionListener() {
            public void widgetSelected(SelectionEvent e) {
              CTLLexer lexer = null;
              try {
                lexer = new CTLLexer(new ANTLRFileStream("test.txt"));
              } catch (IOException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
              }
              CommonTokenStream tokens = new CommonTokenStream(lexer);
              CTLParser p = new CTLParser(tokens);
              p.setBuildParseTree(true);
              p.addParseListener(new CTLBaseListener());
              ParserRuleContext t = p.f();
              // ctl=((CTLBaseListener)(p.getParseListeners().get(0)))
              CTLBaseListener q = (CTLBaseListener) (p.getParseListeners().get(0));
              PrintWriter zzz = null;
              try {
                zzz = new PrintWriter(new FileOutputStream("parseTree.txt"));
                showMessage("Done");
              } catch (FileNotFoundException e1) {
                System.out.println("parseTree.txt");
              }
              zzz.print(q.st + "\r\n}");
              zzz.close();
              ctl = q.getFormula();
              for (String ap : q.atomic) {
                predCombo.add(ap);
              }
              cButton.setEnabled(true);

              //
            }

            public void widgetDefaultSelected(SelectionEvent e) {
              widgetSelected(e);
            }
          });

      pButton.pack();

      // button2.setBounds(20, 75, 90, 30);

      group.pack();
    }