SHARE
TWEET

Untitled

a guest Aug 14th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. shell.open();
  2.         shell.layout();
  3.         shell.pack(); //for wrap the dialog size to it's content width and height.
  4.  
  5.         //the dialog must be centered after doing shell.pack();
  6.         Rectangle parentSize = getParent().getBounds();
  7.         Rectangle shellSize = shell.getBounds();
  8.         int x = parentSize.x + (parentSize.width - shellSize.width) / 2;
  9.         int y = (int) (parentSize.y + (parentSize.height - shellSize.height) / 3.5);
  10.         shell.setLocation(new Point(x, y));
  11.      
  12. /**
  13.  * Create the dialog.
  14.  * @param parent
  15.  * @param style
  16.  */
  17. public SelectTwoMatrixNumbersDialog(Shell parent, int style, JointBet jointBet) {
  18.     super(parent, style);
  19.     setText("Elegir Números");
  20.     this.jointBet = jointBet;
  21. }
  22.  
  23. /**
  24.  * Open the dialog.
  25.  * @return the result
  26.  */
  27. public boolean open() {
  28.     createContents();
  29.  
  30.     matrixNumbers1 = new ArrayList<Integer>();
  31.     matrixNumbers2 = new ArrayList<Integer>();
  32.  
  33.     GridLayout gl_shell = new GridLayout(1, false);
  34.     gl_shell.marginWidth = 20;
  35.     gl_shell.marginHeight = 20;
  36.     shell.setLayout(gl_shell);
  37.  
  38.     Composite contentComposite = new Composite(shell, SWT.NONE);
  39.     contentComposite.setLayout(new GridLayout(1, false));
  40.     contentComposite.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true, 1, 1));
  41.  
  42.     Label lblNumbers = new Label(contentComposite, SWT.NONE);
  43.     lblNumbers.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
  44.     lblNumbers.setText("Números:");
  45.  
  46.     Composite numbersContainerComposite = new Composite(contentComposite, SWT.NONE);
  47.     numbersContainerComposite.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
  48.  
  49.     //variable values depending of type of game
  50.     boolean firstCellEmpty = jointBet.getGameType().getNumbersMatrixArray()[0].isFirstCellEmpty();      
  51.     int matrix1Rows = jointBet.getGameType().getNumbersMatrixArray()[0].getRows();
  52.     int matrix1Columns = jointBet.getGameType().getNumbersMatrixArray()[0].getColumns();
  53.     int matrix1MinNumber = jointBet.getGameType().getNumbersMatrixArray()[0].getMinNumber();
  54.     int matrix1MaxNumber = jointBet.getGameType().getNumbersMatrixArray()[0].getMaxNumber();        
  55.     GridLayout gl_numbersContainerComposite = new GridLayout(2, false);
  56.     gl_numbersContainerComposite.horizontalSpacing = 15;
  57.     numbersContainerComposite.setLayout(gl_numbersContainerComposite);
  58.     numbersMatrixWidget1 = new NumbersMatrixWidget(numbersContainerComposite, SWT.BORDER, false, jointBet.getGameType().getNumbersMatrixArray()[0].getNumbers(), matrix1Rows, matrix1Columns, matrix1MinNumber, matrix1MaxNumber, firstCellEmpty);
  59.  
  60.     //variable values depending of type of game
  61.     firstCellEmpty = jointBet.getGameType().getNumbersMatrixArray()[1].isFirstCellEmpty();      
  62.     int matrix2Rows = jointBet.getGameType().getNumbersMatrixArray()[1].getRows();
  63.     int matrix2Columns = jointBet.getGameType().getNumbersMatrixArray()[1].getColumns();
  64.     int matrix2MinNumber = jointBet.getGameType().getNumbersMatrixArray()[1].getMinNumber();
  65.     int matrix2MaxNumber = jointBet.getGameType().getNumbersMatrixArray()[1].getMaxNumber();
  66.     numbersMatrixWidget2 = new NumbersMatrixWidget(numbersContainerComposite, SWT.BORDER, false, jointBet.getGameType().getNumbersMatrixArray()[1].getNumbers(), matrix2Rows, matrix2Columns, matrix2MinNumber, matrix2MaxNumber, firstCellEmpty);
  67.     numbersMatrixWidget2.setLayoutData(new GridData(SWT.LEFT, SWT.BOTTOM, false, false, 1, 1));
  68.  
  69.     Composite fillNumbersComposite = new Composite(shell, SWT.NONE);
  70.     fillNumbersComposite.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
  71.     fillNumbersComposite.setLayout(new GridLayout(1, false));
  72.  
  73.     Composite compositeFillMatrix1 = new Composite(fillNumbersComposite, SWT.NONE);
  74.     compositeFillMatrix1.setLayout(new GridLayout(4, false));
  75.  
  76.     Label lblFillMatrix1WithMostCommonNumbers1 = new Label(compositeFillMatrix1, SWT.NONE);
  77.     lblFillMatrix1WithMostCommonNumbers1.setText("Rellenar Matriz 1 con los");
  78.  
  79.     Spinner matrix1NumbersSpinner = new Spinner(compositeFillMatrix1, SWT.BORDER);
  80.     matrix1NumbersSpinner.setMaximum(jointBet.getGameType().getNumbersMatrixArray()[0].getPossibleNumbersCount());
  81.     matrix1NumbersSpinner.setMinimum(1);
  82.  
  83.     Label lblFillMatrix1WithMostCommonNumbers2 = new Label(compositeFillMatrix1, SWT.NONE);
  84.     lblFillMatrix1WithMostCommonNumbers2.setText("números mas repetidos:");
  85.  
  86.     Button btnFillMatrix1 = new Button(compositeFillMatrix1, SWT.NONE);
  87.     btnFillMatrix1.setText("Rellenar");
  88.     btnFillMatrix1.addSelectionListener(new SelectionAdapter() {
  89.         @Override
  90.         public void widgetSelected(SelectionEvent e) {
  91.             String gameType = jointBet.getGameType().getType();
  92.             int matrix = 1;
  93.             int amount = Integer.parseInt(matrix1NumbersSpinner.getText());
  94.             numbersMatrixWidget1.setNumbers(StatisticsManager.getInstance().getMostUsedNumberKeys(gameType, matrix, amount));
  95.         }
  96.     });
  97.  
  98.     Composite compositeFillMatrix2 = new Composite(fillNumbersComposite, SWT.NONE);
  99.     compositeFillMatrix2.setLayout(new GridLayout(4, false));
  100.  
  101.     Label lblFillMatrix2WithMostCommonNumbers1 = new Label(compositeFillMatrix2, SWT.NONE);
  102.     lblFillMatrix2WithMostCommonNumbers1.setText("Rellenar Matriz 2 con los");
  103.  
  104.     Spinner matrix2NumbersSpinner = new Spinner(compositeFillMatrix2, SWT.BORDER);
  105.     matrix2NumbersSpinner.setMaximum(jointBet.getGameType().getNumbersMatrixArray()[1].getPossibleNumbersCount());
  106.     matrix2NumbersSpinner.setMinimum(1);
  107.  
  108.     Label lblFillMatrix2WithMostCommonNumbers2 = new Label(compositeFillMatrix2, SWT.NONE);
  109.     lblFillMatrix2WithMostCommonNumbers2.setText("números mas repetidos:");
  110.  
  111.     Button btnFillMatrix2 = new Button(compositeFillMatrix2, SWT.NONE);
  112.     btnFillMatrix2.setText("Rellenar");
  113.     btnFillMatrix2.addSelectionListener(new SelectionAdapter() {
  114.         @Override
  115.         public void widgetSelected(SelectionEvent e) {
  116.             String gameType = jointBet.getGameType().getType();
  117.             int matrix = 2;
  118.             int amount = Integer.parseInt(matrix2NumbersSpinner.getText());
  119.             numbersMatrixWidget2.setNumbers(StatisticsManager.getInstance().getMostUsedNumberKeys(gameType, matrix, amount));
  120.         }
  121.     });
  122.  
  123.     Composite buttonsComposite = new Composite(shell, SWT.NONE);
  124.     FillLayout fl_buttonsComposite = new FillLayout(SWT.HORIZONTAL);
  125.     fl_buttonsComposite.marginHeight = 10;
  126.     fl_buttonsComposite.spacing = 40;
  127.     buttonsComposite.setLayout(fl_buttonsComposite);
  128.     GridData gd_buttonsComposite = new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1);
  129.     gd_buttonsComposite.heightHint = 45;
  130.     buttonsComposite.setLayoutData(gd_buttonsComposite);
  131.  
  132.     Button acceptButton = new Button(buttonsComposite, SWT.NONE);
  133.     acceptButton.addSelectionListener(new SelectionAdapter() {
  134.         @Override
  135.         public void widgetSelected(SelectionEvent e) {  
  136.             //matrix 1
  137.             matrixNumbers1.clear();
  138.             for (Button b : numbersMatrixWidget1.getButtons()) {
  139.                 if (b.getSelection()) {
  140.                     matrixNumbers1.add(Integer.parseInt(b.getText()));
  141.                 }
  142.             }
  143.  
  144.             //matrix 2
  145.             matrixNumbers2.clear();
  146.             for (Button b : numbersMatrixWidget2.getButtons()) {
  147.                 if (b.getSelection()) {
  148.                     matrixNumbers2.add(Integer.parseInt(b.getText()));
  149.                 }
  150.             }
  151.  
  152.             if (matrixNumbers1.size()<jointBet.getGameType().getNumbersMatrixArray()[0].getNumbersPerBet() || matrixNumbers2.size()<jointBet.getGameType().getNumbersMatrixArray()[1].getNumbersPerBet()) {
  153.                 ErrorDialog dialog = new ErrorDialog(shell, SWT.DIALOG_TRIM | SWT.PRIMARY_MODAL, "El mínimo de números es "+jointBet.getGameType().getNumbersMatrixArray()[0].getNumbersPerBet()+" + "+jointBet.getGameType().getNumbersMatrixArray()[1].getNumbersPerBet());
  154.                 dialog.open();
  155.             }else {                
  156.                 Collections.sort(matrixNumbers1);
  157.                 Collections.sort(matrixNumbers2);
  158.  
  159.                 jointBet.setNumbers(0, matrixNumbers1);
  160.                 jointBet.setNumbers(1, matrixNumbers2);
  161.                 DataManager.getInstance().saveData();
  162.  
  163.                 result = true;
  164.                 shell.close();
  165.             }
  166.         }
  167.     });
  168.     acceptButton.setBounds(0, 0, 75, 25);
  169.     acceptButton.setText("Aceptar");
  170.  
  171.     Button cancelButton = new Button(buttonsComposite, SWT.NONE);
  172.     cancelButton.addSelectionListener(new SelectionAdapter() {
  173.         @Override
  174.         public void widgetSelected(SelectionEvent e) {
  175.             result = false;
  176.             shell.close();
  177.         }
  178.     });
  179.     cancelButton.setBounds(0, 0, 75, 25);
  180.     cancelButton.setText("Cancelar");
  181.  
  182.     shell.setDefaultButton(acceptButton);
  183.  
  184.     shell.open();
  185.     shell.layout();
  186.     shell.pack(); //for wrap the dialog size to it's content width and height.
  187.  
  188.     //the dialog must be centered after doing shell.pack();
  189.     Rectangle parentSize = getParent().getBounds();
  190.     Rectangle shellSize = shell.getBounds();
  191.     int x = parentSize.x + (parentSize.width - shellSize.width) / 2;
  192.     int y = (int) (parentSize.y + (parentSize.height - shellSize.height) / 3.5);
  193.     shell.setLocation(new Point(x, y));
  194.  
  195.     Display display = getParent().getDisplay();
  196.     while (!shell.isDisposed()) {
  197.         if (!display.readAndDispatch()) {
  198.             display.sleep();
  199.         }
  200.     }
  201.  
  202.     return result;
  203. }
  204.  
  205. /**
  206.  * Create contents of the dialog.
  207.  */
  208. private void createContents() {
  209.     shell = new Shell(getParent(), getStyle());
  210.     shell.setText(getText());
  211. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top