List of usage examples for javax.swing JSpinner getEditor
public JComponent getEditor()
From source file:Main.java
public void makeUI() { String[] zones = { "Asia/Tokyo", "Asia/Hong_Kong", "Asia/Calcutta", "Europe/Paris", "Europe/London", "America/New_York", "America/Los_Angeles" }; JLabel[] labels = new JLabel[zones.length]; SimpleDateFormat[] formats = new SimpleDateFormat[zones.length]; JFrame frame = new JFrame(); Calendar cal = Calendar.getInstance(); Date date = cal.getTime();/*from w w w . j a v a 2 s. c om*/ SpinnerDateModel model = new SpinnerDateModel(); model.setValue(date); JSpinner spinner = new JSpinner(model); spinner.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { Date date = (Date) ((JSpinner) e.getSource()).getValue(); for (int i = 0; i < labels.length; i++) { labels[i].setText(formats[i].format(date)); } } }); SimpleDateFormat format = ((JSpinner.DateEditor) spinner.getEditor()).getFormat(); format.setTimeZone(TimeZone.getTimeZone(zones[0])); format.applyPattern("yyyy-MM-dd HH:mm:ss"); JPanel panel = new JPanel(new GridLayout(zones.length, 2, 10, 10)); for (int i = 0; i < zones.length; i++) { formats[i] = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss"); formats[i].setTimeZone(TimeZone.getTimeZone(zones[i])); JLabel label = new JLabel(zones[i]); labels[i] = new JLabel(formats[i].format(date)); panel.add(label); panel.add(labels[i]); } frame.setLayout(new BorderLayout()); frame.add(spinner, BorderLayout.NORTH); frame.add(panel, BorderLayout.CENTER); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); }
From source file:controlador.ControladorReportes.java
private void inicializarReporteMasVendidos() { JSpinner spinner = reportes.getSpinnerCantidadMasVendidos(); ((JSpinner.DefaultEditor) spinner.getEditor()).getTextField().setEditable(false); setControlesReporteMasVendidos(false); }
From source file:ch.fork.AdHocRailway.ui.locomotives.configuration.LocomotiveConfig.java
private void setSpinnerColor(final JSpinner spinner, final Color color) { final JSpinner.DefaultEditor editor = (JSpinner.DefaultEditor) spinner.getEditor(); editor.getTextField().setBackground(color); }
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 ww . jav a2s .c om*/ 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:canreg.client.gui.analysis.TableBuilderInternalFrame.java
private void initData() { JSpinner spinnerStart = (JSpinner) startYearChooser.getSpinner(); spinnerStart.getEditor().addFocusListener(new java.awt.event.FocusAdapter() { @Override// w ww . ja v a 2s. c om public void focusLost(java.awt.event.FocusEvent evt) { startYearChooserFocusLost(evt); } private void startYearChooserFocusLost(FocusEvent evt) { if (startYearChooser.getYear() > endYearChooser.getYear()) { endYearChooser.setYear(startYearChooser.getYear()); warningLabel.setText(java.util.ResourceBundle .getBundle("canreg/client/gui/analysis/resources/TableBuilderInternalFrame") .getString("START_BEFORE_END_MOVING_END")); } else if (startYearChooser.getYear() <= endYearChooser.getYear() - Globals.MAX_POPULATION_DATASETS_IN_TABLE) { endYearChooser.setYear(startYearChooser.getYear() + Globals.MAX_POPULATION_DATASETS_IN_TABLE); warningLabel.setText(java.util.ResourceBundle .getBundle("canreg/client/gui/analysis/resources/TableBuilderInternalFrame") .getString("MAX_SPAN_ALLOWED_IS_") + Globals.MAX_POPULATION_DATASETS_IN_TABLE + java.util.ResourceBundle .getBundle("canreg/client/gui/analysis/resources/TableBuilderInternalFrame") .getString("_MOVING_END.")); } else { warningLabel.setText(""); } updateRangeFields(); } }); JSpinner spinnerEnd = (JSpinner) endYearChooser.getSpinner(); spinnerEnd.getEditor().addFocusListener(new java.awt.event.FocusAdapter() { @Override public void focusLost(java.awt.event.FocusEvent evt) { endYearChooserFocusLost(evt); } private void endYearChooserFocusLost(FocusEvent evt) { if (startYearChooser.getYear() > endYearChooser.getYear()) { startYearChooser.setYear(endYearChooser.getYear()); warningLabel.setText(java.util.ResourceBundle .getBundle("canreg/client/gui/analysis/resources/TableBuilderInternalFrame") .getString("END_BEFORE_START_MOVING_START")); } else if (startYearChooser.getYear() <= endYearChooser.getYear() - Globals.MAX_POPULATION_DATASETS_IN_TABLE) { startYearChooser.setYear(endYearChooser.getYear() - Globals.MAX_POPULATION_DATASETS_IN_TABLE); warningLabel.setText(java.util.ResourceBundle .getBundle("canreg/client/gui/analysis/resources/TableBuilderInternalFrame") .getString("MAX_SPAN_ALLOWED_IS_") + Globals.MAX_POPULATION_DATASETS_IN_TABLE + java.util.ResourceBundle .getBundle("canreg/client/gui/analysis/resources/TableBuilderInternalFrame") .getString("_MOVING_START.")); } else { warningLabel.setText(""); } updateRangeFields(); } }); rangeFilterPanel .setDatabaseDescription(canreg.client.CanRegClientApp.getApplication().getDatabseDescription()); // get population datasets try { populationDatasetsMap = canreg.client.CanRegClientApp.getApplication().getPopulationDatasets(); Collection<PopulationDataset> populationDatasetsCollection; Collection<PopulationDataset> populationDatasetsCollection2 = new LinkedList<>(); populationDatasetsCollection = populationDatasetsMap.values(); populationDatasetsCollection.stream().filter((pd) -> (!pd.isReferencePopulationBool())) .forEachOrdered((pd) -> { populationDatasetsCollection2.add(pd); }); populationDatasetsArray = populationDatasetsCollection2.toArray(new PopulationDataset[0]); populatePopulationDataSetChooser(); } catch (SecurityException | RemoteException ex) { Logger.getLogger(TableBuilderInternalFrame.class.getName()).log(Level.SEVERE, null, ex); } //get table builder engines refreshTableTypeList(); }
From source file:com.xyphos.vmtgen.GUI.java
private void lafSpinner(JSpinner s) { ((JSpinner.NumberEditor) s.getEditor()).getTextField().setDisabledTextColor(Color.RED); }
From source file:edu.snu.leader.discrete.simulator.SimulatorLauncherGUI.java
/** * Create the frame./*from ww w.ja va 2 s.com*/ */ public SimulatorLauncherGUI() { NumberFormat countFormat = NumberFormat.getNumberInstance(); countFormat.setParseIntegerOnly(true); NumberFormat doubleFormat = NumberFormat.getNumberInstance(); doubleFormat.setMinimumIntegerDigits(1); doubleFormat.setMaximumFractionDigits(10); setTitle("Simulator"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 515, 340); setResizable(false); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); contentPane.setLayout(new BorderLayout(0, 0)); setContentPane(contentPane); tabbedPane = new JTabbedPane(JTabbedPane.TOP); contentPane.add(tabbedPane, BorderLayout.CENTER); JPanel panelTab1 = new JPanel(); tabbedPane.addTab("Simulator", null, panelTab1, null); JPanel panelAgentCount = new JPanel(); panelTab1.add(panelAgentCount); JLabel lblNewLabel = new JLabel("Agent Count"); panelAgentCount.add(lblNewLabel); sliderAgent = new JSlider(); panelAgentCount.add(sliderAgent); sliderAgent.setValue(10); sliderAgent.setSnapToTicks(true); sliderAgent.setPaintTicks(true); sliderAgent.setPaintLabels(true); sliderAgent.setMinorTickSpacing(10); sliderAgent.setMajorTickSpacing(10); sliderAgent.setMinimum(10); sliderAgent.setMaximum(70); sliderAgent.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent arg0) { Integer spinnerValue = (Integer) spinnerMaxEaten.getValue(); if (spinnerValue > sliderAgent.getValue()) { spinnerValue = sliderAgent.getValue(); } spinnerMaxEaten.setModel(new SpinnerNumberModel(spinnerValue, new Integer(0), new Integer(sliderAgent.getValue()), new Integer(1))); JFormattedTextField tfMaxEaten = ((JSpinner.DefaultEditor) spinnerMaxEaten.getEditor()) .getTextField(); tfMaxEaten.setEditable(false); } }); JPanel panelCommType = new JPanel(); panelTab1.add(panelCommType); JLabel lblNewLabel_1 = new JLabel("Communication Type"); panelCommType.add(lblNewLabel_1); comboBoxCommType = new JComboBox<String>(); panelCommType.add(comboBoxCommType); comboBoxCommType .setModel(new DefaultComboBoxModel<String>(new String[] { "Global", "Topological", "Metric" })); comboBoxCommType.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { String item = (String) comboBoxCommType.getSelectedItem(); if (item.equals("Topological")) { panelNearestNeighborCount.setVisible(true); panelMaxLocationRadius.setVisible(false); } else if (item.equals("Metric")) { panelNearestNeighborCount.setVisible(false); panelMaxLocationRadius.setVisible(true); } else if (item.equals("Global")) { panelNearestNeighborCount.setVisible(false); panelMaxLocationRadius.setVisible(false); } } }); JPanel panelDestinationRadius = new JPanel(); panelTab1.add(panelDestinationRadius); JLabel lblDestinationRadius = new JLabel("Destination Radius"); panelDestinationRadius.add(lblDestinationRadius); frmtdtxtfldDestinationRadius = new JFormattedTextField(doubleFormat); frmtdtxtfldDestinationRadius.setColumns(4); frmtdtxtfldDestinationRadius.setValue((Number) 10); panelDestinationRadius.add(frmtdtxtfldDestinationRadius); JPanel panelResultsOutput = new JPanel(); panelTab1.add(panelResultsOutput); JLabel lblResultsOutput = new JLabel("Results Output"); panelResultsOutput.add(lblResultsOutput); final JCheckBox chckbxEskridge = new JCheckBox("Eskridge"); panelResultsOutput.add(chckbxEskridge); final JCheckBox chckbxConflict = new JCheckBox("Conflict"); panelResultsOutput.add(chckbxConflict); final JCheckBox chckbxPosition = new JCheckBox("Position"); panelResultsOutput.add(chckbxPosition); final JCheckBox chckbxPredationResults = new JCheckBox("Predation"); panelResultsOutput.add(chckbxPredationResults); JPanel panelMisc = new JPanel(); panelTab1.add(panelMisc); JLabel lblNewLabel_3 = new JLabel("Misc"); panelMisc.add(lblNewLabel_3); chckbxGraphical = new JCheckBox("Graphical?"); chckbxGraphical.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { if (chckbxGraphical.isSelected()) { frmtdtxtfldRunCount.setValue((Number) 1); frmtdtxtfldRunCount.setEnabled(false); chckbxEskridge.setSelected(false); chckbxEskridge.setEnabled(false); String agentBuilder = (String) comboBoxAgentBuilder.getSelectedItem(); if (agentBuilder.equals("Default")) { comboBoxAgentBuilder.setSelectedIndex(1); } } else { chckbxEskridge.setEnabled(true); frmtdtxtfldRunCount.setEnabled(true); } } }); panelMisc.add(chckbxGraphical); chckbxRandomSeed = new JCheckBox("Random Seed?"); panelMisc.add(chckbxRandomSeed); chckbxPredationEnable = new JCheckBox("Predation?"); chckbxPredationEnable.setSelected(true); chckbxPredationEnable.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { if (chckbxPredationEnable.isSelected()) { panelPredationStuff.setVisible(true); panelPredationBoxes.setVisible(true); panelPredationConstant.setVisible(true); panelNonMoversSurvive.setVisible(true); } else { panelPredationStuff.setVisible(false); panelPredationBoxes.setVisible(false); panelPredationConstant.setVisible(false); panelNonMoversSurvive.setVisible(false); } } }); panelMisc.add(chckbxPredationEnable); JPanel panelCounts = new JPanel(); panelTab1.add(panelCounts); JLabel lblNewLabel_4 = new JLabel("Run Count"); panelCounts.add(lblNewLabel_4); frmtdtxtfldRunCount = new JFormattedTextField(countFormat); frmtdtxtfldRunCount.setToolTipText("The number of runs. Each run has a different random seed."); panelCounts.add(frmtdtxtfldRunCount); frmtdtxtfldRunCount.setColumns(4); frmtdtxtfldRunCount.setValue((Number) 1); JLabel lblNewLabel_5 = new JLabel("Sim Count"); panelCounts.add(lblNewLabel_5); frmtdtxtfldSimCount = new JFormattedTextField(countFormat); frmtdtxtfldSimCount .setToolTipText("The number of simulations per run. Each simulation uses the same random seed."); frmtdtxtfldSimCount.setColumns(4); frmtdtxtfldSimCount.setValue((Number) 1); panelCounts.add(frmtdtxtfldSimCount); JLabel lblNewLabel_6 = new JLabel("Max Time Steps"); panelCounts.add(lblNewLabel_6); frmtdtxtfldMaxTimeSteps = new JFormattedTextField(countFormat); frmtdtxtfldMaxTimeSteps.setToolTipText("The max number of time steps per simulation."); frmtdtxtfldMaxTimeSteps.setColumns(6); frmtdtxtfldMaxTimeSteps.setValue((Number) 20000); panelCounts.add(frmtdtxtfldMaxTimeSteps); ////////Panel tab 2 JPanel panelTab2 = new JPanel(); tabbedPane.addTab("Parameters", null, panelTab2, null); JPanel panelDecisionCalculator = new JPanel(); panelTab2.add(panelDecisionCalculator); JLabel lblDecisionCalculator = new JLabel("Decision Calculator"); panelDecisionCalculator.add(lblDecisionCalculator); final JComboBox<String> comboBoxDecisionCalculator = new JComboBox<String>(); panelDecisionCalculator.add(comboBoxDecisionCalculator); comboBoxDecisionCalculator.setModel( new DefaultComboBoxModel<String>(new String[] { "Default", "Conflict", "Conflict Uninformed" })); JPanel panelAgentBuilder = new JPanel(); panelTab2.add(panelAgentBuilder); JLabel lblAgentBuilder = new JLabel("Agent Builder"); panelAgentBuilder.add(lblAgentBuilder); comboBoxAgentBuilder = new JComboBox<String>(); panelAgentBuilder.add(comboBoxAgentBuilder); comboBoxAgentBuilder.setModel(new DefaultComboBoxModel<String>(new String[] { "Default", "Simple Angular", "Personality Simple Angular", "Simple Angular Uninformed" })); comboBoxAgentBuilder.setSelectedIndex(1); comboBoxAgentBuilder.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { if (chckbxGraphical.isSelected()) { String agentBuilder = (String) comboBoxAgentBuilder.getSelectedItem(); if (agentBuilder.equals("Default")) { comboBoxAgentBuilder.setSelectedIndex(1); } } } }); JPanel panelModel = new JPanel(); panelTab2.add(panelModel); JLabel lblModel = new JLabel("Model"); panelModel.add(lblModel); comboBoxModel = new JComboBox<String>(); panelModel.add(comboBoxModel); comboBoxModel.setModel(new DefaultComboBoxModel<String>(new String[] { "Sueur", "Gautrais" })); comboBoxModel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { String item = (String) comboBoxModel.getSelectedItem(); if (item.equals("Sueur")) { panelSueurValues.setVisible(true); panelGautraisValues.setVisible(false); } else if (item.equals("Gautrais")) { panelSueurValues.setVisible(false); panelGautraisValues.setVisible(true); } } }); JPanel panelEnvironment = new JPanel(); panelTab2.add(panelEnvironment); JLabel lblEnvironment = new JLabel("Environment"); panelEnvironment.add(lblEnvironment); comboBoxEnvironment = new JComboBox<String>(); comboBoxEnvironment.setModel( new DefaultComboBoxModel<String>(new String[] { "Minimum", "Medium", "Maximum", "Uninformed" })); comboBoxEnvironment.setSelectedIndex(1); comboBoxEnvironment.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { String item = (String) comboBoxEnvironment.getSelectedItem(); if (!item.equals("Uninformed")) { comboBoxDecisionCalculator.setEnabled(true); comboBoxAgentBuilder.setEnabled(true); } if (item.equals("Medium")) { panelAngle.setVisible(true); panelDistance.setVisible(true); panelPercentage.setVisible(true); panelNumberOfDestinations.setVisible(false); panelInformedCount.setVisible(false); } else if (item.equals("Minimum")) { panelAngle.setVisible(false); panelDistance.setVisible(false); panelPercentage.setVisible(true); panelNumberOfDestinations.setVisible(false); panelInformedCount.setVisible(false); } else if (item.equals("Maximum")) { panelAngle.setVisible(false); panelDistance.setVisible(false); panelPercentage.setVisible(true); panelNumberOfDestinations.setVisible(false); panelInformedCount.setVisible(false); } else if (item.equals("Uninformed")) { panelAngle.setVisible(true); panelDistance.setVisible(true); panelPercentage.setVisible(true); panelNumberOfDestinations.setVisible(false); panelInformedCount.setVisible(true); comboBoxDecisionCalculator.setSelectedIndex(2); comboBoxDecisionCalculator.setEnabled(false); comboBoxAgentBuilder.setSelectedIndex(3); comboBoxAgentBuilder.setEnabled(false); } } }); panelEnvironment.add(comboBoxEnvironment); JPanel panelDefaultConflict = new JPanel(); panelTab2.add(panelDefaultConflict); JLabel lblDefaultConflict = new JLabel("Default Conflict"); panelDefaultConflict.add(lblDefaultConflict); final JSpinner spinnerDefaultConflict = new JSpinner(); panelDefaultConflict.add(spinnerDefaultConflict); spinnerDefaultConflict.setModel( new SpinnerNumberModel(new Float(0.9f), new Float(0.1f), new Float(0.91f), new Float(0.05))); JFormattedTextField tfSpinnerConflict = ((JSpinner.DefaultEditor) spinnerDefaultConflict.getEditor()) .getTextField(); tfSpinnerConflict.setEditable(false); JPanel panelCancelationThreshold = new JPanel(); panelTab2.add(panelCancelationThreshold); JLabel lblCancelationThreshold = new JLabel("Cancelation Threshold"); panelCancelationThreshold.add(lblCancelationThreshold); final JSpinner spinnerCancelationThreshold = new JSpinner(); panelCancelationThreshold.add(spinnerCancelationThreshold); spinnerCancelationThreshold.setModel( new SpinnerNumberModel(new Float(1.0f), new Float(0.0f), new Float(1.01f), new Float(0.05))); JFormattedTextField tfCancelationThreshold = ((JSpinner.DefaultEditor) spinnerCancelationThreshold .getEditor()).getTextField(); tfCancelationThreshold.setEditable(false); JPanel panelStopAnywhere = new JPanel(); panelTab2.add(panelStopAnywhere); final JCheckBox chckbxStopAnywhere = new JCheckBox("Stop Anywhere?"); panelStopAnywhere.add(chckbxStopAnywhere); panelNearestNeighborCount = new JPanel(); panelNearestNeighborCount.setVisible(false); panelTab2.add(panelNearestNeighborCount); JLabel lblNearestNeighborCount = new JLabel("Nearest Neighbor Count"); panelNearestNeighborCount.add(lblNearestNeighborCount); frmtdtxtfldNearestNeighborCount = new JFormattedTextField(countFormat); panelNearestNeighborCount.add(frmtdtxtfldNearestNeighborCount); frmtdtxtfldNearestNeighborCount.setColumns(3); frmtdtxtfldNearestNeighborCount.setValue((Number) 10); panelMaxLocationRadius = new JPanel(); panelMaxLocationRadius.setVisible(false); panelTab2.add(panelMaxLocationRadius); JLabel lblMaxLocationRadius = new JLabel("Max Location Radius"); panelMaxLocationRadius.add(lblMaxLocationRadius); frmtdtxtfldMaxLocationRadius = new JFormattedTextField(doubleFormat); panelMaxLocationRadius.add(frmtdtxtfldMaxLocationRadius); frmtdtxtfldMaxLocationRadius.setColumns(5); frmtdtxtfldMaxLocationRadius.setValue((Number) 10.0); panelPredationBoxes = new JPanel(); panelTab2.add(panelPredationBoxes); final JCheckBox chckbxUsePredationThreshold = new JCheckBox("Use Predation Threshold"); panelPredationBoxes.add(chckbxUsePredationThreshold); final JCheckBox chckbxPopulationIndependent = new JCheckBox("Population Independent"); chckbxPopulationIndependent.setSelected(true); panelPredationBoxes.add(chckbxPopulationIndependent); chckbxPopulationIndependent.setToolTipText( "Select this to allow predation to be independent of population size. Max predation for 10 agents will be the same as for 50 agents. "); panelPredationStuff = new JPanel(); panelTab2.add(panelPredationStuff); JLabel lblPredationMinimum = new JLabel("Predation Minimum"); panelPredationStuff.add(lblPredationMinimum); frmtdtxtfldPredationMinimum = new JFormattedTextField(doubleFormat); frmtdtxtfldPredationMinimum.setColumns(4); frmtdtxtfldPredationMinimum.setValue((Number) 0.0); panelPredationStuff.add(frmtdtxtfldPredationMinimum); JLabel lblPredationThreshold = new JLabel("Predation Threshold"); panelPredationStuff.add(lblPredationThreshold); final JSpinner spinnerPredationThreshold = new JSpinner(); panelPredationStuff.add(spinnerPredationThreshold); spinnerPredationThreshold.setModel( new SpinnerNumberModel(new Float(1.0f), new Float(0.0f), new Float(1.01f), new Float(0.05))); JFormattedTextField tfPredationThreshold = ((JSpinner.DefaultEditor) spinnerPredationThreshold.getEditor()) .getTextField(); tfPredationThreshold.setEditable(false); JLabel lblMaxEaten = new JLabel("Max Eaten"); panelPredationStuff.add(lblMaxEaten); spinnerMaxEaten = new JSpinner(); spinnerMaxEaten.setToolTipText("The max number eaten per time step."); panelPredationStuff.add(spinnerMaxEaten); spinnerMaxEaten.setModel(new SpinnerNumberModel(new Integer(10), new Integer(0), new Integer(sliderAgent.getValue()), new Integer(1))); JFormattedTextField tfMaxEaten = ((JSpinner.DefaultEditor) spinnerMaxEaten.getEditor()).getTextField(); tfMaxEaten.setEditable(false); panelPredationConstant = new JPanel(); panelTab2.add(panelPredationConstant); JLabel lblPredationConstant = new JLabel("Predation Constant"); panelPredationConstant.add(lblPredationConstant); frmtdtxtfldPredationConstant = new JFormattedTextField(doubleFormat); panelPredationConstant.add(frmtdtxtfldPredationConstant); frmtdtxtfldPredationConstant.setToolTipText("Value should be positive. Recommended values are near 0.001"); frmtdtxtfldPredationConstant.setColumns(4); frmtdtxtfldPredationConstant.setValue((Number) 0.001); panelNonMoversSurvive = new JPanel(); panelTab2.add(panelNonMoversSurvive); final JCheckBox chckbxNonMoversSurvive = new JCheckBox("Non-movers Survive?"); chckbxNonMoversSurvive.setSelected(false); panelNonMoversSurvive.add(chckbxNonMoversSurvive); ////////Tab 3 JPanel panelTab3 = new JPanel(); tabbedPane.addTab("Environment", null, panelTab3, null); panelTab3.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5)); panelSueurValues = new JPanel(); panelTab3.add(panelSueurValues); panelSueurValues.setLayout(new BoxLayout(panelSueurValues, BoxLayout.Y_AXIS)); JLabel lblSueurValues = new JLabel("Sueur Values"); lblSueurValues.setHorizontalAlignment(SwingConstants.TRAILING); lblSueurValues.setAlignmentX(Component.CENTER_ALIGNMENT); panelSueurValues.add(lblSueurValues); JPanel panelAlpha = new JPanel(); FlowLayout flowLayout = (FlowLayout) panelAlpha.getLayout(); flowLayout.setAlignment(FlowLayout.RIGHT); panelSueurValues.add(panelAlpha); JLabel lblAlpha = new JLabel("alpha"); lblAlpha.setHorizontalAlignment(SwingConstants.CENTER); panelAlpha.add(lblAlpha); final JFormattedTextField frmtdtxtfldAlpha = new JFormattedTextField(doubleFormat); frmtdtxtfldAlpha.setHorizontalAlignment(SwingConstants.TRAILING); lblAlpha.setLabelFor(frmtdtxtfldAlpha); panelAlpha.add(frmtdtxtfldAlpha); frmtdtxtfldAlpha.setColumns(6); frmtdtxtfldAlpha.setValue((Number) 0.006161429); JPanel panelAlphaC = new JPanel(); FlowLayout flowLayout_2 = (FlowLayout) panelAlphaC.getLayout(); flowLayout_2.setAlignment(FlowLayout.RIGHT); panelSueurValues.add(panelAlphaC); JLabel lblAlphaC = new JLabel("alpha c"); panelAlphaC.add(lblAlphaC); final JFormattedTextField frmtdtxtfldAlphaC = new JFormattedTextField(doubleFormat); frmtdtxtfldAlphaC.setHorizontalAlignment(SwingConstants.TRAILING); lblAlphaC.setLabelFor(frmtdtxtfldAlphaC); panelAlphaC.add(frmtdtxtfldAlphaC); frmtdtxtfldAlphaC.setColumns(6); frmtdtxtfldAlphaC.setValue((Number) 0.009); JPanel panelBeta = new JPanel(); FlowLayout flowLayout_1 = (FlowLayout) panelBeta.getLayout(); flowLayout_1.setAlignment(FlowLayout.RIGHT); panelSueurValues.add(panelBeta); JLabel lblBeta = new JLabel("beta"); panelBeta.add(lblBeta); final JFormattedTextField frmtdtxtfldBeta = new JFormattedTextField(doubleFormat); frmtdtxtfldBeta.setHorizontalAlignment(SwingConstants.TRAILING); panelBeta.add(frmtdtxtfldBeta); frmtdtxtfldBeta.setColumns(6); frmtdtxtfldBeta.setValue((Number) 0.013422819); JPanel panelBetaC = new JPanel(); FlowLayout flowLayout_14 = (FlowLayout) panelBetaC.getLayout(); flowLayout_14.setAlignment(FlowLayout.RIGHT); panelSueurValues.add(panelBetaC); JLabel lblBetaC = new JLabel("beta c"); panelBetaC.add(lblBetaC); final JFormattedTextField frmtdtxtfldBetaC = new JFormattedTextField(doubleFormat); frmtdtxtfldBetaC.setHorizontalAlignment(SwingConstants.TRAILING); panelBetaC.add(frmtdtxtfldBetaC); frmtdtxtfldBetaC.setColumns(6); frmtdtxtfldBetaC.setValue((Number) (-0.009)); JPanel panelS = new JPanel(); FlowLayout flowLayout_3 = (FlowLayout) panelS.getLayout(); flowLayout_3.setAlignment(FlowLayout.RIGHT); panelSueurValues.add(panelS); JLabel lblS = new JLabel("S"); panelS.add(lblS); final JFormattedTextField frmtdtxtfldS = new JFormattedTextField(countFormat); frmtdtxtfldS.setHorizontalAlignment(SwingConstants.TRAILING); panelS.add(frmtdtxtfldS); frmtdtxtfldS.setColumns(6); frmtdtxtfldS.setValue((Number) 2); JPanel panelQ = new JPanel(); FlowLayout flowLayout_4 = (FlowLayout) panelQ.getLayout(); flowLayout_4.setAlignment(FlowLayout.RIGHT); panelSueurValues.add(panelQ); JLabel lblQ = new JLabel("q"); panelQ.add(lblQ); final JFormattedTextField frmtdtxtfldQ = new JFormattedTextField(doubleFormat); frmtdtxtfldQ.setHorizontalAlignment(SwingConstants.TRAILING); panelQ.add(frmtdtxtfldQ); frmtdtxtfldQ.setColumns(6); frmtdtxtfldQ.setValue((Number) 2.3); panelGautraisValues = new JPanel(); panelGautraisValues.setVisible(false); panelTab3.add(panelGautraisValues); panelGautraisValues.setLayout(new BoxLayout(panelGautraisValues, BoxLayout.Y_AXIS)); JLabel label = new JLabel("Gautrais Values"); label.setAlignmentX(Component.CENTER_ALIGNMENT); panelGautraisValues.add(label); JPanel panelTauO = new JPanel(); FlowLayout flowLayout_5 = (FlowLayout) panelTauO.getLayout(); flowLayout_5.setAlignment(FlowLayout.RIGHT); panelGautraisValues.add(panelTauO); JLabel lblTauO = new JLabel("tau o"); panelTauO.add(lblTauO); final JFormattedTextField frmtdtxtfldTaoO = new JFormattedTextField(doubleFormat); frmtdtxtfldTaoO.setHorizontalAlignment(SwingConstants.TRAILING); panelTauO.add(frmtdtxtfldTaoO); frmtdtxtfldTaoO.setColumns(4); frmtdtxtfldTaoO.setValue((Number) 1290); JPanel panelGammaC = new JPanel(); FlowLayout flowLayout_6 = (FlowLayout) panelGammaC.getLayout(); flowLayout_6.setAlignment(FlowLayout.RIGHT); panelGautraisValues.add(panelGammaC); JLabel lblGammaC = new JLabel("gamma c"); panelGammaC.add(lblGammaC); final JFormattedTextField frmtdtxtfldGammaC = new JFormattedTextField(doubleFormat); frmtdtxtfldGammaC.setHorizontalAlignment(SwingConstants.TRAILING); panelGammaC.add(frmtdtxtfldGammaC); frmtdtxtfldGammaC.setColumns(4); frmtdtxtfldGammaC.setValue((Number) 2.0); JPanel panelEpsilonC = new JPanel(); FlowLayout flowLayout_7 = (FlowLayout) panelEpsilonC.getLayout(); flowLayout_7.setAlignment(FlowLayout.RIGHT); panelGautraisValues.add(panelEpsilonC); JLabel lblEpsilonC = new JLabel("epsilon c"); panelEpsilonC.add(lblEpsilonC); final JFormattedTextField frmtdtxtfldEpsilonC = new JFormattedTextField(doubleFormat); frmtdtxtfldEpsilonC.setHorizontalAlignment(SwingConstants.TRAILING); panelEpsilonC.add(frmtdtxtfldEpsilonC); frmtdtxtfldEpsilonC.setColumns(4); frmtdtxtfldEpsilonC.setValue((Number) 2.3); JPanel panelAlphaF = new JPanel(); FlowLayout flowLayout_8 = (FlowLayout) panelAlphaF.getLayout(); flowLayout_8.setAlignment(FlowLayout.RIGHT); panelGautraisValues.add(panelAlphaF); JLabel lblAlphaF = new JLabel("alpha f"); panelAlphaF.add(lblAlphaF); final JFormattedTextField frmtdtxtfldAlphaF = new JFormattedTextField(doubleFormat); frmtdtxtfldAlphaF.setHorizontalAlignment(SwingConstants.TRAILING); panelAlphaF.add(frmtdtxtfldAlphaF); frmtdtxtfldAlphaF.setColumns(4); frmtdtxtfldAlphaF.setValue((Number) 162.3); JPanel panelBetaF = new JPanel(); FlowLayout flowLayout_9 = (FlowLayout) panelBetaF.getLayout(); flowLayout_9.setAlignment(FlowLayout.RIGHT); panelGautraisValues.add(panelBetaF); JLabel lblBetaF = new JLabel("beta f"); panelBetaF.add(lblBetaF); final JFormattedTextField frmtdtxtfldBetaF = new JFormattedTextField(doubleFormat); frmtdtxtfldBetaF.setHorizontalAlignment(SwingConstants.TRAILING); panelBetaF.add(frmtdtxtfldBetaF); frmtdtxtfldBetaF.setColumns(4); frmtdtxtfldBetaF.setValue((Number) 75.4); JPanel panelEnvironmentVariables = new JPanel(); panelTab3.add(panelEnvironmentVariables); panelEnvironmentVariables.setLayout(new BoxLayout(panelEnvironmentVariables, BoxLayout.Y_AXIS)); JLabel lblEnvironmentVariables = new JLabel("Environment Variables"); lblEnvironmentVariables.setAlignmentX(Component.CENTER_ALIGNMENT); panelEnvironmentVariables.add(lblEnvironmentVariables); panelAngle = new JPanel(); FlowLayout flowLayout_10 = (FlowLayout) panelAngle.getLayout(); flowLayout_10.setAlignment(FlowLayout.RIGHT); panelEnvironmentVariables.add(panelAngle); JLabel lblAngle = new JLabel("Angle"); panelAngle.add(lblAngle); final JFormattedTextField frmtdtxtfldAngle = new JFormattedTextField(doubleFormat); frmtdtxtfldAngle.setHorizontalAlignment(SwingConstants.TRAILING); frmtdtxtfldAngle.setToolTipText("Angle between destinations"); panelAngle.add(frmtdtxtfldAngle); frmtdtxtfldAngle.setColumns(3); frmtdtxtfldAngle.setValue((Number) 72.00); panelNumberOfDestinations = new JPanel(); FlowLayout flowLayout_13 = (FlowLayout) panelNumberOfDestinations.getLayout(); flowLayout_13.setAlignment(FlowLayout.RIGHT); panelNumberOfDestinations.setVisible(false); panelEnvironmentVariables.add(panelNumberOfDestinations); JLabel lblNumberOfDestinations = new JLabel("Number of Destinations"); panelNumberOfDestinations.add(lblNumberOfDestinations); JFormattedTextField frmtdtxtfldNumberOfDestinations = new JFormattedTextField(countFormat); frmtdtxtfldNumberOfDestinations.setHorizontalAlignment(SwingConstants.TRAILING); panelNumberOfDestinations.add(frmtdtxtfldNumberOfDestinations); frmtdtxtfldNumberOfDestinations.setColumns(3); frmtdtxtfldNumberOfDestinations.setValue((Number) 2); panelDistance = new JPanel(); FlowLayout flowLayout_11 = (FlowLayout) panelDistance.getLayout(); flowLayout_11.setAlignment(FlowLayout.RIGHT); panelEnvironmentVariables.add(panelDistance); JLabel lblDistance = new JLabel("Distance"); panelDistance.add(lblDistance); frmtdtxtfldDistance = new JFormattedTextField(doubleFormat); frmtdtxtfldDistance.setHorizontalAlignment(SwingConstants.TRAILING); frmtdtxtfldDistance.setToolTipText("Distance the destination is from origin (0,0)"); panelDistance.add(frmtdtxtfldDistance); frmtdtxtfldDistance.setColumns(3); frmtdtxtfldDistance.setValue((Number) 150.0); panelPercentage = new JPanel(); FlowLayout flowLayout_12 = (FlowLayout) panelPercentage.getLayout(); flowLayout_12.setAlignment(FlowLayout.RIGHT); panelEnvironmentVariables.add(panelPercentage); JLabel lblPercentage = new JLabel("Percentage"); panelPercentage.add(lblPercentage); frmtdtxtfldPercentage = new JFormattedTextField(doubleFormat); frmtdtxtfldPercentage.setHorizontalAlignment(SwingConstants.TRAILING); frmtdtxtfldPercentage.setToolTipText( "The percentage moving to one of the two destinations ( The other gets 1 - percentage)."); panelPercentage.add(frmtdtxtfldPercentage); frmtdtxtfldPercentage.setColumns(3); frmtdtxtfldPercentage.setValue((Number) 0.500); panelInformedCount = new JPanel(); panelEnvironmentVariables.add(panelInformedCount); JLabel lblInformedCount = new JLabel("Informed Count"); panelInformedCount.add(lblInformedCount); final JFormattedTextField frmtdtxtfldInformedCount = new JFormattedTextField(countFormat); frmtdtxtfldInformedCount.setHorizontalAlignment(SwingConstants.TRAILING); frmtdtxtfldInformedCount.setColumns(3); frmtdtxtfldInformedCount.setToolTipText( "The number of agents moving toward a preferred destination. This number is duplicated on the southern pole as well."); frmtdtxtfldInformedCount.setValue((Number) 4); panelInformedCount.setVisible(false); panelInformedCount.add(frmtdtxtfldInformedCount); JPanel panelStartButtons = new JPanel(); JButton btnStartSimulation = new JButton("Create Simulator Instance"); btnStartSimulation.setToolTipText("Creates a new simulator instance from the settings provided."); btnStartSimulation.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { boolean isReady = true; ErrorPacketContainer errorPacketContainer = new ErrorPacketContainer(); if (jframeErrorMessages != null && jframeErrorMessages.isVisible()) { jframeErrorMessages.dispose(); } frmtdtxtfldRunCount.setBackground(Color.WHITE); frmtdtxtfldSimCount.setBackground(Color.WHITE); frmtdtxtfldMaxTimeSteps.setBackground(Color.WHITE); frmtdtxtfldPredationMinimum.setBackground(Color.WHITE); frmtdtxtfldPredationConstant.setBackground(Color.WHITE); frmtdtxtfldNearestNeighborCount.setBackground(Color.WHITE); frmtdtxtfldMaxLocationRadius.setBackground(Color.WHITE); frmtdtxtfldPercentage.setBackground(Color.WHITE); frmtdtxtfldDistance.setBackground(Color.WHITE); frmtdtxtfldDestinationRadius.setBackground(Color.WHITE); frmtdtxtfldAngle.setBackground(Color.WHITE); frmtdtxtfldInformedCount.setBackground(Color.WHITE); StringBuilder errorMessages = new StringBuilder(); if (((Number) frmtdtxtfldRunCount.getValue()).intValue() <= 0) { errorMessages.append("Run Count must be positive\n"); frmtdtxtfldRunCount.setBackground(Color.YELLOW); errorPacketContainer.addPacket("Run Count must be positive", frmtdtxtfldRunCount, 0); isReady = false; } if (((Number) frmtdtxtfldSimCount.getValue()).intValue() <= 0) { errorMessages.append("Sim Count must be positive\n"); frmtdtxtfldSimCount.setBackground(Color.YELLOW); errorPacketContainer.addPacket("Sim Count must be positive", frmtdtxtfldSimCount, 0); isReady = false; } if (((Number) frmtdtxtfldMaxTimeSteps.getValue()).intValue() <= 0) { errorMessages.append("Max Time Steps must be positive\n"); frmtdtxtfldMaxTimeSteps.setBackground(Color.YELLOW); errorPacketContainer.addPacket("Max Time Steps must be positive", frmtdtxtfldMaxTimeSteps, 0); isReady = false; } if (((Number) frmtdtxtfldPredationMinimum.getValue()).doubleValue() < 0 && chckbxPredationEnable.isSelected()) { errorMessages.append("Predation Minimum must be positive\n"); frmtdtxtfldPredationMinimum.setBackground(Color.YELLOW); errorPacketContainer.addPacket("Predation Minimum must be positive", frmtdtxtfldPredationMinimum, 1); isReady = false; } if (((Number) frmtdtxtfldPredationConstant.getValue()).doubleValue() <= 0 && chckbxPredationEnable.isSelected()) { errorMessages.append("Predation Constant must be positive\n"); frmtdtxtfldPredationConstant.setBackground(Color.YELLOW); errorPacketContainer.addPacket("Predation Constant must be positive", frmtdtxtfldPredationConstant, 1); isReady = false; } if (((Number) frmtdtxtfldNearestNeighborCount.getValue()).intValue() < 0 && panelNearestNeighborCount.isVisible()) { errorMessages.append("Nearest Neighbor Count must be positive\n"); frmtdtxtfldNearestNeighborCount.setBackground(Color.YELLOW); errorPacketContainer.addPacket("Nearest Neighbor Count must be positive", frmtdtxtfldNearestNeighborCount, 1); isReady = false; } if (((Number) frmtdtxtfldMaxLocationRadius.getValue()).doubleValue() < 0 && panelMaxLocationRadius.isVisible()) { errorMessages.append("Max Location Radius must be positive\n"); frmtdtxtfldMaxLocationRadius.setBackground(Color.YELLOW); errorPacketContainer.addPacket("Max Location Radius must be positive", frmtdtxtfldMaxLocationRadius, 1); isReady = false; } if ((((Number) frmtdtxtfldPercentage.getValue()).doubleValue() < 0.0 || ((Number) frmtdtxtfldPercentage.getValue()).doubleValue() > 1.0) && panelPercentage.isVisible()) { errorMessages.append( "Percentage needs to be greater than or equal to 0 and less than or equal to 1\n"); frmtdtxtfldPercentage.setBackground(Color.YELLOW); errorPacketContainer.addPacket( "Percentage needs to be greater than or equal to 0 and less than or equal to 1", frmtdtxtfldPercentage, 2); isReady = false; } if (((Number) frmtdtxtfldDistance.getValue()).doubleValue() <= 0 && frmtdtxtfldDistance.isVisible()) { errorMessages.append("Distance must be positive\n"); frmtdtxtfldDistance.setBackground(Color.YELLOW); errorPacketContainer.addPacket("Distance must be positive", frmtdtxtfldDistance, 2); isReady = false; } if (((Number) frmtdtxtfldDestinationRadius.getValue()).doubleValue() <= 0) { errorMessages.append("Destination Radius must be positive\n"); frmtdtxtfldDestinationRadius.setBackground(Color.YELLOW); errorPacketContainer.addPacket("Destination Radius must be positive", frmtdtxtfldDestinationRadius, 0); isReady = false; } if (((Number) frmtdtxtfldAngle.getValue()).doubleValue() < 0) { errorMessages.append("Angle must be positive or zero\n"); frmtdtxtfldAngle.setBackground(Color.YELLOW); errorPacketContainer.addPacket("Angle must be positive", frmtdtxtfldAngle, 2); isReady = false; } if (((Number) frmtdtxtfldInformedCount.getValue()).intValue() <= 0) { errorMessages.append("Informed Count must be positive\n"); frmtdtxtfldInformedCount.setBackground(Color.YELLOW); errorPacketContainer.addPacket("Informed Count must be positive", frmtdtxtfldInformedCount, 2); isReady = false; } else if (((Number) frmtdtxtfldInformedCount.getValue()).intValue() * 2 > sliderAgent.getValue()) { errorMessages.append("Informed Count should at most be half the count of total agents\n"); frmtdtxtfldInformedCount.setBackground(Color.YELLOW); errorPacketContainer.addPacket( "Informed Count should at most be half the count of total agents", frmtdtxtfldInformedCount, 2); isReady = false; } if (!isReady) { jframeErrorMessages = createJFrameErrorMessages(errorPacketContainer, tabbedPane); jframeErrorMessages.setVisible(true); } else { _simulatorProperties = new Properties(); _simulatorProperties.put("run-count", String.valueOf(frmtdtxtfldRunCount.getValue())); _simulatorProperties.put("simulation-count", String.valueOf(frmtdtxtfldSimCount.getValue())); _simulatorProperties.put("max-simulation-time-steps", String.valueOf(frmtdtxtfldMaxTimeSteps.getValue())); _simulatorProperties.put("random-seed", String.valueOf(1)); // Doesn't change _simulatorProperties.put("individual-count", String.valueOf(sliderAgent.getValue())); _simulatorProperties.put("run-graphical", String.valueOf(chckbxGraphical.isSelected())); _simulatorProperties.put("pre-calculate-probabilities", String.valueOf(false)); // Doesn't change _simulatorProperties.put("use-random-random-seed", String.valueOf(chckbxRandomSeed.isSelected())); _simulatorProperties.put("can-multiple-initiate", String.valueOf(true)); // Doesn't change _simulatorProperties.put("eskridge-results", String.valueOf(chckbxEskridge.isSelected())); _simulatorProperties.put("conflict-results", String.valueOf(chckbxConflict.isSelected())); _simulatorProperties.put("position-results", String.valueOf(chckbxPosition.isSelected())); _simulatorProperties.put("predation-results", String.valueOf(chckbxPredationResults.isSelected())); _simulatorProperties.put("communication-type", String.valueOf(comboBoxCommType.getSelectedItem()).toLowerCase()); _simulatorProperties.put("nearest-neighbor-count", String.valueOf(frmtdtxtfldNearestNeighborCount.getValue())); _simulatorProperties.put("max-location-radius", String.valueOf(frmtdtxtfldMaxLocationRadius.getValue())); _simulatorProperties.put("destination-size-radius", String.valueOf(frmtdtxtfldDestinationRadius.getValue())); _simulatorProperties.put("max-agents-eaten-per-step", String.valueOf(spinnerMaxEaten.getValue())); _simulatorProperties.put("enable-predator", String.valueOf(chckbxPredationEnable.isSelected())); _simulatorProperties.put("predation-probability-minimum", String.valueOf(frmtdtxtfldPredationMinimum.getValue())); _simulatorProperties.put("predation-multiplier", String.valueOf(frmtdtxtfldPredationConstant.getValue())); _simulatorProperties.put("use-predation-threshold", String.valueOf(chckbxUsePredationThreshold.isSelected())); _simulatorProperties.put("predation-threshold", String.valueOf(spinnerPredationThreshold.getValue())); _simulatorProperties.put("predation-by-population", String.valueOf(chckbxPopulationIndependent.isSelected())); _simulatorProperties.put("count-non-movers-as-survivors", String.valueOf(chckbxNonMoversSurvive.isSelected())); _simulatorProperties.put("stop-at-any-destination", String.valueOf(chckbxStopAnywhere.isSelected())); _simulatorProperties.put("adhesion-time-limit", String.valueOf(frmtdtxtfldMaxTimeSteps.getValue())); _simulatorProperties.put("alpha", String.valueOf(frmtdtxtfldAlpha.getValue())); _simulatorProperties.put("alpha-c", String.valueOf(frmtdtxtfldAlphaC.getValue())); _simulatorProperties.put("beta", String.valueOf(frmtdtxtfldBeta.getValue())); _simulatorProperties.put("beta-c", String.valueOf(frmtdtxtfldBetaC.getValue())); _simulatorProperties.put("S", String.valueOf(frmtdtxtfldS.getValue())); _simulatorProperties.put("q", String.valueOf(frmtdtxtfldQ.getValue())); _simulatorProperties.put("lambda", String.valueOf(0.2)); _simulatorProperties.put("tau-o", String.valueOf(frmtdtxtfldTaoO.getValue())); _simulatorProperties.put("gamma-c", String.valueOf(frmtdtxtfldGammaC.getValue())); _simulatorProperties.put("epsilon-c", String.valueOf(frmtdtxtfldEpsilonC.getValue())); _simulatorProperties.put("alpha-f", String.valueOf(frmtdtxtfldAlphaF.getValue())); _simulatorProperties.put("beta-f", String.valueOf(frmtdtxtfldBetaF.getValue())); _simulatorProperties.put("default-conflict-value", String.valueOf(spinnerDefaultConflict.getValue())); _simulatorProperties.put("cancellation-threshold", String.valueOf(spinnerCancelationThreshold.getValue())); StringBuilder sbAgentBuilder = new StringBuilder(); sbAgentBuilder.append("edu.snu.leader.discrete.simulator.Sueur"); sbAgentBuilder.append(comboBoxAgentBuilder.getSelectedItem().toString().replace(" ", "")); sbAgentBuilder.append("AgentBuilder"); _simulatorProperties.put("agent-builder", String.valueOf(sbAgentBuilder.toString())); StringBuilder sbDecisionCalculator = new StringBuilder(); sbDecisionCalculator.append("edu.snu.leader.discrete.simulator."); sbDecisionCalculator.append(comboBoxModel.getSelectedItem()); // sbDecisionCalculator.append(comboBoxDecisionCalculator.getSelectedItem()); sbDecisionCalculator .append(comboBoxDecisionCalculator.getSelectedItem().toString().replace(" ", "")); sbDecisionCalculator.append("DecisionCalculator"); _simulatorProperties.put("decision-calculator", String.valueOf(sbDecisionCalculator.toString())); StringBuilder sbLocationsFile = new StringBuilder(); sbLocationsFile.append("cfg/sim/locations/metric/valid-metric-loc-"); sbLocationsFile.append(String.format("%03d", sliderAgent.getValue())); sbLocationsFile.append("-seed-00001.dat"); _simulatorProperties.put("locations-file", String.valueOf(sbLocationsFile.toString())); //create destination file DestinationBuilder db = new DestinationBuilder(sliderAgent.getValue(), 1L); StringBuilder sbDestinationsFile = new StringBuilder(); sbDestinationsFile.append("cfg/sim/destinations/destinations-"); switch (comboBoxEnvironment.getSelectedItem().toString()) { case ("Minimum"): sbDestinationsFile.append("diffdis-" + sliderAgent.getValue()); sbDestinationsFile.append("-per-" + frmtdtxtfldPercentage.getValue()); sbDestinationsFile.append("-seed-1.dat"); db.generateDifferentDistance(((Number) frmtdtxtfldPercentage.getValue()).doubleValue(), 200, 100, 75); break; case ("Medium"): sbDestinationsFile.append("split-" + sliderAgent.getValue()); sbDestinationsFile.append("-dis-" + frmtdtxtfldDistance.getValue()); sbDestinationsFile.append("-ang-" + String.format("%.2f", ((Number) frmtdtxtfldAngle.getValue()).doubleValue())); sbDestinationsFile.append("-per-" + String.format("%.3f", ((Number) frmtdtxtfldPercentage.getValue()).doubleValue())); sbDestinationsFile.append("-seed-1.dat"); db.generateSplitNorth(((Number) frmtdtxtfldDistance.getValue()).doubleValue(), ((Number) frmtdtxtfldAngle.getValue()).doubleValue(), ((Number) frmtdtxtfldPercentage.getValue()).doubleValue()); break; case ("Maximum"): sbDestinationsFile.append("poles-" + sliderAgent.getValue()); sbDestinationsFile.append("-per-" + frmtdtxtfldPercentage.getValue()); sbDestinationsFile.append("-seed-1.dat"); db.generatePoles(50, 100, ((Number) frmtdtxtfldPercentage.getValue()).doubleValue()); break; case ("Uninformed"): sbDestinationsFile.append("split-poles-" + frmtdtxtfldInformedCount.getValue()); sbDestinationsFile.append("-dis-" + String.format("%.1f", ((Number) frmtdtxtfldDistance.getValue()).doubleValue())); sbDestinationsFile.append("-ang-" + String.format("%.2f", ((Number) frmtdtxtfldAngle.getValue()).doubleValue())); sbDestinationsFile.append("-per-" + String.format("%.3f", ((Number) frmtdtxtfldPercentage.getValue()).doubleValue())); sbDestinationsFile.append("-seed-1.dat"); db.generateSplitPoles(((Number) frmtdtxtfldDistance.getValue()).doubleValue(), ((Number) frmtdtxtfldAngle.getValue()).doubleValue(), ((Number) frmtdtxtfldPercentage.getValue()).doubleValue(), ((Number) frmtdtxtfldInformedCount.getValue()).intValue()); break; default: //Should never happen break; } _simulatorProperties.put("destinations-file", String.valueOf(sbDestinationsFile.toString())); _simulatorProperties.put("live-delay", String.valueOf(15)); //Doesn't change _simulatorProperties.put("results-dir", "results"); //Doesn't change new Thread(new Runnable() { public void run() { try { runSimulation(); } catch (Exception e) { e.printStackTrace(); } } }).start(); } } }); panelStartButtons.add(btnStartSimulation); JButton btnStartSimulationFrom = new JButton("Run Simulation from Properties File"); btnStartSimulationFrom .setToolTipText("Runs the simulator with the values provided in the properties file."); btnStartSimulationFrom.setEnabled(false); panelStartButtons.add(btnStartSimulationFrom); panelTab3.add(panelStartButtons); }
From source file:org.metawidget.integrationtest.swing.allwidgets.SwingAllWidgetsTest.java
protected void runTest(AdvancedWidgetProcessor<JComponent, SwingMetawidget> processor) throws Exception { // Model/*from ww w. ja va2 s . c om*/ AllWidgets allWidgets = new AllWidgets$$EnhancerByCGLIB$$1234(); // App SwingMetawidget metawidget = new SwingMetawidget(); metawidget.setConfig("org/metawidget/integrationtest/swing/allwidgets/metawidget.xml"); metawidget.addWidgetProcessor(processor); metawidget.addWidgetProcessor(new ReflectionBindingProcessor()); metawidget.setMetawidgetLayout(new SeparatorLayoutDecorator(new SeparatorLayoutDecoratorConfig().setLayout( new org.metawidget.swing.layout.GridBagLayout(new GridBagLayoutConfig().setNumberOfColumns(2))))); metawidget.setToInspect(allWidgets); metawidget.add(new Stub("mystery")); // Test missing components try { metawidget.getValue("no-such-component"); fail(); } catch (MetawidgetException e1) { assertEquals("No component named 'no-such-component'", e1.getMessage()); try { metawidget.getValue("textbox", "no-such-component"); fail(); } catch (MetawidgetException e2) { assertEquals("No component named 'textbox', 'no-such-component'", e2.getMessage()); try { metawidget.getValue("textbox", "no-such-component1", "no-such-component2"); fail(); } catch (MetawidgetException e3) { assertEquals( "No such component 'no-such-component1' of 'textbox', 'no-such-component1', 'no-such-component2'", e3.getMessage()); } } } try { metawidget.setValue(null, "no-such-component"); fail(); } catch (MetawidgetException e1) { assertEquals("No component named 'no-such-component'", e1.getMessage()); try { metawidget.setValue(null, "textbox", "no-such-component"); fail(); } catch (MetawidgetException e2) { assertEquals("No component named 'textbox', 'no-such-component'", e2.getMessage()); try { metawidget.setValue(null, "textbox", "no-such-component1", "no-such-component2"); fail(); } catch (MetawidgetException e3) { assertEquals( "No such component 'no-such-component1' of 'textbox', 'no-such-component1', 'no-such-component2'", e3.getMessage()); } } } // Check what created, and edit it assertEquals("Textbox*:", ((JLabel) metawidget.getComponent(0)).getText()); assertTrue(metawidget.getComponent(1) instanceof JTextField); assertEquals("Textbox", metawidget.getValue("textbox")); ((JTextField) metawidget.getComponent(1)).setText("Textbox1"); assertEquals("Limited Textbox:", ((JLabel) metawidget.getComponent(2)).getText()); assertTrue(metawidget.getComponent(3) instanceof JTextField); assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(3)).gridx); assertEquals("Limited Textbox", metawidget.getValue("limitedTextbox")); ((JTextField) metawidget.getComponent(3)).setText("Limited Textbox1"); assertEquals("Textarea:", ((JLabel) metawidget.getComponent(4)).getText()); assertTrue(metawidget.getComponent(5) instanceof JScrollPane); assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(5)).gridx); assertEquals("Textarea", metawidget.getValue("textarea")); JTextArea textarea = (JTextArea) ((JScrollPane) metawidget.getComponent(5)).getViewport().getView(); assertEquals(2, textarea.getRows()); assertEquals(true, textarea.getLineWrap()); assertEquals(true, textarea.getWrapStyleWord()); textarea.setText("Textarea1"); assertEquals("Password:", ((JLabel) metawidget.getComponent(6)).getText()); assertTrue(metawidget.getComponent(7) instanceof JPasswordField); assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(7)).gridx); assertEquals("Password", metawidget.getValue("password")); ((JPasswordField) metawidget.getComponent(7)).setText("Password1"); // Primitives assertEquals("Byte Primitive:", ((JLabel) metawidget.getComponent(8)).getText()); assertTrue(metawidget.getComponent(9) instanceof JSpinner); assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(9)).gridx); assertTrue(Byte.MAX_VALUE == (Byte) metawidget.getValue("bytePrimitive")); assertTrue(-5 == (Byte) ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(9)).getModel()) .getMinimum()); assertTrue( Byte.MAX_VALUE == (Byte) ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(9)).getModel()) .getMaximum()); assertEquals(0, ((JSpinner.DefaultEditor) ((JSpinner) metawidget.getComponent(9)).getEditor()) .getTextField().getColumns()); JSpinner spinner = (JSpinner) metawidget.getComponent(9); spinner.setValue(spinner.getModel().getPreviousValue()); assertEquals("Byte Object:", ((JLabel) metawidget.getComponent(10)).getText()); assertTrue(metawidget.getComponent(11) instanceof JTextField); assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(11)).gridx); assertEquals(String.valueOf(Byte.MIN_VALUE), metawidget.getValue("byteObject")); ((JTextField) metawidget.getComponent(11)).setText(String.valueOf(Byte.MIN_VALUE + 1)); assertEquals("Short Primitive:", ((JLabel) metawidget.getComponent(12)).getText()); assertTrue(metawidget.getComponent(13) instanceof JSpinner); assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(13)).gridx); assertTrue(Short.MAX_VALUE == (Short) metawidget.getValue("shortPrimitive")); assertTrue(-6 == (Short) ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(13)).getModel()) .getMinimum()); assertTrue(Short.MAX_VALUE == (Short) ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(13)) .getModel()).getMaximum()); spinner = (JSpinner) metawidget.getComponent(13); assertEquals(0, ((JSpinner.DefaultEditor) spinner.getEditor()).getTextField().getColumns()); spinner.setValue(spinner.getModel().getPreviousValue()); assertEquals("Short Object:", ((JLabel) metawidget.getComponent(14)).getText()); assertTrue(metawidget.getComponent(15) instanceof JTextField); assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(15)).gridx); assertEquals(String.valueOf(Short.MIN_VALUE), metawidget.getValue("shortObject")); ((JTextField) metawidget.getComponent(15)).setText(String.valueOf(Short.MIN_VALUE + 1)); assertEquals("Int Primitive:", ((JLabel) metawidget.getComponent(16)).getText()); assertTrue(metawidget.getComponent(17) instanceof JSpinner); assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(17)).gridx); assertTrue(Integer.MAX_VALUE == (Integer) metawidget.getValue("intPrimitive")); assertTrue(Integer.MIN_VALUE == (Integer) ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(17)) .getModel()).getMinimum()); assertTrue(Integer.MAX_VALUE == (Integer) ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(17)) .getModel()).getMaximum()); spinner = (JSpinner) metawidget.getComponent(17); assertEquals(0, ((JSpinner.DefaultEditor) spinner.getEditor()).getTextField().getColumns()); spinner.setValue(spinner.getModel().getPreviousValue()); assertEquals("Integer Object:", ((JLabel) metawidget.getComponent(18)).getText()); assertTrue(metawidget.getComponent(19) instanceof JTextField); assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(19)).gridx); assertEquals(String.valueOf(Integer.MIN_VALUE), metawidget.getValue("integerObject")); ((JTextField) metawidget.getComponent(19)).setText(String.valueOf(Integer.MIN_VALUE + 1)); assertEquals("Ranged Int:", ((JLabel) metawidget.getComponent(20)).getText()); assertTrue(metawidget.getComponent(21) instanceof JSlider); assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(21)).gridx); assertEquals(1, ((JSlider) metawidget.getComponent(21)).getMinimum()); assertEquals(100, ((JSlider) metawidget.getComponent(21)).getMaximum()); assertTrue(32 == (Integer) metawidget.getValue("rangedInt")); ((JSlider) metawidget.getComponent(21)).setValue(33); assertEquals("Ranged Integer:", ((JLabel) metawidget.getComponent(22)).getText()); assertTrue(metawidget.getComponent(23) instanceof JTextField); assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(23)).gridx); assertEquals("33", metawidget.getValue("rangedInteger")); ((JTextField) metawidget.getComponent(23)).setText(String.valueOf(34)); assertEquals("Long Primitive:", ((JLabel) metawidget.getComponent(24)).getText()); assertTrue(metawidget.getComponent(25) instanceof JSpinner); assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(25)).gridx); assertTrue(42 == (Long) metawidget.getValue("longPrimitive")); assertTrue(-7 == (Long) ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(25)).getModel()) .getMinimum()); assertTrue( Long.MAX_VALUE == (Long) ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(25)).getModel()) .getMaximum()); spinner = (JSpinner) metawidget.getComponent(25); assertEquals(0, ((JSpinner.DefaultEditor) spinner.getEditor()).getTextField().getColumns()); spinner.setValue(spinner.getModel().getNextValue()); assertTrue(metawidget.getComponent(26) instanceof JTextField); assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(26)).gridx); assertEquals("43", metawidget.getValue("longObject")); ((JTextField) metawidget.getComponent(26)).setText("44"); assertEquals("Float Primitive:", ((JLabel) metawidget.getComponent(27)).getText()); assertTrue(metawidget.getComponent(28) instanceof JSpinner); assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(28)).gridx); assertEquals(4.2f, metawidget.getValue("floatPrimitive")); assertEquals(-Float.MAX_VALUE, ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(28)).getModel()).getMinimum()); assertTrue(2048 == (Float) ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(28)).getModel()) .getMaximum()); spinner = (JSpinner) metawidget.getComponent(28); assertEquals(0, ((JSpinner.DefaultEditor) spinner.getEditor()).getTextField().getColumns()); spinner.setValue(spinner.getModel().getNextValue()); assertEquals("nullInBundle:", ((JLabel) metawidget.getComponent(29)).getText()); assertTrue(metawidget.getComponent(30) instanceof JTextField); assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(30)).gridx); assertEquals("4.3", metawidget.getValue("floatObject")); ((JTextField) metawidget.getComponent(30)).setText("5.4"); assertEquals("Double Primitive:", ((JLabel) metawidget.getComponent(31)).getText()); assertTrue(metawidget.getComponent(32) instanceof JSpinner); assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(32)).gridx); assertEquals(42.2d, metawidget.getValue("doublePrimitive")); assertTrue(-8 == (Double) ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(32)).getModel()) .getMinimum()); assertEquals(Double.MAX_VALUE, ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(32)).getModel()).getMaximum()); spinner = (JSpinner) metawidget.getComponent(32); assertEquals(0, ((JSpinner.DefaultEditor) spinner.getEditor()).getTextField().getColumns()); spinner.setValue(spinner.getModel().getNextValue()); assertTrue(metawidget.getComponent(33) instanceof JTextField); assertEquals(0, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(33)).gridx); assertEquals(2, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(33)).gridwidth); assertEquals("43.3", metawidget.getValue("doubleObject")); ((JTextField) metawidget.getComponent(33)).setText("54.4"); assertEquals("Char Primitive:", ((JLabel) metawidget.getComponent(34)).getText()); assertTrue(metawidget.getComponent(35) instanceof JTextField); assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(35)).gridx); assertEquals("A", metawidget.getValue("charPrimitive")); ((JTextField) metawidget.getComponent(35)).setText("Z"); assertEquals("Character Object:", ((JLabel) metawidget.getComponent(36)).getText()); assertTrue(metawidget.getComponent(37) instanceof JTextField); assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(37)).gridx); assertEquals("Z", metawidget.getValue("characterObject")); ((JTextField) metawidget.getComponent(37)).setText("A"); assertEquals("Boolean Primitive:", ((JLabel) metawidget.getComponent(38)).getText()); assertTrue(metawidget.getComponent(39) instanceof JCheckBox); assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(39)).gridx); assertTrue(false == (Boolean) metawidget.getValue("booleanPrimitive")); ((JCheckBox) metawidget.getComponent(39)).setSelected(true); assertEquals("Boolean Object:", ((JLabel) metawidget.getComponent(40)).getText()); assertTrue(metawidget.getComponent(41) instanceof JComboBox); assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(37)).gridx); assertEquals(3, ((JComboBox) metawidget.getComponent(41)).getItemCount()); assertEquals(Boolean.TRUE, metawidget.getValue("booleanObject")); ((JComboBox) metawidget.getComponent(41)).setSelectedItem(Boolean.FALSE); assertEquals("Dropdown:", ((JLabel) metawidget.getComponent(42)).getText()); assertTrue(metawidget.getComponent(43) instanceof JComboBox); assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(43)).gridx); assertEquals(4, ((JComboBox) metawidget.getComponent(43)).getItemCount()); assertEquals("dropdown1", metawidget.getValue("dropdown")); ((JComboBox) metawidget.getComponent(43)).setSelectedItem("foo1"); assertEquals("Dropdown With Labels:", ((JLabel) metawidget.getComponent(44)).getText()); assertTrue(metawidget.getComponent(45) instanceof JComboBox); assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(45)).gridx); JComboBox combo = (JComboBox) metawidget.getComponent(45); assertEquals(5, combo.getItemCount()); assertEquals("Foo #2", ((JLabel) combo.getRenderer().getListCellRendererComponent(new JList(), "foo2", 1, false, false)) .getText()); assertEquals("Dropdown #2", ((JLabel) combo.getRenderer().getListCellRendererComponent(new JList(), "dropdown2", 1, false, false)).getText()); assertEquals("Bar #2", ((JLabel) combo.getRenderer().getListCellRendererComponent(new JList(), "bar2", 1, false, false)) .getText()); assertEquals("Baz #2", ((JLabel) combo.getRenderer().getListCellRendererComponent(new JList(), "baz2", 1, false, false)) .getText()); assertEquals("dropdown2", metawidget.getValue("dropdownWithLabels")); ((JComboBox) metawidget.getComponent(45)).setSelectedItem("bar2"); assertEquals("Not Null Dropdown:", ((JLabel) metawidget.getComponent(46)).getText()); assertTrue(metawidget.getComponent(47) instanceof JComboBox); assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(47)).gridx); assertEquals(3, ((JComboBox) metawidget.getComponent(47)).getItemCount()); assertTrue(0 == (Byte) metawidget.getValue("notNullDropdown")); ((JComboBox) metawidget.getComponent(47)).setSelectedItem((byte) 1); assertEquals("Not Null Object Dropdown*:", ((JLabel) metawidget.getComponent(48)).getText()); assertTrue(metawidget.getComponent(49) instanceof JComboBox); assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(49)).gridx); assertEquals(6, ((JComboBox) metawidget.getComponent(49)).getItemCount()); assertEquals("dropdown3", metawidget.getValue("notNullObjectDropdown")); ((JComboBox) metawidget.getComponent(49)).setSelectedIndex(0); assertEquals("Nested Widgets:", ((JLabel) metawidget.getComponent(50)).getText()); assertTrue(metawidget.getComponent(51) instanceof SwingMetawidget); SwingMetawidget metawidgetNested = (SwingMetawidget) metawidget.getComponent(51); assertEquals("Further Nested Widgets:", ((JLabel) metawidgetNested.getComponent(0)).getText()); assertEquals(1, ((GridBagLayout) metawidgetNested.getLayout()) .getConstraints(metawidgetNested.getComponent(1)).gridx); SwingMetawidget metawidgetFurtherNested = (SwingMetawidget) metawidgetNested.getComponent(1); assertEquals("Further Nested Widgets:", ((JLabel) metawidgetFurtherNested.getComponent(0)).getText()); assertTrue(metawidgetFurtherNested.getComponent(1) instanceof SwingMetawidget); assertEquals(((SwingMetawidget) metawidgetFurtherNested.getComponent(1)).getComponentCount(), 0); assertEquals("Nested Textbox 1:", ((JLabel) metawidgetFurtherNested.getComponent(2)).getText()); assertTrue(metawidgetFurtherNested.getComponent(3) instanceof JTextField); assertEquals(1, ((GridBagLayout) metawidgetFurtherNested.getLayout()) .getConstraints(metawidgetFurtherNested.getComponent(3)).gridx); assertEquals("Nested Textbox 1", metawidget.getValue("nestedWidgets", "furtherNestedWidgets", "nestedTextbox1")); ((JTextField) metawidgetFurtherNested.getComponent(3)).setText("Nested Textbox 1.1 (further)"); assertEquals("Nested Textbox 2:", ((JLabel) metawidgetFurtherNested.getComponent(4)).getText()); assertTrue(metawidgetFurtherNested.getComponent(5) instanceof JTextField); // (should be 1, as in next row, if getEffectiveNumberOfColumns is working) assertEquals(1, ((GridBagLayout) metawidgetFurtherNested.getLayout()) .getConstraints(metawidgetFurtherNested.getComponent(5)).gridx); assertEquals("Nested Textbox 2", metawidget.getValue("nestedWidgets", "furtherNestedWidgets", "nestedTextbox2")); ((JTextField) metawidgetFurtherNested.getComponent(5)).setText("Nested Textbox 2.2 (further)"); assertEquals("Nested Textbox 1:", ((JLabel) metawidgetNested.getComponent(2)).getText()); assertTrue(metawidgetNested.getComponent(3) instanceof JTextField); assertEquals(1, ((GridBagLayout) metawidgetNested.getLayout()) .getConstraints(metawidgetNested.getComponent(3)).gridx); assertEquals("Nested Textbox 1", metawidget.getValue("nestedWidgets", "nestedTextbox1")); ((JTextField) metawidgetNested.getComponent(3)).setText("Nested Textbox 1.1"); assertEquals("Nested Textbox 2:", ((JLabel) metawidgetNested.getComponent(4)).getText()); assertTrue(metawidgetNested.getComponent(5) instanceof JTextField); assertEquals(1, ((GridBagLayout) metawidgetNested.getLayout()) .getConstraints(metawidgetNested.getComponent(5)).gridx); assertEquals("Nested Textbox 2", metawidget.getValue("nestedWidgets", "nestedTextbox2")); ((JTextField) metawidgetNested.getComponent(5)).setText("Nested Textbox 2.2"); assertEquals("Read Only Nested Widgets:", ((JLabel) metawidget.getComponent(52)).getText()); assertTrue(metawidget.getComponent(53) instanceof SwingMetawidget); metawidgetNested = (SwingMetawidget) metawidget.getComponent(53); assertEquals("Nested Textbox 1:", ((JLabel) metawidgetNested.getComponent(2)).getText()); assertTrue(metawidgetNested.getComponent(3) instanceof JLabel); assertEquals(1, ((GridBagLayout) metawidgetNested.getLayout()) .getConstraints(metawidgetNested.getComponent(3)).gridx); assertEquals("Nested Textbox 1", metawidget.getValue("readOnlyNestedWidgets", "nestedTextbox1")); assertEquals("Nested Textbox 2:", ((JLabel) metawidgetNested.getComponent(4)).getText()); assertTrue(metawidgetNested.getComponent(5) instanceof JLabel); assertEquals(1, ((GridBagLayout) metawidgetNested.getLayout()) .getConstraints(metawidgetNested.getComponent(5)).gridx); assertEquals("Nested Textbox 2", metawidget.getValue("readOnlyNestedWidgets", "nestedTextbox2")); assertEquals("Nested Widgets Dont Expand:", ((JLabel) metawidget.getComponent(54)).getText()); assertEquals("Nested Textbox 1, Nested Textbox 2", ((JTextField) metawidget.getComponent(55)).getText()); ((JTextField) metawidget.getComponent(55)).setText("Nested Textbox 1.01, Nested Textbox 2.02"); assertEquals("Read Only Nested Widgets Dont Expand:", ((JLabel) metawidget.getComponent(56)).getText()); assertEquals("Nested Textbox 1, Nested Textbox 2", ((JLabel) metawidget.getComponent(57)).getText()); assertEquals("Date:", ((JLabel) metawidget.getComponent(58)).getText()); assertTrue(metawidget.getComponent(59) instanceof JTextField); assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(59)).gridx); DateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT); assertEquals(dateFormat.format(allWidgets.getDate()), metawidget.getValue("date")); ((JTextField) metawidget.getComponent(59)).setText("bad date"); JPanel separatorPanel = (JPanel) metawidget.getComponent(60); assertEquals("Section Break", ((JLabel) separatorPanel.getComponent(0)).getText()); assertEquals(GridBagConstraints.REMAINDER, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(60)).gridwidth); assertTrue(separatorPanel.getComponent(1) instanceof JSeparator); assertEquals("Read Only:", ((JLabel) metawidget.getComponent(61)).getText()); assertTrue(metawidget.getComponent(62) instanceof JLabel); assertEquals("Read Only", metawidget.getValue("readOnly")); assertTrue(metawidget.getComponent(63) instanceof JButton); assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(63)).gridx); assertEquals(GridBagConstraints.NONE, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(63)).fill); JButton button = ((JButton) metawidget.getComponent(63)); assertEquals("Do Action", button.getText()); assertTrue(button.isEnabled()); try { button.doClick(); fail(); } catch (Exception e) { assertEquals("doAction called", e.getCause().getCause().getMessage()); } assertEquals(64, metawidget.getComponentCount()); // Check painting JFrame frame = new JFrame(); metawidget.paint(frame.getGraphics()); // Check MetawidgetException try { processor.getClass().getMethod("save", SwingMetawidget.class).invoke(processor, metawidget); fail(); } catch (Exception e) { assertEquals("Could not parse 'bad date'", e.getCause().getCause().getMessage()); } // Check saving String now = dateFormat.format(new GregorianCalendar().getTime()); ((JTextField) metawidget.getComponent(59)).setText(now); processor.getClass().getMethod("save", SwingMetawidget.class).invoke(processor, metawidget); // Check read-only metawidget.setReadOnly(true); assertEquals("Textbox:", ((JLabel) metawidget.getComponent(0)).getText()); assertEquals("Textbox1", ((JLabel) metawidget.getComponent(1)).getText()); assertEquals("Limited Textbox:", ((JLabel) metawidget.getComponent(2)).getText()); assertEquals("Limited Textbox1", ((JLabel) metawidget.getComponent(3)).getText()); assertEquals("Textarea:", ((JLabel) metawidget.getComponent(4)).getText()); assertEquals("Textarea1", ((JTextArea) ((JScrollPane) metawidget.getComponent(5)).getViewport().getView()).getText()); assertEquals("Password:", ((JLabel) metawidget.getComponent(6)).getText()); assertTrue(metawidget.getComponent(7) instanceof JPanel); assertEquals("Byte Primitive:", ((JLabel) metawidget.getComponent(8)).getText()); assertEquals("126", ((JLabel) metawidget.getComponent(9)).getText()); assertEquals("Byte Object:", ((JLabel) metawidget.getComponent(10)).getText()); assertEquals("-127", ((JLabel) metawidget.getComponent(11)).getText()); assertEquals("Short Primitive:", ((JLabel) metawidget.getComponent(12)).getText()); assertEquals("32766", ((JLabel) metawidget.getComponent(13)).getText()); assertEquals("Short Object:", ((JLabel) metawidget.getComponent(14)).getText()); assertEquals("-32767", ((JLabel) metawidget.getComponent(15)).getText()); assertEquals("Int Primitive:", ((JLabel) metawidget.getComponent(16)).getText()); assertEquals("2147483646", ((JLabel) metawidget.getComponent(17)).getText()); assertEquals("Integer Object:", ((JLabel) metawidget.getComponent(18)).getText()); assertEquals("-2147483647", ((JLabel) metawidget.getComponent(19)).getText()); assertEquals("Ranged Int:", ((JLabel) metawidget.getComponent(20)).getText()); assertEquals("33", ((JLabel) metawidget.getComponent(21)).getText()); assertEquals("Ranged Integer:", ((JLabel) metawidget.getComponent(22)).getText()); assertEquals("34", ((JLabel) metawidget.getComponent(23)).getText()); assertEquals("Long Primitive:", ((JLabel) metawidget.getComponent(24)).getText()); assertEquals("43", ((JLabel) metawidget.getComponent(25)).getText()); assertEquals("44", ((JLabel) metawidget.getComponent(26)).getText()); assertEquals("Float Primitive:", ((JLabel) metawidget.getComponent(27)).getText()); assertTrue(((JLabel) metawidget.getComponent(28)).getText().startsWith("4.3") || ((JLabel) metawidget.getComponent(28)).getText().startsWith("4.299")); assertEquals("nullInBundle:", ((JLabel) metawidget.getComponent(29)).getText()); assertEquals("5.4", ((JLabel) metawidget.getComponent(30)).getText()); assertEquals("Double Primitive:", ((JLabel) metawidget.getComponent(31)).getText()); assertTrue(((JLabel) metawidget.getComponent(32)).getText().startsWith("42.3") || ((JLabel) metawidget.getComponent(32)).getText().startsWith("42.299")); assertEquals("54.4", ((JLabel) metawidget.getComponent(33)).getText()); assertEquals("Char Primitive:", ((JLabel) metawidget.getComponent(34)).getText()); assertEquals("Z", ((JLabel) metawidget.getComponent(35)).getText()); assertEquals("Character Object:", ((JLabel) metawidget.getComponent(36)).getText()); assertEquals("A", ((JLabel) metawidget.getComponent(37)).getText()); assertEquals("Boolean Primitive:", ((JLabel) metawidget.getComponent(38)).getText()); assertEquals("true", ((JLabel) metawidget.getComponent(39)).getText()); assertEquals("Boolean Object:", ((JLabel) metawidget.getComponent(40)).getText()); assertEquals("No", ((JLabel) metawidget.getComponent(41)).getText()); assertEquals("Dropdown:", ((JLabel) metawidget.getComponent(42)).getText()); assertEquals("foo1", ((JLabel) metawidget.getComponent(43)).getText()); assertEquals("Dropdown With Labels:", ((JLabel) metawidget.getComponent(44)).getText()); assertEquals("Bar #2", ((JLabel) metawidget.getComponent(45)).getText()); assertEquals("Not Null Dropdown:", ((JLabel) metawidget.getComponent(46)).getText()); assertEquals("1", ((JLabel) metawidget.getComponent(47)).getText()); assertEquals("Not Null Object Dropdown:", ((JLabel) metawidget.getComponent(48)).getText()); assertEquals("foo3", ((JLabel) metawidget.getComponent(49)).getText()); assertEquals("Nested Widgets:", ((JLabel) metawidget.getComponent(50)).getText()); assertEquals("Further Nested Widgets:", ((JLabel) ((SwingMetawidget) metawidget.getComponent(51)).getComponent(0)).getText()); assertEquals("Further Nested Widgets:", ((JLabel) ((SwingMetawidget) ((SwingMetawidget) metawidget.getComponent(51)).getComponent(1)) .getComponent(0)).getText()); assertEquals("Nested Textbox 1:", ((JLabel) ((SwingMetawidget) ((SwingMetawidget) metawidget.getComponent(51)).getComponent(1)) .getComponent(2)).getText()); assertEquals("Nested Textbox 1.1 (further)", ((JLabel) ((SwingMetawidget) ((SwingMetawidget) metawidget.getComponent(51)).getComponent(1)) .getComponent(3)).getText()); assertEquals("Nested Textbox 2:", ((JLabel) ((SwingMetawidget) ((SwingMetawidget) metawidget.getComponent(51)).getComponent(1)) .getComponent(4)).getText()); assertEquals("Nested Textbox 2.2 (further)", ((JLabel) ((SwingMetawidget) ((SwingMetawidget) metawidget.getComponent(51)).getComponent(1)) .getComponent(5)).getText()); assertEquals("Nested Textbox 1:", ((JLabel) ((SwingMetawidget) metawidget.getComponent(51)).getComponent(2)).getText()); assertEquals("Nested Textbox 1.1", ((JLabel) ((SwingMetawidget) metawidget.getComponent(51)).getComponent(3)).getText()); assertEquals("Nested Textbox 2:", ((JLabel) ((SwingMetawidget) metawidget.getComponent(51)).getComponent(4)).getText()); assertEquals("Nested Textbox 2.2", ((JLabel) ((SwingMetawidget) metawidget.getComponent(51)).getComponent(5)).getText()); assertEquals("Read Only Nested Widgets:", ((JLabel) metawidget.getComponent(52)).getText()); assertEquals("Further Nested Widgets:", ((JLabel) ((SwingMetawidget) metawidget.getComponent(53)).getComponent(0)).getText()); assertEquals("Nested Textbox 1:", ((JLabel) ((SwingMetawidget) metawidget.getComponent(53)).getComponent(2)).getText()); assertEquals("Nested Textbox 1", ((JLabel) ((SwingMetawidget) metawidget.getComponent(53)).getComponent(3)).getText()); assertEquals("Nested Textbox 2:", ((JLabel) ((SwingMetawidget) metawidget.getComponent(53)).getComponent(4)).getText()); assertEquals("Nested Textbox 2", ((JLabel) ((SwingMetawidget) metawidget.getComponent(53)).getComponent(5)).getText()); assertEquals("Nested Widgets Dont Expand:", ((JLabel) metawidget.getComponent(54)).getText()); assertEquals("Nested Textbox 1.01, Nested Textbox 2.02", ((JLabel) metawidget.getComponent(55)).getText()); assertEquals("Read Only Nested Widgets Dont Expand:", ((JLabel) metawidget.getComponent(56)).getText()); assertEquals("Nested Textbox 1, Nested Textbox 2", ((JLabel) metawidget.getComponent(57)).getText()); assertEquals("Date:", ((JLabel) metawidget.getComponent(58)).getText()); assertEquals(now, ((JLabel) metawidget.getComponent(59)).getText()); assertEquals("Section Break", ((JLabel) ((JPanel) metawidget.getComponent(60)).getComponent(0)).getText()); assertEquals("Read Only:", ((JLabel) metawidget.getComponent(61)).getText()); assertEquals("Read Only", ((JLabel) metawidget.getComponent(62)).getText()); assertEquals("Do Action", ((JButton) metawidget.getComponent(63)).getText()); assertTrue(!((JButton) metawidget.getComponent(63)).isEnabled()); assertEquals(metawidget.getComponentCount(), 64); // Test Binding.onStartBuild clears the state assertTrue(null != metawidget.getClientProperty(processor.getClass())); processor.onStartBuild(metawidget); assertEquals(null, metawidget.getClientProperty(processor.getClass())); }
From source file:org.revager.tools.GUITools.java
/** * Formats the given spinner.// w w w . j a v a2 s . c om * * @param sp * the spinner */ public static void formatSpinner(JSpinner sp, boolean hideBorder) { JSpinner.DefaultEditor defEditor = (JSpinner.DefaultEditor) sp.getEditor(); JFormattedTextField ftf = defEditor.getTextField(); ftf.setFocusLostBehavior(JFormattedTextField.COMMIT_OR_REVERT); InternationalFormatter intFormatter = (InternationalFormatter) ftf.getFormatter(); DecimalFormat decimalFormat = (DecimalFormat) intFormatter.getFormat(); decimalFormat.applyPattern("00"); DecimalFormatSymbols geSymbols = new DecimalFormatSymbols(Data.getInstance().getLocale()); decimalFormat.setDecimalFormatSymbols(geSymbols); if (hideBorder) { sp.setBorder(null); } }
From source file:org.rockyroadshub.planner.core.gui.calendar.FormPane.java
private void setAllowsInvalid(JSpinner s) { JFormattedTextField txt = ((JSpinner.NumberEditor) s.getEditor()).getTextField(); ((NumberFormatter) txt.getFormatter()).setAllowsInvalid(false); s.addChangeListener((ChangeEvent e) -> { if (s.getValue().equals(24)) { s.setValue(0);/* w w w . j av a 2 s . co m*/ } }); }