/** * Initialize the GUI components and layout for this component. */ private void init() { // WARNING: called from ctor so must not be overridden (i.e. must be private or final) // The Loop Controller panel can be displayed standalone or inside // another panel. For standalone, we want to display the TITLE, NAME, // etc. (everything). However, if we want to display it within another // panel, we just display the Loop Count fields (not the TITLE and // NAME). // Standalone if (displayName) { setLayout(new BorderLayout(0, 5)); setBorder(makeBorder()); add(makeTitlePanel(), BorderLayout.NORTH); JPanel mainPanel = new JPanel(new BorderLayout()); mainPanel.add(createLoopCountPanel(), BorderLayout.NORTH); add(mainPanel, BorderLayout.CENTER); } else { // Embedded setLayout(new BorderLayout()); add(createLoopCountPanel(), BorderLayout.NORTH); } }
/** * Create a new LoopControlPanel as either a standalone or an embedded * component. * * @param displayName * indicates whether or not this component should display its * name. If true, this is a standalone component. If false, this * component is intended to be used as a subpanel for another * component. */ public RunTimeGui(boolean displayName) { this.displayName = displayName; init(); setState(1); }
@Override public TestElement createTestElement() { RunTime lc = new RunTime(); modifyTestElement(lc); return lc; }
@Override public void modifyTestElement(TestElement lc) { configureTestElement(lc); if (lc instanceof RunTime) { if (seconds.getText().length() > 0) { ((RunTime) lc).setRuntime(seconds.getText()); } else { ((RunTime) lc).setRuntime(0); } } }
/** * A newly created component can be initialized with the contents of a Test * Element object by calling this method. The component is responsible for * querying the Test Element object for the relevant information to display * in its GUI. * * @param element * the TestElement to configure */ @Override public void configure(TestElement element) { super.configure(element); if (element instanceof RunTime) { setState(((RunTime) element).getRuntimeString()); } else { setState(1); } }