/*
Copyright 2008-2010 Gephi
Authors : Mathieu Bastian <mathieu.bastian@gephi.org>
Website : http://www.gephi.org
This file is part of Gephi.
Gephi is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
Gephi is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Gephi. If not, see <http://www.gnu.org/licenses/>.
*/
package org.gephi.ui.filters.plugin.hierarchy;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.SwingUtilities;
import org.gephi.filters.plugin.hierarchy.LevelBuilder.LevelFilter;
import org.jdesktop.swingx.JXHyperlink;
/**
*
* @author Mathieu Bastian
*/
public class LevelPanel extends javax.swing.JPanel implements ActionListener {
private final Object LABEL_KEY = new Object();
private LevelFilter filter;
public LevelPanel() {
initComponents();
net.miginfocom.swing.MigLayout migLayout1 = new net.miginfocom.swing.MigLayout();
migLayout1.setColumnConstraints("[center]");
setLayout(migLayout1);
}
public void actionPerformed(ActionEvent e) {
Integer level = (Integer) ((JXHyperlink) e.getSource()).getClientProperty(LABEL_KEY);
filter.getProperties()[0].setValue(level);
}
public void setup(LevelFilter filter) {
final int height = filter.getHeight();
final int lvl = filter.getLevel();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
removeAll();
for (int i = 0; i < height; i++) {
JXHyperlink label = new JXHyperlink();
label.setText("Level " + i);
if (i == lvl) {
label.setFont(label.getFont().deriveFont(Font.BOLD));
}
label.putClientProperty(LABEL_KEY, new Integer(i));
label.addActionListener(LevelPanel.this);
add(label, "wrap");
}
}
});
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
);
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
// End of variables declaration//GEN-END:variables
}