List of usage examples for javax.swing JCheckBox setSelected
public void setSelected(boolean b)
From source file:com.alvermont.terraj.stargen.ui.StargenFrame.java
/** * Update a linked checkbox and spinner. The spinner will be enabled * if the checkbox is selected/*from w ww. j ava2s.c o m*/ * * @param component1 The checkbox that controls the spinner * @param component2 The spinner * @param state The new state to set the checkbox to * @param value The value to store in the spinner */ protected void updateSpinner(JCheckBox component1, JSpinner component2, boolean state, int value) { component1.setSelected(state); component2.setEnabled(state); component2.setValue(value); }
From source file:com.alvermont.terraj.stargen.ui.StargenFrame.java
/** * Update a linked checkbox and spinner. The spinner will be enabled * if the checkbox is selected// w ww. j a v a 2s . c o m * * @param component1 The checkbox that controls the spinner * @param component2 The spinner * @param state The new state to set the checkbox to * @param value The value to store in the spinner */ protected void updateSpinner(JCheckBox component1, JSpinner component2, boolean state, double value) { component1.setSelected(state); component2.setEnabled(state); component2.setValue(value); }
From source file:com.alvermont.terraj.stargen.ui.StargenFrame.java
/** * Update a linked checkbox and combo box. The combo box will be enabled * if the checkbox is selected//w w w . ja va 2 s . c o m * * @param component1 The checkbox that controls the combobox * @param component2 The combobox * @param state The new state to set the checkbox to * @param value The value to store in the combo box */ protected void updateCombo(JCheckBox component1, JComboBox<String> component2, boolean state, String value) { component1.setSelected(state); component2.setEnabled(state); component2.getModel().setSelectedItem(value); }
From source file:org.esa.snap.rcp.statistics.StatisticsPanel.java
private JPanel createAccuracyPanel() { final JPanel accuracyPanel = new JPanel(new GridBagLayout()); final GridBagConstraints gbc = new GridBagConstraints(); final JLabel label = new JLabel("Histogram accuracy:"); accuracyModel = new AccuracyModel(); final BindingContext bindingContext = new BindingContext( PropertyContainer.createObjectBacked(accuracyModel)); final SpinnerNumberModel accuracyNumberModel = new SpinnerNumberModel(accuracyModel.accuracy, 0, Util.MAX_ACCURACY, 1); final JSpinner accuracySpinner = new JSpinner(accuracyNumberModel); ((JSpinner.DefaultEditor) accuracySpinner.getEditor()).getTextField().setEditable(false); bindingContext.bind("accuracy", accuracySpinner); final JCheckBox checkBox = new JCheckBox("Auto accuracy"); bindingContext.bind("useAutoAccuracy", checkBox); final IntervalValidator rangeValidator = new IntervalValidator(new ValueRange(0, Util.MAX_ACCURACY)); final PropertyDescriptor accuracyDescriptor = bindingContext.getPropertySet().getDescriptor("accuracy"); accuracyDescriptor.setValidator(rangeValidator); checkBox.setSelected(accuracyModel.useAutoAccuracy); bindingContext.getPropertySet().getProperty("useAutoAccuracy") .addPropertyChangeListener(new PropertyChangeListener() { @Override//from w w w.j a v a 2 s. c o m public void propertyChange(PropertyChangeEvent evt) { label.setEnabled(!checkBox.isSelected()); accuracySpinner.setEnabled(!checkBox.isSelected()); if (checkBox.isSelected()) { bindingContext.getBinding("accuracy").setPropertyValue(3); } computePanel.updateEnablement(); } }); label.setEnabled(false); accuracySpinner.setEnabled(false); accuracySpinner.setToolTipText("Specify the number of histogram bins (#bins: 10^accuracy)."); accuracySpinner.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { computePanel.updateEnablement(); } }); GridBagUtils.addToPanel(accuracyPanel, new TitledSeparator("Histogram accuracy"), gbc, "fill=HORIZONTAL, weightx=1.0,anchor=NORTH,gridwidth=2"); GridBagUtils.addToPanel(accuracyPanel, checkBox, gbc, "gridy=1,insets.left=5,insets.top=2"); GridBagUtils.addToPanel(accuracyPanel, label, gbc, "gridy=2, insets.left=26,weightx=0.0,fill=NONE,anchor=WEST,gridwidth=1"); GridBagUtils.addToPanel(accuracyPanel, accuracySpinner, gbc, "gridx=1,weightx=1.0,fill=HORIZONTAL,insets.right=5,insets.left=5"); return accuracyPanel; }
From source file:com.diversityarrays.kdxplore.scatterplot.ScatterPlotPanel.java
@SuppressWarnings("unused") private JPanel getControlPanel() { List<String> pList = Arrays.asList(Msg.CBOX_MEAN(), Msg.CBOX_MEDIAN(), Msg.CBOX_OUTLIERS()); JPanel cPanel = new JPanel(); for (String s : pList) { ActionListener checkBoxActionListener = new ActionListener() { @Override//from ww w . j a v a 2s .c o m public void actionPerformed(ActionEvent e) { redoGenerateChart(s, false); } }; JCheckBox jcb = new JCheckBox(s); jcb.setSelected(true); jcb.addActionListener(checkBoxActionListener); parameters.put(s, jcb); cPanel.add(jcb, BorderLayout.CENTER); } return cPanel; }
From source file:net.pms.newgui.GeneralTab.java
public JComponent build() { // Apply the orientation for the locale Locale locale = new Locale(configuration.getLanguage()); ComponentOrientation orientation = ComponentOrientation.getOrientation(locale); String colSpec = FormLayoutUtil.getColSpec(COL_SPEC, orientation); FormLayout layout = new FormLayout(colSpec, ROW_SPEC); PanelBuilder builder = new PanelBuilder(layout); builder.setBorder(Borders.DLU4_BORDER); builder.setOpaque(true);//w ww . jav a 2 s.c o m CellConstraints cc = new CellConstraints(); smcheckBox = new JCheckBox(Messages.getString("NetworkTab.3")); smcheckBox.setContentAreaFilled(false); smcheckBox.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { configuration.setMinimized((e.getStateChange() == ItemEvent.SELECTED)); } }); if (configuration.isMinimized()) { smcheckBox.setSelected(true); } JComponent cmp = builder.addSeparator(Messages.getString("NetworkTab.5"), FormLayoutUtil.flip(cc.xyw(1, 1, 9), colSpec, orientation)); cmp = (JComponent) cmp.getComponent(0); cmp.setFont(cmp.getFont().deriveFont(Font.BOLD)); builder.addLabel(Messages.getString("NetworkTab.0"), FormLayoutUtil.flip(cc.xy(1, 7), colSpec, orientation)); final KeyedComboBoxModel kcbm = new KeyedComboBoxModel( new Object[] { "ar", "bg", "ca", "zhs", "zht", "cz", "da", "nl", "en", "fi", "fr", "de", "el", "iw", "is", "it", "ja", "ko", "no", "pl", "pt", "br", "ro", "ru", "sl", "es", "sv", "tr" }, new Object[] { "Arabic", "Bulgarian", "Catalan", "Chinese (Simplified)", "Chinese (Traditional)", "Czech", "Danish", "Dutch", "English", "Finnish", "French", "German", "Greek", "Hebrew", "Icelandic", "Italian", "Japanese", "Korean", "Norwegian", "Polish", "Portuguese", "Portuguese (Brazilian)", "Romanian", "Russian", "Slovenian", "Spanish", "Swedish", "Turkish" }); langs = new JComboBox(kcbm); langs.setEditable(false); String defaultLang = null; if (configuration.getLanguage() != null && configuration.getLanguage().length() > 0) { defaultLang = configuration.getLanguage(); } else { defaultLang = Locale.getDefault().getLanguage(); } if (defaultLang == null) { defaultLang = "en"; } kcbm.setSelectedKey(defaultLang); if (langs.getSelectedIndex() == -1) { langs.setSelectedIndex(0); } langs.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { configuration.setLanguage((String) kcbm.getSelectedKey()); } } }); builder.add(langs, FormLayoutUtil.flip(cc.xyw(3, 7, 7), colSpec, orientation)); builder.add(smcheckBox, FormLayoutUtil.flip(cc.xyw(1, 9, 9), colSpec, orientation)); JButton service = new JButton(Messages.getString("NetworkTab.4")); service.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (PMS.get().installWin32Service()) { JOptionPane.showMessageDialog( (JFrame) (SwingUtilities.getWindowAncestor((Component) PMS.get().getFrame())), Messages.getString("NetworkTab.11") + Messages.getString("NetworkTab.12"), Messages.getString("Dialog.Information"), JOptionPane.INFORMATION_MESSAGE); } else { JOptionPane.showMessageDialog( (JFrame) (SwingUtilities.getWindowAncestor((Component) PMS.get().getFrame())), Messages.getString("NetworkTab.14"), Messages.getString("Dialog.Error"), JOptionPane.ERROR_MESSAGE); } } }); builder.add(service, FormLayoutUtil.flip(cc.xy(1, 11), colSpec, orientation)); if (System.getProperty(LooksFrame.START_SERVICE) != null || !Platform.isWindows()) { service.setEnabled(false); } JButton checkForUpdates = new JButton(Messages.getString("NetworkTab.8")); checkForUpdates.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { LooksFrame frame = (LooksFrame) PMS.get().getFrame(); frame.checkForUpdates(); } }); builder.add(checkForUpdates, FormLayoutUtil.flip(cc.xy(1, 13), colSpec, orientation)); autoUpdateCheckBox = new JCheckBox(Messages.getString("NetworkTab.9")); autoUpdateCheckBox.setContentAreaFilled(false); autoUpdateCheckBox.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { configuration.setAutoUpdate((e.getStateChange() == ItemEvent.SELECTED)); } }); if (configuration.isAutoUpdate()) { autoUpdateCheckBox.setSelected(true); } builder.add(autoUpdateCheckBox, FormLayoutUtil.flip(cc.xyw(7, 13, 3), colSpec, orientation)); if (!Build.isUpdatable()) { checkForUpdates.setEnabled(false); autoUpdateCheckBox.setEnabled(false); } host = new JTextField(configuration.getServerHostname()); host.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { configuration.setHostname(host.getText()); } }); port = new JTextField(configuration.getServerPort() != 5001 ? "" + configuration.getServerPort() : ""); port.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { try { String p = port.getText(); if (StringUtils.isEmpty(p)) { p = "5001"; } int ab = Integer.parseInt(p); configuration.setServerPort(ab); } catch (NumberFormatException nfe) { logger.debug("Could not parse port from \"" + port.getText() + "\""); } } }); cmp = builder.addSeparator(Messages.getString("NetworkTab.22"), FormLayoutUtil.flip(cc.xyw(1, 21, 9), colSpec, orientation)); cmp = (JComponent) cmp.getComponent(0); cmp.setFont(cmp.getFont().deriveFont(Font.BOLD)); final KeyedComboBoxModel networkInterfaces = createNetworkInterfacesModel(); networkinterfacesCBX = new JComboBox(networkInterfaces); networkInterfaces.setSelectedKey(configuration.getNetworkInterface()); networkinterfacesCBX.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { configuration.setNetworkInterface((String) networkInterfaces.getSelectedKey()); } } }); ip_filter = new JTextField(configuration.getIpFilter()); ip_filter.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { configuration.setIpFilter(ip_filter.getText()); } }); maxbitrate = new JTextField(configuration.getMaximumBitrate()); maxbitrate.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { PMS.getConfiguration().setMaximumBitrate(maxbitrate.getText()); } }); builder.addLabel(Messages.getString("NetworkTab.20"), FormLayoutUtil.flip(cc.xy(1, 23), colSpec, orientation)); builder.add(networkinterfacesCBX, FormLayoutUtil.flip(cc.xyw(3, 23, 7), colSpec, orientation)); builder.addLabel(Messages.getString("NetworkTab.23"), FormLayoutUtil.flip(cc.xy(1, 25), colSpec, orientation)); builder.add(host, FormLayoutUtil.flip(cc.xyw(3, 25, 7), colSpec, orientation)); builder.addLabel(Messages.getString("NetworkTab.24"), FormLayoutUtil.flip(cc.xy(1, 27), colSpec, orientation)); builder.add(port, FormLayoutUtil.flip(cc.xyw(3, 27, 7), colSpec, orientation)); builder.addLabel(Messages.getString("NetworkTab.30"), FormLayoutUtil.flip(cc.xy(1, 29), colSpec, orientation)); builder.add(ip_filter, FormLayoutUtil.flip(cc.xyw(3, 29, 7), colSpec, orientation)); builder.addLabel(Messages.getString("NetworkTab.35"), FormLayoutUtil.flip(cc.xy(1, 31), colSpec, orientation)); builder.add(maxbitrate, FormLayoutUtil.flip(cc.xyw(3, 31, 7), colSpec, orientation)); cmp = builder.addSeparator(Messages.getString("NetworkTab.31"), FormLayoutUtil.flip(cc.xyw(1, 33, 9), colSpec, orientation)); cmp = (JComponent) cmp.getComponent(0); cmp.setFont(cmp.getFont().deriveFont(Font.BOLD)); newHTTPEngine = new JCheckBox(Messages.getString("NetworkTab.32")); newHTTPEngine.setSelected(configuration.isHTTPEngineV2()); newHTTPEngine.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { configuration.setHTTPEngineV2((e.getStateChange() == ItemEvent.SELECTED)); } }); builder.add(newHTTPEngine, FormLayoutUtil.flip(cc.xyw(1, 35, 9), colSpec, orientation)); preventSleep = new JCheckBox(Messages.getString("NetworkTab.33")); preventSleep.setSelected(configuration.isPreventsSleep()); preventSleep.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { configuration.setPreventsSleep((e.getStateChange() == ItemEvent.SELECTED)); } }); builder.add(preventSleep, FormLayoutUtil.flip(cc.xyw(1, 37, 9), colSpec, orientation)); JCheckBox fdCheckBox = new JCheckBox(Messages.getString("NetworkTab.38")); fdCheckBox.setContentAreaFilled(false); fdCheckBox.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { configuration.setRendererForceDefault((e.getStateChange() == ItemEvent.SELECTED)); } }); if (configuration.isRendererForceDefault()) { fdCheckBox.setSelected(true); } builder.addLabel(Messages.getString("NetworkTab.36"), FormLayoutUtil.flip(cc.xy(1, 39), colSpec, orientation)); ArrayList<RendererConfiguration> allConfs = RendererConfiguration.getAllRendererConfigurations(); ArrayList<Object> keyValues = new ArrayList<Object>(); ArrayList<Object> nameValues = new ArrayList<Object>(); keyValues.add(""); nameValues.add(Messages.getString("NetworkTab.37")); if (allConfs != null) { for (RendererConfiguration renderer : allConfs) { if (renderer != null) { keyValues.add(renderer.getRendererName()); nameValues.add(renderer.getRendererName()); } } } final KeyedComboBoxModel renderersKcbm = new KeyedComboBoxModel( (Object[]) keyValues.toArray(new Object[keyValues.size()]), (Object[]) nameValues.toArray(new Object[nameValues.size()])); renderers = new JComboBox(renderersKcbm); renderers.setEditable(false); String defaultRenderer = configuration.getRendererDefault(); renderersKcbm.setSelectedKey(defaultRenderer); if (renderers.getSelectedIndex() == -1) { renderers.setSelectedIndex(0); } builder.add(renderers, FormLayoutUtil.flip(cc.xyw(3, 39, 7), colSpec, orientation)); builder.add(fdCheckBox, FormLayoutUtil.flip(cc.xyw(1, 41, 9), colSpec, orientation)); cmp = builder.addSeparator(Messages.getString("NetworkTab.34"), FormLayoutUtil.flip(cc.xyw(1, 43, 9), colSpec, orientation)); cmp = (JComponent) cmp.getComponent(0); cmp.setFont(cmp.getFont().deriveFont(Font.BOLD)); pPlugins = new JPanel(new GridLayout()); builder.add(pPlugins, FormLayoutUtil.flip(cc.xyw(1, 45, 9), colSpec, orientation)); JPanel panel = builder.getPanel(); // Apply the orientation to the panel and all components in it panel.applyComponentOrientation(orientation); JScrollPane scrollPane = new JScrollPane(panel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); return scrollPane; }
From source file:com.sec.ose.osi.ui.frm.main.manage.ManagedProjectTableModel.java
public void setColumnType(JTable table) { table.setShowVerticalLines(false);//from w w w.ja v a 2s.co m table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.setColumnSelectionAllowed(false); table.setRowSelectionAllowed(false); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); table.setRowHeight(30); JTableHeader header = table.getTableHeader(); header.setPreferredSize(new java.awt.Dimension(table.getTableHeader().getWidth(), 30)); header.setFont(new Font("Arial", Font.BOLD, 12)); header.setReorderingAllowed(false); TableColumnModel cm = table.getColumnModel(); TableColumn col = null; analyzeHeader = new CheckBoxHeader(new CheckboxHeaderItemListener(table, COL_ANALYZE_TARGET), "Analyze Target"); col = cm.getColumn(COL_ANALYZE_TARGET); col.setHeaderRenderer(analyzeHeader); JCheckBox chkbox = new JCheckBox(); chkbox.setBackground(Color.white); chkbox.setHorizontalAlignment(JLabel.CENTER); col.setCellRenderer(new DefaultTableCellRenderer() { private static final long serialVersionUID = 1L; public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { ManagedProjectTableModel model = (ManagedProjectTableModel) table.getModel(); String sPrjName = (String) table.getValueAt(row, ManagedProjectTableModel.COL_PROJECT_NAME); OSIProjectInfo item = model.getProjectInfo(sPrjName); JCheckBox chkbox = new JCheckBox(); chkbox.setSelected(((Boolean) value).booleanValue()); if (item != null) { chkbox.setEnabled(item.isLocationValid()); } chkbox.setHorizontalAlignment(JLabel.CENTER); chkbox.setBackground(Color.white); return (Component) chkbox; } }); col.setCellEditor(new DefaultCellEditor(chkbox)); col = cm.getColumn(COL_ANALYZE_STATUS); col.setCellRenderer(new StatusIconCellRenderer()); col = cm.getColumn(COL_SOURCE_LOCATION); col.setCellRenderer(new FileBrowseCellRenderer()); col.setCellEditor(new FileBrowseCellEditor()); }
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 www. j a v a2s . co m }); 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); }
From source file:lu.lippmann.cdb.ext.hydviga.ui.GapFillingFrame.java
/** * Constructor./*from ww w .ja v a 2s . com*/ */ public GapFillingFrame(final AbstractTabView atv, final Instances dataSet, final Attribute attr, final int dateIdx, final int valuesBeforeAndAfter, final int position, final int gapsize, final StationsDataProvider gcp, final boolean inBatchMode) { super(); setTitle("Gap filling for " + attr.name() + " (" + dataSet.attribute(dateIdx).formatDate(dataSet.instance(position).value(dateIdx)) + " -> " + dataSet.attribute(dateIdx).formatDate(dataSet.instance(position + gapsize).value(dateIdx)) + ")"); LogoHelper.setLogo(this); this.atv = atv; this.dataSet = dataSet; this.attr = attr; this.dateIdx = dateIdx; this.valuesBeforeAndAfter = valuesBeforeAndAfter; this.position = position; this.gapsize = gapsize; this.gcp = gcp; final Instances testds = WekaDataProcessingUtil.buildFilteredDataSet(dataSet, 0, dataSet.numAttributes() - 1, Math.max(0, position - valuesBeforeAndAfter), Math.min(position + gapsize + valuesBeforeAndAfter, dataSet.numInstances() - 1)); this.attrNames = WekaTimeSeriesUtil.getNamesOfAttributesWithoutGap(testds); this.isGapSimulated = (this.attrNames.contains(attr.name())); this.originaldataSet = new Instances(dataSet); if (this.isGapSimulated) { setTitle(getTitle() + " [SIMULATED GAP]"); /*final JXLabel fictiveGapLabel=new JXLabel(" FICTIVE GAP"); fictiveGapLabel.setForeground(Color.RED); fictiveGapLabel.setFont(new Font(fictiveGapLabel.getFont().getName(), Font.PLAIN,fictiveGapLabel.getFont().getSize()*2)); final JXPanel fictiveGapPanel=new JXPanel(); fictiveGapPanel.setLayout(new BorderLayout()); fictiveGapPanel.add(fictiveGapLabel,BorderLayout.CENTER); getContentPane().add(fictiveGapPanel,BorderLayout.NORTH);*/ this.attrNames.remove(attr.name()); this.originalDataBeforeGapSimulation = dataSet.attributeToDoubleArray(attr.index()); for (int i = position; i < position + gapsize; i++) dataSet.instance(i).setMissing(attr); } final Object[] attrNamesObj = this.attrNames.toArray(); this.centerPanel = new JXPanel(); this.centerPanel.setLayout(new BorderLayout()); getContentPane().add(this.centerPanel, BorderLayout.CENTER); //final JXPanel algoPanel=new JXPanel(); //getContentPane().add(algoPanel,BorderLayout.NORTH); final JXPanel filterPanel = new JXPanel(); //filterPanel.setLayout(new BoxLayout(filterPanel, BoxLayout.Y_AXIS)); filterPanel.setLayout(new GridBagLayout()); final GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 0; gbc.weightx = 1; gbc.weighty = 1; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.insets = new Insets(10, 10, 10, 10); getContentPane().add(filterPanel, BorderLayout.WEST); final JXComboBox algoCombo = new JXComboBox(Algo.values()); algoCombo.setBorder(new TitledBorder("Algorithm")); filterPanel.add(algoCombo, gbc); gbc.gridy++; final JXLabel infoLabel = new JXLabel("Usable = with no missing values on the period"); //infoLabel.setBorder(new TitledBorder("")); filterPanel.add(infoLabel, gbc); gbc.gridy++; final JList<Object> timeSeriesList = new JList<Object>(attrNamesObj); timeSeriesList.setBorder(new TitledBorder("Usable time series")); timeSeriesList.setSelectionMode(DefaultListSelectionModel.MULTIPLE_INTERVAL_SELECTION); final JScrollPane jcpMap = new JScrollPane(timeSeriesList); jcpMap.setPreferredSize(new Dimension(225, 150)); jcpMap.setMinimumSize(new Dimension(225, 150)); filterPanel.add(jcpMap, gbc); gbc.gridy++; final JXPanel mapPanel = new JXPanel(); mapPanel.setBorder(new TitledBorder("")); mapPanel.setLayout(new BorderLayout()); mapPanel.add(gcp.getMapPanel(Arrays.asList(attr.name()), this.attrNames, true), BorderLayout.CENTER); filterPanel.add(mapPanel, gbc); gbc.gridy++; final JXLabel mssLabel = new JXLabel( "<html>Most similar usable serie: <i>[... computation ...]</i></html>"); mssLabel.setBorder(new TitledBorder("")); filterPanel.add(mssLabel, gbc); gbc.gridy++; final JXLabel nsLabel = new JXLabel("<html>Nearest usable serie: <i>[... computation ...]</i></html>"); nsLabel.setBorder(new TitledBorder("")); filterPanel.add(nsLabel, gbc); gbc.gridy++; final JXLabel ussLabel = new JXLabel("<html>Upstream serie: <i>[... computation ...]</i></html>"); ussLabel.setBorder(new TitledBorder("")); filterPanel.add(ussLabel, gbc); gbc.gridy++; final JXLabel dssLabel = new JXLabel("<html>Downstream serie: <i>[... computation ...]</i></html>"); dssLabel.setBorder(new TitledBorder("")); filterPanel.add(dssLabel, gbc); gbc.gridy++; final JCheckBox hideOtherSeriesCB = new JCheckBox("Hide the others series"); hideOtherSeriesCB.setSelected(DEFAULT_HIDE_OTHER_SERIES_OPTION); filterPanel.add(hideOtherSeriesCB, gbc); gbc.gridy++; final JCheckBox showErrorCB = new JCheckBox("Show error on plot"); filterPanel.add(showErrorCB, gbc); gbc.gridy++; final JCheckBox zoomCB = new JCheckBox("Auto-adjusted size"); zoomCB.setSelected(DEFAULT_ZOOM_OPTION); filterPanel.add(zoomCB, gbc); gbc.gridy++; final JCheckBox multAxisCB = new JCheckBox("Multiple axis"); filterPanel.add(multAxisCB, gbc); gbc.gridy++; final JCheckBox showEnvelopeCB = new JCheckBox("Show envelope (all algorithms, SLOW)"); filterPanel.add(showEnvelopeCB, gbc); gbc.gridy++; final JXButton showModelButton = new JXButton("Show the model"); filterPanel.add(showModelButton, gbc); gbc.gridy++; showModelButton.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { final JXFrame dialog = new JXFrame(); dialog.setTitle("Model"); LogoHelper.setLogo(dialog); dialog.getContentPane().removeAll(); dialog.getContentPane().setLayout(new BorderLayout()); final JTextPane modelTxtPane = new JTextPane(); modelTxtPane.setText(gapFiller.getModel()); modelTxtPane.setBackground(Color.WHITE); modelTxtPane.setEditable(false); final JScrollPane jsp = new JScrollPane(modelTxtPane, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); jsp.setSize(new Dimension(400 - 20, 400 - 20)); dialog.getContentPane().add(jsp, BorderLayout.CENTER); dialog.setSize(new Dimension(400, 400)); dialog.setLocationRelativeTo(centerPanel); dialog.pack(); dialog.setVisible(true); } }); algoCombo.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { try { refresh(Algo.valueOf(algoCombo.getSelectedItem().toString()), timeSeriesList.getSelectedIndices(), hideOtherSeriesCB.isSelected(), showErrorCB.isSelected(), zoomCB.isSelected(), showEnvelopeCB.isSelected(), multAxisCB.isSelected()); showModelButton.setEnabled(gapFiller.hasExplicitModel()); } catch (final Exception e1) { e1.printStackTrace(); } } }); timeSeriesList.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(final ListSelectionEvent e) { try { refresh(Algo.valueOf(algoCombo.getSelectedItem().toString()), timeSeriesList.getSelectedIndices(), hideOtherSeriesCB.isSelected(), showErrorCB.isSelected(), zoomCB.isSelected(), showEnvelopeCB.isSelected(), multAxisCB.isSelected()); mapPanel.removeAll(); final List<String> currentlySelected = new ArrayList<String>(); currentlySelected.add(attr.name()); for (final Object sel : timeSeriesList.getSelectedValues()) currentlySelected.add(sel.toString()); mapPanel.add(gcp.getMapPanel(currentlySelected, attrNames, true), BorderLayout.CENTER); } catch (final Exception e1) { e1.printStackTrace(); } } }); hideOtherSeriesCB.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { try { refresh(Algo.valueOf(algoCombo.getSelectedItem().toString()), timeSeriesList.getSelectedIndices(), hideOtherSeriesCB.isSelected(), showErrorCB.isSelected(), zoomCB.isSelected(), showEnvelopeCB.isSelected(), multAxisCB.isSelected()); } catch (final Exception e1) { e1.printStackTrace(); } } }); showErrorCB.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { try { refresh(Algo.valueOf(algoCombo.getSelectedItem().toString()), timeSeriesList.getSelectedIndices(), hideOtherSeriesCB.isSelected(), showErrorCB.isSelected(), zoomCB.isSelected(), showEnvelopeCB.isSelected(), multAxisCB.isSelected()); } catch (Exception e1) { e1.printStackTrace(); } } }); zoomCB.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { try { refresh(Algo.valueOf(algoCombo.getSelectedItem().toString()), timeSeriesList.getSelectedIndices(), hideOtherSeriesCB.isSelected(), showErrorCB.isSelected(), zoomCB.isSelected(), showEnvelopeCB.isSelected(), multAxisCB.isSelected()); } catch (Exception e1) { e1.printStackTrace(); } } }); showEnvelopeCB.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { try { refresh(Algo.valueOf(algoCombo.getSelectedItem().toString()), timeSeriesList.getSelectedIndices(), hideOtherSeriesCB.isSelected(), showErrorCB.isSelected(), zoomCB.isSelected(), showEnvelopeCB.isSelected(), multAxisCB.isSelected()); } catch (Exception e1) { e1.printStackTrace(); } } }); multAxisCB.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { try { refresh(Algo.valueOf(algoCombo.getSelectedItem().toString()), timeSeriesList.getSelectedIndices(), hideOtherSeriesCB.isSelected(), showErrorCB.isSelected(), zoomCB.isSelected(), showEnvelopeCB.isSelected(), multAxisCB.isSelected()); } catch (Exception e1) { e1.printStackTrace(); } } }); this.inBatchMode = inBatchMode; if (!inBatchMode) { try { refresh(Algo.valueOf(algoCombo.getSelectedItem().toString()), new int[0], DEFAULT_HIDE_OTHER_SERIES_OPTION, false, DEFAULT_ZOOM_OPTION, false, false); showModelButton.setEnabled(gapFiller.hasExplicitModel()); } catch (Exception e1) { e1.printStackTrace(); } } if (!inBatchMode) { /* automatically select computed series */ new AbstractSimpleAsync<Void>(true) { @Override public Void execute() throws Exception { mostSimilar = WekaTimeSeriesSimilarityUtil.findMostSimilarTimeSerie(testds, attr, attrNames, false); mssLabel.setText("<html>Most similar usable serie: <b>" + mostSimilar + "</b></html>"); nearest = gcp.findNearestStation(attr.name(), attrNames); nsLabel.setText("<html>Nearest usable serie: <b>" + nearest + "</b></html>"); upstream = gcp.findUpstreamStation(attr.name(), attrNames); if (upstream != null) { ussLabel.setText("<html>Upstream usable serie: <b>" + upstream + "</b></html>"); } else { ussLabel.setText("<html>Upstream usable serie: <b>N/A</b></html>"); } downstream = gcp.findDownstreamStation(attr.name(), attrNames); if (downstream != null) { dssLabel.setText("<html>Downstream usable serie: <b>" + downstream + "</b></html>"); } else { dssLabel.setText("<html>Downstream usable serie: <b>N/A</b></html>"); } timeSeriesList.setSelectedIndices( new int[] { attrNames.indexOf(mostSimilar), attrNames.indexOf(nearest), attrNames.indexOf(upstream), attrNames.indexOf(downstream) }); return null; } @Override public void onSuccess(final Void result) { } @Override public void onFailure(final Throwable caught) { caught.printStackTrace(); } }.start(); } else { try { mostSimilar = WekaTimeSeriesSimilarityUtil.findMostSimilarTimeSerie(testds, attr, attrNames, false); } catch (Exception e1) { e1.printStackTrace(); } nearest = gcp.findNearestStation(attr.name(), attrNames); upstream = gcp.findUpstreamStation(attr.name(), attrNames); downstream = gcp.findDownstreamStation(attr.name(), attrNames); } }
From source file:com.diversityarrays.kdxplore.boxplot.BoxPlotPanel.java
private Box generateControls() { for (JCheckBox jcb : Arrays.asList(showOutliers, showMean, showMedian)) { ActionListener optionsActionListener = new ActionListener() { @Override//from ww w .j a va2s . c o m public void actionPerformed(ActionEvent e) { generateGraph(Why.OPTION_CHANGED); setSpinnerRanges(); } }; jcb.addActionListener(optionsActionListener); jcb.setSelected(true); } JLabel infoLabel = new JLabel(Msg.LABEL_SHOW_PARAMETERS()); infoLabel.setBorder(new EmptyBorder(3, 3, 3, 3)); Box hbox = Box.createHorizontalBox(); hbox.add(syncedOption); hbox.add(minSpinner); hbox.add(new JLabel(" - ")); //$NON-NLS-1$ hbox.add(maxSpinner); hbox.add(infoLabel); hbox.add(showOutliers); hbox.add(showMean); hbox.add(showMedian); return hbox; }