Ignore:
Timestamp:
08/17/12 11:38:43 (12 years ago)
Author:
sherbold
Message:
  • adapted to quest coding style
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/quest-ui-swt/src/main/java/de/ugoe/cs/quest/ui/swt/ModelPropertiesDialog.java

    r526 r570  
     1 
    12package de.ugoe.cs.quest.ui.swt; 
    23 
     
    2223public class ModelPropertiesDialog extends Dialog { 
    2324 
    24         private IStochasticProcess process; 
    25          
    26         protected Shell shlModelProperties; 
     25    private IStochasticProcess process; 
    2726 
    28         /** 
    29          * Create the dialog. 
    30          * @param parent 
    31          * @param style 
    32          */ 
    33         public ModelPropertiesDialog(Shell parent, int style) { 
    34                 super(parent, style); 
    35                 setText("SWT Dialog"); 
    36         } 
     27    protected Shell shlModelProperties; 
    3728 
    38         /** 
    39          * Open the dialog. 
    40          */ 
    41         public void open() { 
    42                 createContents(); 
    43                 shlModelProperties.open(); 
    44                 shlModelProperties.layout(); 
    45                 Display display = getParent().getDisplay(); 
    46                 while (!shlModelProperties.isDisposed()) { 
    47                         if (!display.readAndDispatch()) { 
    48                                 display.sleep(); 
    49                         } 
    50                 } 
    51         } 
     29    /** 
     30     * Create the dialog. 
     31     *  
     32     * @param parent 
     33     * @param style 
     34     */ 
     35    public ModelPropertiesDialog(Shell parent, int style) { 
     36        super(parent, style); 
     37        setText("SWT Dialog"); 
     38    } 
    5239 
    53         /** 
    54          * Create contents of the dialog. 
    55          */ 
    56         private void createContents() { 
    57                 shlModelProperties = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.RESIZE); 
    58                 shlModelProperties.setSize(230, 318); 
    59                 shlModelProperties.setText("Model Properties"); 
    60                 shlModelProperties.setLayout(new GridLayout(2, false)); 
    61                  
    62                 Group grpEvents = new Group(shlModelProperties, SWT.NONE); 
    63                 FillLayout fl_grpEvents = new FillLayout(SWT.HORIZONTAL); 
    64                 fl_grpEvents.marginHeight = 5; 
    65                 fl_grpEvents.marginWidth = 5; 
    66                 grpEvents.setLayout(fl_grpEvents); 
    67                 grpEvents.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); 
    68                 grpEvents.setText("Events"); 
    69                  
    70                 List list = new List(grpEvents, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); 
    71                 for( String symbol : process.getSymbolStrings() ) { 
    72                         if( symbol==null ) { 
    73                                 list.add("null"); 
    74                         } else { 
    75                                 list.add(symbol); 
    76                         } 
    77                 } 
    78                  
    79                 Group grpStatistics = new Group(shlModelProperties, SWT.NONE); 
    80                 grpStatistics.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1)); 
    81                 grpStatistics.setText("Statistics"); 
    82                 grpStatistics.setLayout(new GridLayout(2, false)); 
    83                  
    84                 Label lblNumEvents = new Label(grpStatistics, SWT.NONE); 
    85                 lblNumEvents.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1)); 
    86                 lblNumEvents.setText("Num. Events"); 
    87                  
    88                 Label label = new Label(grpStatistics, SWT.RIGHT); 
    89                 label.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1)); 
    90                 label.setText(""+process.getNumSymbols()); 
    91                  
    92                 Label lblNumTrieLeafs = new Label(grpStatistics, SWT.NONE); 
    93                 lblNumTrieLeafs.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1)); 
    94                 lblNumTrieLeafs.setText("Size (Flattend FOM)"); 
    95                  
    96                 Label label_1 = new Label(grpStatistics, SWT.RIGHT); 
    97                 label_1.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1)); 
    98                 label_1.setText(""+process.getNumFOMStates()); 
    99                  
    100                 Label lblEntropy = new Label(grpStatistics, SWT.NONE); 
    101                 lblEntropy.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1)); 
    102                 lblEntropy.setText("Entropy"); 
    103                  
    104                 final Label label_2 = new Label(grpStatistics, SWT.RIGHT); 
    105                 label_2.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1)); 
    106                 label_2.setText("####"); 
    107                  
    108                 Button btnCalculateEntropy = new Button(shlModelProperties, SWT.NONE); 
    109                 btnCalculateEntropy.addSelectionListener(new SelectionAdapter() { 
    110                         @Override 
    111                         public void widgetSelected(SelectionEvent e) { 
    112                                 if( process instanceof FirstOrderMarkovModel) { 
    113                                         label_2.setText(""+((FirstOrderMarkovModel) process).calcEntropy()); 
    114                                 } else { 
    115                                         MessageBox messageBox = new MessageBox(shlModelProperties, SWT.NONE); 
    116                                         messageBox.setText("Feature Not Available"); 
    117                                         messageBox.setMessage("The feature is currently only available for first-order Markov models."); 
    118                                         messageBox.open(); 
    119                                 } 
    120                         } 
    121                 }); 
    122                 btnCalculateEntropy.setText("Calculate Entropy"); 
    123                  
    124                 Button btnClose = new Button(shlModelProperties, SWT.NONE); 
    125                 btnClose.addSelectionListener(new SelectionAdapter() { 
    126                         @Override 
    127                         public void widgetSelected(SelectionEvent e) { 
    128                                 shlModelProperties.dispose(); 
    129                         } 
    130                 }); 
    131                 btnClose.setText("Close"); 
     40    /** 
     41     * Open the dialog. 
     42     */ 
     43    public void open() { 
     44        createContents(); 
     45        shlModelProperties.open(); 
     46        shlModelProperties.layout(); 
     47        Display display = getParent().getDisplay(); 
     48        while (!shlModelProperties.isDisposed()) { 
     49            if (!display.readAndDispatch()) { 
     50                display.sleep(); 
     51            } 
     52        } 
     53    } 
    13254 
    133         } 
    134          
    135         public void setStochasticProcess(IStochasticProcess process) { 
    136                 this.process = process; 
    137         } 
     55    /** 
     56     * Create contents of the dialog. 
     57     */ 
     58    private void createContents() { 
     59        shlModelProperties = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.RESIZE); 
     60        shlModelProperties.setSize(230, 318); 
     61        shlModelProperties.setText("Model Properties"); 
     62        shlModelProperties.setLayout(new GridLayout(2, false)); 
     63 
     64        Group grpEvents = new Group(shlModelProperties, SWT.NONE); 
     65        FillLayout fl_grpEvents = new FillLayout(SWT.HORIZONTAL); 
     66        fl_grpEvents.marginHeight = 5; 
     67        fl_grpEvents.marginWidth = 5; 
     68        grpEvents.setLayout(fl_grpEvents); 
     69        grpEvents.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); 
     70        grpEvents.setText("Events"); 
     71 
     72        List list = new List(grpEvents, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); 
     73        for (String symbol : process.getSymbolStrings()) { 
     74            if (symbol == null) { 
     75                list.add("null"); 
     76            } 
     77            else { 
     78                list.add(symbol); 
     79            } 
     80        } 
     81 
     82        Group grpStatistics = new Group(shlModelProperties, SWT.NONE); 
     83        grpStatistics.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1)); 
     84        grpStatistics.setText("Statistics"); 
     85        grpStatistics.setLayout(new GridLayout(2, false)); 
     86 
     87        Label lblNumEvents = new Label(grpStatistics, SWT.NONE); 
     88        lblNumEvents.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1)); 
     89        lblNumEvents.setText("Num. Events"); 
     90 
     91        Label label = new Label(grpStatistics, SWT.RIGHT); 
     92        label.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1)); 
     93        label.setText("" + process.getNumSymbols()); 
     94 
     95        Label lblNumTrieLeafs = new Label(grpStatistics, SWT.NONE); 
     96        lblNumTrieLeafs.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1)); 
     97        lblNumTrieLeafs.setText("Size (Flattend FOM)"); 
     98 
     99        Label label_1 = new Label(grpStatistics, SWT.RIGHT); 
     100        label_1.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1)); 
     101        label_1.setText("" + process.getNumFOMStates()); 
     102 
     103        Label lblEntropy = new Label(grpStatistics, SWT.NONE); 
     104        lblEntropy.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1)); 
     105        lblEntropy.setText("Entropy"); 
     106 
     107        final Label label_2 = new Label(grpStatistics, SWT.RIGHT); 
     108        label_2.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1)); 
     109        label_2.setText("####"); 
     110 
     111        Button btnCalculateEntropy = new Button(shlModelProperties, SWT.NONE); 
     112        btnCalculateEntropy.addSelectionListener(new SelectionAdapter() { 
     113            @Override 
     114            public void widgetSelected(SelectionEvent e) { 
     115                if (process instanceof FirstOrderMarkovModel) { 
     116                    label_2.setText("" + ((FirstOrderMarkovModel) process).calcEntropy()); 
     117                } 
     118                else { 
     119                    MessageBox messageBox = new MessageBox(shlModelProperties, SWT.NONE); 
     120                    messageBox.setText("Feature Not Available"); 
     121                    messageBox 
     122                        .setMessage("The feature is currently only available for first-order Markov models."); 
     123                    messageBox.open(); 
     124                } 
     125            } 
     126        }); 
     127        btnCalculateEntropy.setText("Calculate Entropy"); 
     128 
     129        Button btnClose = new Button(shlModelProperties, SWT.NONE); 
     130        btnClose.addSelectionListener(new SelectionAdapter() { 
     131            @Override 
     132            public void widgetSelected(SelectionEvent e) { 
     133                shlModelProperties.dispose(); 
     134            } 
     135        }); 
     136        btnClose.setText("Close"); 
     137 
     138    } 
     139 
     140    public void setStochasticProcess(IStochasticProcess process) { 
     141        this.process = process; 
     142    } 
    138143} 
Note: See TracChangeset for help on using the changeset viewer.