List of usage examples for javax.swing JCheckBox addActionListener
public void addActionListener(ActionListener l)
ActionListener
to the button. From source file:SoundPlayer.java
void addMidiControls() { // Add a slider to control the tempo final JSlider tempo = new JSlider(50, 200); tempo.setValue((int) (sequencer.getTempoFactor() * 100)); tempo.setBorder(new TitledBorder("Tempo Adjustment (%)")); java.util.Hashtable labels = new java.util.Hashtable(); labels.put(new Integer(50), new JLabel("50%")); labels.put(new Integer(100), new JLabel("100%")); labels.put(new Integer(200), new JLabel("200%")); tempo.setLabelTable(labels);/*from w w w . j av a2 s . co m*/ tempo.setPaintLabels(true); // The event listener actually changes the tmpo tempo.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { sequencer.setTempoFactor(tempo.getValue() / 100.0f); } }); this.add(tempo); // Create rows of solo and checkboxes for each track Track[] tracks = sequence.getTracks(); for (int i = 0; i < tracks.length; i++) { final int tracknum = i; // Two checkboxes per track final JCheckBox solo = new JCheckBox("solo"); final JCheckBox mute = new JCheckBox("mute"); // The listeners solo or mute the track solo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { sequencer.setTrackSolo(tracknum, solo.isSelected()); } }); mute.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { sequencer.setTrackMute(tracknum, mute.isSelected()); } }); // Build up a row Box box = Box.createHorizontalBox(); box.add(new JLabel("Track " + tracknum)); box.add(Box.createHorizontalStrut(10)); box.add(solo); box.add(Box.createHorizontalStrut(10)); box.add(mute); box.add(Box.createHorizontalGlue()); // And add it to this component this.add(box); } }
From source file:hr.fer.zemris.vhdllab.platform.gui.dialog.save.SaveDialog.java
public SaveDialog(LocalizationSource source, SaveContext context) { super(source); Validate.notNull(context, "Save variant can't be null"); // setup label JLabel label = new JLabel(getMainMessage(source, context)); int width = DIALOG_WIDTH - 2 * BORDER; int height = LABEL_HEIGHT - 2 * BORDER; label.setPreferredSize(new Dimension(width, height)); label.setBorder(BorderFactory.createEmptyBorder(BORDER, BORDER, BORDER, BORDER)); // setup check box list list = new CheckBoxList(); width = DIALOG_WIDTH - 2 * BORDER;/*from w w w . j a va 2 s .c om*/ height = 0; // because list is a center component and it doesnt need // height list.setPreferredSize(new Dimension(width, height)); list.setBorder(BorderFactory.createEmptyBorder(BORDER, BORDER, BORDER, BORDER)); // setup select all and deselect all buttons JButton selectAll = new JButton(source.getMessage(SELECT_ALL_MESSAGE)); selectAll.setPreferredSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT)); selectAll.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { list.setSelectionToAll(true); } }); JButton deselectAll = new JButton(source.getMessage(DESELECT_ALL_MESSAGE)); deselectAll.setPreferredSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT)); deselectAll.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { list.setSelectionToAll(false); } }); Box selectBox = Box.createHorizontalBox(); selectBox.add(selectAll); selectBox.add(Box.createRigidArea(new Dimension(BORDER, BUTTON_HEIGHT))); selectBox.add(deselectAll); selectBox.setBorder(BorderFactory.createEmptyBorder(0, 0, BORDER, 0)); // setup ok and cancel buttons JButton ok = new JButton(source.getMessage(OK_MESSAGE)); ok.setPreferredSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT)); ok.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { closeDialog(new ArrayList<File>()); } }); JButton cancel = new JButton(source.getMessage(CANCEL_MESSAGE)); cancel.setPreferredSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT)); cancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { closeDialog(null); } }); Box actionBox = Box.createHorizontalBox(); actionBox.add(ok); actionBox.add(Box.createRigidArea(new Dimension(BORDER, BUTTON_HEIGHT))); actionBox.add(cancel); actionBox.setBorder(BorderFactory.createEmptyBorder(BORDER, 0, BORDER, 0)); JPanel selectPanel = new JPanel(new BorderLayout()); selectPanel.add(selectBox, BorderLayout.EAST); JPanel actionPanel = new JPanel(new BorderLayout()); actionPanel.add(actionBox, BorderLayout.EAST); JCheckBox alwaysSave = new JCheckBox(source.getMessage(ALWAYS_SAVE_MESSAGE)); alwaysSave.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JCheckBox checkBox = (JCheckBox) e.getSource(); Preferences preferences = Preferences.userNodeForPackage(SaveDialog.class); preferences.putBoolean(SHOULD_AUTO_SAVE, checkBox.isSelected()); } }); alwaysSave.setSelected(false); JPanel alwaysSavePanel = new JPanel(new BorderLayout()); alwaysSavePanel.add(alwaysSave, BorderLayout.WEST); JPanel lowerPanel = new JPanel(new BorderLayout()); lowerPanel.add(selectPanel, BorderLayout.NORTH); lowerPanel.add(alwaysSavePanel, BorderLayout.CENTER); lowerPanel.add(actionPanel, BorderLayout.SOUTH); this.setLayout(new BorderLayout()); JPanel messagePanel = new JPanel(new BorderLayout()); messagePanel.add(label, BorderLayout.NORTH); messagePanel.add(list, BorderLayout.CENTER); messagePanel.add(lowerPanel, BorderLayout.SOUTH); this.getContentPane().add(messagePanel, BorderLayout.CENTER); this.getRootPane().setDefaultButton(ok); this.setPreferredSize(new Dimension(DIALOG_WIDTH, DIALOG_HEIGHT)); this.setTitle(getTitle(source, context)); }
From source file:com.jbombardier.console.charts.XYTimeChartPanel.java
public XYTimeChartPanel() { DateAxis numberaxis = new DateAxis("Time"); yAxis = new NumberAxis("Count"); yAxis.setAutoRangeIncludesZero(true); XYSplineRenderer renderer = new XYSplineRenderer(); // XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); xyplot = new XYPlot(xyseriescollection, numberaxis, yAxis, renderer); xyplot.setBackgroundPaint(Color.white); xyplot.setDomainGridlinePaint(Color.lightGray); xyplot.setRangeGridlinePaint(Color.lightGray); // xyplot.setAxisOffset(new RectangleInsets(4D, 4D, 4D, 4D)); // XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) // xyplot.getRenderer(); // xylineandshaperenderer.setBaseShapesVisible(false); // xylineandshaperenderer.setBaseShapesFilled(false); chart = new JFreeChart("Running threads", JFreeChart.DEFAULT_TITLE_FONT, xyplot, true); /*// w w w . j a v a 2 s . com * ValueMarker valuemarker1 = new ValueMarker(175D); * valuemarker1.setLabelOffsetType(LengthAdjustmentType.EXPAND); * valuemarker1.setPaint(Color.red); valuemarker1.setLabel("Target Price"); * valuemarker1.setLabelAnchor(RectangleAnchor.TOP_RIGHT); * valuemarker1.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT); * xyplot.addRangeMarker(valuemarker1); */ LegendTitle legend = chart.getLegend(); legend.setPosition(RectangleEdge.RIGHT); // ChartUtilities.applyCurrentTheme(chart); setLayout(new BorderLayout()); jFreeChartPanel = new ChartPanel(chart); jFreeChartPanel.setMinimumDrawHeight(0); jFreeChartPanel.setMinimumDrawWidth(0); jFreeChartPanel.setMaximumDrawHeight(Integer.MAX_VALUE); jFreeChartPanel.setMaximumDrawWidth(Integer.MAX_VALUE); add(jFreeChartPanel, BorderLayout.CENTER); JPanel controls = new JPanel(new MigLayout("gap 0, ins 0", "[grow,center,fill]", "[grow,center]")); final JCheckBox checkbox = new JCheckBox("Auto-scale"); checkbox.setSelected(true); checkbox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { toggleAutoscroll(checkbox.isSelected()); } }); checkbox.setHorizontalAlignment(SwingConstants.RIGHT); controls.add(checkbox, "cell 0 0,alignx center"); add(controls, BorderLayout.SOUTH); }
From source file:com.vgi.mafscaling.LogPlay.java
private JCheckBox addCheckBox(int column, String text) { JCheckBox check = new JCheckBox(text); check.addActionListener(this); GridBagConstraints gbc_check = new GridBagConstraints(); gbc_check.insets = insets0;/*from w ww.j ava 2 s . com*/ gbc_check.anchor = GridBagConstraints.WEST; gbc_check.gridx = column; gbc_check.gridy = 1; playerPanel.add(check, gbc_check); return check; }
From source file:es.emergya.ui.gis.popups.ListaCapas.java
private void addCapa(final GpxLayer layer) { final JPanel capaP = new JPanel(); capaP.setOpaque(false);/*from www . j a va 2 s .com*/ layer.visible = true; mapView.addLayer(layer, false, capasActuales.size()); capasActuales.add(layer); capaP.setLayout(new BoxLayout(capaP, BoxLayout.X_AXIS)); final JCheckBox capa = new JCheckBox(layer.getAssociatedFile().getAbsolutePath()); capa.setSelected(layer.visible); capa.setBackground(Color.WHITE); capa.setToolTipText(i18n.getString("window.gpx.checkbox.show.tooltip")); capa.setActionCommand(layer.name); capa.addActionListener(this); capaP.add(capa); capaP.add(Box.createHorizontalGlue()); JButton eliminar = new JButton(LogicConstants.getIcon("button_delone")); eliminar.setToolTipText(i18n.getString("window.gpx.button.delete.tooltip")); eliminar.setBorderPainted(false); eliminar.setContentAreaFilled(false); capaP.add(eliminar); eliminar.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { mapView.removeLayer(layer); mapView.repaint(); capasGpx.remove(capaP); capasGpx.updateUI(); capasActuales.remove(layer); } }); capasGpx.add(capaP); capasGpx.updateUI(); }
From source file:cool.pandora.modeller.ui.jpanel.base.NewBagInPlaceFrame.java
/** * layoutAddKeepFilesToEmptyCheckBox.//from w w w . j a v a 2 s .com * * <p>Setting and displaying the ".keep Files in Empty Folder(s):" Check Box * on the Create Bag In Place Pane */ private void layoutAddKeepFilesToEmptyCheckBox(final JPanel contentPane, final int row) { // Delete Empty Folder(s) final JLabel addKeepFilesToEmptyFoldersCheckBoxLabel = new JLabel( bagView.getPropertyMessage("bag.label" + ".addkeepfilestoemptyfolders")); addKeepFilesToEmptyFoldersCheckBoxLabel .setToolTipText(bagView.getPropertyMessage("bag" + ".addkeepfilestoemptyfolders" + ".help")); final JCheckBox addKeepFilesToEmptyFoldersCheckBox = new JCheckBox(bagView.getPropertyMessage("")); addKeepFilesToEmptyFoldersCheckBox.setSelected(bag.isAddKeepFilesToEmptyFolders()); addKeepFilesToEmptyFoldersCheckBox.addActionListener(new AddKeepFilesToEmptyFoldersHandler()); GridBagConstraints glbc = new GridBagConstraints(); final JLabel spacerLabel = new JLabel(); glbc = LayoutUtil.buildGridBagConstraints(0, row, 1, 1, 5, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST); contentPane.add(addKeepFilesToEmptyFoldersCheckBoxLabel, glbc); glbc = LayoutUtil.buildGridBagConstraints(1, row, 1, 1, 40, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER); contentPane.add(addKeepFilesToEmptyFoldersCheckBox, glbc); glbc = LayoutUtil.buildGridBagConstraints(2, row, 1, 1, 40, 50, GridBagConstraints.NONE, GridBagConstraints.EAST); contentPane.add(spacerLabel, glbc); }
From source file:utilities.GraphViewer.java
public void addSensor(String fichier) { // ajouter le graphe ajouterFichier(fichier);/* ww w.ja v a2s . co m*/ // this.paneGraphe.add(graphe()); graphe.revalidate(); db.add(this.getSensorName(fichier), fichier); // ajouter un element a la list JCheckBox chckbxNewCheckBox = new JCheckBox(this.getSensorName(fichier)); this.sensors.add(chckbxNewCheckBox); this.sensors1.add(chckbxNewCheckBox); chckbxNewCheckBox.setBackground(new Color(200, 200, 255)); chckbxNewCheckBox.setBorder(new LineBorder(Color.BLACK)); chckbxNewCheckBox.setSelected(true); chckbxNewCheckBox.addActionListener(this); JLabel l = new JLabel(" "); l.setPreferredSize(new Dimension(50, 5)); this.sensorsList.add(l); this.sensorsList.add(chckbxNewCheckBox); this.sensorsList.validate(); }
From source file:com.diversityarrays.dal.server.ServerGui.java
public ServerGui(Image serverIconImage, IDalServer svr, DalServerFactory factory, File wwwRoot, DalServerPreferences prefs) {//from w w w . j a v a2 s . c om this.serverIconImage = serverIconImage; this.dalServerFactory = factory; this.wwwRoot = wwwRoot; this.preferences = prefs; JMenuBar menuBar = new JMenuBar(); JMenu serverMenu = new JMenu("Server"); menuBar.add(serverMenu); serverMenu.add(serverStartAction); serverMenu.add(serverStopAction); serverMenu.add(exitAction); JMenu commandMenu = new JMenu("Command"); menuBar.add(commandMenu); commandMenu.add(doSql); JMenu urlMenu = new JMenu("URL"); menuBar.add(urlMenu); urlMenu.add(new JMenuItem(copyDalUrlAction)); urlMenu.add(new JMenuItem(showDalUrlQRcodeAction)); setJMenuBar(menuBar); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); messages.setFont(GuiUtil.createMonospacedFont(12)); messages.setEditable(false); setServer(svr); quietOption.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { boolean q = quietOption.isSelected(); if (server != null) { server.setQuiet(q); } } }); JScrollPane scrollPane = new JScrollPane(messages, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); final JScrollBar verticalScrollBar = scrollPane.getVerticalScrollBar(); JButton clear = new JButton(new AbstractAction("Clear") { @Override public void actionPerformed(ActionEvent e) { messages.setText(""); } }); final boolean[] follow = new boolean[] { true }; final JCheckBox followTail = new JCheckBox("Follow", follow[0]); followTail.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { follow[0] = followTail.isSelected(); } }); final OutputStream os = new OutputStream() { @Override public void write(int b) throws IOException { char ch = (char) b; messages.append(new Character(ch).toString()); if (ch == '\n' && follow[0]) { verticalScrollBar.setValue(verticalScrollBar.getMaximum()); } } }; TeePrintStream pso = new TeePrintStream(System.out, os); TeePrintStream pse = new TeePrintStream(System.err, os); System.setErr(pse); System.setOut(pso); Box box = Box.createHorizontalBox(); box.add(clear); box.add(followTail); box.add(quietOption); box.add(Box.createHorizontalGlue()); JPanel bottom = new JPanel(new BorderLayout()); bottom.add(BorderLayout.NORTH, box); bottom.add(BorderLayout.SOUTH, statusInfoLine); Container cp = getContentPane(); cp.add(BorderLayout.CENTER, scrollPane); cp.add(BorderLayout.SOUTH, bottom); pack(); setSize(640, 480); final MemoryUsageMonitor mum = new MemoryUsageMonitor(); mum.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { statusInfoLine.setMessage(mum.getMemoryUsage()); } }); if (server == null) { // If initial server is null, allow user to specify addWindowListener(new WindowAdapter() { @Override public void windowOpened(WindowEvent e) { removeWindowListener(this); serverStartAction.actionPerformed(null); } }); } else { addWindowListener(new WindowAdapter() { @Override public void windowOpened(WindowEvent e) { removeWindowListener(this); ensureDatabaseInitialisedThenStartServer(); } }); } }
From source file:gov.sandia.umf.platform.ui.jobs.RunPanel.java
public RunPanel() { root = new NodeBase(); model = new DefaultTreeModel(root); tree = new JTree(model); tree.setRootVisible(false);//from www . j a va 2 s . co m tree.setShowsRootHandles(true); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION); tree.setCellRenderer(new DefaultTreeCellRenderer() { @Override public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus); NodeBase node = (NodeBase) value; Icon icon = node.getIcon(expanded); // A node knows whether it should hold other nodes or not, so don't pass leaf to it. if (icon == null) { if (leaf) icon = getDefaultLeafIcon(); else if (expanded) icon = getDefaultOpenIcon(); else icon = getDefaultClosedIcon(); } setIcon(icon); return this; } }); tree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { NodeBase newNode = (NodeBase) tree.getLastSelectedPathComponent(); if (newNode == null) return; if (newNode == displayNode) return; if (displayThread != null) synchronized (displayText) { displayThread.stop = true; } displayNode = newNode; if (displayNode instanceof NodeFile) viewFile(); else if (displayNode instanceof NodeJob) viewJob(); } }); tree.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { int keycode = e.getKeyCode(); if (keycode == KeyEvent.VK_DELETE || keycode == KeyEvent.VK_BACK_SPACE) { delete(); } } }); tree.addTreeWillExpandListener(new TreeWillExpandListener() { public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException { TreePath path = event.getPath(); // TODO: can this ever be null? Object o = path.getLastPathComponent(); if (o instanceof NodeJob) ((NodeJob) o).build(tree); } public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException { } }); tree.addTreeExpansionListener(new TreeExpansionListener() { public void treeExpanded(TreeExpansionEvent event) { Rectangle node = tree.getPathBounds(event.getPath()); Rectangle visible = treePane.getViewport().getViewRect(); visible.height -= node.y - visible.y; visible.y = node.y; tree.repaint(visible); } public void treeCollapsed(TreeExpansionEvent event) { Rectangle node = tree.getPathBounds(event.getPath()); Rectangle visible = treePane.getViewport().getViewRect(); visible.height -= node.y - visible.y; visible.y = node.y; tree.repaint(visible); } }); Thread refreshThread = new Thread() { public void run() { try { // Initial load synchronized (running) { for (MNode n : AppData.runs) running.add(0, new NodeJob(n)); // This should be efficient on a doubly-linked list. for (NodeJob job : running) root.add(job); } EventQueue.invokeLater(new Runnable() { public void run() { model.nodeStructureChanged(root); if (model.getChildCount(root) > 0) tree.setSelectionRow(0); } }); // Periodic refresh to show status of running jobs int shortCycles = 100; // Force full scan on first cycle. while (true) { NodeBase d = displayNode; // Make local copy (atomic action) to prevent it changing from under us if (d instanceof NodeJob) ((NodeJob) d).monitorProgress(RunPanel.this); if (shortCycles++ < 20) { Thread.sleep(1000); continue; } shortCycles = 0; synchronized (running) { Iterator<NodeJob> i = running.iterator(); while (i.hasNext()) { NodeJob job = i.next(); if (job != d) job.monitorProgress(RunPanel.this); if (job.complete >= 1) i.remove(); } } } } catch (InterruptedException e) { } } }; refreshThread.setDaemon(true); refreshThread.start(); displayText = new JTextArea(); displayText.setEditable(false); final JCheckBox chkFixedWidth = new JCheckBox("Fixed-Width Font"); chkFixedWidth.setFocusable(false); chkFixedWidth.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int size = displayText.getFont().getSize(); if (chkFixedWidth.isSelected()) { displayText.setFont(new Font(Font.MONOSPACED, Font.PLAIN, size)); } else { displayText.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, size)); } } }); displayPane.setViewportView(displayText); ActionListener graphListener = new ActionListener() { public void actionPerformed(ActionEvent e) { if (displayNode instanceof NodeFile) { NodeFile nf = (NodeFile) displayNode; if (nf.type == NodeFile.Type.Output || nf.type == NodeFile.Type.Result) { String graphType = e.getActionCommand(); if (displayPane.getViewport().getView() instanceof ChartPanel && displayGraph.equals(graphType)) { viewFile(); displayGraph = ""; } else { if (graphType.equals("Graph")) { Plot plot = new Plot(nf.path.getAbsolutePath()); if (!plot.columns.isEmpty()) displayPane.setViewportView(plot.createGraphPanel()); } else // Raster { Raster raster = new Raster(nf.path.getAbsolutePath(), displayPane.getHeight()); displayPane.setViewportView(raster.createGraphPanel()); } displayGraph = graphType; } } } } }; buttonGraph = new JButton("Graph", ImageUtil.getImage("analysis.gif")); buttonGraph.setFocusable(false); buttonGraph.addActionListener(graphListener); buttonGraph.setActionCommand("Graph"); buttonRaster = new JButton("Raster", ImageUtil.getImage("prnplot.gif")); buttonRaster.setFocusable(false); buttonRaster.addActionListener(graphListener); buttonRaster.setActionCommand("Raster"); Lay.BLtg(this, "C", Lay.SPL(Lay.BL("C", treePane = Lay.sp(tree)), Lay.BL("N", Lay.FL(chkFixedWidth, Lay.FL(buttonGraph, buttonRaster), "hgap=50"), "C", displayPane), "divpixel=250")); setFocusCycleRoot(true); }
From source file:caarray.client.test.gui.GuiMain.java
public GuiMain() throws Exception { JFrame frame = new JFrame("API Test Suite"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().setLayout(new BorderLayout(6, 6)); JPanel topPanel = new JPanel(); /* ###### Text fields for modifiable parameters ##### */ final JTextField javaHostText = new JTextField(TestProperties.getJavaServerHostname(), 20); JLabel javaHostLabel = new JLabel("Java Service Host"); JButton save = new JButton("Save"); save.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { TestProperties.setJavaServerHostname(javaHostText.getText()); }/*from ww w .j a v a 2 s . c om*/ }); JLabel javaPortLabel = new JLabel("Java Port"); final JTextField javaPortText = new JTextField(Integer.toString(TestProperties.getJavaServerJndiPort()), 5); JButton save2 = new JButton("Save"); save2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { try { int port = Integer.parseInt(javaPortText.getText()); TestProperties.setJavaServerJndiPort(port); } catch (NumberFormatException e) { System.out.println(javaPortText.getText() + " is not a valid port number."); } } }); JLabel gridHostLabel = new JLabel("Grid Service Host"); final JTextField gridHostText = new JTextField(TestProperties.getGridServerHostname(), 20); JButton save3 = new JButton("Save"); save3.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { TestProperties.setGridServerHostname(gridHostText.getText()); } }); JLabel gridPortLabel = new JLabel("Grid Service Port"); final JTextField gridPortText = new JTextField(Integer.toString(TestProperties.getGridServerPort()), 5); JButton save4 = new JButton("Save"); save4.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { try { int port = Integer.parseInt(gridPortText.getText()); TestProperties.setGridServerPort(port); } catch (NumberFormatException e) { System.out.println(gridPortText.getText() + " is not a valid port number."); } } }); JLabel excludeLabel = new JLabel("Exclude test cases (comma-separated list):"); final JTextField excludeText = new JTextField("", 30); JButton save5 = new JButton("Save"); save5.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { String testString = excludeText.getText(); if (testString != null) { String[] testCases = testString.split(","); if (testCases != null && testCases.length > 0) { List<Float> tests = new ArrayList<Float>(); for (String test : testCases) { try { tests.add(Float.parseFloat(test)); } catch (NumberFormatException e) { System.out.println(test + " is not a valid test case."); } } TestProperties.setExcludedTests(tests); } } } }); JLabel includeLabel = new JLabel("Include only (comma-separated list):"); final JTextField includeText = new JTextField("", 30); JButton save6 = new JButton("Save"); save6.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { String testString = includeText.getText(); if (testString != null) { String[] testCases = testString.split(","); if (testCases != null && testCases.length > 0) { List<Float> tests = new ArrayList<Float>(); for (String test : testCases) { try { tests.add(Float.parseFloat(test)); } catch (NumberFormatException e) { System.out.println(test + " is not a valid test case."); } } TestProperties.setIncludeOnlyTests(tests); } } } }); JLabel threadLabel = new JLabel("Number of threads:"); final JTextField threadText = new JTextField(Integer.toString(TestProperties.getNumThreads()), 5); JButton save7 = new JButton("Save"); save7.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { try { int threads = Integer.parseInt(threadText.getText()); TestProperties.setNumThreads(threads); } catch (NumberFormatException e) { System.out.println(threadText.getText() + " is not a valid thread number."); } } }); GridBagLayout topLayout = new GridBagLayout(); topPanel.setLayout(topLayout); JLabel[] labels = new JLabel[] { javaHostLabel, javaPortLabel, gridHostLabel, gridPortLabel, excludeLabel, includeLabel, threadLabel }; JTextField[] textFields = new JTextField[] { javaHostText, javaPortText, gridHostText, gridPortText, excludeText, includeText, threadText }; JButton[] buttons = new JButton[] { save, save2, save3, save4, save5, save6, save7 }; for (int i = 0; i < labels.length; i++) { GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.NONE; c.gridx = 0; c.gridy = i; topPanel.add(labels[i], c); c.gridx = 1; topPanel.add(textFields[i], c); c.gridx = 2; topPanel.add(buttons[i], c); } frame.getContentPane().add(topPanel, BorderLayout.PAGE_START); GridLayout bottomLayout = new GridLayout(0, 4); selectionPanel.setLayout(bottomLayout); JCheckBox selectAll = new JCheckBox("Select/Deselect All"); selectAll.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JCheckBox box = (JCheckBox) e.getSource(); selectAll(box.isSelected()); } }); selectionPanel.add(selectAll); JCheckBox excludeLongTests = new JCheckBox("Exclude Long Tests"); excludeLongTests.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JCheckBox box = (JCheckBox) e.getSource(); if (box.isSelected()) { TestProperties.excludeLongTests(); } else { TestProperties.removeExcludedLongTests(); } } }); TestProperties.excludeLongTests(); excludeLongTests.setSelected(true); selectionPanel.add(excludeLongTests); //Initialize check boxes corresponding to test categories initializeTests(); centerPanel.setLayout(new GridLayout(0, 1)); centerPanel.add(selectionPanel); //Redirect System messages to gui JScrollPane textScroll = new JScrollPane(); textScroll.setViewportView(textDisplay); System.setOut(new PrintStream(new JTextAreaOutputStream(textDisplay))); System.setErr(new PrintStream(new JTextAreaOutputStream(textDisplay))); centerPanel.add(textScroll); JScrollPane scroll = new JScrollPane(centerPanel); frame.getContentPane().add(scroll, BorderLayout.CENTER); JButton runButton = new JButton("Run Tests"); runButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { try { runTests(); } catch (Exception e) { System.out.println("An error occured executing the tests: " + e.getClass() + ". Check error log for details."); log.error("Exception encountered:", e); } } }); JPanel bottomPanel = new JPanel(); bottomPanel.add(runButton); frame.getContentPane().add(bottomPanel, BorderLayout.PAGE_END); frame.pack(); frame.setVisible(true); }