| .. | .. |
|---|
| 16 | 16 | // NumberFilterPanel. |
|---|
| 17 | 17 | // but, i'm not sure how to do it in a way that doesn't make the code |
|---|
| 18 | 18 | // seem too complicated. |
|---|
| 19 | | - |
|---|
| 20 | | -public class FilterDatePanel extends FilterDefinitionPanel |
|---|
| 19 | +public class FilterDatePanel extends FilterDefinitionPanel |
|---|
| 21 | 20 | { |
|---|
| 22 | | - BabyHistogram histogram; |
|---|
| 23 | | - Field field; |
|---|
| 24 | | - JTextField startEntry; |
|---|
| 25 | | - JTextField endEntry; |
|---|
| 26 | | - JCheckBox nullBox; |
|---|
| 27 | | - Runnable action; |
|---|
| 28 | | - SimpleDateFormat df=new SimpleDateFormat("MMM dd yyyy"); |
|---|
| 29 | | - |
|---|
| 30 | | - public FilterDatePanel(final Field field, final Runnable action, final FilterControlPanel parent) |
|---|
| 31 | | - { |
|---|
| 32 | | - this.field=field; |
|---|
| 33 | | - this.action=action; |
|---|
| 34 | | - setLayout(new BorderLayout()); |
|---|
| 35 | | - setBorder(BorderFactory.createEmptyBorder(0,5,0,5)); |
|---|
| 36 | | - setBackground(Color.white); |
|---|
| 37 | | - add(new FilterTitle(field, parent, false), BorderLayout.NORTH); |
|---|
| 38 | | - |
|---|
| 39 | | - Runnable fullAction=new Runnable() |
|---|
| 40 | | - { |
|---|
| 41 | | - public void run() |
|---|
| 42 | | - { |
|---|
| 43 | | - startEntry.setText(format(histogram.getLow())); |
|---|
| 44 | | - endEntry.setText(format(histogram.getHigh())); |
|---|
| 45 | | - action.run(); |
|---|
| 46 | | - } |
|---|
| 47 | | - }; |
|---|
| 48 | | - |
|---|
| 49 | | - histogram=new BabyHistogram(fullAction); |
|---|
| 50 | | - |
|---|
| 51 | | - add(histogram, BorderLayout.CENTER); |
|---|
| 52 | | - |
|---|
| 53 | | - JPanel bottomStuff=new JPanel(); |
|---|
| 54 | | - bottomStuff.setLayout(new GridLayout(2,1)); |
|---|
| 55 | | - add(bottomStuff, BorderLayout.SOUTH); |
|---|
| 56 | | - |
|---|
| 57 | | - JPanel lowHighPanel=new JPanel(); |
|---|
| 58 | | - bottomStuff.add(lowHighPanel); |
|---|
| 59 | | - lowHighPanel.setBackground(Color.white); |
|---|
| 60 | | - lowHighPanel.setLayout(new BorderLayout()); |
|---|
| 61 | | - Font small=parent.getModel().getDisplay().small(); |
|---|
| 62 | | - |
|---|
| 63 | | - startEntry=new JTextField(7); |
|---|
| 64 | | - startEntry.addActionListener(new ActionListener() { |
|---|
| 65 | | - @Override |
|---|
| 66 | | - public void actionPerformed(ActionEvent e) { |
|---|
| 67 | | - setLowFromText(); |
|---|
| 68 | | - action.run(); |
|---|
| 69 | | - }}); |
|---|
| 70 | | - lowHighPanel.add(startEntry, BorderLayout.WEST); |
|---|
| 71 | | - startEntry.setFont(small); |
|---|
| 72 | | - |
|---|
| 73 | | - JLabel rangeLabel=new JLabel("to", JLabel.CENTER); |
|---|
| 74 | | - rangeLabel.setForeground(Color.gray); |
|---|
| 75 | | - rangeLabel.setFont(small); |
|---|
| 76 | | - lowHighPanel.add(rangeLabel, BorderLayout.CENTER); |
|---|
| 77 | | - endEntry=new JTextField(7); |
|---|
| 78 | | - lowHighPanel.add(endEntry, BorderLayout.EAST); |
|---|
| 79 | | - endEntry.addActionListener(new ActionListener() { |
|---|
| 80 | | - @Override |
|---|
| 81 | | - public void actionPerformed(ActionEvent e) { |
|---|
| 82 | | - setHighFromText(); |
|---|
| 83 | | - action.run(); |
|---|
| 84 | | - }}); |
|---|
| 85 | | - endEntry.setFont(small); |
|---|
| 86 | | - |
|---|
| 87 | | - nullBox=new JCheckBox("Include Missing Values"); |
|---|
| 88 | | - nullBox.addActionListener(new ActionListener() { |
|---|
| 89 | | - @Override |
|---|
| 90 | | - public void actionPerformed(ActionEvent e) { |
|---|
| 91 | | - action.run(); |
|---|
| 92 | | - }}); |
|---|
| 93 | | - bottomStuff.add(nullBox); |
|---|
| 94 | | - bottomStuff.setBackground(Color.white); |
|---|
| 95 | | - nullBox.setBackground(Color.white); |
|---|
| 96 | | - nullBox.setForeground(Color.gray); |
|---|
| 97 | | - nullBox.setFont(small); |
|---|
| 98 | | - |
|---|
| 99 | | - } |
|---|
| 100 | | - |
|---|
| 101 | | - String format(double x) |
|---|
| 102 | | - { |
|---|
| 103 | | - Date date=new Date((long)x); |
|---|
| 104 | | - return df.format(date); |
|---|
| 105 | | - } |
|---|
| 106 | | - |
|---|
| 107 | | - void setLowFromText() |
|---|
| 108 | | - { |
|---|
| 109 | | - try |
|---|
| 110 | | - { |
|---|
| 111 | | - long low=df.parse(startEntry.getText()).getTime(); |
|---|
| 112 | | - long high=(long)histogram.getHigh(); |
|---|
| 113 | | - if (low>high) |
|---|
| 114 | | - { |
|---|
| 115 | | - high=low; |
|---|
| 116 | | - endEntry.setText(startEntry.getText()); |
|---|
| 117 | | - } |
|---|
| 118 | | - histogram.setTrueRange(low,high); |
|---|
| 119 | | - |
|---|
| 120 | | - } |
|---|
| 121 | | - catch (Exception e) |
|---|
| 122 | | - { |
|---|
| 123 | | - |
|---|
| 124 | | - } |
|---|
| 125 | | - } |
|---|
| 126 | | - |
|---|
| 127 | | - |
|---|
| 128 | | - void setHighFromText() |
|---|
| 129 | | - { |
|---|
| 130 | | - try |
|---|
| 131 | | - { |
|---|
| 132 | | - long high=df.parse(endEntry.getText()).getTime(); |
|---|
| 133 | | - double low=(long)histogram.getLow(); |
|---|
| 134 | | - if (low>high) |
|---|
| 135 | | - { |
|---|
| 136 | | - low=high; |
|---|
| 137 | | - startEntry.setText(endEntry.getText()); |
|---|
| 138 | | - } |
|---|
| 139 | | - histogram.setTrueRange(low,high); |
|---|
| 140 | | - |
|---|
| 141 | | - } |
|---|
| 142 | | - catch (Exception e) |
|---|
| 143 | | - { |
|---|
| 144 | | - |
|---|
| 145 | | - } |
|---|
| 146 | | - } |
|---|
| 147 | 21 | |
|---|
| 148 | | - public void setData(double[] data) |
|---|
| 149 | | - { |
|---|
| 150 | | - histogram.setData(data); |
|---|
| 151 | | - startEntry.setText(format(histogram.getLow())); |
|---|
| 152 | | - endEntry.setText(format(histogram.getHigh())); |
|---|
| 153 | | - repaint(); |
|---|
| 154 | | - } |
|---|
| 155 | | - |
|---|
| 156 | | - public Dimension getPreferredSize() |
|---|
| 157 | | - { |
|---|
| 158 | | - return new Dimension(200,160); |
|---|
| 159 | | - } |
|---|
| 22 | + BabyHistogram histogram; |
|---|
| 23 | + Field field; |
|---|
| 24 | + JTextField startEntry; |
|---|
| 25 | + JTextField endEntry; |
|---|
| 26 | + JCheckBox nullBox; |
|---|
| 27 | + Runnable action; |
|---|
| 28 | + SimpleDateFormat df = new SimpleDateFormat("MMM dd yyyy"); |
|---|
| 160 | 29 | |
|---|
| 161 | | - @Override |
|---|
| 162 | | - public ActFilter defineFilter() { |
|---|
| 163 | | - long low=(long)histogram.getLow(); |
|---|
| 164 | | - long high=(long)histogram.getHigh(); |
|---|
| 165 | | - boolean acceptNull=nullBox.isSelected(); |
|---|
| 166 | | - return new TimeIntervalFilter(low, high, acceptNull, field); |
|---|
| 167 | | - } |
|---|
| 30 | + public FilterDatePanel(final Field field, final Runnable action, final FilterControlPanel parent) |
|---|
| 31 | + { |
|---|
| 32 | + this.field = field; |
|---|
| 33 | + this.action = action; |
|---|
| 34 | + setLayout(new BorderLayout()); |
|---|
| 35 | + setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5)); |
|---|
| 36 | + setBackground(Color.white); |
|---|
| 37 | + add(new FilterTitle(field, parent, false), BorderLayout.NORTH); |
|---|
| 168 | 38 | |
|---|
| 169 | | - @Override |
|---|
| 170 | | - public void clearFilter() { |
|---|
| 171 | | - histogram.setRelRange(0, 1); |
|---|
| 172 | | - } |
|---|
| 39 | + Runnable fullAction = new Runnable() |
|---|
| 40 | + { |
|---|
| 41 | + |
|---|
| 42 | + public void run() |
|---|
| 43 | + { |
|---|
| 44 | + startEntry.setText(format(histogram.getLow())); |
|---|
| 45 | + endEntry.setText(format(histogram.getHigh())); |
|---|
| 46 | + action.run(); |
|---|
| 47 | + } |
|---|
| 48 | + }; |
|---|
| 49 | + |
|---|
| 50 | + histogram = new BabyHistogram(fullAction); |
|---|
| 51 | + |
|---|
| 52 | + add(histogram, BorderLayout.CENTER); |
|---|
| 53 | + |
|---|
| 54 | + JPanel bottomStuff = new JPanel(); |
|---|
| 55 | + bottomStuff.setLayout(new GridLayout(2, 1)); |
|---|
| 56 | + add(bottomStuff, BorderLayout.SOUTH); |
|---|
| 57 | + |
|---|
| 58 | + JPanel lowHighPanel = new JPanel(); |
|---|
| 59 | + bottomStuff.add(lowHighPanel); |
|---|
| 60 | + lowHighPanel.setBackground(Color.white); |
|---|
| 61 | + lowHighPanel.setLayout(new BorderLayout()); |
|---|
| 62 | + Font small = parent.getModel().getDisplay().small(); |
|---|
| 63 | + |
|---|
| 64 | + startEntry = new JTextField(7); |
|---|
| 65 | + startEntry.addActionListener(new ActionListener() |
|---|
| 66 | + { |
|---|
| 67 | + |
|---|
| 68 | + @Override |
|---|
| 69 | + public void actionPerformed(ActionEvent e) |
|---|
| 70 | + { |
|---|
| 71 | + setLowFromText(); |
|---|
| 72 | + action.run(); |
|---|
| 73 | + } |
|---|
| 74 | + }); |
|---|
| 75 | + lowHighPanel.add(startEntry, BorderLayout.WEST); |
|---|
| 76 | + startEntry.setFont(small); |
|---|
| 77 | + |
|---|
| 78 | + JLabel rangeLabel = new JLabel("to", JLabel.CENTER); |
|---|
| 79 | + rangeLabel.setForeground(Color.gray); |
|---|
| 80 | + rangeLabel.setFont(small); |
|---|
| 81 | + lowHighPanel.add(rangeLabel, BorderLayout.CENTER); |
|---|
| 82 | + endEntry = new JTextField(7); |
|---|
| 83 | + lowHighPanel.add(endEntry, BorderLayout.EAST); |
|---|
| 84 | + endEntry.addActionListener(new ActionListener() |
|---|
| 85 | + { |
|---|
| 86 | + |
|---|
| 87 | + @Override |
|---|
| 88 | + public void actionPerformed(ActionEvent e) |
|---|
| 89 | + { |
|---|
| 90 | + setHighFromText(); |
|---|
| 91 | + action.run(); |
|---|
| 92 | + } |
|---|
| 93 | + }); |
|---|
| 94 | + endEntry.setFont(small); |
|---|
| 95 | + |
|---|
| 96 | + nullBox = new JCheckBox("Include Missing Values"); |
|---|
| 97 | + nullBox.addActionListener(new ActionListener() |
|---|
| 98 | + { |
|---|
| 99 | + |
|---|
| 100 | + @Override |
|---|
| 101 | + public void actionPerformed(ActionEvent e) |
|---|
| 102 | + { |
|---|
| 103 | + action.run(); |
|---|
| 104 | + } |
|---|
| 105 | + }); |
|---|
| 106 | + bottomStuff.add(nullBox); |
|---|
| 107 | + bottomStuff.setBackground(Color.white); |
|---|
| 108 | + nullBox.setBackground(Color.white); |
|---|
| 109 | + nullBox.setForeground(Color.gray); |
|---|
| 110 | + nullBox.setFont(small); |
|---|
| 111 | + |
|---|
| 112 | + } |
|---|
| 113 | + |
|---|
| 114 | + String format(double x) |
|---|
| 115 | + { |
|---|
| 116 | + Date date = new Date((long) x); |
|---|
| 117 | + return df.format(date); |
|---|
| 118 | + } |
|---|
| 119 | + |
|---|
| 120 | + void setLowFromText() |
|---|
| 121 | + { |
|---|
| 122 | + try |
|---|
| 123 | + { |
|---|
| 124 | + long low = df.parse(startEntry.getText()).getTime(); |
|---|
| 125 | + long high = (long) histogram.getHigh(); |
|---|
| 126 | + if (low > high) |
|---|
| 127 | + { |
|---|
| 128 | + high = low; |
|---|
| 129 | + endEntry.setText(startEntry.getText()); |
|---|
| 130 | + } |
|---|
| 131 | + histogram.setTrueRange(low, high); |
|---|
| 132 | + |
|---|
| 133 | + } catch (Exception e) |
|---|
| 134 | + { |
|---|
| 135 | + } |
|---|
| 136 | + } |
|---|
| 137 | + |
|---|
| 138 | + void setHighFromText() |
|---|
| 139 | + { |
|---|
| 140 | + try |
|---|
| 141 | + { |
|---|
| 142 | + long high = df.parse(endEntry.getText()).getTime(); |
|---|
| 143 | + double low = (long) histogram.getLow(); |
|---|
| 144 | + if (low > high) |
|---|
| 145 | + { |
|---|
| 146 | + low = high; |
|---|
| 147 | + startEntry.setText(endEntry.getText()); |
|---|
| 148 | + } |
|---|
| 149 | + histogram.setTrueRange(low, high); |
|---|
| 150 | + |
|---|
| 151 | + } catch (Exception e) |
|---|
| 152 | + { |
|---|
| 153 | + } |
|---|
| 154 | + } |
|---|
| 155 | + |
|---|
| 156 | + public void setData(double[] data) |
|---|
| 157 | + { |
|---|
| 158 | + histogram.setData(data); |
|---|
| 159 | + startEntry.setText(format(histogram.getLow())); |
|---|
| 160 | + endEntry.setText(format(histogram.getHigh())); |
|---|
| 161 | + repaint(); |
|---|
| 162 | + } |
|---|
| 163 | + |
|---|
| 164 | + public Dimension getPreferredSize() |
|---|
| 165 | + { |
|---|
| 166 | + return new Dimension(200, 160); |
|---|
| 167 | + } |
|---|
| 168 | + |
|---|
| 169 | + @Override |
|---|
| 170 | + public ActFilter defineFilter() |
|---|
| 171 | + { |
|---|
| 172 | + long low = (long) histogram.getLow(); |
|---|
| 173 | + long high = (long) histogram.getHigh(); |
|---|
| 174 | + boolean acceptNull = nullBox.isSelected(); |
|---|
| 175 | + return new TimeIntervalFilter(low, high, acceptNull, field); |
|---|
| 176 | + } |
|---|
| 177 | + |
|---|
| 178 | + @Override |
|---|
| 179 | + public void clearFilter() |
|---|
| 180 | + { |
|---|
| 181 | + histogram.setRelRange(0, 1); |
|---|
| 182 | + } |
|---|
| 173 | 183 | } |
|---|