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
| import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.util.Hashtable;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.TreePath;
public class SFPLayout extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel pnlParameter;
private JTree preferenceTree;
public SFPLayout() {
super("SampleTest");
setSize(800, 700);
setDefaultCloseOperation(EXIT_ON_CLOSE);
// Liste des mots-clés par Catégorie
final String[] schoolyard = { "School", "Playground", "Parking Lot",
"Field" };
final String[] mainstreet = { "Grocery", "Shoe Shop", "Five & Dime",
"Post Office" };
final String[] highway = { "Gas Station", "Convenience Store" };
final Hashtable<String, String[]> category = new Hashtable<String, String[]>();
category.put("School grounds", schoolyard);
category.put("Downtown", mainstreet);
category.put("Highway", highway);
final Hashtable<String, Hashtable<String, String[]>> rootNode = new Hashtable<String, Hashtable<String, String[]>>();
rootNode.put("Preferences", category);
preferenceTree = new JTree(rootNode);
pnlParameter = createDefaultPane();
preferenceTree.addTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent e) {
TreePath path = e.getPath();
Object elements[] = path.getPath();
// Si on est sur un élément de paramètre sélectionné, alors on
// fait les opérations
if (elements.length == 4) {
pnlParameter = createParameterPane(elements[3].toString(),"valeur");
}
else{
pnlParameter = createDefaultPane();
}
}
});
Container contentPane = getContentPane();
contentPane.setLayout(new GridLayout(1, 3));
contentPane.add(new JScrollPane(preferenceTree));
contentPane.add(pnlParameter);
}
private JPanel createDefaultPane() {
pnlParameter = new JPanel();
pnlParameter.setLayout(new FlowLayout());
pnlParameter.setPreferredSize(new Dimension(250, 630));
// container.setBorder(BorderFactory.createTitledBorder(title));
JLabel lbPleaseSelect = new JLabel("Please select a parameter");
pnlParameter.add(lbPleaseSelect);
return pnlParameter;
}
private JPanel createParameterPane(String ParameterName, String ParameterValue) {
pnlParameter = new JPanel();
pnlParameter.setLayout(new FlowLayout());
pnlParameter.setPreferredSize(new Dimension(530, 630));
// container.setBorder(BorderFactory.createTitledBorder(title));
JButton btChangeAll = new JButton(
"Change everything in directory");
JButton btChangeSelf = new JButton("Change this file only");
pnlParameter.add(btChangeSelf);
pnlParameter.add(btChangeAll);
return pnlParameter;
}
public static void main(final String args[]) {
final SFPLayout spfWindow = new SFPLayout();
spfWindow.setVisible(true);
}
} |
Partager