private void link(final DoubleJSlider slider, final JTextField text) { slider.addChangeListener( new ChangeListener() { @Override public void stateChanged(final ChangeEvent e) { text.setText("" + slider.getScaledValue()); } }); text.addKeyListener( new KeyAdapter() { @Override public void keyReleased(final KeyEvent ke) { final String typed = text.getText(); try { final double value = Double.parseDouble(typed) * slider.scale; slider.setValue((int) value); } catch (final NumberFormatException nfe) { } } }); }
private void initGUI() { setLayout(new BorderLayout()); tabbedPane = new JTabbedPane(JTabbedPane.TOP); add(tabbedPane); { final JPanel panelIntroduction = new JPanel(); tabbedPane.addTab("Intro", null, panelIntroduction, null); panelIntroduction.setLayout(null); final JLabel lblCrownwearingNucleiTracker = new JLabel("Crown-Wearing Nuclei Segmenter"); lblCrownwearingNucleiTracker.setFont(BIG_FONT); lblCrownwearingNucleiTracker.setHorizontalAlignment(SwingConstants.CENTER); lblCrownwearingNucleiTracker.setBounds(10, 11, 268, 30); panelIntroduction.add(lblCrownwearingNucleiTracker); final JLabel labelIntro = new JLabel(INTRO_TEXT); labelIntro.setFont(SMALL_FONT.deriveFont(11f)); labelIntro.setBounds(10, 52, 268, 173); panelIntroduction.add(labelIntro); final JButton btnTestParamtersLive = new JButton("<html><div align=\"center\">Live test parameters</dic></html>"); btnTestParamtersLive.setBounds(10, 292, 103, 72); btnTestParamtersLive.setFont(FONT); liveLaunched = false; btnTestParamtersLive.addActionListener( new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { if (liveLaunched) { stopLive(); btnTestParamtersLive.setText( "<html><div align=\"center\">Live test parameters</div></html>"); liveLaunched = false; } else { launchLive(); btnTestParamtersLive.setText( "<html><div align=\"center\">Stop live test</div></html>"); liveLaunched = true; } } }); panelIntroduction.add(btnTestParamtersLive); final String segFrameButtonText = "<html><CENTER>Segment current frame</center></html>"; final JButton segFrameButton = new JButton(segFrameButtonText); segFrameButton.addActionListener( new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { new Thread("CWNT thread") { @Override public void run() { segFrameButton.setText("Segmenting..."); segFrameButton.setEnabled(false); try { launchSingleFrameSegmentation(); } finally { segFrameButton.setEnabled(true); segFrameButton.setText(segFrameButtonText); } } }.start(); } }); segFrameButton.setFont(FONT); segFrameButton.setBounds(175, 292, 103, 72); panelIntroduction.add(segFrameButton); labelDurationEstimate = new JLabel(); labelDurationEstimate.setBounds(10, 375, 268, 14); panelIntroduction.setFont(FONT); panelIntroduction.add(labelDurationEstimate); } final JPanel panelParams1 = new JPanel(); { tabbedPane.addTab("Param set 1", null, panelParams1, null); panelParams1.setLayout(null); final JLabel lblFiltering = new JLabel("1. Filtering"); lblFiltering.setFont(BIG_FONT); lblFiltering.setBounds(10, 11, 268, 29); panelParams1.add(lblFiltering); { final JLabel lblGaussianFilter = new JLabel("Gaussian filter \u03C3:"); lblGaussianFilter.setFont(SMALL_FONT); lblGaussianFilter.setBounds(10, 51, 268, 14); panelParams1.add(lblGaussianFilter); gaussFiltSigmaSlider = new DoubleJSlider(0, 5 * scale, (int) (maskingParams[0] * scale), scale); gaussFiltSigmaSlider.setBounds(10, 76, 223, 23); panelParams1.add(gaussFiltSigmaSlider); gaussFiltSigmaText = new JFormattedTextField(new Double(maskingParams[0])); gaussFiltSigmaText.setHorizontalAlignment(SwingConstants.CENTER); gaussFiltSigmaText.setBounds(243, 76, 35, 23); gaussFiltSigmaText.setFont(FONT); panelParams1.add(gaussFiltSigmaText); link(gaussFiltSigmaSlider, gaussFiltSigmaText); gaussFiltSigmaSlider.addChangeListener(step1ChangeListener); gaussFiltSigmaText.addKeyListener(step1KeyListener); } final JLabel lblAnisotropicDiffusion = new JLabel("2. Anisotropic diffusion"); lblAnisotropicDiffusion.setFont(BIG_FONT); lblAnisotropicDiffusion.setBounds(10, 128, 268, 29); panelParams1.add(lblAnisotropicDiffusion); { final JLabel lblNumberOfIterations = new JLabel("Number of iterations:"); lblNumberOfIterations.setFont(SMALL_FONT); lblNumberOfIterations.setBounds(10, 168, 268, 14); panelParams1.add(lblNumberOfIterations); aniDiffNIterText = new JFormattedTextField(new Integer((int) maskingParams[1])); aniDiffNIterText.setHorizontalAlignment(SwingConstants.CENTER); aniDiffNIterText.setFont(FONT); aniDiffNIterText.setBounds(243, 193, 35, 23); panelParams1.add(aniDiffNIterText); aniDiffNIterSlider = new DoubleJSlider(0, 10, (int) maskingParams[1], 1); aniDiffNIterSlider.setBounds(10, 193, 223, 23); panelParams1.add(aniDiffNIterSlider); link(aniDiffNIterSlider, aniDiffNIterText); aniDiffNIterSlider.addChangeListener(step2ChangeListener); aniDiffNIterText.addKeyListener(step2KeyListener); } { final JLabel lblGradientDiffusionThreshold = new JLabel("Gradient diffusion threshold \u03BA:"); lblGradientDiffusionThreshold.setFont(SMALL_FONT); lblGradientDiffusionThreshold.setBounds(10, 227, 268, 14); panelParams1.add(lblGradientDiffusionThreshold); aniDiffKappaText = new JFormattedTextField(new Double(maskingParams[2])); aniDiffKappaText.setHorizontalAlignment(SwingConstants.CENTER); aniDiffKappaText.setFont(FONT); aniDiffKappaText.setBounds(243, 252, 35, 23); panelParams1.add(aniDiffKappaText); aniDiffKappaSlider = new DoubleJSlider(1, 100, (int) maskingParams[2], 1); aniDiffKappaSlider.setBounds(10, 252, 223, 23); panelParams1.add(aniDiffKappaSlider); link(aniDiffKappaSlider, aniDiffKappaText); aniDiffKappaSlider.addChangeListener(step2ChangeListener); aniDiffKappaText.addKeyListener(step2KeyListener); } final JLabel lblDerivativesCalculation = new JLabel("3. Derivatives calculation"); lblDerivativesCalculation.setFont(BIG_FONT); lblDerivativesCalculation.setBounds(10, 298, 268, 29); panelParams1.add(lblDerivativesCalculation); { final JLabel lblGaussianGradient = new JLabel("Gaussian gradient \u03C3:"); lblGaussianGradient.setFont(FONT); lblGaussianGradient.setBounds(10, 338, 268, 14); panelParams1.add(lblGaussianGradient); gaussGradSigmaText = new JFormattedTextField(new Double(maskingParams[3])); gaussGradSigmaText.setFont(FONT); gaussGradSigmaText.setHorizontalAlignment(SwingConstants.CENTER); gaussGradSigmaText.setBounds(243, 363, 35, 23); panelParams1.add(gaussGradSigmaText); gaussGradSigmaSlider = new DoubleJSlider(0, 5 * scale, (int) (maskingParams[3] * scale), scale); gaussGradSigmaSlider.setBounds(10, 363, 223, 23); panelParams1.add(gaussGradSigmaSlider); link(gaussGradSigmaSlider, gaussGradSigmaText); gaussGradSigmaSlider.addChangeListener(step3ChangeListener); gaussGradSigmaText.addKeyListener(step3KeyListener); } } final JPanel panelParams2 = new JPanel(); { tabbedPane.addTab("Param set 2", panelParams2); panelParams2.setLayout(null); final JLabel lblMasking = new JLabel("4. Masking"); lblMasking.setFont(BIG_FONT); lblMasking.setBounds(10, 11, 268, 29); panelParams2.add(lblMasking); { final JLabel gammeLabel = new JLabel("\u03B3: tanh shift"); gammeLabel.setFont(SMALL_FONT); gammeLabel.setBounds(10, 51, 268, 14); panelParams2.add(gammeLabel); gammaSlider = new DoubleJSlider(-5 * scale, 5 * scale, (int) (maskingParams[4] * scale), scale); gammaSlider.setBounds(10, 76, 223, 23); panelParams2.add(gammaSlider); gammaText = new JFormattedTextField(new Double(maskingParams[4])); gammaText.setFont(FONT); gammaText.setBounds(243, 76, 35, 23); panelParams2.add(gammaText); link(gammaSlider, gammaText); gammaSlider.addChangeListener(step4ChangeListener); gammaSlider.addKeyListener(step4KeyListener); } { final JLabel lblNewLabel_3 = new JLabel("\u03B1: gradient prefactor"); lblNewLabel_3.setFont(SMALL_FONT); lblNewLabel_3.setBounds(10, 110, 268, 14); panelParams2.add(lblNewLabel_3); alphaSlider = new DoubleJSlider(0, 20 * scale, (int) (maskingParams[5] * scale), scale); alphaSlider.setBounds(10, 135, 223, 23); panelParams2.add(alphaSlider); alphaText = new JFormattedTextField(new Double(maskingParams[5])); alphaText.setFont(FONT); alphaText.setBounds(243, 135, 35, 23); panelParams2.add(alphaText); link(alphaSlider, alphaText); alphaSlider.addChangeListener(step4ChangeListener); alphaText.addKeyListener(step4KeyListener); } { final JLabel betaLabel = new JLabel("\u03B2: positive laplacian magnitude prefactor"); betaLabel.setFont(SMALL_FONT); betaLabel.setBounds(10, 169, 268, 14); panelParams2.add(betaLabel); betaSlider = new DoubleJSlider(0, 20 * scale, (int) (maskingParams[6] * scale), scale); betaSlider.setBounds(10, 194, 223, 23); panelParams2.add(betaSlider); betaText = new JFormattedTextField(new Double(maskingParams[6])); betaText.setFont(FONT); betaText.setBounds(243, 194, 35, 23); panelParams2.add(betaText); link(betaSlider, betaText); betaSlider.addChangeListener(step4ChangeListener); betaText.addKeyListener(step4KeyListener); } { final JLabel epsilonLabel = new JLabel("\u03B5: negative hessian magnitude"); epsilonLabel.setFont(SMALL_FONT); epsilonLabel.setBounds(10, 228, 268, 14); panelParams2.add(epsilonLabel); epsilonSlider = new DoubleJSlider(0, 20 * scale, (int) (scale * maskingParams[7]), scale); epsilonSlider.setBounds(10, 253, 223, 23); panelParams2.add(epsilonSlider); epsilonText = new JFormattedTextField(new Double(maskingParams[7])); epsilonText.setFont(FONT); epsilonText.setText("" + maskingParams[7]); epsilonText.setBounds(243, 253, 35, 23); panelParams2.add(epsilonText); link(epsilonSlider, epsilonText); epsilonSlider.addChangeListener(step4ChangeListener); epsilonText.addKeyListener(step4KeyListener); } { final JLabel deltaLabel = new JLabel("\u03B4: derivatives sum scale"); deltaLabel.setFont(SMALL_FONT); deltaLabel.setBounds(10, 287, 268, 14); panelParams2.add(deltaLabel); deltaText = new JFormattedTextField(new Double(maskingParams[8])); deltaText.setFont(FONT); deltaText.setText("" + maskingParams[8]); deltaText.setBounds(243, 312, 35, 23); panelParams2.add(deltaText); deltaSlider = new DoubleJSlider(0, 5 * scale, (int) (maskingParams[8] * scale), scale); deltaSlider.setBounds(10, 312, 223, 23); panelParams2.add(deltaSlider); link(deltaSlider, deltaText); deltaSlider.addChangeListener(step4ChangeListener); deltaText.addKeyListener(step4KeyListener); } final JLabel lblEquation = new JLabel( "<html>M = \u00BD ( 1 + <i>tanh</i> ( \u03B3 - ( \u03B1 G + \u03B2 L + \u03B5 H ) / \u03B4 ) )</html>"); lblEquation.setHorizontalAlignment(SwingConstants.CENTER); lblEquation.setFont(FONT.deriveFont(12f)); lblEquation.setBounds(10, 364, 268, 35); panelParams2.add(lblEquation); } { final JPanel panel = new JPanel(); tabbedPane.addTab("Param set 3", null, panel, null); panel.setLayout(null); final JLabel labelThresholding = new JLabel("5. Thresholding"); labelThresholding.setBounds(10, 11, 268, 28); labelThresholding.setFont(BIG_FONT); panel.add(labelThresholding); final JLabel labelThresholdFactor = new JLabel("Threshold factor:"); labelThresholdFactor.setFont(SMALL_FONT); labelThresholdFactor.setBounds(10, 50, 268, 14); panel.add(labelThresholdFactor); thresholdFactorSlider = new DoubleJSlider(0, 5 * scale, (int) (thresholdFactor * scale), scale); thresholdFactorSlider.setBounds(10, 75, 223, 23); panel.add(thresholdFactorSlider); thresholdFactorText = new JFormattedTextField(new Double(thresholdFactor)); thresholdFactorText.setFont(FONT); thresholdFactorText.setBounds(243, 75, 35, 23); panel.add(thresholdFactorText); link(thresholdFactorSlider, thresholdFactorText); thresholdFactorSlider.addChangeListener(step5ChangeListener); thresholdFactorText.addKeyListener(step5KeyListener); } }