~cezary-bartosiak/gephi/spread-simulator

« back to all changes in this revision

Viewing changes to ComplexGeneratorPluginUI/src/org/gephi/ui/complexgenerator/plugin/BarabasiAlbertPanel.java

  • Committer: Cezary Bartosiak
  • Date: 2011-02-21 07:47:23 UTC
  • mfrom: (2044.4.7 generators)
  • Revision ID: cezary.bartosiak@gmail.com-20110221074723-ul2u6nkg1evjvh0a
* merged with generators

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2008-2010 Gephi
 
3
 * Authors : Cezary Bartosiak
 
4
 * Website : http://www.gephi.org
 
5
 *
 
6
 * This file is part of Gephi.
 
7
 *
 
8
 * Gephi is free software: you can redistribute it and/or modify
 
9
 * it under the terms of the GNU General Public License as published by
 
10
 * the Free Software Foundation, either version 3 of the License, or
 
11
 * (at your option) any later version.
 
12
 *
 
13
 * Gephi is distributed in the hope that it will be useful,
 
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
 * GNU General Public License for more details.
 
17
 *
 
18
 * You should have received a copy of the GNU General Public License
 
19
 * along with Gephi.  If not, see <http://www.gnu.org/licenses/>.
 
20
 */
 
21
package org.gephi.ui.complexgenerator.plugin;
 
22
 
 
23
import org.gephi.lib.validation.PositiveNumberValidator;
 
24
import org.netbeans.validation.api.Problems;
 
25
import org.netbeans.validation.api.Validator;
 
26
import org.netbeans.validation.api.builtin.Validators;
 
27
import org.netbeans.validation.api.ui.ValidationGroup;
 
28
import org.netbeans.validation.api.ui.ValidationPanel;
 
29
 
 
30
/**
 
31
 *
 
32
 *
 
33
 * @author Cezary Bartosiak
 
34
 */
 
