public void createCombos(Composite parent) {
    parent.setLayout(
        GridLayoutFactory.fillDefaults().numColumns(2).margins(0, 0).spacing(64, 10).create());

    GridData comboGridData = new GridData();
    comboGridData.widthHint = 100;

    Label label = new Label(parent, SWT.None);
    label.setText("Complex");
    complexCombo = new Combo(parent, SWT.READ_ONLY);
    complexCombo.add("true");
    complexCombo.add("false");
    complexCombo.setToolTipText(
        "Flag to indicate data is complex.  If true, data values assumed to be alternating real and complex float values.");
    complexCombo.setLayoutData(comboGridData);

    label = new Label(parent, SWT.None);
    label.setText("Loop");
    loopCombo = new Combo(parent, SWT.READ_ONLY);
    loopCombo.add("true");
    loopCombo.add("false");
    //		loopCombo.setEnabled(false);
    loopCombo.setToolTipText(
        "Do we continue to replay and loop over the input file when we are done or not");
    loopCombo.setLayoutData(comboGridData);
  }
  /**
   * Creates and returns the control for this contribution item under the given parent composite.
   *
   * @param parent the parent composite
   * @return the new control
   */
  protected Control createControl(final Composite parent) {
    combo = new Combo(parent, SWT.DROP_DOWN);
    combo.addSelectionListener(
        new SelectionListener() {
          public void widgetSelected(final SelectionEvent e) {
            handleWidgetSelected(e);
          }

          public void widgetDefaultSelected(final SelectionEvent e) {
            handleWidgetDefaultSelected(e);
          }
        });
    combo.addFocusListener(
        new FocusListener() {
          public void focusGained(final FocusEvent e) {
            // do nothing
          }

          public void focusLost(final FocusEvent e) {
            refresh(false);
          }
        });

    // Initialize width of combo
    combo.setItems(initStrings);
    toolitem.setWidth(computeWidth(combo));
    combo.setToolTipText("Current concern");
    refresh(true);
    return combo;
  }
Ejemplo n.º 3
0
  private void initComboTimezones(Composite parent) {
    comboViewer = new ComboViewer(this, SWT.READ_ONLY);
    Combo comboTimezones = comboViewer.getCombo();
    comboTimezones.setToolTipText("Timezone");
    comboTimezones.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    comboViewer.setContentProvider(ArrayContentProvider.getInstance());
    comboViewer.setLabelProvider(
        new LabelProvider() {

          @Override
          public String getText(Object element) {
            if (element instanceof TimeZone) {
              return ((TimeZone) element).getID();
            }
            return super.getText(element);
          }
        });
    comboViewer.setInput(getAvailableTimezones());
    comboViewer.addSelectionChangedListener(
        new ISelectionChangedListener() {

          @Override
          public void selectionChanged(SelectionChangedEvent event) {
            if (comboViewer.getSelection() instanceof IStructuredSelection) {
              final IStructuredSelection selection =
                  (IStructuredSelection) comboViewer.getSelection();
              if (!(selection.isEmpty())) {
                final TimeZone seletedTimezone = (TimeZone) selection.getFirstElement();
                calendarValue.setTimeZone(seletedTimezone);
              }
            }
          }
        });
  }
Ejemplo n.º 4
0
 @SuppressWarnings("unchecked")
 private IObservableValue<String> createImageSelectionControls(final Composite container) {
   final Label nameLabel = new Label(container, SWT.NULL);
   nameLabel.setText(WizardMessages.getString("ImagePullPushPage.name.label")); // $NON-NLS-1$
   GridDataFactory.fillDefaults()
       .align(SWT.FILL, SWT.CENTER)
       .grab(false, false)
       .applyTo(nameLabel);
   final Combo imageNameCombo = new Combo(container, SWT.DROP_DOWN);
   imageNameCombo.setToolTipText(WizardMessages.getString("ImagePushName.toolTip")); // $NON-NLS-1$
   GridDataFactory.fillDefaults()
       .align(SWT.FILL, SWT.CENTER)
       .grab(true, false)
       .applyTo(imageNameCombo);
   final ComboViewer imageNameComboViewer = new ComboViewer(imageNameCombo);
   imageNameComboViewer.setContentProvider(new ArrayContentProvider());
   imageNameComboViewer.setInput(getModel().getImage().repoTags());
   // binding must take place after the input is set, so that default
   // repo/name can be selected.
   final IObservableValue<String> imageNameObservable =
       BeanProperties.value(ImagePushPageModel.class, ImagePullPushPageModel.SELECTED_IMAGE_NAME)
           .observe(getModel());
   dbc.bindValue(WidgetProperties.selection().observe(imageNameCombo), imageNameObservable);
   // filler for the last column
   GridDataFactory.fillDefaults()
       .align(SWT.FILL, SWT.CENTER)
       .grab(false, false)
       .applyTo(new Label(container, SWT.NONE));
   return imageNameObservable;
 }
Ejemplo n.º 5
0
  /*
   * (non-Javadoc)
   * @see  it.baeyens.avreclipse.ui.editors.targets.AbstractTargetConfigurationEditorPart#createSectionContent
   * (org.eclipse.swt.widgets.Composite, org.eclipse.ui.forms.widgets.FormToolkit)
   */
  @Override
  protected void createSectionContent(Composite parent, FormToolkit toolkit) {
    GridLayout layout = new GridLayout(2, false);
    layout.horizontalSpacing = 12;
    parent.setLayout(layout);

    //
    // The MCU Combo
    //
    toolkit.createLabel(parent, "MCU type:");
    fMCUcombo = new Combo(parent, SWT.READ_ONLY);
    toolkit.adapt(fMCUcombo, true, true);
    fMCUcombo.setLayoutData(new GridData(SWT.FILL, SWT.NONE, false, false));
    fMCUcombo.addSelectionListener(
        new SelectionAdapter() {

          @Override
          public void widgetSelected(SelectionEvent e) {
            String mcuid = AVRMCUidConverter.name2id(fMCUcombo.getText());
            getTargetConfiguration().setMCU(mcuid);
            refreshMessages();
            getManagedForm().dirtyStateChanged();
          }
        });

    //
    // The FCPU Combo
    //
    toolkit.createLabel(parent, "MCU clock frequency:");
    fFCPUcombo = new Combo(parent, SWT.NONE);
    toolkit.adapt(fFCPUcombo, true, true);
    fFCPUcombo.setLayoutData(new GridData(SWT.FILL, SWT.NONE, false, false));
    fFCPUcombo.setTextLimit(9); // max. 999 MHz
    fFCPUcombo.setToolTipText("Target Hardware Clock Frequency in Hz");
    fFCPUcombo.setVisibleItemCount(FCPU_VALUES.length);
    fFCPUcombo.setItems(FCPU_VALUES);

    fFCPUcombo.addModifyListener(
        new ModifyListener() {
          @Override
          public void modifyText(ModifyEvent e) {
            getTargetConfiguration().setFCPU(Integer.parseInt(fFCPUcombo.getText()));
            getManagedForm().dirtyStateChanged();
          }
        });

    // The verify listener to restrict the input to integers
    fFCPUcombo.addVerifyListener(
        new VerifyListener() {
          @Override
          public void verifyText(VerifyEvent event) {
            String text = event.text;
            if (!text.matches("[0-9]*")) {
              event.doit = false;
            }
          }
        });
  }
