201204 random clustering
DESCRIPTION
make a plugin of random clusteringTRANSCRIPT
![Page 1: 201204 random clustering](https://reader034.vdocument.in/reader034/viewer/2022051613/54c85e854a7959045b8b4644/html5/thumbnails/1.jpg)
1/33
Make a plugin of Random ClusteringMake a plugin of Random Clustering
2012. 4
http://www.mongkie.org
![Page 2: 201204 random clustering](https://reader034.vdocument.in/reader034/viewer/2022051613/54c85e854a7959045b8b4644/html5/thumbnails/2.jpg)
http://www.mongkie.org 2/33
CONTENTSCONTENTS
CONTENTS• Objectives
• Structure of Random Clustering Plugin
• make a plugin
Package– org.mongkie.clustering.plugins.random
Classes– Random.java– RandomBuilder.java– RandomSettingUI.java
Others– Bundle.properties
• Build and Run
![Page 3: 201204 random clustering](https://reader034.vdocument.in/reader034/viewer/2022051613/54c85e854a7959045b8b4644/html5/thumbnails/3.jpg)
http://www.mongkie.org 3/33
ObjectivesObjectives
Objectives• make a plugin of random clustering (add random algo-
rithm)
Add Random Algorithm
![Page 4: 201204 random clustering](https://reader034.vdocument.in/reader034/viewer/2022051613/54c85e854a7959045b8b4644/html5/thumbnails/4.jpg)
http://www.mongkie.org 4/33
Clutering PluginsClutering Plugins
Structure of Random Clustering• org.mongkie.clustering.plugins.random
Bundle.properties
Random.java
RandomBuilder.java
RandomSettingUI.java
Clustering API Clustering Plugins Clustering Plugins
org.mongkie.clustering-ClusteringController-CluteringModel-ClusteringModelListener-DefaultClusterImpl
org.mongkie.clustering.impl-ClusteringControllerImpl-ClusteringModelImpl
org.mongkie.clustering.spi-Cluster-Clustering-CluteringBuilder
org.mongkie.clustering.plugins
org.mongkie.clustering.plugins.clustermaker
org.mongkie.clustering.plugins.clustermaker.con-verters
org.mongkie.clustering.plugins.clustermaker.mcl
org.mongkie.clustering.plugins.mcl
org.mongkie.clustering.plugins.mcode
org.mongkie.ui.clustering-ClusteringTopComponent
org.mongkie.ui.clustering.explorer-ClusterChildFactory-ClusterNode-ClusteringResultView
org.mongkie.ui.clustering.explorer.ac-tions-GroupAction-UngroupAction
org.mongkie.ui.clustering.resources- Image Files
![Page 5: 201204 random clustering](https://reader034.vdocument.in/reader034/viewer/2022051613/54c85e854a7959045b8b4644/html5/thumbnails/5.jpg)
http://www.mongkie.org 5/33
Make a plugin - PackageMake a plugin - Package
[New] –[Java Package]
![Page 6: 201204 random clustering](https://reader034.vdocument.in/reader034/viewer/2022051613/54c85e854a7959045b8b4644/html5/thumbnails/6.jpg)
http://www.mongkie.org 6/33
Make a plugin - PackageMake a plugin - Package
Create a random pacakge• org.mongkie.clustering.plugins.random
![Page 7: 201204 random clustering](https://reader034.vdocument.in/reader034/viewer/2022051613/54c85e854a7959045b8b4644/html5/thumbnails/7.jpg)
http://www.mongkie.org 7/33
Make a plugin - PackageMake a plugin - Package
Create a random pacakge• org.mongkie.clustering.plugins.random
![Page 8: 201204 random clustering](https://reader034.vdocument.in/reader034/viewer/2022051613/54c85e854a7959045b8b4644/html5/thumbnails/8.jpg)
http://www.mongkie.org 8/33
Make a plugin - RandomMake a plugin - Random
Create a random class• Random.java
![Page 9: 201204 random clustering](https://reader034.vdocument.in/reader034/viewer/2022051613/54c85e854a7959045b8b4644/html5/thumbnails/9.jpg)
http://www.mongkie.org 9/33
Make a plugin - RandomMake a plugin - Random
Create a random class• Random.java
![Page 10: 201204 random clustering](https://reader034.vdocument.in/reader034/viewer/2022051613/54c85e854a7959045b8b4644/html5/thumbnails/10.jpg)
http://www.mongkie.org 10/33
Make a plugin - RandomMake a plugin - Random
Create a random class• Random.java
![Page 11: 201204 random clustering](https://reader034.vdocument.in/reader034/viewer/2022051613/54c85e854a7959045b8b4644/html5/thumbnails/11.jpg)
http://www.mongkie.org 11/33
Make a plugin - RandomMake a plugin - Random
Random.java• Source Code
package org.mongkie.clustering.plugins.random;
import java.util.ArrayList;import java.util.Collection;import java.util.Collections;import java.util.Iterator;import java.util.List;import org.mongkie.clustering.spi.Cluster;import org.mongkie.clustering.DefaultClusterImpl;import org.mongkie.clustering.spi.Clustering;import org.mongkie.clustering.spi.ClusteringBuilder;import org.openide.util.Exceptions;import prefuse.data.Graph;import prefuse.data.Node;
![Page 12: 201204 random clustering](https://reader034.vdocument.in/reader034/viewer/2022051613/54c85e854a7959045b8b4644/html5/thumbnails/12.jpg)
http://www.mongkie.org 12/33
Make a plugin - RandomMake a plugin - Random
Random.java• implements
Clustering
• variables (global)
private final RandomBuilder builder;
private int clusterSize;
static final int MIN_CLUSTER_SIZE = 3;
private List<Cluster> clusters = new ArrayList<Cluster>();
• Constructor
Random(RandomBuilder builder) { this.builder = builder; this.clusterSize = MIN_CLUSTER_SIZE; }
![Page 13: 201204 random clustering](https://reader034.vdocument.in/reader034/viewer/2022051613/54c85e854a7959045b8b4644/html5/thumbnails/13.jpg)
http://www.mongkie.org 13/33
Make a plugin - RandomMake a plugin - Random
Random.java• source code
public void execute(Graph g) { clearClusters(); List<Node> nodes = new ArrayList<Node>(g.getNodeCount()); Iterator<Node> nodesIter = g.nodes(); while (nodesIter.hasNext()) { Node n = nodesIter.next(); nodes.add(n); } Collections.shuffle(nodes); int i = 1, j = 1; DefaultClusterImpl c = new DefaultClusterImpl(g, "Random " + j); c.setRank(j - 1); for (Node n : nodes) { c.addNode(n); if (i >= clusterSize) { clusters.add(c); c = new DefaultClusterImpl(g, "Random " + ++j); c.setRank(j - 1); i = 1; } else { i++; } } if (c.getNodesCount() > 0) { clusters.add(c); }
try { synchronized (this) { wait(1000); } } catch (InterruptedException ex) { Exceptions.printStackTrace(ex); } }
![Page 14: 201204 random clustering](https://reader034.vdocument.in/reader034/viewer/2022051613/54c85e854a7959045b8b4644/html5/thumbnails/14.jpg)
http://www.mongkie.org 14/33
Make a plugin - RandomMake a plugin - Random
Random.java• source code
int getClusterSize() { return clusterSize; }
void setClusterSize(int clusterSize) { this.clusterSize = clusterSize < MIN_CLUSTER_SIZE ? MIN_CLUSTER_SIZE : clusterSize; }
public boolean cancel() { synchronized (this) { clearClusters(); notifyAll(); } return true; }
@Override public Collection<Cluster> getClusters() { return clusters; }
@Override public void clearClusters() { clusters.clear(); }
@Override public ClusteringBuilder getBuilder() { return builder; }
![Page 15: 201204 random clustering](https://reader034.vdocument.in/reader034/viewer/2022051613/54c85e854a7959045b8b4644/html5/thumbnails/15.jpg)
http://www.mongkie.org 15/33
Make a plugin - RandomBuilderMake a plugin - RandomBuilder
RandomBuilder.java
![Page 16: 201204 random clustering](https://reader034.vdocument.in/reader034/viewer/2022051613/54c85e854a7959045b8b4644/html5/thumbnails/16.jpg)
http://www.mongkie.org 16/33
Make a plugin - RandomBuilderMake a plugin - RandomBuilder
RandomBuilder
![Page 17: 201204 random clustering](https://reader034.vdocument.in/reader034/viewer/2022051613/54c85e854a7959045b8b4644/html5/thumbnails/17.jpg)
http://www.mongkie.org 17/33
Make a plugin - RandomBuilderMake a plugin - RandomBuilder
RandomBuilder
![Page 18: 201204 random clustering](https://reader034.vdocument.in/reader034/viewer/2022051613/54c85e854a7959045b8b4644/html5/thumbnails/18.jpg)
http://www.mongkie.org 18/33
Make a plugin - RandomBuilderMake a plugin - RandomBuilder
RandomBuilder
![Page 19: 201204 random clustering](https://reader034.vdocument.in/reader034/viewer/2022051613/54c85e854a7959045b8b4644/html5/thumbnails/19.jpg)
http://www.mongkie.org 19/33
Make a plugin - RandomBuilderMake a plugin - RandomBuilder
RandomBuilder• implements
ClusteringBuilder
• variable(Global)
private final Random random = new Random(this);
private final SettingUI settings = new RandomSettingUI();
![Page 20: 201204 random clustering](https://reader034.vdocument.in/reader034/viewer/2022051613/54c85e854a7959045b8b4644/html5/thumbnails/20.jpg)
http://www.mongkie.org 20/33
Make a plugin - RandomBuilderMake a plugin - RandomBuilder
RandomBuilder• source code
package org.mongkie.clustering.plugins.random;
import org.mongkie.clustering.spi.Clustering;import org.mongkie.clustering.spi.ClusteringBuilder;import org.mongkie.clustering.spi.ClusteringBuilder.SettingUI;import org.openide.util.NbBundle;import org.openide.util.lookup.ServiceProvider;
![Page 21: 201204 random clustering](https://reader034.vdocument.in/reader034/viewer/2022051613/54c85e854a7959045b8b4644/html5/thumbnails/21.jpg)
http://www.mongkie.org 21/33
Make a plugin - RandomBuilderMake a plugin - RandomBuilder
RandomBuilder• source code
@ServiceProvider(service = ClusteringBuilder.class)public class RandomBuilder implements ClusteringBuilder {
private final Random random = new Random(this); private final SettingUI settings = new RandomSettingUI();
@Override public Clustering getClustering() { return random; }
@Override public String getName() { return NbBundle.getMessage(RandomBuilder.class, "name"); }
@Override public String getDescription() { return NbBundle.getMessage(RandomBuilder.class, "description"); }
@Override public SettingUI getSettingUI() { return settings; }
@Override public String toString() { return getName(); }}
![Page 22: 201204 random clustering](https://reader034.vdocument.in/reader034/viewer/2022051613/54c85e854a7959045b8b4644/html5/thumbnails/22.jpg)
http://www.mongkie.org 22/33
Make a plugin - RandomSettingUIMake a plugin - RandomSettingUI
RandomSettingUI
![Page 23: 201204 random clustering](https://reader034.vdocument.in/reader034/viewer/2022051613/54c85e854a7959045b8b4644/html5/thumbnails/23.jpg)
http://www.mongkie.org 23/33
Make a plugin - RandomSettingUIMake a plugin - RandomSettingUI
RandomSettingUI
![Page 24: 201204 random clustering](https://reader034.vdocument.in/reader034/viewer/2022051613/54c85e854a7959045b8b4644/html5/thumbnails/24.jpg)
http://www.mongkie.org 24/33
Make a plugin - RandomSettingUIMake a plugin - RandomSettingUI
RandomSettingUI
![Page 25: 201204 random clustering](https://reader034.vdocument.in/reader034/viewer/2022051613/54c85e854a7959045b8b4644/html5/thumbnails/25.jpg)
http://www.mongkie.org 25/33
Make a plugin - RandomSettingUIMake a plugin - RandomSettingUI
RandomSettingUI
![Page 26: 201204 random clustering](https://reader034.vdocument.in/reader034/viewer/2022051613/54c85e854a7959045b8b4644/html5/thumbnails/26.jpg)
http://www.mongkie.org 26/33
Make a plugin - RandomSettingUIMake a plugin - RandomSettingUI
RandomSettingUI• extends
javax.swing.JPanel
• implements
ClusteringBuilder.SettingUI<Random>
• variable(Global)
private SpinnerModel clusterSizeSpinnerModel;
• Constructor
RandomSettingUI() { clusterSizeSpinnerModel = new SpinnerNumberModel( Integer.valueOf(Random.MIN_CLUSTER_SIZE), Integer.valueOf(Random.MIN_CLUSTER_SIZE), null, Integer.valueOf(1)); initComponents(); }
![Page 27: 201204 random clustering](https://reader034.vdocument.in/reader034/viewer/2022051613/54c85e854a7959045b8b4644/html5/thumbnails/27.jpg)
http://www.mongkie.org 27/33
Make a plugin - RandomSettingUIMake a plugin - RandomSettingUI
RandomSettingUI• source code
package org.mongkie.clustering.plugins.random;
import javax.swing.JPanel;import javax.swing.SpinnerModel;import javax.swing.SpinnerNumberModel;import org.mongkie.clustering.spi.ClusteringBuilder;
public class RandomSettingUI extends javax.swing.JPanel implements ClusteringBuilder.SettingUI<Random> {
private SpinnerModel clusterSizeSpinnerModel;
/** Creates new form RandomSettingUI */ RandomSettingUI() { clusterSizeSpinnerModel = new SpinnerNumberModel( Integer.valueOf(Random.MIN_CLUSTER_SIZE), Integer.valueOf(Random.MIN_CLUSTER_SIZE), null, Integer.valueOf(1)); initComponents(); } @Override public JPanel getPanel() { return this; } @Override public void setup(Random random) { clusterSizeSpinner.setValue(random.getClusterSize()); } @Override public void apply(Random random) { random.setClusterSize((Integer) clusterSizeSpinner.getValue()); } // Variables declaration - do not modify private javax.swing.JLabel clusterSizeLabel; private javax.swing.JSpinner clusterSizeSpinner; // End of variables declaration }
![Page 28: 201204 random clustering](https://reader034.vdocument.in/reader034/viewer/2022051613/54c85e854a7959045b8b4644/html5/thumbnails/28.jpg)
http://www.mongkie.org 28/33
Make a plugin - RandomSettingUIMake a plugin - RandomSettingUI
RandomSettingUI• source code
private void initComponents() {
clusterSizeLabel = new javax.swing.JLabel(); clusterSizeSpinner = new javax.swing.JSpinner();
clusterSizeLabel.setText(org.openide.util.NbBundle.getMessage(RandomSettingUI.class, "RandomSettingUI.clusterSizeLabel.text")); // NOI18N
clusterSizeSpinner.setModel(clusterSizeSpinnerModel); clusterSizeSpinner.setPreferredSize(new java.awt.Dimension(50, 26));
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(clusterSizeLabel) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(clusterSizeSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.Grou-pLayout.PREFERRED_SIZE) .addContainerGap(16, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(clusterSizeLabel) .addComponent(clusterSizeSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.Grou-pLayout.PREFERRED_SIZE)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); }
![Page 29: 201204 random clustering](https://reader034.vdocument.in/reader034/viewer/2022051613/54c85e854a7959045b8b4644/html5/thumbnails/29.jpg)
http://www.mongkie.org 29/33
Make a plugin - Bundle.propertiesMake a plugin - Bundle.properties
Bundle.properties
name=Randomdescription=Clusterize nodes randomly according to given size of a clusterRandomSettingUI.clusterSizeLabel.text=Size of a cluster :
![Page 30: 201204 random clustering](https://reader034.vdocument.in/reader034/viewer/2022051613/54c85e854a7959045b8b4644/html5/thumbnails/30.jpg)
http://www.mongkie.org 30/33
Build and RunBuild and Run
Clean and Build
![Page 31: 201204 random clustering](https://reader034.vdocument.in/reader034/viewer/2022051613/54c85e854a7959045b8b4644/html5/thumbnails/31.jpg)
http://www.mongkie.org 31/33
Build and RunBuild and Run
Run
![Page 32: 201204 random clustering](https://reader034.vdocument.in/reader034/viewer/2022051613/54c85e854a7959045b8b4644/html5/thumbnails/32.jpg)
http://www.mongkie.org 32/33
Build and RunBuild and Run
Run
![Page 33: 201204 random clustering](https://reader034.vdocument.in/reader034/viewer/2022051613/54c85e854a7959045b8b4644/html5/thumbnails/33.jpg)
33/33
Q & AQ & AHomepage : http://www.mongkie.org
Forum : http://forum.-mongkie.org
wiki : http://wiki.mongkie.org