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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
| public class MainWindow extends JFrame {
private static final int WIN_WIDTH = 700;
private static final int WIN_HEIGHT = 675;
private static final int PAN_WIDTH = WIN_WIDTH - 20;
// Informations we need to get
private JTextField tFilesDirectory = new JTextField();
private JTextField tSkeletonDirectory = new JTextField();
private List<Algorithm> lAlgorithm = new ArrayList<Algorithm>();
private Component selectMatchingPanel;
public MainWindow(String name) {
super();
setWindowFont(); // pour set la police d'écriture
buildWindow(name); // créer la fenêtre basic
buildMenuBar(); // créer la barre de menu
buildContentPane(); // remplir la fenêtre
}
private void buildContentPane() {
Container contentPane = getContentPane();
contentPane.add(basicOptionsPanel(), BorderLayout.PAGE_START);
JPanel panel = new JPanel();
panel.add(selectMatchingPanel());
contentPane.add(panel, BorderLayout.CENTER);
contentPane.add(selectProcessPanel(), BorderLayout.PAGE_END);
}
private JPanel basicOptionsPanel() {
JPanel panel = new JPanel();
... remplissage du panel ...
return panel;
}
private JScrollPane selectMatchingPanel() {
JPanel panel = new JPanel();
panel.setBorder(BorderFactory.createTitledBorder("Algorithm selection"));
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
try {
List<String> tmp = Utils.getClasses("dssc"); // Récupération de la liste des classes dans le package dssc
int i = 0;
for (Iterator it = tmp.iterator(); it.hasNext();i++) {
String sAlgorithm = (String)it.next();
JCheckBox cAlgorithm = new JCheckBox(sAlgorithm);
cAlgorithm.setName(sAlgorithm);
Algorithm aAlgorithm = new Algorithm(cAlgorithm);
// Adding the CheckBox to a list
lAlgorithm.add(aAlgorithm);
// Creating
JPanel pAlgorithm = new JPanel();
pAlgorithm.setBorder(BorderFactory.createTitledBorder(""));
GroupLayout gAlgorithm = new GroupLayout(pAlgorithm);
pAlgorithm.setLayout(gAlgorithm);
gAlgorithm.setAutoCreateGaps(true);
gAlgorithm.setAutoCreateContainerGaps(true);
JPanel pPreprocessors = fillPreprocessorsWindow(aAlgorithm, i);
if ((i % 2) == 0) {
cAlgorithm.setBackground(Color.GRAY);
pAlgorithm.setBackground(Color.GRAY);
pPreprocessors.setBackground(Color.GRAY);
}
pPreprocessors.setBorder(BorderFactory.createTitledBorder("Preprocessors"));
gAlgorithm.setHorizontalGroup(gAlgorithm.createSequentialGroup()
.addComponent(cAlgorithm)
.addComponent(pPreprocessors));
gAlgorithm.setVerticalGroup(gAlgorithm.createSequentialGroup()
.addComponent(cAlgorithm)
.addComponent(pPreprocessors));
panel.add(pAlgorithm);
if (it.hasNext())
panel.add(Box.createRigidArea(new Dimension(0, 10)));
}
} catch (Exception e) {}
return new JScrollPane(panel);
}
private JPanel fillPreprocessorsWindow(Algorithm algorithm, int i) {
JPanel panel = new JPanel();
panel.setBorder(BorderFactory.createLineBorder(Color.red));
try {
List<String> tmp = Utils.getClasses("maingui");
for (Iterator it = tmp.iterator(); it.hasNext();) {
String sPreprocessor = (String)it.next();
JCheckBox cPreprocessor = new JCheckBox(sPreprocessor);
cPreprocessor.setName(sPreprocessor);
if ((i % 2) == 0)
cPreprocessor.setBackground(Color.GRAY);
panel.add(cPreprocessor);
algorithm.addPreprocessor(cPreprocessor);
if (it.hasNext())
panel.add(Box.createRigidArea(new Dimension(10, 0)));
}
} catch (Exception e) {}
return panel;
}
private JPanel selectProcessPanel() {
JPanel panel = new JPanel();
panel.setPreferredSize(new Dimension(PAN_WIDTH, 50));
panel.setMaximumSize(new Dimension(PAN_WIDTH, 50));
JButton process = new JButton("Process files");
process.setPreferredSize(new Dimension(100, 40));
process.setMaximumSize(new Dimension(100, 40));
process.setAlignmentX(Component.CENTER_ALIGNMENT);
process.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
showAlgoAndPreproList();
}
});
panel.add(process, BorderLayout.CENTER);
return panel;
}
private void setWindowFont() {
UIManager.put("Button.font", new Font("Serif", Font.PLAIN, 12));
UIManager.put("CheckBox.font", new Font("Serif", Font.PLAIN, 12));
UIManager.put("Label.font", new Font("Serif", Font.PLAIN, 12));
UIManager.put("TitledBorder.font", new Font("Serif", Font.BOLD, 12));
}
private void buildWindow(String name) {
setTitle(name);
setPreferredSize(new Dimension(WIN_WIDTH, WIN_HEIGHT));
// setResizable(false); // Avoid resize
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Close the application when user click on the cross
}
private void buildMenuBar() {
JMenuBar menuBar = new JMenuBar();
// File Menu
JMenu file = new JMenu("File");
JMenuItem exit = new JMenuItem(new ExitAction("Exit"));
file.add(exit);
// Help menu
JMenu help = new JMenu("Help");
JMenuItem aPropos = new JMenuItem(new AboutAction(this, "About"));
help.add(aPropos);
// adding menus
menuBar.add(file);
menuBar.add(help);
// Setting the MenuBar
setJMenuBar(menuBar);
}
} |