Skip to content

Commit

Permalink
fix modif compo dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
pierre-marie broca committed Oct 2, 2018
1 parent 1427595 commit b176a9a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,37 @@ public class ModifyCompositionDialog extends JDialog {
private JTextField titre;
private JComboBox<RecordType> type;
private boolean sendData;
private int artistIndex;
private int titleIndex;
private int typeIndex;

/**
* Constructeur de {@link ModifyCompositionDialog}.
*
* @param parent {@link JFrame} la fenetre parente
* @param header {@link String} les entetes de la popup
* @param modal {@code boolean} si la popup bloque l'utilisateur
* @param files {@code List<Fichier>} la liste des fichier à afficher
* @param dim {@link Dimension} les dimension de la popup
* @param compo {@link Vector} la compo à modifier
* @param artistIndex index de l'artiste dans la composition
* @param titleIndex index du titre dans la composition
* @param typeIndex index du type dans la composition
*/
public ModifyCompositionDialog(JFrame parent, String header, boolean modal, Dimension dim, Vector compo) {
public ModifyCompositionDialog(JFrame parent, String header, boolean modal, Dimension dim, Vector compo,
int artistIndex, int titleIndex, int typeIndex) {
super(parent, header, modal);
LOG.debug("Start DialogFileTable");
this.artistIndex = artistIndex;
this.titleIndex = titleIndex;
this.typeIndex = typeIndex;
this.setSize(dim);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
this.compo = compo;
this.setResizable(true);
initComposant();
this.getRootPane().registerKeyboardAction(e -> {
this.dispose();
this.dispose();
}, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW);
LOG.debug("End DialogFileTable");
}
Expand All @@ -72,7 +81,7 @@ private void initComposant() {
JPanel artistPanel = new JPanel();
artistPanel.setPreferredSize(new Dimension(250, 60));
JLabel artistLabel = new JLabel("Artiste : ");
artist = new JTextField((String) compo.get(0));
artist = new JTextField((String) compo.get(artistIndex));
artist.setPreferredSize(new Dimension(230, 30));
artistPanel.add(artistLabel);
artistPanel.add(artist);
Expand All @@ -81,7 +90,7 @@ private void initComposant() {
JPanel titrePanel = new JPanel();
titrePanel.setPreferredSize(new Dimension(300, 60));
JLabel titreLabel = new JLabel("Titre : ");
titre = new JTextField((String) compo.get(1));
titre = new JTextField((String) compo.get(titleIndex));
titre.setPreferredSize(new Dimension(270, 30));
titrePanel.add(titreLabel);
titrePanel.add(titre);
Expand All @@ -90,13 +99,9 @@ private void initComposant() {
JPanel typePanel = new JPanel();
typePanel.setPreferredSize(new Dimension(180, 60));
JLabel typeLabel = new JLabel("Type : ");
type = new JComboBox<>();
RecordType[] valuesType = RecordType.values();
for (int i = 0; i < valuesType.length; i++) {
type.addItem(valuesType[i]);
}
type = new JComboBox<>(RecordType.values());
type.setPreferredSize(new Dimension(150, 25));
type.setSelectedItem(RecordType.valueOf((String) compo.get(2)));
type.setSelectedItem(RecordType.valueOf((String) compo.get(typeIndex)));
typePanel.add(typeLabel);
typePanel.add(type);

Expand All @@ -111,9 +116,9 @@ private void initComposant() {
okBouton.addActionListener((ActionEvent arg0) -> {
setVisible(false);
sendData = true;
compo.set(0, artist.getText());
compo.set(1, titre.getText());
compo.set(2, type.getSelectedItem().toString());
compo.set(artistIndex, artist.getText());
compo.set(titleIndex, titre.getText());
compo.set(typeIndex, type.getSelectedItem().toString());
});

JButton cancelBouton = new JButton("Annuler");
Expand All @@ -140,10 +145,16 @@ public void showDialogFileTable() {
LOG.debug("End showDialogFileTable");
}

/**
* @return la composition à modifier
*/
public Vector getCompo() {
return compo;
}

/**
* @return if true the user has validate the modifications
*/
public boolean isSendData() {
return sendData;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ private void modifyCompositionAction(final ArtistPanel artistPanel, Vector<Strin
int indexOfResult = compositionList.indexOf(compoToModifInTable);
// Lancement de la popup de modification
ModifyCompositionDialog md = new ModifyCompositionDialog(null, "Modifier une composition", true,
new Dimension(800, 150), v);
new Dimension(800, 150), v, INDEX_COMPO_ARTIST, INDEX_COMPO_TITLE, INDEX_COMPO_TYPE);
md.showDialogFileTable();
if (md.isSendData()) {
// On recupère la compo si elle a bien été modifiée
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ private void modifAction(final ArtistPanel artist2) {
}
// Lancement de la popup de modification
ModifyCompositionDialog md = new ModifyCompositionDialog(null, "Modifier une composition", true,
new Dimension(800, 150), v);
new Dimension(800, 150), v, INDEX_ARTIST, INDEX_TITRE, INDEX_TYPE);
md.showDialogFileTable();
if (md.isSendData()) {
// On recupère la compo si elle a bien été modifiée
Expand Down

0 comments on commit b176a9a

Please sign in to comment.