private static JComponent makeUI() { // final JProgressBar progressBar = new JProgressBar(SwingConstants.VERTICAL); final JProgressBar progressBar = new JProgressBar(); progressBar.setOpaque(false); progressBar.setUI(new GradientPalletProgressBarUI()); GridBagConstraints c = new GridBagConstraints(); JPanel p = new JPanel(new GridBagLayout()); p.setBorder(BorderFactory.createEmptyBorder(32, 8, 0, 8)); c.gridheight = 1; c.gridwidth = 1; c.gridy = 0; c.gridx = 0; c.insets = new Insets(0, 0, 0, 4); c.weightx = 1d; c.fill = GridBagConstraints.HORIZONTAL; p.add(progressBar, c); c.gridx = 1; c.weightx = 0d; p.add( new JButton( new AbstractAction("Start") { @Override public void actionPerformed(ActionEvent e) { final JButton b = (JButton) e.getSource(); b.setEnabled(false); SwingWorker<Void, Void> worker = new Task() { @Override public void done() { if (b.isDisplayable()) { b.setEnabled(true); } } }; worker.addPropertyChangeListener(new ProgressListener(progressBar)); worker.execute(); } }), c); return p; }
private void init(EditorPatternButton imgBtn, JLabel msgApplied) { _imgBtn = imgBtn; JLabel lblPath = new JLabel(_I("lblPath")); JLabel lblFilename = new JLabel(_I("lblFilename")); String filename = _imgBtn.getFilename(); File f = new File(filename); String fullpath = f.getParent(); filename = getFilenameWithoutExt(f); _oldFilename = filename; BufferedImage thumb = _imgBtn.createThumbnailImage(THUMB_MAX_HEIGHT); Border border = LineBorder.createGrayLineBorder(); JLabel lblThumb = new JLabel(new ImageIcon(thumb)); lblThumb.setBorder(border); _txtPath = new JTextField(fullpath, TXT_FILENAME_LENGTH); _txtPath.setEditable(false); _txtPath.setEnabled(false); String[] candidates = new String[] {filename}; // <editor-fold defaultstate="collapsed" desc="OCR --- not used"> /* String ocrText = getFilenameFromImage(thumb); if(ocrText.length()>0 && !ocrText.equals(filename)) candidates = new String[] {filename, ocrText}; */ // </editor-fold> _txtFilename = new AutoCompleteCombo(candidates); _txtFileExt = new JTextField(getFileExt(f), TXT_FILE_EXT_LENGTH); _txtFileExt.setEditable(false); _txtFileExt.setEnabled(false); GridBagConstraints c = new GridBagConstraints(); c.gridy = 0; c.insets = new Insets(100, 0, 0, 0); this.add(new JLabel(""), c); c = new GridBagConstraints(); c.fill = 0; c.gridwidth = 3; c.gridy = 1; c.insets = new Insets(0, 10, 20, 10); this.add(lblThumb, c); c = new GridBagConstraints(); c.fill = 1; c.gridy = 2; this.add(lblPath, c); c.gridx = 1; c.gridwidth = 2; this.add(_txtPath, c); c = new GridBagConstraints(); c.gridy = 3; c.fill = 0; this.add(lblFilename, c); this.add(_txtFilename, c); this.add(_txtFileExt, c); c = new GridBagConstraints(); c.gridy = 4; c.gridx = 1; c.insets = new Insets(200, 0, 0, 0); this.add(msgApplied, c); }
public BandAdjuster() { super("Threshold Colour"); if (instance != null) { instance.toFront(); return; } imp = WindowManager.getCurrentImage(); if (imp == null) { IJ.beep(); IJ.showStatus("No image"); return; } IJ.run("Select None"); thread = new Thread(this, "BandAdjuster"); WindowManager.addWindow(this); instance = this; IJ.register(PasteController.class); ij = IJ.getInstance(); Font font = new Font("SansSerif", Font.PLAIN, 10); GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); setLayout(gridbag); int y = 0; c.gridx = 0; c.gridy = y; c.gridwidth = 1; c.weightx = 0; c.insets = new Insets(5, 0, 0, 0); labelh = new Label("Hue", Label.CENTER); add(labelh, c); c.gridx = 1; c.gridy = y++; c.gridwidth = 1; c.weightx = 0; c.insets = new Insets(7, 0, 0, 0); labelf = new Label("Filter type", Label.RIGHT); add(labelf, c); // plot c.gridx = 0; c.gridy = y; c.gridwidth = 1; c.fill = c.BOTH; c.anchor = c.CENTER; c.insets = new Insets(0, 5, 0, 0); add(plot, c); // checkboxes panelh = new Panel(); filterTypeH = new CheckboxGroup(); bandPassH = new Checkbox("Pass"); bandPassH.setCheckboxGroup(filterTypeH); bandPassH.addItemListener(this); panelh.add(bandPassH); bandStopH = new Checkbox("Stop"); bandStopH.setCheckboxGroup(filterTypeH); bandStopH.addItemListener(this); panelh.add(bandStopH); bandPassH.setState(true); c.gridx = 1; c.gridy = y++; c.gridwidth = 2; c.insets = new Insets(5, 0, 0, 0); add(panelh, c); // minHue slider minSlider = new Scrollbar(Scrollbar.HORIZONTAL, 0, 1, 0, sliderRange); c.gridx = 0; c.gridy = y++; c.gridwidth = 1; c.weightx = IJ.isMacintosh() ? 90 : 100; c.fill = c.HORIZONTAL; c.insets = new Insets(5, 5, 0, 0); add(minSlider, c); minSlider.addAdjustmentListener(this); minSlider.setUnitIncrement(1); // minHue slider label c.gridx = 1; c.gridwidth = 1; c.weightx = IJ.isMacintosh() ? 10 : 0; c.insets = new Insets(5, 0, 0, 0); label1 = new Label(" ", Label.LEFT); label1.setFont(font); add(label1, c); // maxHue sliderHue maxSlider = new Scrollbar(Scrollbar.HORIZONTAL, 0, 1, 0, sliderRange); c.gridx = 0; c.gridy = y; c.gridwidth = 1; c.weightx = 100; c.insets = new Insets(5, 5, 0, 0); add(maxSlider, c); maxSlider.addAdjustmentListener(this); maxSlider.setUnitIncrement(1); // maxHue slider label c.gridx = 1; c.gridwidth = 1; c.gridy = y++; c.weightx = 0; c.insets = new Insets(5, 0, 0, 0); label2 = new Label(" ", Label.LEFT); label2.setFont(font); add(label2, c); // ===== c.gridx = 0; c.gridy = y++; c.gridwidth = 1; c.weightx = 0; c.insets = new Insets(10, 0, 0, 0); labels = new Label("Saturation", Label.CENTER); add(labels, c); // plot c.gridx = 0; c.gridy = y; c.gridwidth = 1; c.fill = c.BOTH; c.anchor = c.CENTER; c.insets = new Insets(0, 5, 0, 0); add(splot, c); // checkboxes panels = new Panel(); filterTypeS = new CheckboxGroup(); bandPassS = new Checkbox("Pass"); bandPassS.setCheckboxGroup(filterTypeS); bandPassS.addItemListener(this); panels.add(bandPassS); bandStopS = new Checkbox("Stop"); bandStopS.setCheckboxGroup(filterTypeS); bandStopS.addItemListener(this); panels.add(bandStopS); bandPassS.setState(true); c.gridx = 1; c.gridy = y++; c.gridwidth = 2; c.insets = new Insets(5, 0, 0, 0); add(panels, c); // minSat slider minSlider2 = new Scrollbar(Scrollbar.HORIZONTAL, 0, 1, 0, sliderRange); c.gridx = 0; c.gridy = y++; c.gridwidth = 1; c.weightx = IJ.isMacintosh() ? 90 : 100; c.fill = c.HORIZONTAL; c.insets = new Insets(5, 5, 0, 0); add(minSlider2, c); minSlider2.addAdjustmentListener(this); minSlider2.setUnitIncrement(1); // minSat slider label c.gridx = 1; c.gridwidth = 1; c.weightx = IJ.isMacintosh() ? 10 : 0; c.insets = new Insets(5, 0, 0, 0); label3 = new Label(" ", Label.LEFT); label3.setFont(font); add(label3, c); // maxSat slider maxSlider2 = new Scrollbar(Scrollbar.HORIZONTAL, 0, 1, 0, sliderRange); c.gridx = 0; c.gridy = y++; c.gridwidth = 1; c.weightx = 100; c.insets = new Insets(5, 5, 0, 0); add(maxSlider2, c); maxSlider2.addAdjustmentListener(this); maxSlider2.setUnitIncrement(1); // maxSat slider label c.gridx = 1; c.gridwidth = 1; c.weightx = 0; c.insets = new Insets(5, 0, 0, 0); label4 = new Label(" ", Label.LEFT); label4.setFont(font); add(label4, c); // ===== c.gridx = 0; c.gridwidth = 1; c.gridy = y++; c.weightx = 0; c.insets = new Insets(10, 0, 0, 0); labelb = new Label("Brightness", Label.CENTER); add(labelb, c); c.gridx = 0; c.gridwidth = 1; c.gridy = y; c.fill = c.BOTH; c.anchor = c.CENTER; c.insets = new Insets(0, 5, 0, 0); add(bplot, c); // checkboxes panelb = new Panel(); filterTypeB = new CheckboxGroup(); bandPassB = new Checkbox("Pass"); bandPassB.setCheckboxGroup(filterTypeB); bandPassB.addItemListener(this); panelb.add(bandPassB); bandStopB = new Checkbox("Stop"); bandStopB.setCheckboxGroup(filterTypeB); bandStopB.addItemListener(this); panelb.add(bandStopB); bandPassB.setState(true); c.gridx = 1; c.gridy = y++; c.gridwidth = 2; c.insets = new Insets(5, 0, 0, 0); add(panelb, c); // minBri slider minSlider3 = new Scrollbar(Scrollbar.HORIZONTAL, 0, 1, 0, sliderRange); c.gridx = 0; c.gridy = y++; c.gridwidth = 1; c.weightx = IJ.isMacintosh() ? 90 : 100; c.fill = c.HORIZONTAL; c.insets = new Insets(5, 5, 0, 0); add(minSlider3, c); minSlider3.addAdjustmentListener(this); minSlider3.setUnitIncrement(1); // minBri slider label c.gridx = 1; c.gridwidth = 1; c.weightx = IJ.isMacintosh() ? 10 : 0; c.insets = new Insets(5, 0, 0, 0); label5 = new Label(" ", Label.LEFT); label5.setFont(font); add(label5, c); // maxBri slider maxSlider3 = new Scrollbar(Scrollbar.HORIZONTAL, 0, 1, 0, sliderRange); c.gridx = 0; c.gridy = y++; c.gridwidth = 1; c.weightx = 100; c.insets = new Insets(5, 5, 0, 0); add(maxSlider3, c); maxSlider3.addAdjustmentListener(this); maxSlider3.setUnitIncrement(1); // maxBri slider label c.gridx = 1; c.gridwidth = 1; c.weightx = 0; c.insets = new Insets(5, 0, 0, 0); label6 = new Label(" ", Label.LEFT); label6.setFont(font); add(label6, c); // ===== panelt = new Panel(); threshold = new Checkbox("Threshold"); threshold.addItemListener(this); panelt.add(threshold); invert = new Checkbox("Invert"); invert.addItemListener(this); panelt.add(invert); c.gridx = 0; c.gridy = y++; c.gridwidth = 2; c.insets = new Insets(0, 0, 0, 0); add(panelt, c); // buttons panel = new Panel(); // panel.setLayout(new GridLayout(2, 2, 0, 0)); originalB = new Button("Original"); originalB.setEnabled(false); originalB.addActionListener(this); originalB.addKeyListener(ij); panel.add(originalB); filteredB = new Button("Filtered"); filteredB.setEnabled(false); filteredB.addActionListener(this); filteredB.addKeyListener(ij); panel.add(filteredB); stackB = new Button("Stack"); stackB.addActionListener(this); stackB.addKeyListener(ij); panel.add(stackB); helpB = new Button("Help"); helpB.addActionListener(this); helpB.addKeyListener(ij); panel.add(helpB); c.gridx = 0; c.gridy = y++; c.gridwidth = 2; c.insets = new Insets(0, 0, 0, 0); add(panel, c); panelMode = new Panel(); sampleB = new Button("Sample"); sampleB.addActionListener(this); sampleB.addKeyListener(ij); panelMode.add(sampleB); colourMode = new CheckboxGroup(); hsb = new Checkbox("HSB"); hsb.setCheckboxGroup(colourMode); hsb.addItemListener(this); panelMode.add(hsb); hsb.setState(true); rgb = new Checkbox("RGB"); rgb.setCheckboxGroup(colourMode); rgb.addItemListener(this); panelMode.add(rgb); c.gridx = 0; c.gridy = y++; c.gridwidth = 2; c.insets = new Insets(0, 0, 0, 0); add(panelMode, c); addKeyListener(ij); // ImageJ handles keyboard shortcuts pack(); GUI.center(this); setVisible(true); ip = setup(imp); if (ip == null) { imp.unlock(); IJ.beep(); IJ.showStatus("RGB image cannot be thresholded"); return; } thread.start(); }
public void run() { // Collect some user data. dlg = new JDialog(console.frame, "Example 1 Setup", true); dlg.getContentPane().setLayout(new BorderLayout()); // Properties area propPanel = new JPanel(); dlg.getContentPane().add(propPanel, BorderLayout.CENTER); GridBagLayout gbl = new GridBagLayout(); propPanel.setLayout(gbl); // List of voice resources DefaultListModel dlm = new DefaultListModel(); for (int x = 1; ; x++) { try { int c = x % 4 == 0 ? 4 : x % 4; int b = c == 4 ? x / 4 : x / 4 + 1; String devName = "dxxxB" + b + "C" + c; int dev = dx.open(devName, 0); try { // If any of the voice resources _are not_ connected to // analog loop-start lines, then they will be suppressed // here because sethook() will not be supported. dx.sethook(dev, dx.DX_ONHOOK, dx.EV_SYNC); dlm.addElement(devName); } catch (Exception ignore) { } dx.close(dev); } catch (Exception ignore) { break; } } analogDxList = new JList(dlm); { GridBagConstraints gbc; // Choose a voice resource: gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 0; gbc.fill = GridBagConstraints.BOTH; JTextField t = new JTextField("Analog Voice Resource"); t.setEditable(false); gbl.setConstraints(t, gbc); propPanel.add(t); gbc = new GridBagConstraints(); gbc.gridx = 1; gbc.gridy = 0; gbc.fill = GridBagConstraints.BOTH; JScrollPane s = new JScrollPane(analogDxList); gbl.setConstraints(s, gbc); propPanel.add(s); } // Dialog buttons at the bottom. JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS)); dlg.getContentPane().add(buttonPanel, BorderLayout.SOUTH); // "Run" { JButton b = new JButton("Run"); b.addActionListener( new AbstractAction() { public void actionPerformed(ActionEvent e) { final Object[] dx = analogDxList.getSelectedValues(); if (dx.length != 1) { // "Please select one, and only one, voice resource." JOptionPane.showMessageDialog( dlg, "Please select one, and only one, resource.", "Error", JOptionPane.ERROR_MESSAGE); return; } Thread t = new Thread() { public void run() { runExample((String) dx[0]); } }; t.start(); dlg.dispose(); } }); buttonPanel.add(b); } // "Cancel" { JButton b = new JButton("Cancel"); b.addActionListener( new AbstractAction() { public void actionPerformed(ActionEvent e) { dlg.dispose(); } }); buttonPanel.add(b); } // Pack and Show dlg.pack(); dlg.setLocationRelativeTo(console.frame); dlg.setVisible(true); }