|
| 1 | +package projections.Tools.MessageSizeEvolution; |
| 2 | + |
| 3 | +import projections.gui.JIntTextField; |
| 4 | +import projections.gui.JLongTextField; |
| 5 | +import projections.gui.RangeDialog; |
| 6 | +import projections.gui.RangeDialogExtensionPanel; |
| 7 | +import projections.gui.U; |
| 8 | +import projections.gui.Util; |
| 9 | + |
| 10 | +import javax.swing.JLabel; |
| 11 | +import javax.swing.JPanel; |
| 12 | +import javax.swing.JCheckBox; |
| 13 | +import javax.swing.border.LineBorder; |
| 14 | +import javax.swing.border.TitledBorder; |
| 15 | + |
| 16 | +import java.awt.GridBagLayout; |
| 17 | +import java.awt.GridBagConstraints; |
| 18 | +import java.awt.Insets; |
| 19 | +import java.awt.Color; |
| 20 | +import java.awt.BorderLayout; |
| 21 | + |
| 22 | +import java.text.DecimalFormat; |
| 23 | + |
| 24 | +class BinDialogPanel |
| 25 | + extends RangeDialogExtensionPanel { |
| 26 | + |
| 27 | + private JLabel timeBinRangeLabel; |
| 28 | + private JIntTextField timeNumBinsField; |
| 29 | + private long timeBinSize; |
| 30 | + private long startTime; |
| 31 | + |
| 32 | + private JLabel msgBinRangeLabel; |
| 33 | + private JIntTextField msgNumBinsField; |
| 34 | + private JLongTextField msgBinSizeField; |
| 35 | + private JLongTextField msgMinBinSizeField; |
| 36 | + private JCheckBox msgLogScale; |
| 37 | + private JCheckBox msgIncludeCreation; |
| 38 | + |
| 39 | + private boolean prevScale; |
| 40 | + |
| 41 | + private RangeDialog parent; |
| 42 | + |
| 43 | + BinDialogPanel() { |
| 44 | + JPanel timeBinPanel; |
| 45 | + JPanel msgBinPanel; |
| 46 | + |
| 47 | + JLabel timeNumBinsLabel; |
| 48 | + |
| 49 | + JLabel msgNumBinsLabel; |
| 50 | + JLabel msgBinSizeLabel; |
| 51 | + JLabel msgMinBinSizeLabel; |
| 52 | + |
| 53 | + GridBagLayout gbl = new GridBagLayout(); |
| 54 | + GridBagConstraints gbc = new GridBagConstraints(); |
| 55 | + gbc.fill = GridBagConstraints.BOTH; |
| 56 | + gbc.insets = new Insets(2, 2, 2, 2); |
| 57 | + |
| 58 | + // Time Panel |
| 59 | + timeBinPanel = new JPanel(); |
| 60 | + timeBinPanel.setLayout(gbl); |
| 61 | + timeBinPanel.setBorder(new TitledBorder(new LineBorder(Color.black), "TIME-BASED BINS")); |
| 62 | + |
| 63 | + timeNumBinsLabel = new JLabel("# of Time Bins:", JLabel.LEFT); |
| 64 | + timeNumBinsField = new JIntTextField(-1, 5); |
| 65 | + |
| 66 | + timeBinRangeLabel = new JLabel("", JLabel.LEFT); |
| 67 | + |
| 68 | + Util.gblAdd(timeBinPanel, timeNumBinsLabel, gbc, 0, 0, 1, 1, 1, 1); |
| 69 | + Util.gblAdd(timeBinPanel, timeNumBinsField, gbc, 1, 0, 1, 1, 1, 1); |
| 70 | + Util.gblAdd(timeBinPanel, timeBinRangeLabel, gbc, 0, 1, 4, 1, 1, 1); |
| 71 | + |
| 72 | + // Messages Panel |
| 73 | + msgBinPanel = new JPanel(); |
| 74 | + msgBinPanel.setLayout(gbl); |
| 75 | + msgBinPanel.setBorder(new TitledBorder(new LineBorder(Color.black), |
| 76 | + "MESSAGE-BASED BINS")); |
| 77 | + |
| 78 | + msgNumBinsLabel = new JLabel("# of Msg Bins:", JLabel.LEFT); |
| 79 | + msgNumBinsField = new JIntTextField(-1, 5); |
| 80 | + |
| 81 | + msgBinSizeLabel = new JLabel("Bin Size (bytes):", JLabel.LEFT); |
| 82 | + msgBinSizeField = new JLongTextField(-1, 12); |
| 83 | + |
| 84 | + msgMinBinSizeLabel = new JLabel("Starting Bin Size:", JLabel.LEFT); |
| 85 | + msgMinBinSizeField = new JLongTextField(-1, 12); |
| 86 | + |
| 87 | + msgBinRangeLabel = new JLabel("", JLabel.LEFT); |
| 88 | + |
| 89 | + msgLogScale = new JCheckBox("Log Scale"); |
| 90 | + msgIncludeCreation = new JCheckBox("Creation Events"); |
| 91 | + |
| 92 | + Util.gblAdd(msgBinPanel, msgNumBinsLabel, gbc, 0, 0, 1, 1, 1, 1); |
| 93 | + Util.gblAdd(msgBinPanel, msgNumBinsField, gbc, 1, 0, 1, 1, 1, 1); |
| 94 | + Util.gblAdd(msgBinPanel, msgLogScale, gbc, 2, 0, 1, 1, 1, 1); |
| 95 | + Util.gblAdd(msgBinPanel, msgIncludeCreation, gbc, 3, 0, 1, 1, 1, 1); |
| 96 | + Util.gblAdd(msgBinPanel, msgMinBinSizeLabel, gbc, 0, 1, 1, 1, 1, 1); |
| 97 | + Util.gblAdd(msgBinPanel, msgMinBinSizeField, gbc, 1, 1, 1, 1, 1, 1); |
| 98 | + Util.gblAdd(msgBinPanel, msgBinSizeLabel, gbc, 2, 1, 1, 1, 1, 1); |
| 99 | + Util.gblAdd(msgBinPanel, msgBinSizeField, gbc, 3, 1, 1, 1, 1, 1); |
| 100 | + Util.gblAdd(msgBinPanel, msgBinRangeLabel, gbc, 0, 2, 4, 1, 1, 1); |
| 101 | + |
| 102 | + this.setLayout(new BorderLayout()); |
| 103 | + this.add(timeBinPanel, BorderLayout.CENTER); |
| 104 | + this.add(msgBinPanel, BorderLayout.SOUTH); |
| 105 | + } |
| 106 | + |
| 107 | + // Accessor methods |
| 108 | + int getTimeNumBins() { |
| 109 | + if (timeNumBinsField.getValue() - 1 >= 0) |
| 110 | + return timeNumBinsField.getValue() - 1; |
| 111 | + else |
| 112 | + return 0; |
| 113 | + } |
| 114 | + |
| 115 | + public void setTimeNumBins(int numBins) { |
| 116 | + timeNumBinsField.setValue(numBins); |
| 117 | + parent.someInputChanged(); |
| 118 | + } |
| 119 | + |
| 120 | + long getTimeBinSize() { |
| 121 | + return timeBinSize; |
| 122 | + } |
| 123 | + |
| 124 | + public void setTimeBinSize(long binSize) { |
| 125 | + timeBinSize = binSize; |
| 126 | + parent.someInputChanged(); |
| 127 | + } |
| 128 | + |
| 129 | + long getStartTime() { |
| 130 | + return startTime; |
| 131 | + } |
| 132 | + |
| 133 | + public void setStartTime(long size) { |
| 134 | + startTime = size; |
| 135 | + parent.someInputChanged(); |
| 136 | + } |
| 137 | + |
| 138 | + // Messages |
| 139 | + int getMsgNumBins() { |
| 140 | + if (msgNumBinsField.getValue() - 1 >= 0) |
| 141 | + return msgNumBinsField.getValue() - 1; |
| 142 | + else |
| 143 | + return 0; |
| 144 | + } |
| 145 | + |
| 146 | + public void setMsgNumBins(int numBins) { |
| 147 | + msgNumBinsField.setValue(numBins); |
| 148 | + parent.someInputChanged(); |
| 149 | + } |
| 150 | + |
| 151 | + long getMsgBinSize() { |
| 152 | + return msgBinSizeField.getValue(); |
| 153 | + } |
| 154 | + |
| 155 | + public void setMsgBinSize(long binSize) { |
| 156 | + msgBinSizeField.setValue(binSize); |
| 157 | + parent.someInputChanged(); |
| 158 | + } |
| 159 | + |
| 160 | + long getMsgMinBinSize() { |
| 161 | + return msgMinBinSizeField.getValue(); |
| 162 | + } |
| 163 | + |
| 164 | + public void setMsgMinBinSize(long size) { |
| 165 | + msgMinBinSizeField.setValue(size); |
| 166 | + parent.someInputChanged(); |
| 167 | + } |
| 168 | + |
| 169 | + boolean getMsgLogScale() { |
| 170 | + return msgLogScale.isSelected(); |
| 171 | + } |
| 172 | + |
| 173 | + public void setMsgLogScale(boolean logScale) { |
| 174 | + msgLogScale.setSelected(logScale); |
| 175 | + parent.someInputChanged(); |
| 176 | + } |
| 177 | + |
| 178 | + boolean getMsgCreationEvent() { |
| 179 | + return msgIncludeCreation.isSelected(); |
| 180 | + } |
| 181 | + |
| 182 | + public void setMsgIncludeCreation(boolean includeCreation) { |
| 183 | + msgIncludeCreation.setSelected(includeCreation); |
| 184 | + parent.someInputChanged(); |
| 185 | + } |
| 186 | + |
| 187 | + public boolean isInputValid() { |
| 188 | + return true; |
| 189 | + } |
| 190 | + |
| 191 | + public void setInitialFields() { |
| 192 | + // default values for time 1ms to 100ms |
| 193 | + timeNumBinsField.setText("100"); |
| 194 | + startTime = parent.getStartTime(); |
| 195 | + timeBinSize = parent.getSelectedTotalTime() / 100; |
| 196 | + |
| 197 | + // default values for messages 100 bytes to 2k |
| 198 | + msgNumBinsField.setText("10"); |
| 199 | + msgBinSizeField.setText("1000"); |
| 200 | + msgBinSizeField.setEnabled(false); |
| 201 | + msgMinBinSizeField.setText("128"); |
| 202 | + msgLogScale.setSelected(true); |
| 203 | + msgIncludeCreation.setSelected(false); |
| 204 | + |
| 205 | + prevScale = true; |
| 206 | + updateFields(); |
| 207 | + } |
| 208 | + |
| 209 | + public void setParentDialogBox(RangeDialog parent) { |
| 210 | + this.parent = parent; |
| 211 | + timeNumBinsField.addActionListener(parent); |
| 212 | + timeNumBinsField.addKeyListener(parent); |
| 213 | + timeNumBinsField.addFocusListener(parent); |
| 214 | + msgNumBinsField.addActionListener(parent); |
| 215 | + msgNumBinsField.addKeyListener(parent); |
| 216 | + msgNumBinsField.addFocusListener(parent); |
| 217 | + msgBinSizeField.addActionListener(parent); |
| 218 | + msgBinSizeField.addKeyListener(parent); |
| 219 | + msgBinSizeField.addFocusListener(parent); |
| 220 | + msgMinBinSizeField.addActionListener(parent); |
| 221 | + msgMinBinSizeField.addKeyListener(parent); |
| 222 | + msgMinBinSizeField.addFocusListener(parent); |
| 223 | + msgLogScale.addActionListener(parent); |
| 224 | + } |
| 225 | + |
| 226 | + public void updateFields() { |
| 227 | + startTime = parent.getStartTime(); |
| 228 | + timeBinSize = parent.getSelectedTotalTime() / getTimeNumBins(); |
| 229 | + |
| 230 | + timeBinRangeLabel.setText("Bin size ranges from : " + |
| 231 | + U.humanReadableString(startTime) + |
| 232 | + " to " + |
| 233 | + U.humanReadableString(startTime + |
| 234 | + parent.getSelectedTotalTime())); |
| 235 | + |
| 236 | + boolean currScale = getMsgLogScale(); |
| 237 | + DecimalFormat _format = new DecimalFormat(); |
| 238 | + if (currScale) { |
| 239 | + if (!prevScale) { |
| 240 | + if (msgMinBinSizeField.getValue() < 128) |
| 241 | + msgMinBinSizeField.setText("128"); |
| 242 | + msgBinSizeField.setEnabled(false); |
| 243 | + prevScale = true; |
| 244 | + } |
| 245 | + |
| 246 | + msgBinRangeLabel.setText("Bin size ranges from : " + |
| 247 | + _format.format(msgMinBinSizeField.getValue()) + |
| 248 | + " bytes to " + |
| 249 | + _format.format(msgMinBinSizeField.getValue() * |
| 250 | + Math.pow(2, msgNumBinsField.getValue())) + " bytes."); |
| 251 | + } else { |
| 252 | + if (prevScale) { |
| 253 | + msgBinSizeField.setEnabled(true); |
| 254 | + prevScale = false; |
| 255 | + } |
| 256 | + msgBinRangeLabel.setText("Bin size ranges from : " + |
| 257 | + _format.format(msgMinBinSizeField.getValue()) + |
| 258 | + " bytes to " + |
| 259 | + _format.format(msgMinBinSizeField.getValue() + |
| 260 | + getMsgNumBins() * msgBinSizeField.getValue()) + " bytes."); |
| 261 | + } |
| 262 | + } |
| 263 | +} |
0 commit comments