List of usage examples for javax.swing SpinnerNumberModel SpinnerNumberModel
public SpinnerNumberModel(double value, double minimum, double maximum, double stepSize)
SpinnerNumberModel
with the specified value
, minimum
/maximum
bounds, and stepSize
. From source file:geneticalgorithm.gui.view.VExperiment.java
public VExperiment() { setLayout(new BorderLayout()); setSize(900, 700);//from w w w .j av a2 s .c o m setLocationRelativeTo(this); setResizable(false); buttons = new ArrayList<JButton>(); // CENTER pnlCentral = new JPanel(); pnlCentral.setLayout(new MigLayout()); add(pnlCentral, BorderLayout.CENTER); lblLocale = new JLabel(); cmbModelSelectLocale = new DefaultComboBoxModel<String>(); cmbSelectLocale = new JComboBox<String>(cmbModelSelectLocale); lblLimLow = new JLabel(); spiLow = new JSpinner(); spiLow.setModel(new SpinnerNumberModel(-10., -100000., 100000., .5)); lblLimUp = new JLabel(); spiUp = new JSpinner(); spiUp.setModel(new SpinnerNumberModel(10., -100000., 100000., .5)); lblChromosome = new JLabel(); spiChromosome = new JSpinner(); spiChromosome.setModel(new SpinnerNumberModel(10, 0, 63, 1)); lblPopulation = new JLabel(); spiPopulation = new JSpinner(); spiPopulation.setModel(new SpinnerNumberModel(10, 0, 100000, 1)); lblGenerations = new JLabel(); spiGenerations = new JSpinner(); spiGenerations.setModel(new SpinnerNumberModel(100, 0, 100000, 1)); lblProbCrossover = new JLabel(); txtProbCrossover = new JTextField("0.5"); lblProbMutation = new JLabel(); txtProbMutation = new JTextField("0.001"); lblIndividual = new JLabel(); cmbModelIndividual = new DefaultComboBoxModel<ClassWrapper>(); cmbIndividual = new JComboBox<ClassWrapper>(cmbModelIndividual); lblCrossover = new JLabel(); cmbModelCrossover = new DefaultComboBoxModel<ClassWrapper>(); cmbCrossover = new JComboBox<ClassWrapper>(cmbModelCrossover); lblMutation = new JLabel(); cmbModelMutation = new DefaultComboBoxModel<ClassWrapper>(); cmbMutation = new JComboBox<ClassWrapper>(cmbModelMutation); lblSelection = new JLabel(); cmbModelSelection = new DefaultComboBoxModel<ClassWrapper>(); cmbSelection = new JComboBox<ClassWrapper>(cmbModelSelection); lblFitness = new JLabel(); cmbModelFitness = new DefaultComboBoxModel<ClassWrapper>(); cmbFitness = new JComboBox<ClassWrapper>(cmbModelFitness); lblPathOutput = new JLabel(); txtPathOutput = new JTextField(); btnPathOutput = new JButton("..."); lblName = new JLabel(); txtName = new JTextField(); lblAverage = new JLabel(""); lblAverage.setHorizontalTextPosition(SwingConstants.LEFT); lblAverageTitle = new JLabel("Average: "); lblOffline = new JLabel(""); lblOffline.setHorizontalTextPosition(SwingConstants.LEFT); lblOfflineTitle = new JLabel("Offline: "); lblOnline = new JLabel(""); lblOnline.setHorizontalTextPosition(SwingConstants.LEFT); lblOnlineTitle = new JLabel("Online: "); lblElite = new JLabel(""); lblElite.setHorizontalTextPosition(SwingConstants.LEFT); lblEliteTitle = new JLabel("Elite: "); average = new XYSeries("Average"); offline = new XYSeries("Offline"); online = new XYSeries("Online"); elite = new XYSeries("Elite"); dataset = new XYSeriesCollection(); dataset.addSeries(average); dataset.addSeries(online); dataset.addSeries(elite); dataset.addSeries(offline); chart = ChartFactory.createXYLineChart("title", "xLabel", "yLabel", dataset, PlotOrientation.VERTICAL, true, true, false); chartPanel = new ChartPanel(chart); pnlCentral.add(lblLocale, "width 120, height 25"); pnlCentral.add(cmbSelectLocale, "width 120, height 25, wrap"); pnlCentral.add(lblLimLow, "width 120, height 25"); pnlCentral.add(spiLow, "width 120, height 25"); pnlCentral.add(lblIndividual, "width 80, height 25"); pnlCentral.add(cmbIndividual, "growx, height 25, span 2, wrap"); pnlCentral.add(lblLimUp, "width 120, height 25"); pnlCentral.add(spiUp, "width 120, height 25"); pnlCentral.add(lblCrossover, "width 80, height 25"); pnlCentral.add(cmbCrossover, "growx, height 25, span 2, wrap"); pnlCentral.add(lblChromosome, "width 120, height 25"); pnlCentral.add(spiChromosome, "width 120, height 25"); pnlCentral.add(lblMutation, "width 80, height 25"); pnlCentral.add(cmbMutation, "growx, height 25, span 2, wrap"); pnlCentral.add(lblPopulation, "width 120, height 25"); pnlCentral.add(spiPopulation, "width 120, height 25"); pnlCentral.add(lblSelection, "width 80, height 25"); pnlCentral.add(cmbSelection, "growx, height 25, span 2"); pnlCentral.add(lblAverageTitle, "width 70, height 25"); pnlCentral.add(lblAverage, "width 200, height 25, wrap"); pnlCentral.add(lblGenerations, "width 120, height 25"); pnlCentral.add(spiGenerations, "width 120, height 25"); pnlCentral.add(lblFitness, "width 80, height 25"); pnlCentral.add(cmbFitness, "growx, height 25, span 2"); pnlCentral.add(lblOnlineTitle, "growx, height 25"); pnlCentral.add(lblOnline, "growx, height 25, wrap"); pnlCentral.add(lblProbCrossover, "width 120, height 25"); pnlCentral.add(txtProbCrossover, "width 120, height 25"); pnlCentral.add(lblPathOutput, "width 80, height 25"); pnlCentral.add(txtPathOutput, "width 280, height 25"); pnlCentral.add(btnPathOutput, "width 20, height 25"); pnlCentral.add(lblEliteTitle, "growx, height 25"); pnlCentral.add(lblElite, "growx, height 25, wrap"); pnlCentral.add(lblProbMutation, "width 120, height 25"); pnlCentral.add(txtProbMutation, "width 120, height 25"); pnlCentral.add(lblName, "width 80, height 25"); pnlCentral.add(txtName, "growx, height 25, span 2"); pnlCentral.add(lblOfflineTitle, "growx, height 25"); pnlCentral.add(lblOffline, "growx, height 25, wrap"); pnlCentral.add(chartPanel, "growx, span 7"); // SOUTH pnlSouth = new JPanel(); add(pnlSouth, BorderLayout.SOUTH); btnRun = new JButton(); btnStop = new JButton(); btnClose = new JButton(); pnlSouth.add(btnRun); pnlSouth.add(btnStop); pnlSouth.add(btnClose); // ADD BUTTONS buttons.add(btnClose); buttons.add(btnStop); buttons.add(btnPathOutput); buttons.add(btnRun); }
From source file:de.atomfrede.tools.evalutation.options.ui.OptionsDialog.java
private JSpinner getSampleSpinner() { if (sampleSpinner == null) { sampleSpinner = new JSpinner(); SpinnerNumberModel numberModel = new SpinnerNumberModel(TypeAEvaluationOptions.getSampleRate(), 1.0, 10.0, 1.0);//from ww w . j ava 2s . c o m sampleSpinner.setModel(numberModel); sampleSpinner.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { SpinnerNumberModel model = (SpinnerNumberModel) sampleSpinner.getModel(); double selectedValue = model.getNumber().doubleValue(); sampleRate = selectedValue; } }); } return sampleSpinner; }
From source file:ru.codemine.pos.ui.salespanel.QuantitySetupWindow.java
public void showWindow() { if (!actionListenersInit) setupActionListeners();/* w w w .j a va 2 s . c om*/ mainWindow.blockBarcodeInput(); Product product = salesPanel.getChequeSetupPanel().getSelectedProduct(); if (product == null) { mainWindow.unblockBarcodeInput(); return; } int maxQuantity = storeService.getAvaibleStocksOnRetail(product); onStoresLabel.setText("?: " + String.valueOf(maxQuantity) + " ."); setTitle("? - " + product.getName()); spinner.setModel(new SpinnerNumberModel(1, 1, maxQuantity, 1)); JTextField ft = ((WebSpinner.DefaultEditor) spinner.getEditor()).getTextField(); ft.addFocusListener(new FocusAdapter() { @Override public void focusGained(FocusEvent e) { final JTextComponent txtcomp = (JTextComponent) e.getSource(); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { txtcomp.selectAll(); } }); } }); ft.requestFocus(); setVisible(true); }
From source file:edu.clemson.cs.nestbed.client.gui.MoteConfigPanel.java
public MoteConfigPanel(MoteTestbedAssignment mtbAssignment, ProgramManager programManager, int projDepConfID, MoteManager moteManager, MoteTypeManager moteTypeManager, MoteDeploymentConfigurationManager mdcManager) throws RemoteException, NotBoundException, MalformedURLException { this.programManager = programManager; this.mtbAssignment = mtbAssignment; this.projDepConfID = projDepConfID; this.mote = moteManager.getMote(mtbAssignment.getMoteID()); this.moteType = moteTypeManager.getMoteType(mote.getMoteTypeID()); this.mdcManager = mdcManager; this.moteDepConfig = mdcManager.getMoteDeploymentConfiguration(projDepConfID, mote.getID()); this.radioChangeListener = new RadioChangeListener(); this.radioSpinner = new JSpinner( new SpinnerNumberModel(MAX_RADIO_POWER, MIN_RADIO_POWER, MAX_RADIO_POWER, RADIO_POWER_INCR)); setIcon(new ImageIcon(moteType.getImage()).getImage()); if (this.moteDepConfig != null) { this.program = programManager.getProgram(moteDepConfig.getProgramID()); radioSpinner.setValue(moteDepConfig.getRadioPowerLevel()); } else {//from www.j av a 2 s .c om radioSpinner.setEnabled(false); } radioSpinner.setToolTipText("Radio Power Level"); Dimension labelSize = new Dimension(LABEL_WIDTH, LABEL_HEIGHT); JLabel addressLabel = new JLabel("" + mtbAssignment.getMoteAddress()); addressLabel.setSize(labelSize); addressLabel.setPreferredSize(labelSize); Dimension spinnerSize = new Dimension(SPINNER_WIDTH, SPINNER_HEIGHT); radioSpinner.setSize(spinnerSize); radioSpinner.setPreferredSize(spinnerSize); radioSpinner.addChangeListener(radioChangeListener); setToolTipText(getToolTipString()); addMouseListener(new MotePanelMouseListener()); add(addressLabel); addressLabel.setLocation(2, 0); add(radioSpinner); radioSpinner.setLocation(getWidth() - SPINNER_WIDTH - 2, getHeight() - SPINNER_HEIGHT - 2); mdcManager.addRemoteObserver(new MoteDeploymentConfigObserver()); new DropTarget(this, DnDConstants.ACTION_COPY_OR_MOVE, new ProgramDropTarget(), true); }
From source file:com.mirth.connect.client.ui.browsers.message.MessageBrowserAdvancedFilter.java
private void initComponentsManual() { // restrict the message ID and import ID fields to integer input only messageIdLowerField.setDocument(new MirthFieldConstraints(19, false, false, true)); messageIdUpperField.setDocument(new MirthFieldConstraints(19, false, false, true)); originalIdLowerField.setDocument(new MirthFieldConstraints(19, false, false, true)); originalIdUpperField.setDocument(new MirthFieldConstraints(19, false, false, true)); importIdLowerField.setDocument(new MirthFieldConstraints(19, false, false, true)); importIdUpperField.setDocument(new MirthFieldConstraints(19, false, false, true)); sendAttemptsLower.setModel(new SpinnerNumberModel(0, 0, null, 1)); }
From source file:com.willwinder.ugp.tools.GcodeTilerTopComponent.java
public GcodeTilerTopComponent() { setName(GcodeTilerTitle);/*from w ww . j a v a 2 s.c o m*/ setToolTipText(GcodeTilerTooltip); backend = CentralLookup.getDefault().lookup(BackendAPI.class); numCopiesX = new SpinnerNumberModel(3, 1, 1000, 1); numCopiesY = new SpinnerNumberModel(3, 1, 1000, 1); padding = new SpinnerNumberModel(5, 0, 1000, 0.1); units = new JComboBox<>(SwingHelpers.getUnitOptions()); // Button callbacks generateGcodeButton.addActionListener(al -> generateGcode()); exportGcodeButton.addActionListener(al -> exportGcode()); // Change listeners numCopiesX.addChangeListener(l -> controlChangeListener()); numCopiesY.addChangeListener(l -> controlChangeListener()); padding.addChangeListener(l -> controlChangeListener()); // Dowel settings setLayout(new MigLayout("fillx, wrap 4")); add(new JLabel(Localization.getString("platform.plugin.dowel-module.x")), "growx"); add(new JSpinner(numCopiesX), "growx"); add(new JLabel(Localization.getString("gcode.setting.units")), "growx"); add(units, "growx"); add(new JLabel(Localization.getString("platform.plugin.dowel-module.y")), "growx"); add(new JSpinner(numCopiesY), "growx"); add(new JLabel(Localization.getString("platform.plugin.gcode-tools.tiler.padding")), "growx"); add(new JSpinner(padding), "growx"); add(generateGcodeButton, "growx, span2"); add(exportGcodeButton, "growx, span2"); }
From source file:org.fhcrc.cpl.viewer.gui.SpectrumComponent.java
public SpectrumComponent() { try {//from w w w . jav a 2 s. c o m Localizer.getSwingEngine(this).render("org/fhcrc/cpl/viewer/gui/SpectrumComponentForm.xml"); Localizer.localizeComponentTree(contentPanel); contentPanel.doLayout(); } catch (Exception x) { ApplicationContext.errorMessage(TextProvider.getText("ERROR_CREATING_DIALOG"), x); throw new RuntimeException(x); } if (null != displayMode) { displayMode.addItem("raw"); displayMode.addItem("background centroided"); displayMode.addItem("clean centroided"); displayMode.addItem("resampled"); displayMode.addItem("subtract background"); displayMode.addItem("smoothed"); displayMode.addItem("peaks"); displayMode.addItem("wavelet peaks"); displayMode.addItem("wavelet decomposition"); displayMode.addItem("wavelet decomposition 2"); displayMode.addItem("wavelet multiresolution"); displayMode.addItem("haar8"); displayMode.addItem("haar16"); helper.addListener(displayMode, "display_actionPerformed"); } if (null != copyButton) { helper.addListener(copyButton, "copy_actionPerformed"); } if (null != scanSpinner) { scanSpinner.setModel(new SpinnerRunModel()); helper.addListener(scanSpinner, "scanSpinner_stateChanged"); } if (null != mzSpinner) { mzSpinner.setModel(new SpinnerNumberModel(0.0, 0.0, 1000000.0, 1.0 / 36)); helper.addListener(mzSpinner, "mzSpinner_stateChanged"); } //dhmay changing from radio group to combo box, 12/19/2005 if (null != spectrumElutionComboBox) { spectrumElutionComboBox.addItem("spectrum"); spectrumElutionComboBox.addItem("elution"); helper.addListener(spectrumElutionComboBox, "spectrumElutionComboBox_actionPerformed"); } helper.addListener(contentPanel, "_componentResized"); helper.addListener(Application.getInstance(), "updateChart_propertyChange", "thresholding"); //helper.addListener(ApplicationContext, "scan_propertyChange", "MSScan"); helper.addListener(Application.getInstance(), "selectedPoint_propertyChange", SharedProperties.SELECTED_POINT); helper.addListener(Application.getInstance(), "run_propertyChange", SharedProperties.MS_RUN); }
From source file:de.unibayreuth.bayeos.goat.options.JOptionDialog.java
/** This method is called from within the constructor to * initialize the form./*from ww w . j a v a 2 s . co m*/ * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ private void initComponents() {//GEN-BEGIN:initComponents java.awt.GridBagConstraints gridBagConstraints; jLabel1 = new javax.swing.JLabel(); optionTabbedPane = new javax.swing.JTabbedPane(); panelGlobal = new javax.swing.JPanel(); jPanel2 = new javax.swing.JPanel(); lastConnectionCheckBox = new javax.swing.JCheckBox(); lblMaxRecNumber = new javax.swing.JLabel(); jspMaxRecNumber = new javax.swing.JSpinner(); panelChart = new javax.swing.JPanel(); panelStatus = new javax.swing.JPanel(); panelPoints = new javax.swing.JPanel(); lblType = new javax.swing.JLabel(); jcbType = new javax.swing.JComboBox(); jSliderShapeSize = new javax.swing.JSlider(); lblShapeSize = new javax.swing.JLabel(); jLabelSizeMax = new javax.swing.JLabel(); jLabelSizeMin = new javax.swing.JLabel(); jCheckBoxToolTips = new javax.swing.JCheckBox(); lblGapThreshold = new javax.swing.JLabel(); jspGapThreshold = new javax.swing.JSpinner(); panelApp = new javax.swing.JPanel(); buttonPanel = new javax.swing.JPanel(); exitButton = new javax.swing.JButton(); jLabel1.setText("jLabel1"); addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { closeDialog(evt); } }); panelGlobal.setLayout(new javax.swing.BoxLayout(panelGlobal, javax.swing.BoxLayout.Y_AXIS)); jPanel2.setLayout(new java.awt.GridBagLayout()); jPanel2.setBorder(new javax.swing.border.EmptyBorder(new java.awt.Insets(10, 10, 10, 10))); lastConnectionCheckBox.setText("Remember Last Connection"); lastConnectionCheckBox.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { lastUserCheckBoxActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 3; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.ipadx = 9; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; jPanel2.add(lastConnectionCheckBox, gridBagConstraints); lblMaxRecNumber.setText("Maximum Number of Records:"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; jPanel2.add(lblMaxRecNumber, gridBagConstraints); jspMaxRecNumber.setModel(new SpinnerNumberModel(pref.getInt("maxrecnumber", 200000), 0, 400000, 1000)); jspMaxRecNumber.addChangeListener(new javax.swing.event.ChangeListener() { public void stateChanged(javax.swing.event.ChangeEvent evt) { jspMaxRecNumberStateChanged(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 0; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); jPanel2.add(jspMaxRecNumber, gridBagConstraints); panelGlobal.add(jPanel2); optionTabbedPane.addTab("Global", panelGlobal); panelChart.setLayout(new java.awt.BorderLayout()); panelChart.setBorder(new javax.swing.border.EmptyBorder(new java.awt.Insets(1, 1, 1, 1))); panelStatus.setLayout(new java.awt.BorderLayout()); panelStatus.setBorder(new javax.swing.border.TitledBorder("Status Colors")); panelStatus.setMaximumSize(new java.awt.Dimension(250, 120)); panelChart.add(panelStatus, java.awt.BorderLayout.CENTER); panelPoints.setLayout(new java.awt.GridBagLayout()); panelPoints.setBorder(new javax.swing.border.TitledBorder("Drawing")); lblType.setText("Drawing Type:"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 0); panelPoints.add(lblType, gridBagConstraints); jcbType.setModel( new javax.swing.DefaultComboBoxModel(new String[] { "Shapes", "Lines", "Shapes and Lines" })); jcbType.setPreferredSize(new java.awt.Dimension(150, 25)); jcbType.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jcbTypeActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 0; gridBagConstraints.gridwidth = 3; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 0); panelPoints.add(jcbType, gridBagConstraints); jSliderShapeSize.setMajorTickSpacing(2); jSliderShapeSize.setMaximum(20); jSliderShapeSize.setMinorTickSpacing(1); jSliderShapeSize.setPaintTicks(true); jSliderShapeSize.setValue(8); jSliderShapeSize.addChangeListener(new javax.swing.event.ChangeListener() { public void stateChanged(javax.swing.event.ChangeEvent evt) { jSliderShapeSizeStateChanged(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 2; gridBagConstraints.gridy = 1; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 0); panelPoints.add(jSliderShapeSize, gridBagConstraints); lblShapeSize.setText("Shape Size:"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 0); panelPoints.add(lblShapeSize, gridBagConstraints); jLabelSizeMax.setText("10"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 3; gridBagConstraints.gridy = 1; gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHWEST; gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 0); panelPoints.add(jLabelSizeMax, gridBagConstraints); jLabelSizeMin.setText("0"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 1; gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHWEST; gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 0); panelPoints.add(jLabelSizeMin, gridBagConstraints); jCheckBoxToolTips.setText("Show Tool Tips"); jCheckBoxToolTips.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jCheckBoxToolTipsActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 3; gridBagConstraints.gridwidth = 3; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 0); panelPoints.add(jCheckBoxToolTips, gridBagConstraints); lblGapThreshold.setText("Gap Threshold:"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 2; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 0); panelPoints.add(lblGapThreshold, gridBagConstraints); jspGapThreshold.setPreferredSize(new java.awt.Dimension(80, 24)); jspGapThreshold.addChangeListener(new javax.swing.event.ChangeListener() { public void stateChanged(javax.swing.event.ChangeEvent evt) { jspGapThresholdStateChanged(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 2; gridBagConstraints.gridwidth = 3; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 0); panelPoints.add(jspGapThreshold, gridBagConstraints); panelChart.add(panelPoints, java.awt.BorderLayout.SOUTH); optionTabbedPane.addTab("Chart", panelChart); getContentPane().add(optionTabbedPane, java.awt.BorderLayout.CENTER); buttonPanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT)); exitButton.setText("Ok"); exitButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { exitButtonActionPerformed(evt); } }); buttonPanel.add(exitButton); getContentPane().add(buttonPanel, java.awt.BorderLayout.SOUTH); pack(); }
From source file:at.tuwien.ifs.somtoolbox.apps.viewer.controls.ClusteringControl.java
public void init() { maxCluster = state.growingLayer.getXSize() * state.growingLayer.getYSize(); spinnerNoCluster = new JSpinner(new SpinnerNumberModel(1, 1, maxCluster, 1)); spinnerNoCluster.addChangeListener(new ChangeListener() { @Override//from ww w . j a v a 2 s . c o m public void stateChanged(ChangeEvent e) { numClusters = (Integer) ((JSpinner) e.getSource()).getValue(); SortedMap<Integer, ClusterElementsStorage> m = mapPane.getMap().getCurrentClusteringTree() .getAllClusteringElements(); if (m.containsKey(numClusters)) { st = m.get(numClusters).sticky; } else { st = false; } sticky.setSelected(st); redrawClustering(); } }); JPanel clusterPanel = UiUtils.makeBorderedPanel(new FlowLayout(FlowLayout.LEFT, 10, 0), "Clusters"); sticky.setToolTipText( "Marks this number of clusters as sticky for a certain leve; the next set of clusters will have a smaller boundary"); sticky.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { st = sticky.isSelected(); SortedMap<Integer, ClusterElementsStorage> m = mapPane.getMap().getCurrentClusteringTree() .getAllClusteringElements(); if (m.containsKey(numClusters)) { ClusterElementsStorage c = m.get(numClusters); c.sticky = st; // System.out.println("test"); // ((ClusterElementsStorageNode)m.get(numClusters)).sticky = st; redrawClustering(); } } }); colorCluster = new JCheckBox("colour", state.colorClusters); colorCluster.setToolTipText("Fill the clusters in colours"); colorCluster.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { state.colorClusters = colorCluster.isSelected(); // TODO: Palette anzeigen (?) redrawClustering(); } }); UiUtils.fillPanel(clusterPanel, new JLabel("#"), spinnerNoCluster, sticky, colorCluster); getContentPane().add(clusterPanel, c.nextRow()); dendogramPanel = UiUtils.makeBorderedPanel(new GridLayout(0, 1), "Dendogram"); getContentPane().add(dendogramPanel, c.nextRow()); JPanel numLabelPanel = UiUtils.makeBorderedPanel(new GridBagLayout(), "Labels"); GridBagConstraintsIFS gcLabels = new GridBagConstraintsIFS(); labelSpinner = new JSpinner(new SpinnerNumberModel(0, 0, 99, 1)); labelSpinner.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { numLabels = (Integer) ((JSpinner) e.getSource()).getValue(); state.clusterWithLabels = numLabels; redrawClustering(); } }); this.showValues = new JCheckBox("values", state.labelsWithValues); this.showValues.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { state.labelsWithValues = showValues.isSelected(); redrawClustering(); } }); int start = new Double((1 - state.clusterByValue) * 100).intValue(); valueQe = new JSlider(0, 100, start); valueQe.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { int byValue = ((JSlider) e.getSource()).getValue(); state.clusterByValue = 1 - byValue / 100; redrawClustering(); } }); numLabelPanel.add(new JLabel("# Labels"), gcLabels); numLabelPanel.add(labelSpinner, gcLabels.nextCol()); numLabelPanel.add(showValues, gcLabels.nextCol()); numLabelPanel.add(valueQe, gcLabels.nextRow().setGridWidth(3).setFill(GridBagConstraints.HORIZONTAL)); getContentPane().add(numLabelPanel, c.nextRow()); Hashtable<Integer, JLabel> labelTable = new Hashtable<Integer, JLabel>(); labelTable.put(0, new JLabel("by Value")); labelTable.put(100, new JLabel("by Qe")); valueQe.setToolTipText("Method how to select representative labels - by QE, or the attribute values"); valueQe.setLabelTable(labelTable); valueQe.setPaintLabels(true); final JComboBox initialisationBox = new JComboBox(KMeans.InitType.values()); initialisationBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Object o = mapPane.getMap().getClusteringTreeBuilder(); if (o instanceof KMeansTreeBuilder) { ((KMeansTreeBuilder) o).reInit((KMeans.InitType) initialisationBox.getSelectedItem()); // FIXME: is this call needed? mapPane.getMap().getCurrentClusteringTree().getAllClusteringElements(); redrawClustering(); } } }); getContentPane().add(UiUtils.fillPanel(kmeansInitialisationPanel, new JLabel("k-Means initialisation"), initialisationBox), c.nextRow()); JPanel borderPanel = new TitledCollapsiblePanel("Border", new GridLayout(1, 4), true); JSpinner borderSpinner = new JSpinner( new SpinnerNumberModel(ClusteringTree.INITIAL_BORDER_WIDTH_MAGNIFICATION_FACTOR, 0.1, 5, 0.1)); borderSpinner.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { state.clusterBorderWidthMagnificationFactor = ((Double) ((JSpinner) e.getSource()).getValue()) .floatValue(); redrawClustering(); } }); borderPanel.add(new JLabel("width")); borderPanel.add(borderSpinner); borderPanel.add(new JLabel("colour")); buttonColour = new JButton(""); buttonColour.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { new ClusterBoderColorChooser(state.parentFrame, state.clusterBorderColour, ClusteringControl.this); } }); buttonColour.setBackground(state.clusterBorderColour); borderPanel.add(buttonColour); getContentPane().add(borderPanel, c.nextRow()); JPanel evaluationPanel = new TitledCollapsiblePanel("Cluster Evaluation", new GridLayout(3, 2), true); evaluationPanel.add(new JLabel("quality measure")); qualityMeasureButton = new JButton(); qualityMeasureButton.setText("ent/pur calc"); qualityMeasureButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.out.println("doing entropy here"); ClusteringTree clusteringTree = state.mapPNode.getClusteringTree(); if (clusteringTree == null) { // we have not clustered yet return; } // System.out.println(clusteringTree.getChildrenCount()); // FIXME put this in a method and call it on numcluster.change() SOMLibClassInformation classInfo = state.inputDataObjects.getClassInfo(); ArrayList<ClusterNode> clusters = clusteringTree.getNodesAtLevel(numClusters); System.out.println(clusters.size()); // EntropyMeasure.computeEntropy(clusters, classInfo); EntropyAndPurityCalculator eapc = new EntropyAndPurityCalculator(clusters, classInfo); // FIXME round first entropyLabel.setText(String.valueOf(eapc.getEntropy())); purityLabel.setText(String.valueOf(eapc.getPurity())); } }); evaluationPanel.add(qualityMeasureButton); GridBagConstraintsIFS gcEval = new GridBagConstraintsIFS(); evaluationPanel.add(new JLabel("entropy"), gcEval); evaluationPanel.add(new JLabel("purity"), gcEval.nextCol()); entropyLabel = new JLabel("n/a"); purityLabel = new JLabel("n/a"); evaluationPanel.add(entropyLabel, gcEval.nextRow()); evaluationPanel.add(purityLabel, gcEval.nextCol()); getContentPane().add(evaluationPanel, c.nextRow()); JPanel panelButtons = new JPanel(new GridLayout(1, 4)); JButton saveButton = new JButton("Save"); saveButton.setFont(smallFont); saveButton.setMargin(SMALL_INSETS); saveButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JFileChooser fileChooser; if (state.fileChooser.getSelectedFile() != null) { fileChooser = new JFileChooser(state.fileChooser.getSelectedFile().getPath()); } else { fileChooser = new JFileChooser(); } fileChooser.addChoosableFileFilter(clusteringFilter); fileChooser.addChoosableFileFilter(xmlFilter); File filePath = ExportUtils.getFilePath(ClusteringControl.this, fileChooser, "Save Clustering and Labels"); if (filePath != null) { if (xmlFilter.accept(filePath)) { LabelXmlUtils.saveLabelsToFile(state.mapPNode, filePath); } else { try { FileOutputStream fos = new FileOutputStream(filePath); GZIPOutputStream gzipOs = new GZIPOutputStream(fos); PObjectOutputStream oos = new PObjectOutputStream(gzipOs); oos.writeObjectTree(mapPane.getMap().getCurrentClusteringTree()); oos.writeObjectTree(mapPane.getMap().getManualLabels()); oos.writeInt(state.clusterWithLabels); oos.writeBoolean(state.labelsWithValues); oos.writeDouble(state.clusterByValue); oos.writeObject(spinnerNoCluster.getValue()); oos.close(); } catch (Exception ex) { ex.printStackTrace(); } } // keep the selected path for future references state.fileChooser.setSelectedFile(filePath.getParentFile()); } } }); panelButtons.add(saveButton); JButton loadButton = new JButton("Load"); loadButton.setFont(smallFont); loadButton.setMargin(SMALL_INSETS); loadButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JFileChooser fileChooser = getFileChooser(); fileChooser.setName("Open Clustering"); fileChooser.addChoosableFileFilter(xmlFilter); fileChooser.addChoosableFileFilter(clusteringFilter); int returnVal = fileChooser.showDialog(ClusteringControl.this, "Open"); if (returnVal == JFileChooser.APPROVE_OPTION) { File filePath = fileChooser.getSelectedFile(); if (xmlFilter.accept(filePath)) { PNode restoredLabels = null; try { restoredLabels = LabelXmlUtils.restoreLabelsFromFile(fileChooser.getSelectedFile()); PNode manual = state.mapPNode.getManualLabels(); ArrayList<PNode> tmp = new ArrayList<PNode>(); for (ListIterator<?> iter = restoredLabels.getChildrenIterator(); iter.hasNext();) { PNode element = (PNode) iter.next(); tmp.add(element); } manual.addChildren(tmp); Logger.getLogger("at.tuwien.ifs.somtoolbox") .info("Successfully loaded cluster labels."); } catch (Exception e1) { e1.printStackTrace(); Logger.getLogger("at.tuwien.ifs.somtoolbox") .info("Error loading cluster labels: " + e1.getMessage()); } } else { try { FileInputStream fis = new FileInputStream(filePath); GZIPInputStream gzipIs = new GZIPInputStream(fis); ObjectInputStream ois = new ObjectInputStream(gzipIs); ClusteringTree tree = (ClusteringTree) ois.readObject(); PNode manual = (PNode) ois.readObject(); PNode all = mapPane.getMap().getManualLabels(); ArrayList<PNode> tmp = new ArrayList<PNode>(); for (ListIterator<?> iter = manual.getChildrenIterator(); iter.hasNext();) { PNode element = (PNode) iter.next(); tmp.add(element); } all.addChildren(tmp); state.clusterWithLabels = ois.readInt(); labelSpinner.setValue(state.clusterWithLabels); state.labelsWithValues = ois.readBoolean(); showValues.setSelected(state.labelsWithValues); state.clusterByValue = ois.readDouble(); valueQe.setValue(new Double((1 - state.clusterByValue) * 100).intValue()); mapPane.getMap().buildTree(tree); spinnerNoCluster.setValue(ois.readObject()); ois.close(); Logger.getLogger("at.tuwien.ifs.somtoolbox").info("Successfully loaded clustering."); } catch (Exception ex) { ex.printStackTrace(); Logger.getLogger("at.tuwien.ifs.somtoolbox") .info("Error loading clustering: " + ex.getMessage()); } } // keep the selected path for future references state.fileChooser.setSelectedFile(filePath.getParentFile()); } } }); panelButtons.add(loadButton); JButton exportImages = new JButton("Export"); exportImages.setFont(smallFont); exportImages.setMargin(SMALL_INSETS); exportImages.setToolTipText("Export labels as images (not yet working)"); exportImages.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JFileChooser fileChooser = new JFileChooser(); if (CommonSOMViewerStateData.fileNamePrefix != null && !CommonSOMViewerStateData.fileNamePrefix.equals("")) { fileChooser.setCurrentDirectory(new File(CommonSOMViewerStateData.fileNamePrefix)); } else { fileChooser.setCurrentDirectory(state.getFileChooser().getCurrentDirectory()); } fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (fileChooser.getSelectedFile() != null) { // reusing the dialog fileChooser.setSelectedFile(null); } fileChooser.setName("Choose path"); int returnVal = fileChooser.showDialog(ClusteringControl.this, "Choose path"); if (returnVal == JFileChooser.APPROVE_OPTION) { // save images String path = fileChooser.getSelectedFile().getAbsolutePath(); Logger.getLogger("at.tuwien.ifs.somtoolbox").info("Writing label images to " + path); } } }); panelButtons.add(exportImages); JButton deleteManual = new JButton("Delete"); deleteManual.setFont(smallFont); deleteManual.setMargin(SMALL_INSETS); deleteManual.setToolTipText("Delete manually added labels."); deleteManual.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { state.mapPNode.getManualLabels().removeAllChildren(); Logger.getLogger("at.tuwien.ifs.somtoolbox").info("Manual Labels deleted."); } }); panelButtons.add(deleteManual); c.anchor = GridBagConstraints.NORTH; this.getContentPane().add(panelButtons, c.nextRow()); this.setVisible(true); }
From source file:com.anrisoftware.prefdialog.fields.spinner.SpinnerField.java
private SpinnerModel createNumberModel() { Object value = getValue();//from w ww . j a v a 2 s . co m if (!(value instanceof Number)) { return null; } double[] max = annotationAccess.getValue(MAXIMUM_ATTRIBUTE); double[] min = annotationAccess.getValue(MINIMUM_ATTRIBUTE); double size = annotationAccess.getValue(STEP_SIZE_ATTRIBUTE); if (value instanceof Integer) { Comparable<?> maximum = max.length == 0 ? null : (int) max[0]; Comparable<?> minimum = min.length == 0 ? null : (int) min[0]; return new SpinnerNumberModel((Number) getValue(), minimum, maximum, (int) size); } if (value instanceof Long) { Comparable<?> maximum = max.length == 0 ? null : (long) max[0]; Comparable<?> minimum = min.length == 0 ? null : (long) min[0]; return new SpinnerNumberModel((Number) getValue(), minimum, maximum, (long) size); } if (value instanceof Double) { Comparable<?> maximum = max.length == 0 ? null : max[0]; Comparable<?> minimum = min.length == 0 ? null : min[0]; return new SpinnerNumberModel((Number) getValue(), minimum, maximum, size); } return null; }