Ejemplo n.º 6
0
  /** 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);
  }
  /**
   * create Label and Combo width a Array of String.
   *
   * @param parent
   * @param labelStr
   * @param tip
   * @param item
   * @param horizontalSpan
   * @param isFill
   * @param style
   */
  private void createLabelledCombo(
      final Composite parent,
      final String labelStr,
      final String tip,
      final String[] item,
      int horizontalSpan,
      boolean isFill,
      int style) {

    // label
    label = new Label(parent, SWT.LEFT);
    label.setText(labelStr);
    label.addListener(
        SWT.MouseEnter,
        new Listener() {

          public void handleEvent(final Event e) {
            checkbox.forceFocus();
          }
        });

    // checkbox
    checkbox = new Button(parent, SWT.CHECK);

    // combo
    GridData gridData;
    if (isFill) {
      gridData = new GridData(GridData.FILL_HORIZONTAL);
    } else {
      gridData = new GridData();
    }
    gridData.horizontalSpan = horizontalSpan;
    combo = new Combo(parent, style);
    combo.setLayoutData(gridData);
    combo.setSize(A_100, A_20);

    for (int i = 0; i < item.length; i++) {
      combo.add(item[i]);
    }
    int visibleItemCount = combo.getItemCount();
    if (visibleItemCount > MAX_VISIBLE_ITEM_COUNT) {
      visibleItemCount = MAX_VISIBLE_ITEM_COUNT;
    }
    combo.setVisibleItemCount(visibleItemCount);

    if (tip != null) {
      combo.setToolTipText(tip);
    }
    combo.setEnabled(false);

    addControls(parent);
  }
  /**
   * creates the control area for the priority
   *
   * @param control the parent composite
   */
  protected void createPriorityControl(Composite control) {
    final Label priorityLabel = new Label(control, SWT.NONE);
    priorityLabel.setText(Messages.Local_Palette_Priority);
    priorityLabel.setToolTipText(Messages.Local_Palette_Priority_Tooltip);

    // choice widget among priority values
    priorityCombo = new Combo(control, SWT.READ_ONLY);
    priorityCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    priorityCombo.setToolTipText(Messages.Local_Palette_Priority_Tooltip);
    priorityCombo.setItems(priorityList);

    // initialize, then add the listener...
    initialPopulatePriorityField();

    priorityCombo.addListener(SWT.Modify, this);
  }
  /**
   * {@inheritDoc}
   *
   * @see
   *     org.teiid.designer.ui.preferences.IGeneralPreferencePageContributor#createPreferenceEditor(org.eclipse.swt.widgets.Composite)
   */
  @Override
  public void createPreferenceEditor(Composite parent) {
    shell = parent.getShell();
    Composite panel = new Composite(parent, SWT.NONE);
    GridLayoutFactory.swtDefaults().numColumns(2).applyTo(panel);

    versionCombo = new Combo(panel, SWT.DROP_DOWN);
    versionCombo.setFont(JFaceResources.getDialogFont());
    versionCombo.setToolTipText(Util.getStringOrKey(PREFIX + "toolTip")); // $NON-NLS-1$
    GridDataFactory.swtDefaults()
        .grab(true, true)
        .align(SWT.LEFT, SWT.CENTER)
        .applyTo(versionCombo);

    Label title = new Label(panel, SWT.NONE);
    title.setText(Util.getStringOrKey(PREFIX + "title")); // $NON-NLS-1$
    GridDataFactory.swtDefaults().grab(true, true).align(SWT.LEFT, SWT.CENTER).applyTo(title);

    // initialize state
    refresh();
  }
