Commit 84a0ec3a authored by coman's avatar coman

Creation of a class which display a dialog which allows the user to change the...

Creation of a class which display a dialog which allows the user to change the color of the constraints.
parent 75fd0e0f
package mustic.gui.dialog.classifier;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JColorChooser;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ScrollPaneConstants;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
/**
* Dialog that allows the user to change the color of the constraints
*/
public class ConstraintsColor extends JDialog {
private static final long serialVersionUID = 1L;
/** constraints colors */
private Color mustLinkColor = new Color(124, 252, 0);
private Color cannotLinkColor = new Color(255, 0, 255);
private Vector<Color> labelConstraintColor = new Vector<Color>();
/** constraints buttons */
private JButton jb_mustLinkChooseColor = new JButton();
private JButton jb_cannotLinkChooseColor = new JButton();
private Vector<JButton> jb_labelConstraintClassChooseColor = new Vector<JButton>();
/** dynamic JPanel Colors of Label Constraints Classes*/
JPanel labelColorConstraintPanel = new JPanel(new GridLayout(0,1));
private ConstraintsSelectionDialog dialog = null;
/**
* @brief Constructor dialog window that allows the user to change the color of the constraints
* @param d
* @param colorML
* @param colorCL
* @param colorVectorLabel
*/
public ConstraintsColor(ConstraintsSelectionDialog d, Color colorML, Color colorCL, Vector<Color> colorVectorLabel) {
this.dialog = d;
this.mustLinkColor = colorML;
this.cannotLinkColor = colorCL;
this.labelConstraintColor = colorVectorLabel;
//buttons action listeners that allow the user to choose the color of the constraint
jb_cannotLinkChooseColor.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
chooseCannotLinkColor();
}
});
jb_mustLinkChooseColor.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
chooseMustLinkColor();
}
});
// creates the panel for the label constraints
for(int i=0; i<dialog.getClassCounter(); i++) {
JButton jb = new JButton();
jb_labelConstraintClassChooseColor.add(jb);
jb_labelConstraintClassChooseColor.get(i).putClientProperty("index", i);
jb_labelConstraintClassChooseColor.get(i).setBackground(labelConstraintColor.get(i));
createLabelColorConstraintsPanel(i);
}
this.setTitle("Choose Constraints Colors");
chooseConstraintColors();
}
/**
* Add the last created label constraint class name(number) and its color
* button to the panel labelColorConstraintPanel. The button allows user to
* choose the label constraint class color.
**/
protected void createLabelColorConstraintsPanel(int index) {
JPanel classNameButtonPanel = new JPanel(new GridLayout(1, 2));
classNameButtonPanel.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
classNameButtonPanel.add(new JLabel("Class "+ (index+1) + ":"));
jb_labelConstraintClassChooseColor.get(index).addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
JButton lblClassColorButtonClicked = (JButton) event.getSource();
int buttonIndex = (int) lblClassColorButtonClicked.getClientProperty("index");
chooseLabelClassColor(buttonIndex);
}
});
classNameButtonPanel.add(jb_labelConstraintClassChooseColor.get(index));
labelColorConstraintPanel.add(classNameButtonPanel);
}
/** Opens a JDialog for choosing the Constraints Colors*/
protected void chooseConstraintColors() {
JPanel constraintsPanel=new JPanel(new BorderLayout());
JPanel mlConstraintsPanel=new JPanel();
JPanel clConstraintsPanel=new JPanel();
JPanel mlclConstraintsPanel=new JPanel(new GridLayout(2,1));
JPanel supportPanel=new JPanel(new BorderLayout());
supportPanel.add(labelColorConstraintPanel,BorderLayout.NORTH);
JScrollPane lblConstraintsPane=new JScrollPane(supportPanel,ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
TitledBorder lblcBorder=BorderFactory.createTitledBorder( BorderFactory.createEtchedBorder(EtchedBorder.LOWERED),"Label Constraints Color",TitledBorder.LEFT,TitledBorder.TOP);
lblConstraintsPane.setBorder(lblcBorder);
// must-link constraints panel
mlConstraintsPanel.setLayout(new BorderLayout());
TitledBorder mlcBorder=BorderFactory.createTitledBorder( BorderFactory.createEtchedBorder(EtchedBorder.LOWERED),"Must-Link Constraints Color",TitledBorder.LEFT,TitledBorder.TOP);
mlConstraintsPanel.setBorder(mlcBorder);
mlConstraintsPanel.add(jb_mustLinkChooseColor,BorderLayout.CENTER);
mlclConstraintsPanel.add(mlConstraintsPanel);
// cannot-link constraints panel
clConstraintsPanel.setLayout(new BorderLayout());
TitledBorder clcBorder=BorderFactory.createTitledBorder( BorderFactory.createEtchedBorder(EtchedBorder.LOWERED),"Cannot-Link Constraints Color",TitledBorder.LEFT,TitledBorder.TOP);
clConstraintsPanel.setBorder(clcBorder);
clConstraintsPanel.add(jb_cannotLinkChooseColor,BorderLayout.CENTER);
mlclConstraintsPanel.add(clConstraintsPanel);
// button panel
JPanel buttonPanel=new JPanel();
JButton ok = new JButton("OK");// update color changes on ok, update only fields that have changed
ok.addActionListener( new ActionListener() {
@Override public void actionPerformed(ActionEvent event) {
dialog.setColorML(mustLinkColor);
dialog.setColorCL(cannotLinkColor);
dialog.setColorLabels(labelConstraintColor);
ConstraintsColor.this.dispose();
}
});
// exit dialog on cancel
JButton cancel = new JButton("Cancel");
cancel.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent event) {
ConstraintsColor.this.dispose();
}
});
jb_mustLinkChooseColor.setBackground(mustLinkColor);
jb_cannotLinkChooseColor.setBackground(cannotLinkColor);
buttonPanel.add(ok);
buttonPanel.add(cancel);
constraintsPanel.add(mlclConstraintsPanel,BorderLayout.NORTH);
constraintsPanel.add(lblConstraintsPane,BorderLayout.CENTER);
constraintsPanel.add(buttonPanel,BorderLayout.SOUTH);
this.add(constraintsPanel,BorderLayout.CENTER);
this.setPreferredSize(new Dimension(270, 270));
this.pack();
this.setLocationRelativeTo(null);
this.setModal(true);
this.setVisible(true);
}
/**
* Color Chooser for Must-Link constraints\n Sets the temporary color and
* button indicating the chosen color.
*/
protected void chooseMustLinkColor() {
mustLinkColor = JColorChooser.showDialog(this,"Must-Link Color Chooser",Color.red);
this.jb_mustLinkChooseColor.setBackground(mustLinkColor);
}
/**
* Color Chooser for Cannot-Link constraints\n Sets the temporary color and
* button indicating the chosen color.
**/
protected void chooseCannotLinkColor() {
this.cannotLinkColor = JColorChooser.showDialog(this, "Cannot-Link Color Chooser", //$NON-NLS-1$
cannotLinkColor);
this.jb_cannotLinkChooseColor.setBackground(cannotLinkColor);
}
/**
* Color Chooser for a Label constraint of the class "classID" \n Sets the
* temporary color and button indicating the chosen color for the class.
**/
protected void chooseLabelClassColor(int indexClass) {
Color lblCColorTemp = JColorChooser.showDialog(this, "Label Class Color Chooser", Color.red); //$NON-NLS-1$
this.labelConstraintColor.set(indexClass, lblCColorTemp);
this.jb_labelConstraintClassChooseColor.get(indexClass).setBackground(lblCColorTemp);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment