Search in sources :

Example 1 with OptionPanel

use of ini.trakem2.utils.OptionPanel in project TrakEM2 by trakem2.

the class Display method createFilterOptionPanel.

private OptionPanel createFilterOptionPanel() {
    final OptionPanel fop = new OptionPanel();
    final Runnable reaction = new Runnable() {

        @Override
        public void run() {
            Display.repaint(getLayer());
        }
    };
    fop.addCheckbox("Live filters enabled", filter_enabled, new OptionPanel.BooleanSetter(this, "filter_enabled", reaction));
    fop.addMessage("Contrast:");
    fop.addCheckbox("Min/Max enabled", filter_min_max_enabled, new OptionPanel.BooleanSetter(this, "filter_min_max_enabled", reaction));
    fop.addNumericField("Min:", filter_min, 0, new OptionPanel.IntSetter(this, "filter_min", reaction, 0, 255));
    fop.addNumericField("Max:", filter_max, 0, new OptionPanel.IntSetter(this, "filter_max", reaction, 0, 255));
    fop.addCheckbox("Invert", filter_invert, new OptionPanel.BooleanSetter(this, "filter_invert", reaction));
    fop.addMessage("CLAHE options:");
    fop.addCheckbox("CLAHE enabled", filter_clahe_enabled, new OptionPanel.BooleanSetter(this, "filter_clahe_enabled", reaction));
    fop.addNumericField("block size:", filter_clahe_block_size, 0, new OptionPanel.IntSetter(this, "filter_clahe_block_size", reaction, 1, Integer.MAX_VALUE));
    fop.addNumericField("histogram bins:", filter_clahe_histogram_bins, 0, new OptionPanel.IntSetter(this, "filter_clahe_histogram_bins", reaction, 1, Integer.MAX_VALUE));
    fop.addNumericField("max slope:", filter_clahe_max_slope, 2, new OptionPanel.FloatSetter(this, "filter_clahe_max_slope", reaction, 0, Integer.MAX_VALUE));
    return fop;
}
Also used : OptionPanel(ini.trakem2.utils.OptionPanel)

Example 2 with OptionPanel

use of ini.trakem2.utils.OptionPanel in project TrakEM2 by trakem2.

the class Display method makeGUI.