Ejemplo n.º 10
0
  public void createPage(final Composite composite) {
    this.composite = composite;
    composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    composite.setLayout(new GridLayout(2, false));

    final Label nameLabel = new Label(composite, 0);
    nameLabel.setText(Messages.Annotation_Name);
    nameLabel.setLayoutData(new GridData());

    nameText = new Text(composite, SWT.BORDER | SWT.SINGLE);
    nameText.setToolTipText(Messages.Annotation_NameTT);
    nameText.setLayoutData(new GridData(SWT.FILL, 0, true, false));

    snapToTrace = new Button(composite, SWT.CHECK);
    snapToTrace.setText(Messages.Annotation_Snap);
    snapToTrace.setToolTipText(Messages.Annotation_SnapTT);
    snapToTrace.setLayoutData(new GridData(0, 0, false, false, 2, 1));

    xAxisLabel = new Label(composite, 0);
    xAxisLabel.setLayoutData(new GridData());

    xAxisOrTraceCombo = new Combo(composite, SWT.DROP_DOWN);
    xAxisOrTraceCombo.setLayoutData(new GridData(SWT.FILL, 0, true, false));

    yAxisLabel = new Label(composite, 0);
    yAxisLabel.setText(Messages.Annotation_YAxis);
    yAxisLabel.setLayoutData(new GridData());

    yAxisCombo = new Combo(composite, SWT.DROP_DOWN);
    yAxisCombo.setToolTipText(Messages.Annotation_YAxisSnapTT);
    yAxisCombo.setLayoutData(new GridData(SWT.FILL, 0, true, false));

    // snapToTrace listener
    snapToTrace.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(final SelectionEvent e) {
            if (snapToTrace.getSelection()) {
              xAxisLabel.setText(Messages.Annotation_Trace);
              xAxisOrTraceCombo.setToolTipText(Messages.Annotation_TraceSnapTT);
            } else {
              xAxisLabel.setText(Messages.Annotation_XAxis);
              xAxisOrTraceCombo.setToolTipText(Messages.Annotation_XAxisSnapTT);
            }

            xAxisOrTraceCombo.removeAll();
            if (snapToTrace.getSelection()) {
              for (Trace trace : xyGraph.getPlotArea().getTraceList())
                xAxisOrTraceCombo.add(trace.getName());
            } else {
              for (Axis axis : xyGraph.getXAxisList()) xAxisOrTraceCombo.add(axis.getTitle());
            }
            xAxisOrTraceCombo.select(0);
            if (annotation.isFree() && !snapToTrace.getSelection())
              xAxisOrTraceCombo.select(xyGraph.getXAxisList().indexOf(annotation.getXAxis()));
            else if (!annotation.isFree() && snapToTrace.getSelection())
              xAxisOrTraceCombo.select(
                  xyGraph.getPlotArea().getTraceList().indexOf(annotation.getTrace()));

            yAxisLabel.setVisible(!snapToTrace.getSelection());
            yAxisCombo.setVisible(!snapToTrace.getSelection());
            composite.layout(true, true);
          }
        });
    // annotation color
    useDefaultColorButton = new Button(composite, SWT.CHECK);
    useDefaultColorButton.setText(Messages.Annotation_ColorFromYAxis);
    useDefaultColorButton.setLayoutData(new GridData(SWT.FILL, 0, false, false, 2, 1));

    colorLabel = new Label(composite, 0);
    colorLabel.setText(Messages.Annotation_Color);
    colorLabel.setLayoutData(new GridData());

    colorSelector = new ColorSelector(composite);
    colorSelector.getButton().setLayoutData(new GridData());
    useDefaultColorButton.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            colorSelector.getButton().setVisible(!useDefaultColorButton.getSelection());
            colorLabel.setVisible(!useDefaultColorButton.getSelection());
          }
        });

    fontLabel = new Label(composite, 0);
    fontLabel.setLayoutData(new GridData());

    final Button fontButton = new Button(composite, SWT.PUSH);
    fontButton.setText(Messages.Annotation_ChangeFont);
    fontButton.setLayoutData(new GridData());
    fontButton.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            FontDialog fontDialog = new FontDialog(composite.getShell());
            if (font != null) fontDialog.setFontList(font.getFontData());
            FontData fontData = fontDialog.open();
            if (fontData != null) {
              font = XYGraphMediaFactory.getInstance().getFont(fontData);
              fontLabel.setFont(font);
              fontLabel.setText(Messages.Annotation_Font + fontData.getName());
              composite.getShell().layout(true, true);
            }
          }
        });

    final Label cursorLineLabel = new Label(composite, 0);
    cursorLineLabel.setText(Messages.Annotation_Cursor);
    cursorLineLabel.setLayoutData(new GridData());

    cursorLineCombo = new Combo(composite, SWT.DROP_DOWN);
    cursorLineCombo.setItems(CursorLineStyle.stringValues());
    cursorLineCombo.setLayoutData(new GridData());

    showNameButton = new Button(composite, SWT.CHECK);
    showNameButton.setText(Messages.Annotation_ShowName);
    showNameButton.setLayoutData(new GridData(0, 0, false, false, 2, 1));

    showSampleInfoButton = new Button(composite, SWT.CHECK);
    showSampleInfoButton.setText(Messages.Annotation_ShowInfo);
    showSampleInfoButton.setLayoutData(new GridData(0, 0, false, false, 2, 1));

    showPositionButton = new Button(composite, SWT.CHECK);
    showPositionButton.setText(Messages.Annotation_ShowPosition);
    showPositionButton.setLayoutData(new GridData(0, 0, false, false, 2, 1));
    initialize();
  }
  /* (non-Javadoc)
   * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
   */
  @Override
  public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NULL);
    container.setLayout(new GridLayout(3, false));

    Group runtimeGrp = new Group(container, SWT.NONE);
    GridData runtimeGrpData = new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1);
    runtimeGrp.setLayout(new GridLayout(3, false));
    runtimeGrp.setLayoutData(runtimeGrpData);
    runtimeGrp.setText(Messages.newProjectWizardRuntimePageRuntimeGroupLabel);

    Label runtimeLabel = new Label(runtimeGrp, SWT.NONE);
    GridData runtimeLabelData = new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1);
    runtimeLabel.setLayoutData(runtimeLabelData);
    runtimeLabel.setText(Messages.newProjectWizardRuntimePageRuntimeLabel);

    runtimeComboViewer = new ComboViewer(runtimeGrp, SWT.NONE | SWT.READ_ONLY);
    runtimeComboViewer.setComparator(
        new ViewerComparator(
            new Comparator<String>() {

              @Override
              public int compare(String o1, String o2) {
                if (Messages.newProjectWizardRuntimePageNoRuntimeSelectedLabel.equals(o1)) {
                  return -1;
                }
                return o1.compareTo(o2);
              }
            }));

    GridData runtimeComboData = new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1);
    runtimeComboViewer.getCombo().setLayoutData(runtimeComboData);
    runtimeComboViewer
        .getCombo()
        .setToolTipText(Messages.newProjectWizardRuntimePageRuntimeDescription);
    runtimeComboViewer.setContentProvider(ArrayContentProvider.getInstance());
    runtimeComboViewer
        .getCombo()
        .addModifyListener(
            new ModifyListener() {
              /*
               * (non-Javadoc)
               * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
               */
              @Override
              public void modifyText(ModifyEvent e) {
                lastSelectedRuntime = runtimeComboViewer.getSelection().toString();
                preselectCamelVersionForRuntime(determineRuntimeCamelVersion(getSelectedRuntime()));
                validate();
              }
            });

    try {
      configureRuntimeCombo();
    } catch (CoreException ex) {
      ProjectTemplatesActivator.pluginLog().logError(ex);
    }

    Button runtimeNewButton = new Button(runtimeGrp, SWT.NONE);
    GridData runtimeNewButtonData = new GridData(SWT.FILL, SWT.CENTER, false, false);
    runtimeNewButton.setLayoutData(runtimeNewButtonData);
    runtimeNewButton.setText(Messages.newProjectWizardRuntimePageRuntimeNewButtonLabel);
    runtimeNewButton.setToolTipText(
        Messages.newProjectWizardRuntimePageRuntimeNewButtonDescription);
    runtimeNewButton.addSelectionListener(
        new SelectionAdapter() {
          /*
           * (non-Javadoc)
           * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
           */

          @Override
          public void widgetSelected(SelectionEvent e) {
            String[] oldRuntimes = runtimeComboViewer.getCombo().getItems();
            boolean created = ServerUIUtil.showNewRuntimeWizard(getShell(), null, null);
            if (created) {
              String[] newRuntimes = runtimeComboViewer.getCombo().getItems();
              String newRuntime = getNewRuntime(oldRuntimes, newRuntimes);
              if (newRuntime != null) {
                runtimeComboViewer.setSelection(new StructuredSelection(newRuntime));
              }
            }
          }
        });

    new Label(runtimeGrp, SWT.None);

    Group camelGrp = new Group(container, SWT.NONE);
    GridData camelGrpData = new GridData(SWT.FILL, SWT.FILL, true, true, 3, 20);
    camelGrp.setLayout(new GridLayout(3, false));
    camelGrp.setLayoutData(camelGrpData);
    camelGrp.setText(Messages.newProjectWizardRuntimePageCamelGroupLabel);

    Label camelVersionLabel = new Label(camelGrp, SWT.NONE);
    GridData camelLabelData = new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1);
    camelVersionLabel.setLayoutData(camelLabelData);
    camelVersionLabel.setText(Messages.newProjectWizardRuntimePageCamelLabel);

    camelVersionCombo = new Combo(camelGrp, SWT.RIGHT | SWT.READ_ONLY);
    GridData camelComboData = new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1);
    camelVersionCombo.setLayoutData(camelComboData);
    camelVersionCombo.setItems(getSupportedCamelVersions());
    camelVersionCombo.select(Math.max(camelVersionCombo.getItemCount() - 1, 0));
    camelVersionCombo.setToolTipText(Messages.newProjectWizardRuntimePageCamelDescription);
    camelVersionCombo.addSelectionListener(
        new SelectionAdapter() {
          /* (non-Javadoc)
           * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
           */
          @Override
          public void widgetSelected(SelectionEvent e) {
            validate();
          }
        });
    // TODO: leaving that out until we decide to support other camel versions than the ones we ship
    //		camelVersionCombo.addFocusListener(new FocusAdapter() {
    //			/* (non-Javadoc)
    //			 * @see org.eclipse.swt.events.FocusAdapter#focusLost(org.eclipse.swt.events.FocusEvent)
    //			 */
    //			@Override
    //			public void focusLost(FocusEvent e) {
    //				super.focusLost(e);
    //				validate();
    //			}
    //
    //			/* (non-Javadoc)
    //			 * @see org.eclipse.swt.events.FocusAdapter#focusGained(org.eclipse.swt.events.FocusEvent)
    //			 */
    //			@Override
    //			public void focusGained(FocusEvent e) {
    //				super.focusGained(e);
    //				setPageComplete(false);
    //			}
    //		});

    new Label(camelGrp, SWT.None);

    warningIconLabel = new Label(camelGrp, SWT.None);
    GridData camelLblData = new GridData(SWT.FILL, SWT.TOP, false, true, 1, 20);
    camelLblData.verticalIndent = 20;
    warningIconLabel.setImage(getSWTImage(SWT.ICON_WARNING));
    warningIconLabel.setLayoutData(camelLblData);
    warningIconLabel.setVisible(false);

    camelInfoText = new StyledText(camelGrp, SWT.WRAP | SWT.MULTI);
    GridData camelInfoData = new GridData(SWT.FILL, SWT.TOP, true, true, 2, 20);
    camelInfoData.verticalIndent = 0;
    camelInfoData.heightHint = 150;
    camelInfoText.setLayoutData(camelInfoData);
    camelInfoText.setEnabled(false);
    camelInfoText.setEditable(false);
    camelInfoText.setBackground(container.getBackground());

    new Label(camelGrp, SWT.None);

    setControl(container);

    IRuntimeLifecycleListener listener =
        new IRuntimeLifecycleListener() {

          @Override
          public void runtimeRemoved(IRuntime runtime) {
            runInUIThread();
          }

          @Override
          public void runtimeChanged(IRuntime runtime) {
            runInUIThread();
          }

          @Override
          public void runtimeAdded(IRuntime runtime) {
            runInUIThread();
          }

          private void runInUIThread() {
            Display.getDefault()
                .asyncExec(
                    new Runnable() {

                      @Override
                      public void run() {
                        try {
                          configureRuntimeCombo();
                        } catch (CoreException ex) {
                          ProjectTemplatesActivator.pluginLog()
                              .logError("Unable to handle runtime change event", ex); // $NON-NLS-1$
                        }
                      }
                    });
          }
        };
    ServerCore.addRuntimeLifecycleListener(listener);
    validate();
  }
  /**
   * Called by the parent Wizard to create the UI for this Wizard Page.
   *
   * <p>{@inheritDoc}
   *
   * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
   */
  @Override
  @SuppressWarnings("unused") // SWT constructors have side effects, they aren't unused
  public void createControl(Composite parent) {
    // This UI is maintained with WindowBuilder.

    Composite composite = new Composite(parent, SWT.NULL);
    composite.setLayout(new GridLayout(2, false /*makeColumnsEqualWidth*/));
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));

    // label before type radios
    Label typeLabel = new Label(composite, SWT.NONE);
    typeLabel.setText("Resource Type:");

    mTypeCombo = new Combo(composite, SWT.DROP_DOWN | SWT.READ_ONLY);
    mTypeCombo.setToolTipText("What type of resource would you like to create?");
    mTypeCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    if (mInitialFolderType != null) {
      mTypeCombo.setEnabled(false);
    }
    mTypeCombo.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            TypeInfo type = getSelectedType();
            if (type != null) {
              onSelectType(type);
            }
          }
        });

    // separator
    Label separator = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL);
    GridData gd2 = new GridData(GridData.GRAB_HORIZONTAL);
    gd2.horizontalAlignment = SWT.FILL;
    gd2.horizontalSpan = 2;
    separator.setLayoutData(gd2);

    // Project: [button]
    String tooltip = "The Android Project where the new resource file will be created.";
    Label projectLabel = new Label(composite, SWT.NONE);
    projectLabel.setText("Project:");
    projectLabel.setToolTipText(tooltip);

    ProjectChooserHelper helper = new ProjectChooserHelper(getShell(), null /* filter */);

    mProjectButton = new ProjectCombo(helper, composite, mValues.project);
    mProjectButton.setToolTipText(tooltip);
    mProjectButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    mProjectButton.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            IProject project = mProjectButton.getSelectedProject();
            if (project != mValues.project) {
              changeProject(project);
            }
          };
        });

    // Filename: [text]
    Label fileLabel = new Label(composite, SWT.NONE);
    fileLabel.setText("File:");
    fileLabel.setToolTipText("The name of the resource file to create.");

    mFileNameTextField = new Text(composite, SWT.BORDER);
    mFileNameTextField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    mFileNameTextField.setToolTipText(tooltip);
    mFileNameTextField.addModifyListener(
        new ModifyListener() {
          @Override
          public void modifyText(ModifyEvent e) {
            mValues.name = mFileNameTextField.getText();
            validatePage();
          }
        });

    // separator
    Label rootSeparator = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL);
    GridData gd = new GridData(GridData.GRAB_HORIZONTAL);
    gd.horizontalAlignment = SWT.FILL;
    gd.horizontalSpan = 2;
    rootSeparator.setLayoutData(gd);

    // Root Element:
    // [TableViewer]
    Label rootLabel = new Label(composite, SWT.NONE);
    rootLabel.setText("Root Element:");
    new Label(composite, SWT.NONE);

    mRootTableViewer = new TableViewer(composite, SWT.BORDER | SWT.FULL_SELECTION);
    mRootTable = mRootTableViewer.getTable();
    GridData tableGridData = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
    tableGridData.heightHint = 200;
    mRootTable.setLayoutData(tableGridData);

    setControl(composite);

    // Update state the first time
    setErrorMessage(null);
    setMessage(null);

    initializeFromSelection(mInitialSelection);
    updateAvailableTypes();
    initializeFromFixedType();
    initializeRootValues();
    installTargetChangeListener();

    initialSelectType();
    validatePage();
  }
