2020-12-07 22:18:54 +01:00
|
|
|
import javax.imageio.ImageIO;
|
|
|
|
|
import javax.swing.*;
|
|
|
|
|
import javax.swing.border.Border;
|
|
|
|
|
import javax.swing.table.DefaultTableModel;
|
|
|
|
|
import javax.swing.table.TableCellEditor;
|
|
|
|
|
import javax.swing.table.TableColumn;
|
|
|
|
|
import java.awt.*;
|
|
|
|
|
import java.awt.event.*;
|
|
|
|
|
import java.util.Vector;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Classe permettant la création de fenêtres pour la modification des propriétés des classes.
|
|
|
|
|
* @author V.BOULANGER
|
|
|
|
|
*/
|
2020-12-09 22:43:01 +01:00
|
|
|
public class ClassPropertiesWindow extends JDialog {
|
|
|
|
|
|
|
|
|
|
public static int UPDATE_ATTR = 0;
|
|
|
|
|
public static int UPDATE_METH = 1;
|
|
|
|
|
private static int UPDATE_ALL = 2;
|
2020-12-07 22:18:54 +01:00
|
|
|
|
|
|
|
|
private UmlDiagram _umlDiagram;
|
|
|
|
|
private Class _class;
|
|
|
|
|
private JTextField _nameField;
|
|
|
|
|
private JTable _attributesTable;
|
|
|
|
|
private JScrollPane _scrollAttributes;
|
2020-12-09 12:48:52 +01:00
|
|
|
private String[] _attributesColumns = {"Name", "Access modifier", "Type", "Static", "Final", "Abstract", "Synchronised", "Volatile", "Transient"};
|
2020-12-07 22:18:54 +01:00
|
|
|
private DefaultTableModel _attributeModel;
|
|
|
|
|
private JTable _methodsTable;
|
|
|
|
|
private JScrollPane _scrollMethods;
|
2020-12-09 12:48:52 +01:00
|
|
|
private String[] _methodsColumns = {"Name", "Access modifier", "Type", "Arguments", "Static", "Final", "Abstract", "Synchronised", "Volatile", "Transient"};
|
2020-12-07 22:18:54 +01:00
|
|
|
private DefaultTableModel _methodModel;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Constructeur - Crée une instance de la fenêtre de propriétés de classe à partir d'un diagramme et de la classe à modifier.
|
|
|
|
|
* @param umlDiagram Le diagramme qui contient la classe.
|
|
|
|
|
* @param a La classe à modifier.
|
|
|
|
|
*/
|
|
|
|
|
public ClassPropertiesWindow(UmlDiagram umlDiagram, Class a){
|
|
|
|
|
_umlDiagram = umlDiagram;
|
|
|
|
|
_class = a;
|
|
|
|
|
|
|
|
|
|
//Paramétrage de la fenêtre
|
|
|
|
|
this.setTitle("Edit properties - " + a.getName());
|
2020-12-09 22:43:01 +01:00
|
|
|
this.setModal(true);
|
|
|
|
|
this.setSize(new Dimension(800, 350));
|
2020-12-07 22:18:54 +01:00
|
|
|
Image img = null;
|
|
|
|
|
try { img = ImageIO.read(AppThinker.class.getResource("img/logoAppThinker.png")); } catch (Exception ex) { }
|
|
|
|
|
this.setIconImage(img);
|
|
|
|
|
this.setResizable(false);
|
|
|
|
|
this.setLocationRelativeTo(null);
|
|
|
|
|
this.setLayout(new BorderLayout());
|
|
|
|
|
|
|
|
|
|
//Espace général de la fenêtre
|
|
|
|
|
JPanel generalPanel = new JPanel();
|
|
|
|
|
generalPanel.setLayout(new BoxLayout(generalPanel, BoxLayout.Y_AXIS));
|
|
|
|
|
|
|
|
|
|
//Espace de modification du nom
|
|
|
|
|
JPanel namePan = new JPanel();
|
|
|
|
|
namePan.setLayout(new BoxLayout(namePan, BoxLayout.X_AXIS));
|
|
|
|
|
JLabel nameLbl = new JLabel("Name : ");
|
|
|
|
|
_nameField = new JTextField();
|
|
|
|
|
_nameField.setPreferredSize(new Dimension(300, 20));
|
|
|
|
|
_nameField.setText(a.getName());
|
|
|
|
|
namePan.add(nameLbl);
|
|
|
|
|
namePan.add(_nameField);
|
|
|
|
|
generalPanel.add(namePan);
|
|
|
|
|
|
|
|
|
|
JLabel attrLbl = new JLabel("Edit attributes");
|
|
|
|
|
generalPanel.add(attrLbl);
|
|
|
|
|
|
|
|
|
|
//Espace de modification des attributs
|
|
|
|
|
JPanel attributesPan = new JPanel();
|
|
|
|
|
attributesPan.setLayout(new BoxLayout(attributesPan, BoxLayout.X_AXIS));
|
|
|
|
|
|
|
|
|
|
_attributeModel = new DefaultTableModel(_attributesColumns, 0);
|
|
|
|
|
_attributesTable = new JTable(_attributeModel);
|
|
|
|
|
|
|
|
|
|
_scrollAttributes = new JScrollPane(_attributesTable);
|
|
|
|
|
_scrollAttributes.setPreferredSize(new Dimension(350, 100));
|
|
|
|
|
attributesPan.add(_scrollAttributes);
|
|
|
|
|
|
|
|
|
|
JPanel attributesTableModifier = new JPanel();
|
|
|
|
|
attributesTableModifier.setLayout(new BoxLayout(attributesTableModifier, BoxLayout.Y_AXIS));
|
2020-12-09 22:43:01 +01:00
|
|
|
JButton addAttribute = new JButton(" + ");
|
|
|
|
|
addAttribute.setToolTipText("Add a new attribute.");
|
2020-12-07 22:18:54 +01:00
|
|
|
addAttribute.addActionListener(new ActionListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
|
|
addAttribute();
|
|
|
|
|
}
|
|
|
|
|
});
|
2020-12-09 22:43:01 +01:00
|
|
|
attributesTableModifier.add(addAttribute);
|
|
|
|
|
JButton removeAttribute = new JButton(" - ");
|
|
|
|
|
removeAttribute.setToolTipText("Remove the selected attribute.");
|
2020-12-07 22:18:54 +01:00
|
|
|
removeAttribute.addActionListener(new ActionListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
|
|
removeAttribute();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
attributesTableModifier.add(removeAttribute);
|
2020-12-09 22:43:01 +01:00
|
|
|
JButton upAttribute = new JButton("▲");
|
|
|
|
|
upAttribute.setToolTipText("Go up the selected attribute.");
|
|
|
|
|
upAttribute.addActionListener(new ActionListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
|
|
int selected = _attributesTable.getSelectedRow();
|
|
|
|
|
if(_class.upAttribute(selected)){
|
|
|
|
|
save(ClassPropertiesWindow.UPDATE_ATTR, false);
|
|
|
|
|
listAttributes();
|
|
|
|
|
_attributesTable.setRowSelectionInterval(selected - 1, selected - 1);
|
|
|
|
|
_umlDiagram.repaint();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
attributesTableModifier.add(upAttribute);
|
|
|
|
|
JButton downAttribute = new JButton("▼");
|
|
|
|
|
downAttribute.setToolTipText("Go down the selected attribute.");
|
|
|
|
|
downAttribute.addActionListener(new ActionListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
|
|
int selected = _attributesTable.getSelectedRow();
|
|
|
|
|
if(_class.downAttribute(selected)){
|
|
|
|
|
save(ClassPropertiesWindow.UPDATE_ATTR, false);
|
|
|
|
|
listAttributes();
|
|
|
|
|
_attributesTable.setRowSelectionInterval(selected + 1, selected + 1);
|
|
|
|
|
_umlDiagram.repaint();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
attributesTableModifier.add(downAttribute);
|
2020-12-07 22:18:54 +01:00
|
|
|
attributesPan.add(attributesTableModifier);
|
|
|
|
|
|
|
|
|
|
generalPanel.add(attributesPan);
|
|
|
|
|
|
|
|
|
|
JLabel methLbl = new JLabel("Edit methods");
|
|
|
|
|
generalPanel.add(methLbl);
|
|
|
|
|
|
|
|
|
|
//Espace de modification des méthodes
|
|
|
|
|
JPanel methodsPan = new JPanel();
|
|
|
|
|
methodsPan.setLayout(new BoxLayout(methodsPan, BoxLayout.X_AXIS));
|
|
|
|
|
|
|
|
|
|
_methodModel = new DefaultTableModel(_methodsColumns, 0);
|
|
|
|
|
_methodsTable = new JTable(_methodModel);
|
|
|
|
|
|
|
|
|
|
_methodsTable.addMouseListener(new MouseAdapter() {
|
|
|
|
|
|
|
|
|
|
public void mouseClicked(MouseEvent e) {
|
|
|
|
|
Point p = e.getPoint();
|
|
|
|
|
int col = _methodsTable.columnAtPoint(p);
|
|
|
|
|
int row = _methodsTable.rowAtPoint(p);
|
|
|
|
|
System.out.println("clic");
|
|
|
|
|
if (col == 3) {
|
|
|
|
|
openArgumentsWindow(_class.getMethods().get(row));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
_scrollMethods = new JScrollPane(_methodsTable);
|
|
|
|
|
_scrollMethods.setPreferredSize(new Dimension(350, 100));
|
|
|
|
|
methodsPan.add(_scrollMethods);
|
|
|
|
|
|
|
|
|
|
JPanel methodsTableModifier = new JPanel();
|
|
|
|
|
methodsTableModifier.setLayout(new BoxLayout(methodsTableModifier, BoxLayout.Y_AXIS));
|
2020-12-09 22:43:01 +01:00
|
|
|
JButton addMethod = new JButton(" + ");
|
|
|
|
|
addMethod.setToolTipText("Add a new method.");
|
2020-12-07 22:18:54 +01:00
|
|
|
addMethod.addActionListener(new ActionListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
|
|
addMethod();
|
|
|
|
|
}
|
|
|
|
|
});
|
2020-12-09 22:43:01 +01:00
|
|
|
methodsTableModifier.add(addMethod);
|
|
|
|
|
|
|
|
|
|
JButton generateConstructor = new JButton("Generate constructor");
|
|
|
|
|
generateConstructor.setToolTipText("Generate constructor for this class.");
|
|
|
|
|
generateConstructor.addActionListener(new ActionListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
|
|
System.out.println("Generate constructor");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
methodsTableModifier.add(generateConstructor);
|
|
|
|
|
|
|
|
|
|
JButton removeMethod = new JButton(" - ");
|
|
|
|
|
removeMethod.setToolTipText("Remove the selected method.");
|
2020-12-07 22:18:54 +01:00
|
|
|
removeMethod.addActionListener(new ActionListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
|
|
removeMethod();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
methodsTableModifier.add(removeMethod);
|
2020-12-09 22:43:01 +01:00
|
|
|
JButton upMethod = new JButton("▲");
|
|
|
|
|
upMethod.setToolTipText("Go up the selected method.");
|
|
|
|
|
upMethod.addActionListener(new ActionListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
|
|
int selected = _methodsTable.getSelectedRow();
|
|
|
|
|
if(_class.upMethod(selected)){
|
|
|
|
|
save(ClassPropertiesWindow.UPDATE_METH, false);
|
|
|
|
|
listMethods();
|
|
|
|
|
_methodsTable.setRowSelectionInterval(selected - 1, selected - 1);
|
|
|
|
|
_umlDiagram.repaint();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
methodsTableModifier.add(upMethod);
|
|
|
|
|
JButton downMethod = new JButton("▼");
|
|
|
|
|
downMethod.setToolTipText("Go down the selected method.");
|
|
|
|
|
downMethod.addActionListener(new ActionListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
|
|
int selected = _methodsTable.getSelectedRow();
|
|
|
|
|
if(_class.downMethod(selected)){
|
|
|
|
|
save(ClassPropertiesWindow.UPDATE_METH, false);
|
|
|
|
|
listMethods();
|
|
|
|
|
_methodsTable.setRowSelectionInterval(selected + 1, selected + 1);
|
|
|
|
|
_umlDiagram.repaint();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
methodsTableModifier.add(downMethod);
|
2020-12-07 22:18:54 +01:00
|
|
|
|
|
|
|
|
methodsPan.add(methodsTableModifier);
|
|
|
|
|
|
|
|
|
|
generalPanel.add(methodsPan);
|
|
|
|
|
|
|
|
|
|
//Bouton de sauvegarde
|
|
|
|
|
JButton saveBtn = new JButton("Save changes and quit");
|
|
|
|
|
saveBtn.addActionListener(new ActionListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
2020-12-09 22:43:01 +01:00
|
|
|
save(ClassPropertiesWindow.UPDATE_ALL, true);
|
2020-12-07 22:18:54 +01:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
generalPanel.add(saveBtn);
|
|
|
|
|
|
|
|
|
|
this.add(generalPanel, BorderLayout.CENTER);
|
|
|
|
|
|
|
|
|
|
this.setVisible(true);
|
|
|
|
|
|
|
|
|
|
//Import des attributs et méthodes dans les tableaux
|
|
|
|
|
this.listAttributes();
|
|
|
|
|
this.listMethods();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Ouvre une fenêtre d'édition des arguments pour la méthode sélectionnée
|
2020-12-09 12:48:52 +01:00
|
|
|
* @param m La méthode dans laquelle seront modifiés les arguments.
|
2020-12-07 22:18:54 +01:00
|
|
|
*/
|
|
|
|
|
public void openArgumentsWindow(Method m){
|
|
|
|
|
ArgumentsPropertiesWindow argsWin = new ArgumentsPropertiesWindow(this, _umlDiagram, m);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Récupère la classe en cours d'édition.
|
|
|
|
|
* @return La classe en cours d'édition.
|
|
|
|
|
*/
|
|
|
|
|
public Class getEditingClass(){
|
|
|
|
|
return _class;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Ajoute un attribut à la classe et rafraîchit la liste des attributs.
|
|
|
|
|
*/
|
|
|
|
|
public void addAttribute(){
|
2020-12-09 22:43:01 +01:00
|
|
|
this.save(ClassPropertiesWindow.UPDATE_ATTR, false);
|
2020-12-07 22:18:54 +01:00
|
|
|
_class.addAttribute(new Attribute());
|
|
|
|
|
this.listAttributes();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retire un attribut à la classe et rafraîchit la liste des attributs.
|
|
|
|
|
*/
|
|
|
|
|
public void removeAttribute(){
|
2020-12-09 22:43:01 +01:00
|
|
|
this.save(ClassPropertiesWindow.UPDATE_ATTR, false);
|
2020-12-07 22:18:54 +01:00
|
|
|
int i = _attributesTable.getSelectedRow();
|
|
|
|
|
if(i != -1){
|
|
|
|
|
_class.removeAttribute(i);
|
|
|
|
|
this.listAttributes();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Affiche la liste des attributs de la classe dans le tableau
|
|
|
|
|
*/
|
|
|
|
|
public void listAttributes(){
|
|
|
|
|
//Import des attributs dans la table
|
|
|
|
|
_attributeModel.setDataVector((Object[][]) null, _attributesColumns);
|
|
|
|
|
for(Attribute attr : _class.getAttributes()){
|
|
|
|
|
String access = attr.getAccess();
|
|
|
|
|
switch(access){
|
|
|
|
|
case "-":
|
|
|
|
|
access = "PRIVATE";
|
|
|
|
|
break;
|
|
|
|
|
case "+":
|
|
|
|
|
access = "PUBLIC";
|
|
|
|
|
break;
|
|
|
|
|
case "#":
|
|
|
|
|
access = "PROTECTED";
|
|
|
|
|
break;
|
|
|
|
|
}
|
2020-12-09 12:48:52 +01:00
|
|
|
_attributeModel.addRow(new Object[]{attr.getName(), access, attr.getType(), attr.isStatic(), attr.isFinal(), attr.isAbstract(), attr.isSynchronized(), attr.isVolatile(), attr.isTransient()});
|
2020-12-07 22:18:54 +01:00
|
|
|
}
|
|
|
|
|
//On ajoute les contrôles pour chaque colonne
|
|
|
|
|
JComboBox accessComboBox = new JComboBox();
|
|
|
|
|
accessComboBox.setEditable(true);
|
|
|
|
|
accessComboBox.addItem("PRIVATE");
|
|
|
|
|
accessComboBox.addItem("PUBLIC");
|
|
|
|
|
accessComboBox.addItem("PROTECTED");
|
|
|
|
|
TableColumn accessColumn = _attributesTable.getColumn(_attributesColumns[1]);
|
|
|
|
|
accessColumn.setCellEditor(new DefaultCellEditor(accessComboBox));
|
|
|
|
|
|
|
|
|
|
JComboBox typeComboBox = new JComboBox();
|
|
|
|
|
typeComboBox.setEditable(true);
|
|
|
|
|
typeComboBox.addItem("boolean");
|
|
|
|
|
typeComboBox.addItem("char");
|
|
|
|
|
typeComboBox.addItem("byte");
|
|
|
|
|
typeComboBox.addItem("short");
|
|
|
|
|
typeComboBox.addItem("int");
|
|
|
|
|
typeComboBox.addItem("long");
|
|
|
|
|
typeComboBox.addItem("float");
|
|
|
|
|
typeComboBox.addItem("double");
|
|
|
|
|
typeComboBox.addItem("String");
|
|
|
|
|
TableColumn typeColumn = _attributesTable.getColumn(_attributesColumns[2]);
|
|
|
|
|
typeColumn.setCellEditor(new DefaultCellEditor(typeComboBox));
|
2020-12-09 12:48:52 +01:00
|
|
|
|
|
|
|
|
JCheckBox staticComboBox = new JCheckBox();
|
|
|
|
|
TableColumn staticColumn = _attributesTable.getColumn(_attributesColumns[3]);
|
|
|
|
|
staticColumn.setCellEditor(new DefaultCellEditor(staticComboBox));
|
|
|
|
|
JCheckBox finalComboBox = new JCheckBox();
|
|
|
|
|
TableColumn finalColumn = _attributesTable.getColumn(_attributesColumns[4]);
|
|
|
|
|
finalColumn.setCellEditor(new DefaultCellEditor(finalComboBox));
|
|
|
|
|
JCheckBox abstractComboBox = new JCheckBox();
|
|
|
|
|
TableColumn abstractColumn = _attributesTable.getColumn(_attributesColumns[5]);
|
|
|
|
|
abstractColumn.setCellEditor(new DefaultCellEditor(abstractComboBox));
|
|
|
|
|
JCheckBox synchronizedComboBox = new JCheckBox();
|
|
|
|
|
TableColumn synchronizedColumn = _attributesTable.getColumn(_attributesColumns[6]);
|
|
|
|
|
synchronizedColumn.setCellEditor(new DefaultCellEditor(synchronizedComboBox));
|
|
|
|
|
JCheckBox volatileComboBox = new JCheckBox();
|
|
|
|
|
TableColumn volatileColumn = _attributesTable.getColumn(_attributesColumns[7]);
|
|
|
|
|
volatileColumn.setCellEditor(new DefaultCellEditor(volatileComboBox));
|
|
|
|
|
JCheckBox transientComboBox = new JCheckBox();
|
|
|
|
|
TableColumn transientColumn = _attributesTable.getColumn(_attributesColumns[8]);
|
|
|
|
|
transientColumn.setCellEditor(new DefaultCellEditor(transientComboBox));
|
2020-12-07 22:18:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Ajoute une méthode à la classe et rafraîchit la liste des méthodes.
|
|
|
|
|
*/
|
|
|
|
|
public void addMethod(){
|
2020-12-09 22:43:01 +01:00
|
|
|
this.save(ClassPropertiesWindow.UPDATE_METH, false);
|
2020-12-07 22:18:54 +01:00
|
|
|
_class.addMethod(new Method());
|
|
|
|
|
this.listMethods();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retire une méthode à la classe et rafraîchit la liste des méthodes.
|
|
|
|
|
*/
|
|
|
|
|
public void removeMethod(){
|
2020-12-09 22:43:01 +01:00
|
|
|
this.save(ClassPropertiesWindow.UPDATE_METH, false);
|
2020-12-07 22:18:54 +01:00
|
|
|
int i = _methodsTable.getSelectedRow();
|
|
|
|
|
if(i != -1){
|
|
|
|
|
_class.removeMethod(i);
|
|
|
|
|
this.listMethods();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Affiche la liste des méthodes de la classe dans le tableau
|
|
|
|
|
*/
|
|
|
|
|
public void listMethods(){
|
|
|
|
|
//Import des attributs dans la table
|
|
|
|
|
_methodModel.setDataVector((Object[][]) null, _methodsColumns);
|
|
|
|
|
for(Method meth : _class.getMethods()){
|
|
|
|
|
String access = meth.getAccess();
|
|
|
|
|
switch(access){
|
|
|
|
|
case "-":
|
|
|
|
|
access = "PRIVATE";
|
|
|
|
|
break;
|
|
|
|
|
case "+":
|
|
|
|
|
access = "PUBLIC";
|
|
|
|
|
break;
|
|
|
|
|
case "#":
|
|
|
|
|
access = "PROTECTED";
|
|
|
|
|
break;
|
|
|
|
|
}
|
2020-12-09 12:48:52 +01:00
|
|
|
_methodModel.addRow(new Object[]{meth.getName(), access, meth.getType(), "...", meth.isStatic(), meth.isFinal(), meth.isAbstract(), meth.isSynchronized(), meth.isVolatile(), meth.isTransient()});
|
2020-12-07 22:18:54 +01:00
|
|
|
}
|
|
|
|
|
//On ajoute les contrôles pour chaque colonne
|
|
|
|
|
JComboBox accessComboBox = new JComboBox();
|
|
|
|
|
accessComboBox.setEditable(true);
|
|
|
|
|
accessComboBox.addItem("PRIVATE");
|
|
|
|
|
accessComboBox.addItem("PUBLIC");
|
|
|
|
|
accessComboBox.addItem("PROTECTED");
|
|
|
|
|
TableColumn accessColumn = _methodsTable.getColumn(_methodsColumns[1]);
|
|
|
|
|
accessColumn.setCellEditor(new DefaultCellEditor(accessComboBox));
|
|
|
|
|
|
|
|
|
|
JComboBox typeComboBox = new JComboBox();
|
|
|
|
|
typeComboBox.setEditable(true);
|
|
|
|
|
typeComboBox.addItem("boolean");
|
|
|
|
|
typeComboBox.addItem("char");
|
|
|
|
|
typeComboBox.addItem("byte");
|
|
|
|
|
typeComboBox.addItem("short");
|
|
|
|
|
typeComboBox.addItem("int");
|
|
|
|
|
typeComboBox.addItem("long");
|
|
|
|
|
typeComboBox.addItem("float");
|
|
|
|
|
typeComboBox.addItem("double");
|
|
|
|
|
typeComboBox.addItem("String");
|
|
|
|
|
TableColumn typeColumn = _methodsTable.getColumn(_methodsColumns[2]);
|
|
|
|
|
typeColumn.setCellEditor(new DefaultCellEditor(typeComboBox));
|
|
|
|
|
|
|
|
|
|
JTextField argsField = new JTextField();
|
|
|
|
|
argsField.setEnabled(false);
|
|
|
|
|
TableColumn argColumn = _methodsTable.getColumn(_methodsColumns[3]);
|
|
|
|
|
argColumn.setCellEditor(new DefaultCellEditor(argsField));
|
2020-12-09 12:48:52 +01:00
|
|
|
|
|
|
|
|
JCheckBox staticComboBox = new JCheckBox();
|
|
|
|
|
TableColumn staticColumn = _methodsTable.getColumn(_methodsColumns[4]);
|
|
|
|
|
staticColumn.setCellEditor(new DefaultCellEditor(staticComboBox));
|
|
|
|
|
JCheckBox finalComboBox = new JCheckBox();
|
|
|
|
|
TableColumn finalColumn = _methodsTable.getColumn(_methodsColumns[5]);
|
|
|
|
|
finalColumn.setCellEditor(new DefaultCellEditor(finalComboBox));
|
|
|
|
|
JCheckBox abstractComboBox = new JCheckBox();
|
|
|
|
|
TableColumn abstractColumn = _methodsTable.getColumn(_methodsColumns[6]);
|
|
|
|
|
abstractColumn.setCellEditor(new DefaultCellEditor(abstractComboBox));
|
|
|
|
|
JCheckBox synchronizedComboBox = new JCheckBox();
|
|
|
|
|
TableColumn synchronizedColumn = _methodsTable.getColumn(_methodsColumns[7]);
|
|
|
|
|
synchronizedColumn.setCellEditor(new DefaultCellEditor(synchronizedComboBox));
|
|
|
|
|
JCheckBox volatileComboBox = new JCheckBox();
|
|
|
|
|
TableColumn volatileColumn = _methodsTable.getColumn(_methodsColumns[8]);
|
|
|
|
|
volatileColumn.setCellEditor(new DefaultCellEditor(volatileComboBox));
|
|
|
|
|
JCheckBox transientComboBox = new JCheckBox();
|
|
|
|
|
TableColumn transientColumn = _methodsTable.getColumn(_methodsColumns[9]);
|
|
|
|
|
transientColumn.setCellEditor(new DefaultCellEditor(transientComboBox));
|
2020-12-07 22:18:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sauvegarde les modifications pour la classe en cours et ferme la fenêtre.
|
2020-12-09 22:43:01 +01:00
|
|
|
* @param focusUpdate Les éléments à sauvegarder.
|
|
|
|
|
* @param quit Fermer la fenêtre après la sauvegarde.
|
2020-12-07 22:18:54 +01:00
|
|
|
*/
|
2020-12-09 22:43:01 +01:00
|
|
|
public void save(int focusUpdate, boolean quit){
|
|
|
|
|
//Si la sauvegarde des attributs est demandée
|
|
|
|
|
if(focusUpdate == ClassPropertiesWindow.UPDATE_ATTR || focusUpdate == ClassPropertiesWindow.UPDATE_ALL){
|
|
|
|
|
//Termine l'édition en sélectionnant une autre cellule
|
|
|
|
|
_attributesTable.editCellAt(0,0);
|
|
|
|
|
//Changement du nom de la classe
|
|
|
|
|
_class.setName(_nameField.getText());
|
|
|
|
|
//Enregistrement des attributs
|
|
|
|
|
for(int i = 0; i <= _attributeModel.getRowCount()-1; i++){
|
|
|
|
|
Vector vect = (Vector)_attributeModel.getDataVector().elementAt(i);
|
|
|
|
|
String access = vect.get(1).toString();
|
|
|
|
|
switch(access){
|
|
|
|
|
case "PRIVATE" :
|
|
|
|
|
_class.getAttributes().get(i).setAccess(Attribute.PRIVATE);
|
|
|
|
|
break;
|
|
|
|
|
case "PUBLIC" :
|
|
|
|
|
_class.getAttributes().get(i).setAccess(Attribute.PUBLIC);
|
|
|
|
|
break;
|
|
|
|
|
case "PROTECTED" :
|
|
|
|
|
_class.getAttributes().get(i).setAccess(Attribute.PROTECTED);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
_class.getAttributes().get(i).setName(vect.get(0).toString());
|
|
|
|
|
_class.getAttributes().get(i).setType(vect.get(2).toString());
|
|
|
|
|
_class.getAttributes().get(i).setStatic((boolean) vect.get(3));
|
|
|
|
|
_class.getAttributes().get(i).setFinal((boolean) vect.get(4));
|
|
|
|
|
_class.getAttributes().get(i).setAbstract((boolean) vect.get(5));
|
|
|
|
|
_class.getAttributes().get(i).setSynchronized((boolean) vect.get(6));
|
|
|
|
|
_class.getAttributes().get(i).setVolatile((boolean) vect.get(7));
|
|
|
|
|
_class.getAttributes().get(i).setTransient((boolean) vect.get(8));
|
2020-12-07 22:18:54 +01:00
|
|
|
}
|
2020-12-09 22:43:01 +01:00
|
|
|
|
2020-12-07 22:18:54 +01:00
|
|
|
}
|
2020-12-09 22:43:01 +01:00
|
|
|
//Si la sauvegarde des méthodes est demandée
|
|
|
|
|
if(focusUpdate == ClassPropertiesWindow.UPDATE_METH || focusUpdate == ClassPropertiesWindow.UPDATE_ALL){
|
|
|
|
|
//Enregistrement des méthodes
|
|
|
|
|
_methodsTable.editCellAt(0,0);
|
|
|
|
|
for(int i = 0; i <= _methodModel.getRowCount()-1; i++){
|
|
|
|
|
Vector vect = (Vector)_methodModel.getDataVector().elementAt(i);
|
|
|
|
|
String access = vect.get(1).toString();
|
|
|
|
|
switch(access){
|
|
|
|
|
case "PRIVATE" :
|
|
|
|
|
_class.getMethods().get(i).setAccess(Method.PRIVATE);
|
|
|
|
|
break;
|
|
|
|
|
case "PUBLIC" :
|
|
|
|
|
_class.getMethods().get(i).setAccess(Method.PUBLIC);
|
|
|
|
|
break;
|
|
|
|
|
case "PROTECTED" :
|
|
|
|
|
_class.getMethods().get(i).setAccess(Method.PROTECTED);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
_class.getMethods().get(i).setName(vect.get(0).toString());
|
|
|
|
|
_class.getMethods().get(i).setType(vect.get(2).toString());
|
|
|
|
|
_class.getMethods().get(i).setStatic((boolean) vect.get(4));
|
|
|
|
|
_class.getMethods().get(i).setFinal((boolean) vect.get(5));
|
|
|
|
|
_class.getMethods().get(i).setAbstract((boolean) vect.get(6));
|
|
|
|
|
_class.getMethods().get(i).setSynchronized((boolean) vect.get(7));
|
|
|
|
|
_class.getMethods().get(i).setVolatile((boolean) vect.get(8));
|
|
|
|
|
_class.getMethods().get(i).setTransient((boolean) vect.get(9));
|
2020-12-07 22:18:54 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Rafraichissement de l'affichage
|
|
|
|
|
this._class.computeMinSize();
|
|
|
|
|
_umlDiagram.repaint();
|
2020-12-09 22:43:01 +01:00
|
|
|
if(quit) this.dispose();
|
2020-12-07 22:18:54 +01:00
|
|
|
}
|
|
|
|
|
}
|