1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.cosylab.gui.infopanel;
21
22 import java.awt.BorderLayout;
23 import java.awt.GridBagConstraints;
24 import java.awt.GridBagLayout;
25 import java.awt.Insets;
26
27 import javax.swing.DefaultListModel;
28 import javax.swing.JLabel;
29 import javax.swing.JList;
30 import javax.swing.JPanel;
31
32 import com.cosylab.gui.adapters.Converter;
33 import com.cosylab.gui.adapters.ConverterChain;
34 import com.cosylab.gui.adapters.ConverterUtilities;
35 import com.cosylab.gui.displayers.DataSource;
36
37
38
39
40
41
42
43
44 public class ConverterPanel extends JPanel {
45 private static final long serialVersionUID = -7953031747105924874L;
46 private Converter converter;
47 private DataSource dataSource;
48 private JLabel functionLabel;
49 private JLabel dataSourceLabel;
50 private JLabel dataSourceL;
51 private JList converterList;
52 private DefaultListModel model;
53
54
55
56
57
58 public ConverterPanel() {
59 super();
60 initialize();
61 }
62
63 private void initialize() {
64 this.setLayout(new BorderLayout());
65
66 dataSourceLabel = new JLabel("Data Source:");
67 dataSourceL = new JLabel("N/A");
68 JPanel northPanel = new JPanel(new GridBagLayout());
69 northPanel.add(dataSourceLabel, new GridBagConstraints(0,0,1,1,0,0,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1,1,1,1),0,0));
70 northPanel.add(dataSourceL, new GridBagConstraints(1,0,1,1,1,0,GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, new Insets(1,1,1,1),0,0));
71 this.add(northPanel, BorderLayout.NORTH);
72
73 converterList = new JList();
74 model = new DefaultListModel();
75 converterList.setModel(model);
76 this.add(converterList, BorderLayout.CENTER);
77 functionLabel = new JLabel("id");
78 this.add(functionLabel, BorderLayout.SOUTH);
79 }
80
81
82
83
84
85
86 public void setConverter(Converter c) {
87 this.converter = c;
88 if (converter != null) {
89 functionLabel.setText("f(x) = " + ConverterUtilities.composeFunctionString(c, "x"));
90 model.clear();
91 if (converter instanceof ConverterChain) {
92 Converter[] converters = ((ConverterChain)converter).getConverters();
93 for (Converter co : converters) {
94 model.addElement(co);
95 }
96 } else {
97 model.addElement(converter);
98 }
99 } else {
100 model.clear();
101 functionLabel.setText("id");
102 }
103 }
104
105
106
107
108
109
110 public Converter getConverter() {
111 return converter;
112 }
113
114
115
116
117
118 public void setDataSource(DataSource dataSource) {
119 this.dataSource = dataSource;
120 if (this.dataSource != null) {
121 dataSourceL.setText(dataSource.toString());
122 } else {
123 dataSourceL.setText("N/A");
124 }
125 }
126
127
128
129
130
131
132 public DataSource getDataSource() {
133 return dataSource;
134 }
135
136 }