-
Notifications
You must be signed in to change notification settings - Fork 1
/
MyListSelectionListener.java
39 lines (35 loc) · 1.79 KB
/
MyListSelectionListener.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
class MyListSelectionListener implements ListSelectionListener {
private final DPGenGUI genGUI;
MyListSelectionListener(DPGenGUI genGUI) {
this.genGUI = genGUI;
}
@Override
public void valueChanged(ListSelectionEvent e) {
if (!e.getValueIsAdjusting()) {
int index = genGUI.elementList.getSelectedIndex();
if (index < 0) return;
genGUI.selectedBlock = genGUI.materialBlocks.get(index);
genGUI.selectedIndex = index;
genGUI.updateResultSelectionWithoutComposing();
//switching panel
if (genGUI.selectedBlock instanceof PictureBlock) {
genGUI.mainCardLayout.show(genGUI.mainCardPanel, "picture");
genGUI.currentImage = ((PictureBlock) genGUI.selectedBlock).picture;
genGUI.imageOnEditLabel.setIcon(new ImageIcon(DPGenGUI.getResizedImageByWidth(genGUI.currentImage, 300)));
genGUI.imageTextField.setText(((PictureBlock) genGUI.selectedBlock).description);
genGUI.imageTextField.requestFocus();
} else if (genGUI.selectedBlock instanceof Article) {
genGUI.mainCardLayout.show(genGUI.mainCardPanel, "article");
genGUI.articleArea.setText(DPGenGUI.getStringFromStringVector(((Article)genGUI.selectedBlock).article, true));
genGUI.articleArea.requestFocus();
} else if (genGUI.selectedBlock instanceof Title) {
genGUI.mainCardLayout.show(genGUI.mainCardPanel, "title");
genGUI.titleField.setText(((Title)genGUI.selectedBlock).header);
genGUI.titleField.requestFocus();
}
}
}
}