35
public class BarabasiAlbertPanel extends javax.swing.JPanel {
 
36
 
 
37
    /** Creates new form BarabasiAlbertPanel */
 
38
    public BarabasiAlbertPanel() {
 
39
        initComponents();
 
40
    }
 
41
 
 
42
        public static ValidationPanel createValidationPanel(BarabasiAlbertPanel innerPanel) {
 
43
                ValidationPanel validationPanel = new ValidationPanel();
 
44
                if (innerPanel == null)
 
45
                        innerPanel = new BarabasiAlbertPanel();
 
46
                validationPanel.setInnerComponent(innerPanel);
 
47
 
 
48
                ValidationGroup group = validationPanel.getValidationGroup();
 
49
 
 
50
                group.add(innerPanel.NField, Validators.REQUIRE_NON_EMPTY_STRING,
 
51
                                new PositiveNumberValidator());
 
52
                group.add(innerPanel.m0Field, Validators.REQUIRE_NON_EMPTY_STRING,
 
53
                                new PositiveNumberValidator());
 
54
                group.add(innerPanel.m0Field, Validators.REQUIRE_NON_EMPTY_STRING,
 
55
                                new m0Validator(innerPanel));
 
56
                group.add(innerPanel.MField, Validators.REQUIRE_NON_EMPTY_STRING,
 
57
                                new PositiveNumberValidator());
 
58
                group.add(innerPanel.MField, Validators.REQUIRE_NON_EMPTY_STRING,
 
59
                                new MValidator(innerPanel));
 
60
 
 
61
                return validationPanel;
 
62
        }
 
63
 
 
64
        private static class m0Validator implements Validator<String> {
 
65
                private BarabasiAlbertPanel innerPanel;
 
66
 
 
67
                public m0Validator(BarabasiAlbertPanel innerPanel) {
 
68
                        this.innerPanel = innerPanel;
 
69
                }
 
70
 
 
71
                @Override
 
72
                public boolean validate(Problems problems, String compName, String model) {
 
73
                        boolean result = false;
 
74
 
 
75
                        try {
 
76
                                Integer N  = Integer.parseInt(innerPanel.NField.getText());
 
77
                                Integer m0 = Integer.parseInt(innerPanel.m0Field.getText());
 
78
                                result = m0 < N;
 
79
                        }
 
80
                        catch (Exception e) { }
 
81
                        if (!result) {
 
82
                                String message = "<html>m0 &lt; N</html>";
 
83
                                problems.add(message);
 
84
                        }
 
85
 
 
86
                        return result;
 
87
                }
 
88
    }
 
89
 
 
90
        private static class MValidator implements Validator<String> {
 
91
                private BarabasiAlbertPanel innerPanel;
 
92
 
 
93
                public MValidator(BarabasiAlbertPanel innerPanel) {
 
94
                        this.innerPanel = innerPanel;
 
95
                }
 
96
 
 
97
                @Override
 
98
                public boolean validate(Problems problems, String compName, String model) {
 
99
                        boolean result = false;
 
100
 
 
101
                        try {
 
102
                                Integer m0 = Integer.parseInt(innerPanel.m0Field.getText());
 
103
                                Integer M  = Integer.parseInt(innerPanel.MField.getText());
 
104
                                result = M <= m0;
 
105
                        }
 
106
                        catch (Exception e) { }
 
107
                        if (!result) {
 
108
                                String message = "<html>M &lt;= m0</html>";
 
109
                                problems.add(message);
 
110
                        }
 
111
 
 
112
                        return result;
 
113
                }
 
114
    }
 
115
 
 
116
    /** This method is called from within the constructor to
 
117
     * initialize the form.
 
118
     * WARNING: Do NOT modify this code. The content of this method is
 
119
     * always regenerated by the Form Editor.
 
120
     */
 
121
    @SuppressWarnings("unchecked")
 
122
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
 
123
    private void initComponents() {
 
124
 
 
125
        MLabel = new javax.swing.JLabel();
 
126
        MField = new javax.swing.JTextField();
 
127
        NField = new javax.swing.JTextField();
 
128
        m0Field = new javax.swing.JTextField();
 
129
        NLabel = new javax.swing.JLabel();
 
130
        m0Label = new javax.swing.JLabel();
 
131
        constraintsLabel = new javax.swing.JLabel();
 
132
 
 
133
        setPreferredSize(new java.awt.Dimension(451, 170));
 
134
 
 
135
        MLabel.setText(org.openide.util.NbBundle.getMessage(BarabasiAlbertPanel.class, "BarabasiAlbertPanel.MLabel.text")); // NOI18N
 
136
 
 
137
        MField.setText(org.openide.util.NbBundle.getMessage(BarabasiAlbertPanel.class, "BarabasiAlbertPanel.MField.text")); // NOI18N
 
138
 
 
139
        NField.setText(org.openide.util.NbBundle.getMessage(BarabasiAlbertPanel.class, "BarabasiAlbertPanel.NField.text")); // NOI18N
 
140
 
 
141
        m0Field.setText(org.openide.util.NbBundle.getMessage(BarabasiAlbertPanel.class, "BarabasiAlbertPanel.m0Field.text")); // NOI18N
 
142
 
 
143
        NLabel.setText(org.openide.util.NbBundle.getMessage(BarabasiAlbertPanel.class, "BarabasiAlbertPanel.NLabel.text")); // NOI18N
 
144
 
 
145
        m0Label.setText(org.openide.util.NbBundle.getMessage(BarabasiAlbertPanel.class, "BarabasiAlbertPanel.m0Label.text")); // NOI18N
 
146
 
 
147
        constraintsLabel.setText(org.openide.util.NbBundle.getMessage(BarabasiAlbertPanel.class, "BarabasiAlbertPanel.constraintsLabel.text")); // NOI18N
 
148
 
 
149
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
 
150
        this.setLayout(layout);
 
151
        layout.setHorizontalGroup(
 
152
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
153
            .addGroup(layout.createSequentialGroup()
 
154
                .addContainerGap()
 
155
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
 
156
                    .addComponent(constraintsLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
 
157
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
158
                        .addComponent(NLabel)
 
159
                        .addComponent(m0Label)
 
160
                        .addComponent(MLabel)))
 
161
                .addGap(25, 25, 25)
 
162
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
 
163
                    .addComponent(m0Field, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 161, Short.MAX_VALUE)
 
164
                    .addComponent(MField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 161, Short.MAX_VALUE)
 
165
                    .addComponent(NField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 161, Short.MAX_VALUE))
 
166
                .addContainerGap())
 
167
        );
 
168
        layout.setVerticalGroup(
 
169
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
170
            .addGroup(layout.createSequentialGroup()
 
171
                .addContainerGap()
 
172
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
 
173
                    .addComponent(NField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
 
174
                    .addComponent(NLabel))
 
175
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 
176
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
 
177
                    .addComponent(m0Field, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
 
178
                    .addComponent(m0Label))
 
179
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 
180
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
 
181
                    .addComponent(MField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
 
182
                    .addComponent(MLabel))
 
183
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 
184
                .addComponent(constraintsLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
 
185
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
 
186
        );
 
187
    }// </editor-fold>//GEN-END:initComponents
 
188
 
 
189
 
 
190
    // Variables declaration - do not modify//GEN-BEGIN:variables
 
191
    protected javax.swing.JTextField MField;
 
192
    private javax.swing.JLabel MLabel;
 
193
    protected javax.swing.JTextField NField;
 
194
    private javax.swing.JLabel NLabel;
 
195
    private javax.swing.JLabel constraintsLabel;
 
196
    protected javax.swing.JTextField m0Field;
 
197
    private javax.swing.JLabel m0Label;
 
198
    // End of variables declaration//GEN-END:variables
 
199
 
 
200
}