2
* Copyright 2008-2010 Gephi
3
* Authors : Cezary Bartosiak
4
* Website : http://www.gephi.org
6
* This file is part of Gephi.
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.
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.
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/>.
21
package org.gephi.ui.complexgenerator.plugin;
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;
33
* @author Cezary Bartosiak
35
public class BarabasiAlbertPanel extends javax.swing.JPanel {
37
/** Creates new form BarabasiAlbertPanel */
38
public BarabasiAlbertPanel() {
42
public static ValidationPanel createValidationPanel(BarabasiAlbertPanel innerPanel) {
43
ValidationPanel validationPanel = new ValidationPanel();
44
if (innerPanel == null)
45
innerPanel = new BarabasiAlbertPanel();
46
validationPanel.setInnerComponent(innerPanel);
48
ValidationGroup group = validationPanel.getValidationGroup();
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));
61
return validationPanel;
64
private static class m0Validator implements Validator<String> {
65
private BarabasiAlbertPanel innerPanel;
67
public m0Validator(BarabasiAlbertPanel innerPanel) {
68
this.innerPanel = innerPanel;
72
public boolean validate(Problems problems, String compName, String model) {
73
boolean result = false;
76
Integer N = Integer.parseInt(innerPanel.NField.getText());
77
Integer m0 = Integer.parseInt(innerPanel.m0Field.getText());
80
catch (Exception e) { }
82
String message = "<html>m0 < N</html>";
83
problems.add(message);
90
private static class MValidator implements Validator<String> {
91
private BarabasiAlbertPanel innerPanel;
93
public MValidator(BarabasiAlbertPanel innerPanel) {
94
this.innerPanel = innerPanel;
98
public boolean validate(Problems problems, String compName, String model) {
99
boolean result = false;
102
Integer m0 = Integer.parseInt(innerPanel.m0Field.getText());
103
Integer M = Integer.parseInt(innerPanel.MField.getText());
106
catch (Exception e) { }
108
String message = "<html>M <= m0</html>";
109
problems.add(message);
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.
121
@SuppressWarnings("unchecked")
122
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
123
private void initComponents() {
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();
133
setPreferredSize(new java.awt.Dimension(451, 170));
135
MLabel.setText(org.openide.util.NbBundle.getMessage(BarabasiAlbertPanel.class, "BarabasiAlbertPanel.MLabel.text")); // NOI18N
137
MField.setText(org.openide.util.NbBundle.getMessage(BarabasiAlbertPanel.class, "BarabasiAlbertPanel.MField.text")); // NOI18N
139
NField.setText(org.openide.util.NbBundle.getMessage(BarabasiAlbertPanel.class, "BarabasiAlbertPanel.NField.text")); // NOI18N
141
m0Field.setText(org.openide.util.NbBundle.getMessage(BarabasiAlbertPanel.class, "BarabasiAlbertPanel.m0Field.text")); // NOI18N
143
NLabel.setText(org.openide.util.NbBundle.getMessage(BarabasiAlbertPanel.class, "BarabasiAlbertPanel.NLabel.text")); // NOI18N
145
m0Label.setText(org.openide.util.NbBundle.getMessage(BarabasiAlbertPanel.class, "BarabasiAlbertPanel.m0Label.text")); // NOI18N
147
constraintsLabel.setText(org.openide.util.NbBundle.getMessage(BarabasiAlbertPanel.class, "BarabasiAlbertPanel.constraintsLabel.text")); // NOI18N
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()
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)))
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))
168
layout.setVerticalGroup(
169
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
170
.addGroup(layout.createSequentialGroup()
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))
187
}// </editor-fold>//GEN-END:initComponents
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