private void makeGUI(final Layer layer, final Object[] props) {
    // gather properties
    final Point p;
    double mag = 1.0D;
    Rectangle srcRect = null;
    if (null != props) {
        p = (Point) props[0];
        mag = ((Double) props[1]).doubleValue();
        srcRect = (Rectangle) props[2];
    } else {
        p = null;
    }
    // transparency slider
    this.transp_slider = new JSlider(javax.swing.SwingConstants.HORIZONTAL, 0, 100, 100);
    this.transp_slider.setBackground(Color.white);
    this.transp_slider.setMinimumSize(new Dimension(250, 20));
    this.transp_slider.setMaximumSize(new Dimension(250, 20));
    this.transp_slider.setPreferredSize(new Dimension(250, 20));
    final TransparencySliderListener tsl = new TransparencySliderListener();
    this.transp_slider.addChangeListener(tsl);
    this.transp_slider.addMouseListener(tsl);
    for (final KeyListener kl : this.transp_slider.getKeyListeners()) {
        this.transp_slider.removeKeyListener(kl);
    }
    // Tabbed pane on the left
    this.tabs = new JTabbedPane();
    this.tabs.setMinimumSize(new Dimension(250, 300));
    this.tabs.setBackground(Color.white);
    this.tabs.addChangeListener(tabs_listener);
    // Tab 1: Patches
    this.panel_patches = new RollingPanel(this, Patch.class);
    this.addTab("Patches", panel_patches);
    // Tab 2: Profiles
    this.panel_profiles = new RollingPanel(this, Profile.class);
    this.addTab("Profiles", panel_profiles);
    // Tab 3: ZDisplayables
    this.panel_zdispl = new RollingPanel(this, ZDisplayable.class);
    this.addTab("Z space", panel_zdispl);
    // Tab 4: channels
    this.panel_channels = makeTabPanel();
    this.scroll_channels = makeScrollPane(panel_channels);
    this.channels = new Channel[4];
    this.channels[0] = new Channel(this, Channel.MONO);
    this.channels[1] = new Channel(this, Channel.RED);
    this.channels[2] = new Channel(this, Channel.GREEN);
    this.channels[3] = new Channel(this, Channel.BLUE);
    // this.panel_channels.add(this.channels[0]);
    addGBRow(this.panel_channels, this.channels[1], null);
    addGBRow(this.panel_channels, this.channels[2], this.channels[1]);
    addGBRow(this.panel_channels, this.channels[3], this.channels[2]);
    this.addTab("Opacity", scroll_channels);
    // Tab 5: labels
    this.panel_labels = new RollingPanel(this, DLabel.class);
    this.addTab("Labels", panel_labels);
    // Tab 6: layers
    this.panel_layers = makeTabPanel();
    this.scroll_layers = makeScrollPane(panel_layers);
    recreateLayerPanels(layer);
    this.scroll_layers.addMouseWheelListener(canvas);
    this.addTab("Layers", scroll_layers);
    // Tab 7: tool options
    // empty
    this.tool_options = new OptionPanel();
    this.scroll_options = makeScrollPane(this.tool_options);
    this.scroll_options.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    this.addTab("Tool options", this.scroll_options);
    // Tab 8: annotations
    this.annot_editor = new JEditorPane();
    // by default, nothing is selected
    this.annot_editor.setEnabled(false);
    this.annot_editor.setMinimumSize(new Dimension(200, 50));
    this.annot_label = new JLabel("(No selected object)");
    this.annot_panel = makeAnnotationsPanel(this.annot_editor, this.annot_label);
    this.addTab("Annotations", this.annot_panel);
    // Tab 9: filter options
    this.filter_options = createFilterOptionPanel();
    this.scroll_filter_options = makeScrollPane(this.filter_options);
    this.scroll_filter_options.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    this.addTab("Live filter", this.scroll_filter_options);
    this.ht_tabs = new Hashtable<Class<?>, RollingPanel>();
    this.ht_tabs.put(Patch.class, panel_patches);
    this.ht_tabs.put(Profile.class, panel_profiles);
    this.ht_tabs.put(ZDisplayable.class, panel_zdispl);
    this.ht_tabs.put(AreaList.class, panel_zdispl);
    this.ht_tabs.put(Pipe.class, panel_zdispl);
    this.ht_tabs.put(Polyline.class, panel_zdispl);
    this.ht_tabs.put(Treeline.class, panel_zdispl);
    this.ht_tabs.put(AreaTree.class, panel_zdispl);
    this.ht_tabs.put(Connector.class, panel_zdispl);
    this.ht_tabs.put(Ball.class, panel_zdispl);
    this.ht_tabs.put(Dissector.class, panel_zdispl);
    this.ht_tabs.put(DLabel.class, panel_labels);
    this.ht_tabs.put(Stack.class, panel_zdispl);
    // channels not included
    // layers not included
    // tools not included
    // annotations not included
    // Navigator
    this.navigator = new DisplayNavigator(this, layer.getLayerWidth(), layer.getLayerHeight());
    // Layer scroller (to scroll slices)
    int extent = (int) (250.0 / layer.getParent().size());
    if (extent < 10)
        extent = 10;
    this.scroller = new JScrollBar(JScrollBar.HORIZONTAL);
    this.scroller.setModel(new ScrollerModel(layer));
    updateLayerScroller(layer);
    this.scroller.addAdjustmentListener(scroller_listener);
    // LAYOUT
    final GridBagLayout layout = new GridBagLayout();
    final GridBagConstraints c = new GridBagConstraints();
    c.anchor = GridBagConstraints.NORTHWEST;
    c.fill = GridBagConstraints.NONE;
    c.weightx = 0;
    c.weighty = 0;
    c.gridx = 0;
    c.gridy = 0;
    c.ipadx = 0;
    c.ipady = 0;
    c.gridwidth = 1;
    c.gridheight = 1;
    Display.this.all = new JPanel();
    all.setBackground(Color.white);
    all.setLayout(layout);
    c.insets = new Insets(0, 0, 0, 5);
    // 1
    // fixed dimensions
    toolbar_panel = new ToolbarPanel();
    layout.setConstraints(toolbar_panel, c);
    all.add(toolbar_panel);
    // 2
    c.gridy++;
    c.fill = GridBagConstraints.HORIZONTAL;
    layout.setConstraints(transp_slider, c);
    all.add(transp_slider);
    // 3
    c.gridy++;
    c.weighty = 1;
    c.fill = GridBagConstraints.BOTH;
    layout.setConstraints(tabs, c);
    all.add(tabs);
    // 4
    c.gridy++;
    c.weighty = 0;
    c.fill = GridBagConstraints.NONE;
    layout.setConstraints(navigator, c);
    all.add(navigator);
    // 5
    c.gridy++;
    c.fill = GridBagConstraints.HORIZONTAL;
    layout.setConstraints(scroller, c);
    all.add(scroller);
    // Canvas
    this.canvas = new DisplayCanvas(this, (int) Math.ceil(layer.getLayerWidth()), (int) Math.ceil(layer.getLayerHeight()));
    c.insets = new Insets(0, 0, 0, 0);
    c.fill = GridBagConstraints.BOTH;
    c.anchor = GridBagConstraints.NORTHWEST;
    c.gridx = 1;
    c.gridy = 0;
    c.gridheight = GridBagConstraints.REMAINDER;
    c.weightx = 1;
    c.weighty = 1;
    layout.setConstraints(Display.this.canvas, c);
    all.add(canvas);
    // prevent new Displays from screwing up if input is globally disabled
    if (!project.isInputEnabled())
        Display.this.canvas.setReceivesInput(false);
    this.canvas.addComponentListener(canvas_size_listener);
    this.navigator.addMouseWheelListener(canvas);
    this.transp_slider.addKeyListener(canvas);
    // JFrame to show the split pane
    this.frame = ControlWindow.createJFrame(layer.toString());
    this.frame.setBackground(Color.white);
    this.frame.getContentPane().setBackground(Color.white);
    if (IJ.isMacintosh() && IJ.getInstance() != null) {
        // may be needed for Java 1.4 on OS X
        IJ.wait(10);
        this.frame.setMenuBar(ij.Menus.getMenuBar());
    }
    this.frame.addWindowListener(window_listener);
    // this.frame.addComponentListener(display_frame_listener);
    this.frame.getContentPane().add(all);
    if (null != props) {
        // restore canvas
        canvas.setup(mag, srcRect);
        // restore visibility of each channel
        // aka c_alphas_state
        final int cs = ((Integer) props[5]).intValue();
        final int[] sel = new int[4];
        sel[0] = ((cs & 0xff000000) >> 24);
        sel[1] = ((cs & 0xff0000) >> 16);
        sel[2] = ((cs & 0xff00) >> 8);
        sel[3] = (cs & 0xff);
        // restore channel alphas
        Display.this.c_alphas = ((Integer) props[4]).intValue();
        channels[0].setAlpha((float) ((c_alphas & 0xff000000) >> 24) / 255.0f, 0 != sel[0]);
        channels[1].setAlpha((float) ((c_alphas & 0xff0000) >> 16) / 255.0f, 0 != sel[1]);
        channels[2].setAlpha((float) ((c_alphas & 0xff00) >> 8) / 255.0f, 0 != sel[2]);
        channels[3].setAlpha((float) (c_alphas & 0xff) / 255.0f, 0 != sel[3]);
        // restore visibility in the working c_alphas
        Display.this.c_alphas = ((0 != sel[0] ? (int) (255 * channels[0].getAlpha()) : 0) << 24) + ((0 != sel[1] ? (int) (255 * channels[1].getAlpha()) : 0) << 16) + ((0 != sel[2] ? (int) (255 * channels[2].getAlpha()) : 0) << 8) + (0 != sel[3] ? (int) (255 * channels[3].getAlpha()) : 0);
    }
    if (null != active && null != layer) {
        final Rectangle r = active.getBoundingBox();
        r.x -= r.width / 2;
        r.y -= r.height / 2;
        r.width += r.width;
        r.height += r.height;
        if (r.x < 0)
            r.x = 0;
        if (r.y < 0)
            r.y = 0;
        if (r.width > layer.getLayerWidth())
            r.width = (int) layer.getLayerWidth();
        if (r.height > layer.getLayerHeight())
            r.height = (int) layer.getLayerHeight();
        final double magn = layer.getLayerWidth() / (double) r.width;
        canvas.setup(magn, r);
    }
    // add keyListener to the whole frame
    this.tabs.addKeyListener(canvas);
    this.frame.addKeyListener(canvas);
    // create a drag and drop listener
    dnd = new DNDInsertImage(Display.this);
    Utils.invokeLater(new Runnable() {

        @Override
        public void run() {
            Display.this.frame.pack();
            ij.gui.GUI.center(Display.this.frame);
            Display.this.frame.setVisible(true);
            // doesn't get it through events
            ProjectToolbar.setProjectToolbar();
            final Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
            if (null != props) {
                // fix positioning outside the screen (dual to single monitor)
                if (p.x >= 0 && p.x < screen.width - 50 && p.y >= 0 && p.y <= screen.height - 50)
                    Display.this.frame.setLocation(p);
                else
                    frame.setLocation(0, 0);
            }
            // fix excessive size
            final Rectangle box = Display.this.frame.getBounds();
            int x = box.x;
            int y = box.y;
            int width = box.width;
            int height = box.height;
            if (box.width > screen.width) {
                x = 0;
                width = screen.width;
            }
            if (box.height > screen.height) {
                y = 0;
                height = screen.height;
            }
            if (x != box.x || y != box.y) {
                // added insets for bad window managers
                Display.this.frame.setLocation(x, y + (0 == y ? 30 : 0));
            }
            if (width != box.width || height != box.height) {
                // added insets for bad window managers
                Display.this.frame.setSize(new Dimension(width - 10, height - 30));
            }
            if (null == props) {
                // try to optimize canvas dimensions and magn
                double magn = layer.getLayerHeight() / screen.height;
                if (magn > 1.0)
                    magn = 1.0;
                long size = 0;
                // limit magnification if appropriate
                for (final Displayable pa : layer.getDisplayables(Patch.class)) {
                    final Rectangle ba = pa.getBoundingBox();
                    size += (long) (ba.width * ba.height);
                }
                if (// 10 Mb
                size > 10000000)
                    // 10 Mb
                    canvas.setInitialMagnification(0.25);
                else {
                    Display.this.frame.setSize(new Dimension((int) (screen.width * 0.66), (int) (screen.height * 0.66)));
                }
            }
            updateTab(panel_patches);
            // re-layout:
            tabs.validate();
            // Set the calibration of the FakeImagePlus to that of the LayerSet
            ((FakeImagePlus) canvas.getFakeImagePlus()).setCalibrationSuper(layer.getParent().getCalibrationCopy());
            updateFrameTitle(layer);
            // Set the FakeImagePlus as the current image
            setTempCurrentImage();
            // start a repainting thread
            if (null != props) {
                // repaint() is unreliable
                canvas.repaint(true);
            }
            ControlWindow.setLookAndFeel();
        }
    });
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) JTabbedPane(javax.swing.JTabbedPane) DNDInsertImage(ini.trakem2.utils.DNDInsertImage) Rectangle(java.awt.Rectangle) JScrollBar(javax.swing.JScrollBar) JSlider(javax.swing.JSlider) OptionPanel(ini.trakem2.utils.OptionPanel) JLabel(javax.swing.JLabel) Point(java.awt.Point) Dimension(java.awt.Dimension) Point(java.awt.Point) JEditorPane(javax.swing.JEditorPane) KeyListener(java.awt.event.KeyListener)

