/*
* Copyright (C) 2013-2014 Dio
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gui;
import java.awt.Color;
import java.awt.FontMetrics;
import java.awt.GridBagLayout;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import logic.Colors;
import logic.Node;
import logic.NodeTreePane;
import logic.TreeNodeExtentProvider;
import org.abego.treelayout.TreeForTreeLayout;
import org.abego.treelayout.TreeLayout;
import org.abego.treelayout.util.DefaultConfiguration;
import org.abego.treelayout.util.DefaultTreeForTreeLayout;
/**
*
* @author Dio
*/
public class CustomizeGraph extends javax.swing.JDialog {
/**
* Creates new form CustomizeGraph
* @param parent
* @param modal
*/
public CustomizeGraph(JFrame parent, boolean modal) {
super(parent, modal);
initComponents();
this.setLocationRelativeTo(parent);
createTestNode(jPanel2);
}
/**
* 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() {
java.awt.GridBagConstraints gridBagConstraints;
jPanel3 = new javax.swing.JPanel();
jPanel1 = new javax.swing.JPanel();
jCheckBox1 = new javax.swing.JCheckBox();
jCheckBox2 = new javax.swing.JCheckBox();
jCheckBox3 = new javax.swing.JCheckBox();
jComboBox1 = new javax.swing.JComboBox();
jComboBox2 = new javax.swing.JComboBox();
jComboBox3 = new javax.swing.JComboBox();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jCheckBox4 = new javax.swing.JCheckBox();
jPanel2 = new javax.swing.JPanel();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Custimize Tree Graph Colors");
setModal(true);
setResizable(false);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
formWindowClosing(evt);
}
});
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Color customization", javax.swing.border.TitledBorder.LEFT, javax.swing.border.TitledBorder.TOP));
jPanel1.setPreferredSize(new java.awt.Dimension(290, 190));
jPanel1.setLayout(new java.awt.GridBagLayout());
jCheckBox1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
jCheckBox1.setText("Set Text color");
jCheckBox1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jCheckBox1ActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
gridBagConstraints.gridwidth = 2;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
gridBagConstraints.insets = new java.awt.Insets(36, 24, 0, 0);
jPanel1.add(jCheckBox1, gridBagConstraints);
jCheckBox2.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
jCheckBox2.setText("Set Graph color");
jCheckBox2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jCheckBox2ActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 2;
gridBagConstraints.gridwidth = 3;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
gridBagConstraints.insets = new java.awt.Insets(12, 24, 0, 0);
jPanel1.add(jCheckBox2, gridBagConstraints);
jCheckBox3.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
jCheckBox3.setText("Set Border color");
jCheckBox3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jCheckBox3ActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 4;
gridBagConstraints.gridwidth = 4;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
gridBagConstraints.insets = new java.awt.Insets(12, 24, 0, 0);
jPanel1.add(jCheckBox3, gridBagConstraints);
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "black", "blue", "cyan", "dark gray", "gray", "green", "light gray", "magenta", "orange", "pink", "red", "white", "yellow" }));
jComboBox1.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
jComboBox1ItemStateChanged(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 4;
gridBagConstraints.gridy = 0;
gridBagConstraints.gridwidth = 2;
gridBagConstraints.gridheight = 2;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
gridBagConstraints.insets = new java.awt.Insets(36, 17, 0, 0);
jPanel1.add(jComboBox1, gridBagConstraints);
jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "black", "blue", "cyan", "dark gray", "gray", "green", "light gray", "magenta", "orange", "pink", "red", "white", "yellow" }));
jComboBox2.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
jComboBox2ItemStateChanged(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 4;
gridBagConstraints.gridy = 2;
gridBagConstraints.gridwidth = 3;
gridBagConstraints.gridheight = 2;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
gridBagConstraints.insets = new java.awt.Insets(12, 18, 0, 13);
jPanel1.add(jComboBox2, gridBagConstraints);
jComboBox3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "black", "blue", "cyan", "dark gray", "gray", "green", "light gray", "magenta", "orange", "pink", "red", "white", "yellow" }));
jComboBox3.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
jComboBox3ItemStateChanged(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 4;
gridBagConstraints.gridy = 4;
gridBagConstraints.gridwidth = 3;
gridBagConstraints.gridheight = 2;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
gridBagConstraints.insets = new java.awt.Insets(12, 18, 0, 13);
jPanel1.add(jComboBox3, gridBagConstraints);
jButton1.setText("Apply");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 7;
gridBagConstraints.gridwidth = 4;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
gridBagConstraints.insets = new java.awt.Insets(12, 63, 12, 0);
jPanel1.add(jButton1, gridBagConstraints);
jButton2.setText("Cancel");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 4;
gridBagConstraints.gridy = 7;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
gridBagConstraints.insets = new java.awt.Insets(12, 6, 12, 0);
jPanel1.add(jButton2, gridBagConstraints);
jCheckBox4.setSelected(true);
jCheckBox4.setText("Default");
jCheckBox4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jCheckBox4ActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 6;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
gridBagConstraints.insets = new java.awt.Insets(12, 24, 0, 0);
jPanel1.add(jCheckBox4, gridBagConstraints);
jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Preview", javax.swing.border.TitledBorder.LEFT, javax.swing.border.TitledBorder.TOP));
jPanel2.setPreferredSize(new java.awt.Dimension(290, 160));
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 278, Short.MAX_VALUE)
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 114, Short.MAX_VALUE)
);
javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
jPanel3.setLayout(jPanel3Layout);
jPanel3Layout.setHorizontalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
.addGroup(jPanel3Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel3Layout.setVerticalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 229, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 377, Short.MAX_VALUE)
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox1ActionPerformed
controlCheckBoxes();
changeColors(jCheckBox1, jComboBox1);
}//GEN-LAST:event_jCheckBox1ActionPerformed
private void jCheckBox2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox2ActionPerformed
controlCheckBoxes();
changeColors(jCheckBox2, jComboBox2);
}//GEN-LAST:event_jCheckBox2ActionPerformed
private void jCheckBox3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox3ActionPerformed
controlCheckBoxes();
changeColors(jCheckBox3, jComboBox3);
}//GEN-LAST:event_jCheckBox3ActionPerformed
private void jComboBox1ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBox1ItemStateChanged
changeColors(jCheckBox1, jComboBox1);
}//GEN-LAST:event_jComboBox1ItemStateChanged
private void jComboBox2ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBox2ItemStateChanged
changeColors(jCheckBox2, jComboBox2);
}//GEN-LAST:event_jComboBox2ItemStateChanged
private void jComboBox3ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBox3ItemStateChanged
changeColors(jCheckBox3, jComboBox3);
}//GEN-LAST:event_jComboBox3ItemStateChanged
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
Colors.getLastColors();
dispose();
}//GEN-LAST:event_jButton2ActionPerformed
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
dispose();
}//GEN-LAST:event_jButton1ActionPerformed
private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
Colors.getLastColors();
}//GEN-LAST:event_formWindowClosing
private void jCheckBox4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox4ActionPerformed
jCheckBox4.setSelected(true);
}//GEN-LAST:event_jCheckBox4ActionPerformed
//<editor-fold defaultstate="collapsed" desc="member variable declarations">
private DefaultTreeForTreeLayout<Node> testTree;
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JCheckBox jCheckBox1;
private javax.swing.JCheckBox jCheckBox2;
private javax.swing.JCheckBox jCheckBox3;
private javax.swing.JCheckBox jCheckBox4;
private javax.swing.JComboBox jComboBox1;
private javax.swing.JComboBox jComboBox2;
private javax.swing.JComboBox jComboBox3;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
// End of variables declaration//GEN-END:variables
//</editor-fold>
private void changeColors(JCheckBox checkbox, JComboBox comboBox) {
if (checkbox.isSelected() == true) {
String color = String.valueOf(comboBox.getSelectedItem());
if (checkbox == jCheckBox1) {
Colors.setTEXT_COLOR(findAndSetColor(color));
} else if (checkbox == jCheckBox2) {
Colors.setBOX_COLOR(findAndSetColor(color));
} else if (checkbox == jCheckBox3) {
Colors.setBORDER_COLOR(findAndSetColor(color));
}
previewNode(testTree, jPanel2);
}
}
private void controlCheckBoxes() {
if (jCheckBox1.isSelected() || jCheckBox2.isSelected() || jCheckBox3.isSelected()) {
jCheckBox4.setSelected(false);
jCheckBox4.setEnabled(false);
} else {
jCheckBox4.setEnabled(true);
jCheckBox4.setSelected(true);
Colors.setBOX_COLOR(Color.orange);
Colors.setBORDER_COLOR(Color.darkGray);
Colors.setTEXT_COLOR(Color.black);
previewNode(testTree, jPanel2);
}
}
private Color findAndSetColor(String theColor) {
switch (theColor) {
case "black":
return Color.BLACK;
case "blue":
return Color.BLUE;
case "cyan":
return Color.CYAN;
case "dark gray":
return Color.DARK_GRAY;
case "gray":
return Color.GRAY;
case "green":
return Color.GREEN;
case "light gray":
return Color.LIGHT_GRAY;
case "magenta":
return Color.MAGENTA;
case "orange":
return Color.ORANGE;
case "pink":
return Color.PINK;
case "red":
return Color.RED;
case "white":
return Color.WHITE;
case "yellow":
return Color.YELLOW;
default:
return Color.red;
}
}
private void createTestNode(JPanel previewPanel) {
FontMetrics fm = getFontMetrics(getFont());
int width = fm.stringWidth("Preview your customizations");
int height = fm.getHeight() * 5;
Node testNode = new Node("#0, Test Node", "Testing", "Customization", "No links", "Preview your customizations", 0, "");
testTree = new DefaultTreeForTreeLayout<>(testNode);
previewNode(testTree, previewPanel);
}
private void previewNode(DefaultTreeForTreeLayout<Node> defaultTree, JPanel previewPanel) {
TreeForTreeLayout<Node> tree = defaultTree;
double gapBetweenLevels = 50;
double gapBetweenNodes = 10;
DefaultConfiguration<Node> configuration = new DefaultConfiguration<>(
gapBetweenLevels, gapBetweenNodes);
// create the NodeExtentProvider for Node nodes
TreeNodeExtentProvider nodeExtentProvider = new TreeNodeExtentProvider();
// create the layout
TreeLayout<Node> treeLayout = new TreeLayout<>(tree,
nodeExtentProvider, configuration);
// Create a panel that draws the nodes and edges and show the panel
NodeTreePane panel = new NodeTreePane(treeLayout);
previewPanel.removeAll();
previewPanel.setLayout(new GridBagLayout());
previewPanel.add(panel);
previewPanel.revalidate();
previewPanel.repaint();
}
}