Example #1
0
 /**
  * Tests if the Combo value is empty. If so, it adds an error color to the background of the cell.
  *
  * @param combo the combo to validate
  * @param validSelectionIndex the first item that is a "valid" selection
  * @return boolean
  */
 public static boolean validateCombo(Combo combo, int validSelectionIndex) {
   int selectionIndex = Math.max(validSelectionIndex, 0);
   String text = combo.getText();
   if (text == null || text.length() == 0 || combo.getSelectionIndex() < selectionIndex) {
     combo.setBackground(backgroundErrorColor);
     return false;
   }
   combo.setBackground(null);
   return true;
 }
Example #2
0
  private static void createCombo(final Group group) {
    group.setLayout(new GridLayout(2, false));
    group.setText("Combo widget");

    final Label lbl0 = new Label(group, SWT.NONE);
    lbl0.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false));
    lbl0.setText("No prompt :");

    final Combo combo0 = new Combo(group, SWT.BORDER);
    combo0.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));

    final Label lbl1 = new Label(group, SWT.NONE);
    lbl1.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false));
    lbl1.setText("Simple text prompt :");

    final Combo combo1 = new Combo(group, SWT.BORDER);
    combo1.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
    PromptSupport.setPrompt("Type anything you want", combo1);

    final Label lbl2 = new Label(group, SWT.NONE);
    lbl2.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false));
    lbl2.setText("Other style (bold) :");

    final Combo combo2 = new Combo(group, SWT.BORDER);
    combo2.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
    PromptSupport.setPrompt("Type anything you want in bold", combo2);
    PromptSupport.setFontStyle(SWT.BOLD, combo2);

    final Label lbl3 = new Label(group, SWT.NONE);
    lbl3.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false));
    lbl3.setText("Behaviour highlight :");

    final Combo combo3 = new Combo(group, SWT.BORDER);
    combo3.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
    PromptSupport.setPrompt("Type anything you want", combo3);
    PromptSupport.setFocusBehavior(FocusBehavior.HIGHLIGHT_PROMPT, combo3);

    final Label lbl4 = new Label(group, SWT.NONE);
    lbl4.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false));
    lbl4.setText("Change colors :");

    final Combo combo4 = new Combo(group, SWT.BORDER);
    combo4.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
    PromptSupport.setPrompt("Type anything you want", combo4);
    PromptSupport.setForeground(combo4.getDisplay().getSystemColor(SWT.COLOR_YELLOW), combo4);
    PromptSupport.setBackground(combo4.getDisplay().getSystemColor(SWT.COLOR_BLACK), combo4);

    final Label lbl5 = new Label(group, SWT.NONE);
    lbl5.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false));
    lbl5.setText("Change when widget is initialized :");

    final Combo combo5 = new Combo(group, SWT.BORDER);
    combo5.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
    combo5.setText("Remove what is typed...");
    combo5.setBackground(combo4.getDisplay().getSystemColor(SWT.COLOR_BLACK));
    combo5.setForeground(combo4.getDisplay().getSystemColor(SWT.COLOR_YELLOW));

    PromptSupport.setPrompt("Type anything you want", combo5);
    PromptSupport.setForeground(combo4.getDisplay().getSystemColor(SWT.COLOR_DARK_BLUE), combo5);
    PromptSupport.setBackground(combo4.getDisplay().getSystemColor(SWT.COLOR_WHITE), combo5);
  }
Example #3
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();
    }
  }
Example #4
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();
 }