Example 3 with OptionPanel

use of ini.trakem2.utils.OptionPanel in project TrakEM2 by trakem2.

the class Display method updateToolTab.

private void updateToolTab() {
    OptionPanel op = null;
    switch(ProjectToolbar.getToolId()) {
        case ProjectToolbar.PENCIL:
            op = Segmentation.fmp.asOptionPanel();
            break;
        case ProjectToolbar.BRUSH:
            op = AreaWrapper.PP.asOptionPanel();
            break;
        default:
            break;
    }
    scroll_options.getViewport().removeAll();
    if (null != op) {
        op.bottomPadding();
        scroll_options.setViewportView(op);
    }
    scroll_options.invalidate();
    scroll_options.validate();
    scroll_options.repaint();
}
Also used : OptionPanel(ini.trakem2.utils.OptionPanel)

Aggregations

OptionPanel (ini.trakem2.utils.OptionPanel)3 DNDInsertImage (ini.trakem2.utils.DNDInsertImage)1 Dimension (java.awt.Dimension)1 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 Insets (java.awt.Insets)1 Point (java.awt.Point)1 Rectangle (java.awt.Rectangle)1 KeyListener (java.awt.event.KeyListener)1 JEditorPane (javax.swing.JEditorPane)1 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1 JScrollBar (javax.swing.JScrollBar)1 JSlider (javax.swing.JSlider)1 JTabbedPane (javax.swing.JTabbedPane)1