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.netbeans.validation.api.Problems;
24
import org.netbeans.validation.api.Validator;
25
import org.netbeans.validation.api.builtin.Validators;
26
import org.netbeans.validation.api.ui.ValidationGroup;
27
import org.netbeans.validation.api.ui.ValidationPanel;
32
* @author Cezary Bartosiak
34
public class KleinbergPanel extends javax.swing.JPanel {
36
/** Creates new form BarabasiAlbertPanel */
37
public KleinbergPanel() {
41
public static ValidationPanel createValidationPanel(KleinbergPanel innerPanel) {
42
ValidationPanel validationPanel = new ValidationPanel();
43
if (innerPanel == null)
44
innerPanel = new KleinbergPanel();
45
validationPanel.setInnerComponent(innerPanel);
47
ValidationGroup group = validationPanel.getValidationGroup();
49
group.add(innerPanel.nField, Validators.REQUIRE_NON_EMPTY_STRING,
50
new nValidator(innerPanel));
51
group.add(innerPanel.pField, Validators.REQUIRE_NON_EMPTY_STRING,
52
new pValidator(innerPanel));
53
group.add(innerPanel.qField, Validators.REQUIRE_NON_EMPTY_STRING,
54
new qValidator(innerPanel));
55
group.add(innerPanel.rField, Validators.REQUIRE_NON_EMPTY_STRING,
56
new rValidator(innerPanel));
58
return validationPanel;
61
private static class nValidator implements Validator<String> {
62
private KleinbergPanel innerPanel;
64
public nValidator(KleinbergPanel innerPanel) {
65
this.innerPanel = innerPanel;
69
public boolean validate(Problems problems, String compName, String model) {
70
boolean result = false;
73
Integer n = Integer.parseInt(innerPanel.nField.getText());
76
catch (Exception e) { }
78
String message = "<html>n >= 2</html>";
79
problems.add(message);
86
private static class pValidator implements Validator<String> {
87
private KleinbergPanel innerPanel;
89
public pValidator(KleinbergPanel innerPanel) {
90
this.innerPanel = innerPanel;
94
public boolean validate(Problems problems, String compName, String model) {
95
boolean result = false;
98
Integer n = Integer.parseInt(innerPanel.nField.getText());
99
Integer p = Integer.parseInt(innerPanel.pField.getText());
100
result = p >= 1 && p <= 2 * n - 2;
102
catch (Exception e) { }
104
String message = "<html>1 <= p <= 2n - 2</html>";
105
problems.add(message);
112
private static class qValidator implements Validator<String> {
113
private KleinbergPanel innerPanel;
115
public qValidator(KleinbergPanel innerPanel) {
116
this.innerPanel = innerPanel;
120
public boolean validate(Problems problems, String compName, String model) {
121
boolean result = false;
124
Integer n = Integer.parseInt(innerPanel.nField.getText());
125
Integer p = Integer.parseInt(innerPanel.pField.getText());
126
Integer q = Integer.parseInt(innerPanel.qField.getText());
128
result = q >= 0 && q <= n * n - p * (p + 3) / 2 - 1;
129
else result = q >= 0 && q <= (2 * n - p - 3) * (2 * n - p) / 2 + 1;
131
catch (Exception e) { }
134
"<html>q >= 0<br>" +
135
"q <= n^2 - p * (p + 3) / 2 - 1 for p < n<br>" +
136
"q <= (2n - p - 3) * (2n - p) / 2 + 1 for p >= n<br></html>";
137
problems.add(message);
144
private static class rValidator implements Validator<String> {
145
private KleinbergPanel innerPanel;
147
public rValidator(KleinbergPanel innerPanel) {
148
this.innerPanel = innerPanel;
152
public boolean validate(Problems problems, String compName, String model) {
153
boolean result = false;
156
Integer r = Integer.parseInt(innerPanel.rField.getText());
159
catch (Exception e) { }
161
String message = "<html>r >= 0</html>";
162
problems.add(message);
169
/** This method is called from within the constructor to
170
* initialize the form.
171
* WARNING: Do NOT modify this code. The content of this method is
172
* always regenerated by the Form Editor.
174
@SuppressWarnings("unchecked")
175
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
176
private void initComponents() {
178
qLabel = new javax.swing.JLabel();
179
qField = new javax.swing.JTextField();
180
nField = new javax.swing.JTextField();
181
pField = new javax.swing.JTextField();
182
nLabel = new javax.swing.JLabel();
183
pLabel = new javax.swing.JLabel();
184
constraintsLabel = new javax.swing.JLabel();
185
rLabel = new javax.swing.JLabel();
186
rField = new javax.swing.JTextField();
187
torusCheckBox = new javax.swing.JCheckBox();
189
setPreferredSize(new java.awt.Dimension(399, 247));
191
qLabel.setText(org.openide.util.NbBundle.getMessage(KleinbergPanel.class, "KleinbergPanel.qLabel.text")); // NOI18N
193
qField.setText(org.openide.util.NbBundle.getMessage(KleinbergPanel.class, "KleinbergPanel.qField.text")); // NOI18N
195
nField.setText(org.openide.util.NbBundle.getMessage(KleinbergPanel.class, "KleinbergPanel.nField.text")); // NOI18N
197
pField.setText(org.openide.util.NbBundle.getMessage(KleinbergPanel.class, "KleinbergPanel.pField.text")); // NOI18N
199
nLabel.setText(org.openide.util.NbBundle.getMessage(KleinbergPanel.class, "KleinbergPanel.nLabel.text")); // NOI18N
201
pLabel.setText(org.openide.util.NbBundle.getMessage(KleinbergPanel.class, "KleinbergPanel.pLabel.text")); // NOI18N
203
constraintsLabel.setText(org.openide.util.NbBundle.getMessage(KleinbergPanel.class, "KleinbergPanel.constraintsLabel.text")); // NOI18N
205
rLabel.setText(org.openide.util.NbBundle.getMessage(KleinbergPanel.class, "KleinbergPanel.rLabel.text")); // NOI18N
207
rField.setText(org.openide.util.NbBundle.getMessage(KleinbergPanel.class, "KleinbergPanel.rField.text")); // NOI18N
209
torusCheckBox.setText(org.openide.util.NbBundle.getMessage(KleinbergPanel.class, "KleinbergPanel.torusCheckBox.text")); // NOI18N
211
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
212
this.setLayout(layout);
213
layout.setHorizontalGroup(
214
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
215
.addGroup(layout.createSequentialGroup()
217
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
218
.addGroup(layout.createSequentialGroup()
219
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
220
.addComponent(nLabel)
221
.addComponent(pLabel)
222
.addComponent(qLabel)
223
.addComponent(rLabel))
225
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
226
.addComponent(rField, javax.swing.GroupLayout.DEFAULT_SIZE, 136, Short.MAX_VALUE)
227
.addComponent(pField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 136, Short.MAX_VALUE)
228
.addComponent(qField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 136, Short.MAX_VALUE)
229
.addComponent(nField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 136, Short.MAX_VALUE))
231
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
232
.addComponent(constraintsLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
234
.addGroup(layout.createSequentialGroup()
235
.addComponent(torusCheckBox)
236
.addContainerGap(306, Short.MAX_VALUE))))
238
layout.setVerticalGroup(
239
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
240
.addGroup(layout.createSequentialGroup()
242
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
243
.addComponent(nField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
244
.addComponent(nLabel))
245
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
246
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
247
.addComponent(pField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
248
.addComponent(pLabel))
249
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
250
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
251
.addComponent(qField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
252
.addComponent(qLabel))
253
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
254
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
255
.addComponent(rField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
256
.addComponent(rLabel))
257
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
258
.addComponent(torusCheckBox)
260
.addComponent(constraintsLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
263
}// </editor-fold>//GEN-END:initComponents
266
// Variables declaration - do not modify//GEN-BEGIN:variables
267
private javax.swing.JLabel constraintsLabel;
268
protected javax.swing.JTextField nField;
269
private javax.swing.JLabel nLabel;
270
protected javax.swing.JTextField pField;
271
private javax.swing.JLabel pLabel;
272
protected javax.swing.JTextField qField;
273
private javax.swing.JLabel qLabel;
274
protected javax.swing.JTextField rField;
275
private javax.swing.JLabel rLabel;
276
protected javax.swing.JCheckBox torusCheckBox;
277
// End of variables declaration//GEN-END:variables