| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package us.paulevans.basicxslt; |
| 17 | |
|
| 18 | |
import java.awt.BorderLayout; |
| 19 | |
import java.awt.FlowLayout; |
| 20 | |
import java.awt.Frame; |
| 21 | |
import java.awt.GridBagConstraints; |
| 22 | |
import java.awt.GridBagLayout; |
| 23 | |
import java.awt.event.ActionEvent; |
| 24 | |
import java.awt.event.ActionListener; |
| 25 | |
import java.awt.event.WindowAdapter; |
| 26 | |
import java.awt.event.WindowEvent; |
| 27 | |
|
| 28 | |
import javax.swing.JButton; |
| 29 | |
import javax.swing.JLabel; |
| 30 | |
import javax.swing.JPanel; |
| 31 | |
import javax.swing.JScrollPane; |
| 32 | |
import javax.swing.JSeparator; |
| 33 | |
|
| 34 | |
import net.blueslate.commons.gui.GUIUtils; |
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | 0 | public class TimingsFrame extends DisposableFrame implements ActionListener { |
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
private static final String DEFAULT_FRAME_WIDTH = "400"; |
| 46 | |
private static final String DEFAULT_FRAME_HEIGHT = "200"; |
| 47 | |
|
| 48 | |
|
| 49 | 0 | private static final LabelStringFactory stringFactory = |
| 50 | |
LabelStringFactory.getInstance(); |
| 51 | |
|
| 52 | |
|
| 53 | |
private static final String PROPERTY_NAME_PREFIX = "timings_"; |
| 54 | |
|
| 55 | |
|
| 56 | |
private JButton closeBtn; |
| 57 | |
private UserPreferences userPrefs; |
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | 0 | public TimingsFrame(Frame aParent, XSLRow aXSLRows[]) { |
| 65 | |
|
| 66 | |
JPanel southPanel, mainPanel; |
| 67 | |
int width, height; |
| 68 | |
|
| 69 | 0 | userPrefs = Utils.getUserPrefs(); |
| 70 | 0 | addWindowListener(new WindowAdapter() { |
| 71 | 0 | public void windowClosing(WindowEvent evt) { |
| 72 | 0 | dispose(userPrefs, PROPERTY_NAME_PREFIX); |
| 73 | 0 | } |
| 74 | |
}); |
| 75 | 0 | mainPanel = new JPanel(new BorderLayout()); |
| 76 | 0 | mainPanel.add(buildMainPanel(aXSLRows), BorderLayout.CENTER); |
| 77 | 0 | southPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); |
| 78 | 0 | southPanel.add(closeBtn = new JButton(stringFactory.getString( |
| 79 | |
LabelStringFactory.CLOSE_BUTTON))); |
| 80 | 0 | closeBtn.addActionListener(this); |
| 81 | 0 | getContentPane().setLayout(new BorderLayout()); |
| 82 | 0 | getContentPane().add(southPanel, BorderLayout.SOUTH); |
| 83 | 0 | getContentPane().add(new JScrollPane(mainPanel), BorderLayout.CENTER); |
| 84 | 0 | setTitle(stringFactory.getString( |
| 85 | |
LabelStringFactory.TIMINGS_FRAME_XSL_TRANSFORMATION_TIMINGS)); |
| 86 | 0 | width = Integer.parseInt(userPrefs.getProperty(PROPERTY_NAME_PREFIX + |
| 87 | |
AppConstants.FRAME_WIDTH_PROP, DEFAULT_FRAME_WIDTH)); |
| 88 | 0 | height = Integer.parseInt(userPrefs.getProperty(PROPERTY_NAME_PREFIX + |
| 89 | |
AppConstants.FRAME_HEIGHT_PROP, DEFAULT_FRAME_HEIGHT)); |
| 90 | 0 | setSize(width, height); |
| 91 | 0 | GUIUtils.center(this, aParent); |
| 92 | 0 | setVisible(true); |
| 93 | 0 | } |
| 94 | |
|
| 95 | |
|
| 96 | |
|
| 97 | |
|
| 98 | |
|
| 99 | |
|
| 100 | |
private JPanel buildMainPanel(XSLRow aXSLRows[]) { |
| 101 | |
|
| 102 | |
int row, col, loop; |
| 103 | |
GridBagLayout layout; |
| 104 | |
GridBagConstraints constraints; |
| 105 | |
JPanel main; |
| 106 | |
JLabel xslHeading, timingHeading; |
| 107 | |
long totalTransformTime; |
| 108 | |
|
| 109 | 0 | layout = new GridBagLayout(); |
| 110 | 0 | constraints = new GridBagConstraints(); |
| 111 | 0 | main = new JPanel(layout); |
| 112 | 0 | totalTransformTime = 0; |
| 113 | 0 | row = 0; |
| 114 | 0 | col = 0; |
| 115 | 0 | xslHeading = new JLabel(stringFactory.getString( |
| 116 | |
LabelStringFactory.TIMINGS_FRAME_TRANSFORMATION_XSL)); |
| 117 | 0 | timingHeading = new JLabel(" | " + stringFactory.getString( |
| 118 | |
LabelStringFactory.TIMINGS_FRAME_TIME_TO_TRANSFORM)); |
| 119 | 0 | GUIUtils.add(main, xslHeading, layout, constraints, row, col++, 1, 1, |
| 120 | |
GridBagConstraints.WEST, GridBagConstraints.NONE, |
| 121 | |
GUIUtils.SMALL_INSETS); |
| 122 | 0 | GUIUtils.add(main, timingHeading, layout, constraints, row++, col++, 1, |
| 123 | |
1, GridBagConstraints.WEST, GridBagConstraints.NONE, |
| 124 | |
GUIUtils.SMALL_INSETS); |
| 125 | 0 | GUIUtils.add(main, new JSeparator(), layout, constraints, row++, col=0, |
| 126 | |
1, 2); |
| 127 | 0 | for (loop = 0; loop < aXSLRows.length; loop++) { |
| 128 | 0 | totalTransformTime += aXSLRows[loop].getTimeToTransform(); |
| 129 | 0 | col = 0; |
| 130 | 0 | GUIUtils.add(main, new JLabel(aXSLRows[loop].getLabel().getText()), |
| 131 | |
layout, constraints, row, col++, 1, 1, |
| 132 | |
GridBagConstraints.WEST, GridBagConstraints.NONE, |
| 133 | |
GUIUtils.SMALL_INSETS); |
| 134 | 0 | GUIUtils.add(main, new JLabel(" | " + |
| 135 | |
aXSLRows[loop].getTimeToTransform()), layout, constraints, |
| 136 | |
row++, col, 1, 1, GridBagConstraints.WEST, |
| 137 | |
GridBagConstraints.NONE, GUIUtils.SMALL_INSETS); |
| 138 | |
|
| 139 | |
} |
| 140 | 0 | GUIUtils.add(main, new JSeparator(), layout, constraints, row++, col=0, |
| 141 | |
1, 2); |
| 142 | 0 | GUIUtils.add(main, new JLabel(stringFactory.getString( |
| 143 | |
LabelStringFactory.TIMINGS_FRAME_TOTAL_LBL)), |
| 144 | |
layout, constraints, row, col++, 1, 1, GridBagConstraints.WEST, |
| 145 | |
GridBagConstraints.NONE, GUIUtils.SMALL_INSETS); |
| 146 | 0 | GUIUtils.add(main, new JLabel(" | " + |
| 147 | |
totalTransformTime), layout, constraints, |
| 148 | |
row++, col, 1, 1, GridBagConstraints.WEST, |
| 149 | |
GridBagConstraints.NONE, GUIUtils.SMALL_INSETS); |
| 150 | 0 | return main; |
| 151 | |
} |
| 152 | |
|
| 153 | |
|
| 154 | |
|
| 155 | |
|
| 156 | |
public void actionPerformed(ActionEvent aEvent) { |
| 157 | |
|
| 158 | |
Object eventSource; |
| 159 | |
|
| 160 | 0 | eventSource = aEvent.getSource(); |
| 161 | 0 | if (eventSource == closeBtn) { |
| 162 | 0 | dispose(userPrefs, PROPERTY_NAME_PREFIX); |
| 163 | |
} |
| 164 | 0 | } |
| 165 | |
} |