Ejemplo n.º 13
0
  /** Initializes the GUI. */
  private void initGUI() {
    try {
      this.setSize(731, 385);
      this.setBackground(SWTResourceManager.getColor(219, 219, 219));
      FormLayout thisLayout = new FormLayout();
      this.setLayout(thisLayout);
      this.setOrientation(SWT.HORIZONTAL);
      this.setToolTipText("MKD- Image SteganoGraphy");
      {
        Enter = new Label(this, SWT.NONE);
        FormData EnterLData = new FormData();
        EnterLData.left = new FormAttachment(0, 1000, 266);
        EnterLData.top = new FormAttachment(0, 1000, 140);
        EnterLData.width = 43;
        EnterLData.height = 15;
        Enter.setLayoutData(EnterLData);
        Enter.setText("Enter");
        Enter.setVisible(false);
      }
      {
        GenPubPara = new Button(this, SWT.PUSH | SWT.CENTER);
        FormData GenPubParaLData = new FormData();
        GenPubParaLData.left = new FormAttachment(0, 1000, 174);
        GenPubParaLData.top = new FormAttachment(0, 1000, 142);
        GenPubParaLData.width = 132;
        GenPubParaLData.height = 25;
        GenPubPara.setLayoutData(GenPubParaLData);
        GenPubPara.setText("Generate Public Values");
        GenPubPara.setVisible(false);
        GenPubPara.addSelectionListener(
            new SelectionAdapter() {
              public void widgetSelected(SelectionEvent e) {
                Random prng = new SecureRandom();
                BigInteger q = BigInteger.probablePrime(32, prng);
                System.out.println("" + q);
                QValue.setText(q.toString());
                // code for generating alpha
                BigInteger alpha;
                primitiveRoot pr = new primitiveRoot();

                for (alpha = BigInteger.valueOf(2);
                    alpha.compareTo(q) > 0;
                    alpha = alpha.add(BigInteger.ONE)) {
                  if (pr.isPrimitive(q, alpha)) break;
                }
                System.out.println("" + alpha);
                AlphaValue.setText(alpha.toString());
              }
            });
      }
      {
        FormData PubKeyLData = new FormData();
        PubKeyLData.left = new FormAttachment(0, 1000, 326);
        PubKeyLData.top = new FormAttachment(0, 1000, 188);
        PubKeyLData.width = 121;
        PubKeyLData.height = 15;
        PubKey = new Text(this, SWT.NONE);
        PubKey.setLayoutData(PubKeyLData);
        PubKey.setVisible(false);
      }
      {
        PUBKey = new Label(this, SWT.NONE);
        FormData PUBKeyLData = new FormData();
        PUBKeyLData.left = new FormAttachment(0, 1000, 217);
        PUBKeyLData.top = new FormAttachment(0, 1000, 187);
        PUBKeyLData.width = 97;
        PUBKeyLData.height = 15;
        PUBKey.setLayoutData(PUBKeyLData);
        PUBKey.setText("Public Key is");
        PUBKey.setVisible(false);
      }
      {
        FormData PKeyLData = new FormData();
        PKeyLData.left = new FormAttachment(0, 1000, 326);
        PKeyLData.top = new FormAttachment(0, 1000, 166);
        PKeyLData.width = 121;
        PKeyLData.height = 15;
        PKey = new Text(this, SWT.NONE);
        PKey.setLayoutData(PKeyLData);
        PKey.setVisible(false);

        PKey.addModifyListener(
            new ModifyListener() {

              @Override
              public void modifyText(ModifyEvent arg0) {
                // TODO Auto-generated method stub
                BigInteger alpha = new BigInteger(AlphaValue.getText());
                BigInteger xa = new BigInteger(PKey.getText());
                BigInteger q = new BigInteger(QValue.getText());
                BigInteger ya = alpha.modPow(xa, q);
                System.out.println("Y a is " + ya);
                PubKey.setText(ya.toString());
                PubKey.setEditable(false);
              }
            });

        /*Adapter() {
        public void widgetSelected(SelectionEvent e){
        	BigInteger alpha=new BigInteger(AlphaValue.getText());
        	BigInteger xa=new BigInteger(PKey.getText());
        	BigInteger q=new BigInteger(QValue.getText());
        	BigInteger ya = alpha.modPow(xa, q);
        	System.out.println("Y a is "+ya);
        	PubKey.setText(ya.toString());
        	PubKey.setEditable(false);
        }});*/
      }
      {
        PKLabel = new Label(this, SWT.NONE);
        FormData PKLabelLData = new FormData();
        PKLabelLData.left = new FormAttachment(0, 1000, 217);
        PKLabelLData.top = new FormAttachment(0, 1000, 166);
        PKLabelLData.width = 97;
        PKLabelLData.height = 15;
        PKLabel.setLayoutData(PKLabelLData);
        PKLabel.setText("Enter Private Key");
        PKLabel.setVisible(false);
      }
      {
        FormData AlphaValueLData = new FormData();
        AlphaValueLData.left = new FormAttachment(0, 1000, 504);
        AlphaValueLData.top = new FormAttachment(0, 1000, 138);
        AlphaValueLData.width = 64;
        AlphaValueLData.height = 15;
        AlphaValue = new Text(this, SWT.NONE);
        AlphaValue.setLayoutData(AlphaValueLData);
        AlphaValue.setVisible(false);
      }
      {
        FormData QValueLData = new FormData();
        QValueLData.left = new FormAttachment(0, 1000, 340);
        QValueLData.top = new FormAttachment(0, 1000, 137);
        QValueLData.width = 107;
        QValueLData.height = 15;
        QValue = new Text(this, SWT.NONE);
        QValue.setLayoutData(QValueLData);
        QValue.setVisible(false);
      }
      {
        Alpha = new Label(this, SWT.NONE);
        FormData AlphaLData = new FormData();
        AlphaLData.left = new FormAttachment(0, 1000, 465);
        AlphaLData.top = new FormAttachment(0, 1000, 138);
        AlphaLData.width = 40;
        AlphaLData.height = 15;
        Alpha.setLayoutData(AlphaLData);
        Alpha.setText("Alpha");
        Alpha.setVisible(false);
      }
      {
        Q = new Label(this, SWT.NONE);
        FormData QLData = new FormData();
        QLData.left = new FormAttachment(0, 1000, 328);
        QLData.top = new FormAttachment(0, 1000, 138);
        QLData.width = 12;
        QLData.height = 15;
        Q.setLayoutData(QLData);
        Q.setText("Q");
        Q.setVisible(false);
      }

      {
        group1 = new Group(this, SWT.NONE);
        GridLayout group1Layout = new GridLayout();
        group1Layout.makeColumnsEqualWidth = true;
        group1.setLayout(group1Layout);
        FormData group1LData = new FormData();
        group1LData.left = new FormAttachment(0, 1000, 149);
        group1LData.top = new FormAttachment(0, 1000, 127);
        group1LData.width = 429;
        group1LData.height = 64;
        group1.setLayoutData(group1LData);
        group1.setText("Diffie-Hellman Key Exchange");
        group1.setVisible(false);
      }
      {
        button1 = new Button(this, SWT.PUSH | SWT.CENTER);
        FormData button1LData = new FormData();
        button1LData.width = 100;
        button1LData.height = 32;
        button1LData.right = new FormAttachment(568, 1000, 0);
        button1LData.bottom = new FormAttachment(650, 1000, 0);
        button1LData.top = new FormAttachment(567, 1000, 0);
        button1LData.left = new FormAttachment(431, 1000, 0);
        button1.setLayoutData(button1LData);
        button1.setText("Proceed");
        // button1.setBackground(SWTResourceManager.getColor(128, 0, 255));
        button1.addSelectionListener(
            new SelectionAdapter() {
              public void widgetSelected(SelectionEvent e) {
                String s = new String(Option.getText());
                String s1 = new String("Encrypt the Data into an Image");
                String s2 = new String("Decrypt the Message from an Image");
                if (s.equals(s1)) {
                  xa = PKey.getText();
                  q = QValue.getText();
                  Display display = Display.getDefault();
                  Shell shell = new Shell(display);
                  EncryptWindow inst = new EncryptWindow(shell, SWT.NULL);
                  Point size = inst.getSize();
                  // shell.setLayout(new FillLayout());
                  shell.layout();
                  new Label(shell, SWT.NONE).setText("Operation:");
                  final Label returnVal = new Label(shell, SWT.NONE);
                  // returnVal.setLayoutData(new FillLayout(SWT.NULL));
                  returnVal.setText("");

                  returnVal.setText(Option.getText());
                  if (size.x == 0 && size.y == 0) {
                    inst.pack();
                    shell.pack();
                  } else {
                    Rectangle shellBounds = shell.computeTrim(0, 0, size.x, size.y);
                    shell.setSize(shellBounds.width, shellBounds.height);
                  }
                  shell.open();

                  while (!shell.isDisposed()) {
                    if (!display.readAndDispatch()) display.sleep();
                  }
                } else if (s.equals(s2)) {
                  xa = PKey.getText();
                  q = QValue.getText();
                  Display display = Display.getDefault();
                  Shell shell = new Shell(display);
                  DecryptWindow inst = new DecryptWindow(shell, SWT.NULL);
                  Point size = inst.getSize();
                  // shell.setLayout(new FillLayout());
                  shell.layout();
                  new Label(shell, SWT.NONE).setText("Operation:");
                  final Label returnVal = new Label(shell, SWT.NONE);
                  // returnVal.setLayoutData(new FillLayout(SWT.NULL));
                  returnVal.setText("");

                  returnVal.setText(Option.getText());
                  if (size.x == 0 && size.y == 0) {
                    inst.pack();
                    shell.pack();
                  } else {
                    Rectangle shellBounds = shell.computeTrim(0, 0, size.x, size.y);
                    shell.setSize(shellBounds.width, shellBounds.height);
                  }
                  shell.open();

                  while (!shell.isDisposed()) {
                    if (!display.readAndDispatch()) display.sleep();
                  }
                }
              }
            });
      }

      {
        Label2 = new Label(this, SWT.NONE);
        FormData Label2LData = new FormData();
        Label2LData.width = 443;
        Label2LData.height = 49;
        Label2LData.bottom = new FormAttachment(144, 1000, 0);
        Label2LData.right = new FormAttachment(811, 1000, 0);
        Label2LData.top = new FormAttachment(16, 1000, 0);
        Label2LData.left = new FormAttachment(205, 1000, 0);
        Label2.setLayoutData(Label2LData);
        Label2.setText("V's Image Steganography ");
        Label2.setFont(SWTResourceManager.getFont("Lucida Handwriting", 22, 1, false, false));
        Label2.setAlignment(SWT.CENTER);
        Label2.setBackground(SWTResourceManager.getColor(219, 219, 219));
      }
      {
        Label1 = new Label(this, SWT.NONE);
        FormData Label1LData = new FormData();
        Label1LData.width = 234;
        Label1LData.height = 22;
        Label1LData.left = new FormAttachment(204, 1000, 0);
        Label1LData.right = new FormAttachment(524, 1000, 0);
        Label1LData.bottom = new FormAttachment(232, 1000, 0);
        Label1LData.top = new FormAttachment(175, 1000, 0);
        Label1.setLayoutData(Label1LData);
        Label1.setText("What you want to do...?");
        Label1.setBackground(SWTResourceManager.getColor(219, 219, 219));
      }
      {
        Option = new Combo(this, SWT.NONE);
        FormLayout OptionLayout = new FormLayout();
        Option.setLayout(OptionLayout);
        FormData OptionLData = new FormData();
        OptionLData.left = new FormAttachment(204, 1000, 0);
        OptionLData.top = new FormAttachment(232, 1000, 0);
        OptionLData.width = 408;
        OptionLData.height = 19;
        OptionLData.right = new FormAttachment(799, 1000, 0);
        OptionLData.bottom = new FormAttachment(287, 1000, 0);
        Option.setLayoutData(OptionLData);
        Option.setText("Select Option");
        Option.setBackground(SWTResourceManager.getColor(192, 192, 192));
        Option.setToolTipText("\r\n");
        Option.addSelectionListener(
            new SelectionAdapter() {
              public void widgetSelected(SelectionEvent e) {
                if (Option.getText().equals("Encrypt the Data into an Image")) {
                  xa = PKey.getText();
                  q = QValue.getText();
                  group1.setVisible(true);
                  PubKey.setVisible(true);
                  PUBKey.setVisible(true);
                  PKey.setVisible(true);
                  PKLabel.setVisible(true);
                  AlphaValue.setVisible(true);
                  QValue.setVisible(true);
                  Alpha.setVisible(true);
                  Q.setVisible(true);
                  GenPubPara.setVisible(true);
                  Enter.setVisible(false);
                }
                if (Option.getText().equals("Decrypt the Message from an Image")) {
                  /*PubKey.setText("");
                  PKey.setText("null");
                  QValue.setText("null");
                  AlphaValue.setText("0");*/
                  group1.setVisible(true);
                  PubKey.setVisible(true);
                  PUBKey.setVisible(true);
                  PKey.setVisible(true);
                  PKLabel.setVisible(true);
                  AlphaValue.setVisible(true);
                  QValue.setVisible(true);
                  Alpha.setVisible(true);
                  Q.setVisible(true);
                  Enter.setVisible(true);
                  GenPubPara.setVisible(false);
                }
              } // Encrypt e=new Encrypt();
            });
        Option.add("Encrypt the Data into an Image");
        Option.add("Decrypt the Message from an Image");
      }
      {
        label1 = new Label(this, SWT.NONE);
        FormData label1LData = new FormData();
        label1LData.left = new FormAttachment(0, 1000, 149);
        label1LData.top = new FormAttachment(0, 1000, 285);
        label1LData.width = 429;
        label1LData.height = 35;
        label1.setLayoutData(label1LData);
        label1.setText(
            "                             Copyright 2012., All Rights Reserved.,\r\n                              Vinaykumar M Kolli & Vaishakh B N  ");
        label1.setBackground(SWTResourceManager.getColor(192, 192, 192));
      }
      {
        menu1 = new Menu(getShell(), SWT.BAR);
        getShell().setMenuBar(menu1);
        /*{
        	fileMenuItem = new MenuItem(menu1, SWT.CASCADE);
        	fileMenuItem.setText("File");
        	{
        		fileMenu = new Menu(fileMenuItem);
        		{
        			openFileMenuItem = new MenuItem(fileMenu, SWT.CASCADE);
        			openFileMenuItem.setText("Open");
        		}
        		{
        			newFileMenuItem = new MenuItem(fileMenu, SWT.CASCADE);
        			newFileMenuItem.setText("New");
        		}
        		{
        			saveFileMenuItem = new MenuItem(fileMenu, SWT.CASCADE);
        			saveFileMenuItem.setText("Save");
        		}
        		{
        			closeFileMenuItem = new MenuItem(fileMenu, SWT.CASCADE);
        			closeFileMenuItem.setText("Close");
        		}
        		{
        			exitMenuItem = new MenuItem(fileMenu, SWT.CASCADE);
        			exitMenuItem.setText("Exit");
        		}
        		fileMenuItem.setMenu(fileMenu);
        	}
        }*/
        {
          helpMenuItem = new MenuItem(menu1, SWT.CASCADE);
          helpMenuItem.setText("Help");
          {
            helpMenu = new Menu(helpMenuItem);
            {
              contentsMenuItem = new MenuItem(helpMenu, SWT.CASCADE);
              contentsMenuItem.setText("Help Contents");
              contentsMenuItem.addSelectionListener(new SelectionAdapter() {});
            }
            {
              aboutMenuItem = new MenuItem(helpMenu, SWT.CASCADE);
              aboutMenuItem.setText("About");
              aboutMenuItem.addSelectionListener(
                  new SelectionAdapter() {
                    public void widgetSelected(SelectionEvent e) {
                      Display display = Display.getDefault();
                      Shell shell = new Shell(display);
                      HelpPage help = new HelpPage(shell, SWT.NULL);
                      Point size = help.getSize();
                      // shell.setLayout(new FillLayout());
                      shell.layout();
                      // new Label(shell, SWT.NONE).setText("Operation:");
                      // final Label returnVal = new Label(shell, SWT.NONE);
                      // returnVal.setLayoutData(new FillLayout(SWT.NULL));
                      // returnVal.setText("");

                      // returnVal.setText(Option.getText());
                      if (size.x == 0 && size.y == 0) {
                        help.pack();
                        shell.pack();
                      } else {
                        Rectangle shellBounds = shell.computeTrim(0, 0, size.x, size.y);
                        shell.setSize(shellBounds.width, shellBounds.height);
                      }
                      shell.open();

                      while (!shell.isDisposed()) {
                        if (!display.readAndDispatch()) display.sleep();
                      }
                    }
                  });
            }
            helpMenuItem.setMenu(helpMenu);
          }
        }
      }
      this.layout();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Ejemplo n.º 14
0
  /**
   * view command
   *
   * @param shell shell
   * @param repositoryTab repository tab
   * @param fileData file to view
   * @param revision revision to view
   */
  CommandView(
      final Shell shell,
      final RepositoryTab repositoryTab,
      final FileData fileData,
      final String revision) {
    Composite composite, subComposite;
    Label label;
    Button button;
    Listener listener;

    // initialize variables
    this.repositoryTab = repositoryTab;
    this.fileData = fileData;

    // get display
    display = shell.getDisplay();
    clipboard = new Clipboard(display);

    // add files dialog
    dialog = Dialogs.open(shell, "View: " + fileData.getFileName(), new double[] {1.0, 0.0}, 1.0);

    composite = Widgets.newComposite(dialog);
    composite.setLayout(new TableLayout(new double[] {0.0, 1.0, 0.0}, 1.0, 4));
    Widgets.layout(composite, 0, 0, TableLayoutData.NSWE, 0, 0, 4);
    {
      subComposite = Widgets.newComposite(composite);
      subComposite.setLayout(new TableLayout(1.0, new double[] {0.0, 1.0}));
      Widgets.layout(subComposite, 0, 0, TableLayoutData.WE);
      {
        label = Widgets.newLabel(subComposite, "Revision:");
        Widgets.layout(label, 0, 0, TableLayoutData.W);

        widgetRevision = Widgets.newSelect(subComposite);
        widgetRevision.setEnabled(false);
        Widgets.layout(widgetRevision, 0, 1, TableLayoutData.WE);
        Widgets.addModifyListener(
            new WidgetListener(widgetRevision, data) {
              public void modified(Control control) {
                Widgets.setEnabled(control, (data.revisionNames != null));
              }
            });
        widgetRevision.setToolTipText("Revision to view.");

        widgetRevisionPrev = Widgets.newButton(subComposite, Onzen.IMAGE_ARROW_LEFT);
        widgetRevisionPrev.setEnabled(false);
        Widgets.layout(widgetRevisionPrev, 0, 2, TableLayoutData.NSW);
        Widgets.addModifyListener(
            new WidgetListener(widgetRevisionPrev, data) {
              public void modified(Control control) {
                Widgets.setEnabled(
                    control,
                    (data.revisionNames != null) && (widgetRevision.getSelectionIndex() > 0));
              }
            });
        widgetRevisionPrev.setToolTipText("Show previous revision.");

        widgetRevisionNext = Widgets.newButton(subComposite, Onzen.IMAGE_ARROW_RIGHT);
        widgetRevisionNext.setEnabled(false);
        Widgets.layout(widgetRevisionNext, 0, 3, TableLayoutData.NSW);
        Widgets.addModifyListener(
            new WidgetListener(widgetRevisionNext, data) {
              public void modified(Control control) {

                Widgets.setEnabled(
                    control,
                    (data.revisionNames != null)
                        && (widgetRevision.getSelectionIndex() < data.revisionNames.length - 1));
              }
            });
        widgetRevisionNext.setToolTipText("Show next revision.");
      }

      subComposite = Widgets.newComposite(composite, SWT.H_SCROLL | SWT.V_SCROLL);
      subComposite.setLayout(new TableLayout(1.0, new double[] {0.0, 1.0}));
      Widgets.layout(subComposite, 1, 0, TableLayoutData.NSWE);
      {
        widgetLineNumbers = Widgets.newTextView(subComposite, SWT.RIGHT | SWT.BORDER | SWT.MULTI);
        widgetLineNumbers.setForeground(Onzen.COLOR_GRAY);
        Widgets.layout(widgetLineNumbers, 0, 0, TableLayoutData.NS, 0, 0, 0, 0, 60, SWT.DEFAULT);
        Widgets.addModifyListener(
            new WidgetListener(widgetLineNumbers, data) {
              public void modified(Control control) {
                control.setForeground((data.lines != null) ? null : Onzen.COLOR_GRAY);
              }
            });

        widgetText = Widgets.newTextView(subComposite, SWT.LEFT | SWT.BORDER | SWT.MULTI);
        widgetText.setForeground(Onzen.COLOR_GRAY);
        Widgets.layout(widgetText, 0, 1, TableLayoutData.NSWE);
        Widgets.addModifyListener(
            new WidgetListener(widgetText, data) {
              public void modified(Control control) {
                control.setForeground((data.lines != null) ? null : Onzen.COLOR_GRAY);
              }
            });
      }
      widgetHorizontalScrollBar = subComposite.getHorizontalBar();
      widgetVerticalScrollBar = subComposite.getVerticalBar();

      subComposite = Widgets.newComposite(composite);
      subComposite.setLayout(new TableLayout(1.0, new double[] {0.0, 1.0}));
      Widgets.layout(subComposite, 2, 0, TableLayoutData.NSWE);
      {
        label = Widgets.newLabel(subComposite, "Find:", SWT.NONE, Settings.keyFind);
        Widgets.layout(label, 0, 0, TableLayoutData.W);

        widgetFind = Widgets.newText(subComposite, SWT.SEARCH | SWT.ICON_CANCEL);
        widgetFind.setMessage("Enter text to find");
        Widgets.layout(widgetFind, 0, 1, TableLayoutData.WE);

        widgetFindPrev = Widgets.newButton(subComposite, Onzen.IMAGE_ARROW_UP);
        widgetFindPrev.setEnabled(false);
        Widgets.layout(widgetFindPrev, 0, 2, TableLayoutData.NSW);
        Widgets.addModifyListener(
            new WidgetListener(widgetFindPrev, data) {
              public void modified(Control control) {
                Widgets.setEnabled(control, (data.lines != null));
              }
            });
        widgetFindPrev.setToolTipText(
            "Find previous occurrence of text ["
                + Widgets.acceleratorToText(Settings.keyFindPrev)
                + "].");

        widgetFindNext = Widgets.newButton(subComposite, Onzen.IMAGE_ARROW_DOWN);
        widgetFindNext.setEnabled(false);
        Widgets.layout(widgetFindNext, 0, 3, TableLayoutData.NSW);
        Widgets.addModifyListener(
            new WidgetListener(widgetFindNext, data) {
              public void modified(Control control) {
                Widgets.setEnabled(control, (data.lines != null));
              }
            });
        widgetFindNext.setToolTipText(
            "Find next occurrence of text  ["
                + Widgets.acceleratorToText(Settings.keyFindNext)
                + "].");
      }
    }

    // buttons
    composite = Widgets.newComposite(dialog);
    composite.setLayout(new TableLayout(0.0, 1.0));
    Widgets.layout(composite, 1, 0, TableLayoutData.WE, 0, 0, 4);
    {
      button = Widgets.newButton(composite, "Save as...");
      Widgets.layout(
          button, 0, 0, TableLayoutData.W, 0, 0, 0, 0, SWT.DEFAULT, SWT.DEFAULT, 70, SWT.DEFAULT);
      button.addSelectionListener(
          new SelectionListener() {
            public void widgetDefaultSelected(SelectionEvent selectionEvent) {}

            public void widgetSelected(SelectionEvent selectionEvent) {
              // get file name
              String fileName = Dialogs.fileSave(dialog, "Save file", "", new String[] {"*"});
              if (fileName == null) {
                return;
              }

              // check if file exists: overwrite or append
              File file = new File(fileName);
              if (file.exists()) {
                switch (Dialogs.select(
                    dialog,
                    "Confirmation",
                    String.format("File '%s' already exists.", fileName),
                    new String[] {"Overwrite", "Append", "Cancel"},
                    2)) {
                  case 0:
                    if (!file.delete()) {
                      Dialogs.error(dialog, "Cannot delete file!");
                      return;
                    }
                  case 1:
                    break;
                  case 2:
                    return;
                }
              }

              PrintWriter output = null;
              try {
                // open file
                output = new PrintWriter(new FileWriter(file, true));

                // write/append file
                for (String line : data.lines) {
                  output.println(line);
                }

                // close file
                output.close();
              } catch (IOException exception) {
                Dialogs.error(
                    dialog,
                    "Cannot write file '" + file.getName() + "' (error: " + exception.getMessage());
                return;
              } finally {
                if (output != null) output.close();
              }
            }
          });

      widgetClose = Widgets.newButton(composite, "Close");
      Widgets.layout(
          widgetClose,
          0,
          1,
          TableLayoutData.E,
          0,
          0,
          0,
          0,
          SWT.DEFAULT,
          SWT.DEFAULT,
          70,
          SWT.DEFAULT);
      widgetClose.addSelectionListener(
          new SelectionListener() {
            public void widgetDefaultSelected(SelectionEvent selectionEvent) {}

            public void widgetSelected(SelectionEvent selectionEvent) {
              Settings.geometryView = dialog.getSize();

              Dialogs.close(dialog, false);
            }
          });
    }

    // listeners
    widgetRevision.addSelectionListener(
        new SelectionListener() {
          public void widgetDefaultSelected(SelectionEvent selectionEvent) {}

          public void widgetSelected(SelectionEvent selectionEvent) {
            Combo widget = (Combo) selectionEvent.widget;

            int index = widget.getSelectionIndex();
            if ((data.revisionNames != null)
                && (index >= 0)
                && (index < data.revisionNames.length)) {
              show(data.revisionNames[index]);
            }
          }
        });
    widgetRevisionPrev.addSelectionListener(
        new SelectionListener() {
          public void widgetDefaultSelected(SelectionEvent selectionEvent) {}

          public void widgetSelected(SelectionEvent selectionEvent) {
            int index = widgetRevision.getSelectionIndex();
            if (index > 0) {
              show(data.revisionNames[index - 1]);
            }
          }
        });
    widgetRevisionNext.addSelectionListener(
        new SelectionListener() {
          public void widgetDefaultSelected(SelectionEvent selectionEvent) {}

          public void widgetSelected(SelectionEvent selectionEvent) {
            int index = widgetRevision.getSelectionIndex();
            if ((data.revisionNames != null) && (index < data.revisionNames.length - 1)) {
              show(data.revisionNames[index + 1]);
            }
          }
        });

    listener =
        new Listener() {
          public void handleEvent(Event event) {
            StyledText widget = (StyledText) event.widget;
            int topIndex = widget.getTopIndex();
            // Dprintf.dprintf("%d %d",widget.getTopPixel(),widgetText.getTopPixel());

            widgetText.setTopIndex(topIndex);
            widgetText.setCaretOffset(widgetText.getOffsetAtLine(topIndex));
          }
        };
    widgetLineNumbers.addListener(SWT.KeyDown, listener);
    widgetLineNumbers.addListener(SWT.KeyUp, listener);
    widgetLineNumbers.addListener(SWT.MouseDown, listener);
    widgetLineNumbers.addListener(SWT.MouseUp, listener);
    widgetLineNumbers.addListener(SWT.MouseMove, listener);
    widgetLineNumbers.addListener(SWT.Resize, listener);

    listener =
        new Listener() {
          public void handleEvent(Event event) {
            StyledText widget = (StyledText) event.widget;
            int topIndex = widget.getTopIndex();
            // Dprintf.dprintf("widget=%s: %d",widget,widget.getTopIndex());

            widgetLineNumbers.setTopIndex(topIndex);
            widgetVerticalScrollBar.setSelection(topIndex);
          }
        };
    widgetText.addListener(SWT.KeyDown, listener);
    widgetText.addListener(SWT.KeyUp, listener);
    widgetText.addListener(SWT.MouseDown, listener);
    widgetText.addListener(SWT.MouseUp, listener);
    widgetText.addListener(SWT.MouseMove, listener);
    widgetText.addListener(SWT.Resize, listener);
    widgetText.addLineStyleListener(
        new LineStyleListener() {
          public void lineGetStyle(LineStyleEvent lineStyleEvent) {
            // Dprintf.dprintf("x %d %s",lineStyleEvent.lineOffset,lineStyleEvent.lineText);
            String findText = widgetFind.getText().toLowerCase();
            int findTextLength = findText.length();
            if (findTextLength > 0) {
              ArrayList<StyleRange> styleRangeList = new ArrayList<StyleRange>();
              int index = 0;
              while ((index = lineStyleEvent.lineText.toLowerCase().indexOf(findText, index))
                  >= 0) {
                styleRangeList.add(
                    new StyleRange(
                        lineStyleEvent.lineOffset + index,
                        findTextLength,
                        COLOR_VIEW_SEARCH_TEXT,
                        COLOR_VIEW_SEARCH_BACKGROUND));
                index += findTextLength;
              }
              lineStyleEvent.styles = styleRangeList.toArray(new StyleRange[styleRangeList.size()]);
              // Dprintf.dprintf("lineStyleEvent.styles=%d",lineStyleEvent.styles.length);
            } else {
              lineStyleEvent.styles = null;
            }
          }
        });
    widgetText.addKeyListener(
        new KeyListener() {
          public void keyPressed(KeyEvent keyEvent) {
            if (Widgets.isAccelerator(keyEvent, SWT.CTRL + 'c')) {
              Widgets.setClipboard(clipboard, widgetText.getSelectionText());
            }
          }

          public void keyReleased(KeyEvent keyEvent) {}
        });
    widgetHorizontalScrollBar.addSelectionListener(
        new SelectionListener() {
          public void widgetDefaultSelected(SelectionEvent selectionEvent) {}

          public void widgetSelected(SelectionEvent selectionEvent) {
            ScrollBar widget = (ScrollBar) selectionEvent.widget;
            int index = widget.getSelection();

            // sync text widget
            widgetText.setHorizontalIndex(index);
          }
        });
    widgetVerticalScrollBar.addSelectionListener(
        new SelectionListener() {
          public void widgetDefaultSelected(SelectionEvent selectionEvent) {}

          public void widgetSelected(SelectionEvent selectionEvent) {
            ScrollBar widget = (ScrollBar) selectionEvent.widget;
            int index = widget.getSelection();
            // Dprintf.dprintf("widget=%s: %d %d
            // %d",widget,widget.getSelection(),widget.getMinimum(),widget.getMaximum());

            // sync  number text widget, text widget
            widgetLineNumbers.setTopIndex(index);
            widgetText.setTopIndex(index);
          }
        });

    widgetFind.addSelectionListener(
        new SelectionListener() {
          public void widgetDefaultSelected(SelectionEvent selectionEvent) {
            findNext(widgetText, widgetFind);
          }

          public void widgetSelected(SelectionEvent selectionEvent) {}
        });
    widgetFind.addKeyListener(
        new KeyListener() {
          public void keyPressed(KeyEvent keyEvent) {}

          public void keyReleased(KeyEvent keyEvent) {
            updateViewFindText(widgetText, widgetFind);
          }
        });
    widgetFindPrev.addSelectionListener(
        new SelectionListener() {
          public void widgetDefaultSelected(SelectionEvent selectionEvent) {}

          public void widgetSelected(SelectionEvent selectionEvent) {
            findPrev(widgetText, widgetFind);
          }
        });
    widgetFindNext.addSelectionListener(
        new SelectionListener() {
          public void widgetDefaultSelected(SelectionEvent selectionEvent) {}

          public void widgetSelected(SelectionEvent selectionEvent) {
            findNext(widgetText, widgetFind);
          }
        });

    KeyListener keyListener =
        new KeyListener() {
          public void keyPressed(KeyEvent keyEvent) {
            if (Widgets.isAccelerator(keyEvent, Settings.keyFind)) {
              widgetFind.forceFocus();
            } else if (Widgets.isAccelerator(keyEvent, Settings.keyFindPrev)) {
              Widgets.invoke(widgetFindPrev);
            } else if (Widgets.isAccelerator(keyEvent, Settings.keyFindNext)) {
              Widgets.invoke(widgetFindNext);
            }
          }

          public void keyReleased(KeyEvent keyEvent) {}
        };
    widgetText.addKeyListener(keyListener);
    widgetFind.addKeyListener(keyListener);
    widgetFindPrev.addKeyListener(keyListener);
    widgetFindNext.addKeyListener(keyListener);

    dialog.addListener(
        USER_EVENT_NEW_REVISION,
        new Listener() {
          public void handleEvent(Event event) {}
        });

    // show dialog
    Dialogs.show(dialog, Settings.geometryView, Settings.setWindowLocation);

    // start show file
    show(revision);

    // start add revisions (only if single file is seleccted)
    Background.run(
        new BackgroundRunnable(fileData, revision) {
          public void run(FileData fileData, final String revision) {
            // get revisions
            repositoryTab.setStatusText("Get revisions for '%s'...", fileData.getFileName());
            try {
              data.revisionNames = repositoryTab.repository.getRevisionNames(fileData);
            } catch (RepositoryException exception) {
              final String exceptionMessage = exception.getMessage();
              display.syncExec(
                  new Runnable() {
                    public void run() {
                      Dialogs.error(
                          dialog, String.format("Getting revisions fail: %s", exceptionMessage));
                    }
                  });
              return;
            } finally {
              repositoryTab.clearStatusText();
            }

            if (data.revisionNames.length > 0) {
              // add revisions
              if (!dialog.isDisposed()) {
                display.syncExec(
                    new Runnable() {
                      public void run() {
                        if (!widgetRevision.isDisposed()) {
                          int selectIndex = -1;
                          for (int z = 0; z < data.revisionNames.length; z++) {
                            widgetRevision.add(data.revisionNames[z]);
                            if ((revision != null) && revision.equals(data.revisionNames[z])) {
                              selectIndex = z;
                            }
                          }
                          widgetRevision.add(repositoryTab.repository.getLastRevision());
                          if ((revision != null)
                              && revision.equals(repositoryTab.repository.getLastRevision()))
                            selectIndex = data.revisionNames.length;
                          if (selectIndex == -1) selectIndex = data.revisionNames.length;
                          widgetRevision.select(selectIndex);
                        }

                        // notify modification
                        Widgets.modified(data);
                      }
                    });
              }
            }
          }
        });
  }
Ejemplo n.º 15
0
 @Test
 public void testPreserveValues() {
   Combo combo = new Combo(shell, SWT.READ_ONLY);
   Fixture.markInitialized(display);
   // Test preserving a combo with no items and (naturally) no selection
   Fixture.preserveWidgets();
   WidgetAdapter adapter = WidgetUtil.getAdapter(combo);
   String[] items = ((String[]) adapter.getPreserved(PROP_ITEMS));
   assertEquals(0, items.length);
   assertEquals(new Integer(-1), adapter.getPreserved(PROP_SELECTION_INDEX));
   assertNull(adapter.getPreserved(ComboLCA.PROP_TEXT_LIMIT));
   Object visibleItemCount = adapter.getPreserved(ComboLCA.PROP_VISIBLE_ITEM_COUNT);
   assertEquals(new Integer(combo.getVisibleItemCount()), visibleItemCount);
   assertEquals(Boolean.FALSE, adapter.getPreserved(ComboLCA.PROP_EDITABLE));
   assertEquals(new Point(0, 0), adapter.getPreserved(ComboLCA.PROP_SELECTION));
   // Test preserving combo with items were one is selected
   Fixture.clearPreserved();
   combo.add("item 1");
   combo.add("item 2");
   combo.select(1);
   combo.setListVisible(true);
   SelectionListener selectionListener = new SelectionAdapter() {};
   combo.addSelectionListener(selectionListener);
   combo.addModifyListener(
       new ModifyListener() {
         public void modifyText(ModifyEvent event) {}
       });
   Fixture.preserveWidgets();
   adapter = WidgetUtil.getAdapter(combo);
   items = ((String[]) adapter.getPreserved(PROP_ITEMS));
   assertEquals(2, items.length);
   assertEquals("item 1", items[0]);
   assertEquals("item 2", items[1]);
   assertEquals(new Integer(1), adapter.getPreserved(PROP_SELECTION_INDEX));
   visibleItemCount = adapter.getPreserved(ComboLCA.PROP_VISIBLE_ITEM_COUNT);
   assertEquals(new Integer(combo.getVisibleItemCount()), visibleItemCount);
   assertEquals("item 2", adapter.getPreserved(Props.TEXT));
   assertEquals(Boolean.FALSE, adapter.getPreserved(ComboLCA.PROP_EDITABLE));
   Fixture.clearPreserved();
   // foreground background font
   Color background = new Color(display, 122, 33, 203);
   combo.setBackground(background);
   Color foreground = new Color(display, 211, 178, 211);
   combo.setForeground(foreground);
   Font font = new Font(display, "font", 12, SWT.BOLD);
   combo.setFont(font);
   Fixture.preserveWidgets();
   adapter = WidgetUtil.getAdapter(combo);
   assertEquals(background, adapter.getPreserved(Props.BACKGROUND));
   assertEquals(foreground, adapter.getPreserved(Props.FOREGROUND));
   assertEquals(font, adapter.getPreserved(Props.FONT));
   Fixture.clearPreserved();
   // tooltiptext
   Fixture.preserveWidgets();
   adapter = WidgetUtil.getAdapter(combo);
   assertEquals(null, combo.getToolTipText());
   Fixture.clearPreserved();
   combo.setToolTipText("some text");
   Fixture.preserveWidgets();
   adapter = WidgetUtil.getAdapter(combo);
   assertEquals("some text", combo.getToolTipText());
   Fixture.clearPreserved();
 }