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 153 154 155 156 157 158 159
| public class ChartOption extends JFrame {
private static final long serialVersionUID = 1L;
private final Map<String, JFrame> chartFrameMap = new HashMap<String, JFrame>();
public JPanel panelMain = new JPanel(new BorderLayout());
public JPanel panelCombo = new JPanel(new MigLayout("fill, wrap 2, insets 2"));
public JPanel panelBtn = new JPanel();
public JLabel labelTitle = new JLabel("Title : ");
public JLabel labelIcon = new JLabel("Icon : ");
public JButton boutonOk = new JButton("OK");
public JButton boutonCancel = new JButton("Cancel");
JComboBox comboPlot;
JComboBox comboIcon;
private final ImageIcon CHART_LINE = new ImageIcon(getClass().getResource("/com/famfamfam/silk/chart_line.png"));
private final ImageIcon CHART_CURVE = new ImageIcon(getClass().getResource("/com/famfamfam/silk/chart_curve.png"));
private final ImageIcon CHART_PIE = new ImageIcon(getClass().getResource("/com/famfamfam/silk/chart_pie.png"));
private final ImageIcon CHART_BAR = new ImageIcon(getClass().getResource("/com/famfamfam/silk/chart_bar.png"));
private final ImageIcon ASTERISK_YELLOW = new ImageIcon(getClass().getResource(
"/com/famfamfam/silk/asterisk_yellow.png"));
private final ImageIcon WORLD_ICON = new ImageIcon(getClass().getResource("/com/famfamfam/silk/world.png"));
private final ImageIcon FLAG_BLUE = new ImageIcon(getClass().getResource("/com/famfamfam/silk/flag_blue.png"));
private final ImageIcon FLAG_GREEN = new ImageIcon(getClass().getResource("/com/famfamfam/silk/flag_green.png"));
private final ImageIcon RAINBOW_ICON = new ImageIcon(getClass().getResource("/com/famfamfam/silk/rainbow.png"));
private final ImageIcon SHIELD = new ImageIcon(getClass().getResource("/com/famfamfam/silk/shield.png"));
public final ImageIcon[] images = { CHART_LINE, CHART_PIE, CHART_CURVE, CHART_BAR, ASTERISK_YELLOW, WORLD_ICON,
FLAG_BLUE, FLAG_GREEN, SHIELD, RAINBOW_ICON };
public ChartOption() {
this.setTitle("Chart Option");
this.setSize(250, 250);
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
this.setLocationRelativeTo(null);
this.addWindowListener(new WindowListener() {
@Override
public void windowOpened(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowIconified(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowDeiconified(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowDeactivated(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowClosing(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowClosed(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowActivated(WindowEvent e) {
// TODO Auto-generated method stub
}
});
this.setVisible(true);
comboPlot = new JComboBox();
comboPlot.setEditable(true);
comboIcon = new JComboBox();
for (ImageIcon icon : images) {
comboIcon.addItem(icon);
}
ListCellRenderer renderer = comboIcon.getRenderer();
ComboIconRenderer iconRenderer = new ComboIconRenderer(renderer);
comboIcon.setRenderer(iconRenderer);
panelMain.add(panelCombo, BorderLayout.CENTER);
panelCombo.add(labelTitle);
panelCombo.add(comboPlot);
panelCombo.add(labelIcon);
panelCombo.add(comboIcon);
panelMain.add(panelBtn, BorderLayout.SOUTH);
panelBtn.add(boutonOk);
panelBtn.add(boutonCancel);
boutonOk.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String title = comboPlot.getSelectedItem().toString();
String icon = comboIcon.getSelectedItem().toString();
// chartFrameMap.put("Title", frame);
// chartFrameMap.keySet();
comboPlot.addItem(title);
ChartViewFrame chartViewf = new ChartViewFrame();
chartViewf.setTitle(title);
}
});
boutonCancel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setVisible(false);
}
});
this.setContentPane(panelMain);
}
private class ComboIconRenderer extends DefaultListCellRenderer {
ListCellRenderer renderer;
public ComboIconRenderer(ListCellRenderer renderer) {
this.renderer = renderer;
}
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
boolean cellHasFocus) {
Component comp = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (comp instanceof JLabel && value instanceof ImageIcon) {
((JLabel) comp).setIcon((ImageIcon) value);
}
return comp;
}
}
public static void main(String[] args) {
ChartOption chart = new ChartOption();
chart.setVisible(true);
}
} |
Partager