Commit 22e861e6 authored by Lukáš Machálek's avatar Lukáš Machálek Committed by Radek Ošlejšek
Browse files

Added GUI element for list of feature points.

parent bf08a3d1
Loading
Loading
Loading
Loading
+322 −10
Original line number Diff line number Diff line
package cz.fidentis.analyst.gui.builder;

import cz.fidentis.analyst.drawables.DrawableFeaturePoints;
import cz.fidentis.analyst.gui.elements.ColorListPanel;
import cz.fidentis.analyst.gui.elements.FeaturePointListPanel;
import cz.fidentis.analyst.gui.elements.PlaneManipulationPanel;
import cz.fidentis.analyst.gui.elements.SingleAxisAnimationPanel;
import cz.fidentis.analyst.gui.elements.SpinSlider;
import cz.fidentis.analyst.gui.elements.TripleAxisAnimationPanel;
import cz.fidentis.analyst.gui.elements.cbox.SelectableComboBox;
import cz.fidentis.analyst.rendering.RotationAnimator;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionListener;
import java.util.Map;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
@@ -21,6 +26,8 @@ import javax.swing.JFormattedTextField;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.text.DefaultFormatterFactory;

@@ -42,8 +49,9 @@ import javax.swing.text.DefaultFormatterFactory;
 * This builder adds components from left to right on a single line, until
 * nextLine() method is called.
 *
 * For concrete example of this builder usage, check RegistrationPanel or
 * TripleAxisAnimationPanel.
 * For concrete example of this builder usage, check RegistrationPanel,
 * TripleAxisAnimationPanel or FeaturePointsPanel. These panels were created
 * using this builder.
 *
 * @author Lukas Machalek
 */
@@ -179,6 +187,54 @@ public class PanelBuilder {
        return this;
    }

    /**
     * Sets Vertical stretch On or Off depending on the parameter given. This
     * vertical stretch takes effect if the Component is given more space than
     * it needs.
     *
     * @param b parameter to turn on/off stretch
     * @return this panel builder
     */
    public PanelBuilder setVerticalStretch(boolean b) {
        if (subPanelsDepth > 0) {
            subPanel.setVerticalStretch(b);
            return this;
        }

        if (b) {
            constraints.weighty = 1;
            return this;
        }

        constraints.weighty = 0;
        return this;
    }

    /**
     * Sets Vertical and Horizontal stretch On or Off depending on the parameter
     * given. This stretch takes effect if the Component is given more space
     * than it needs.
     *
     * @param b parameter to turn on/off stretch
     * @return this panel builder
     */
    public PanelBuilder setBothStretch(boolean b) {
        if (subPanelsDepth > 0) {
            subPanel.setBothStretch(b);
            return this;
        }

        if (b) {
            constraints.weighty = 1;
            constraints.weightx = 1;
            return this;
        }

        constraints.weighty = 0;
        constraints.weightx = 0;
        return this;
    }

    /**
     * Sets the placement of future components to the left side of their cell.
     *
@@ -199,6 +255,16 @@ public class PanelBuilder {
        return this;
    }

    /**
     * Sets the placement of future components to the right side of their cell.
     *
     * @return this panel builder
     */
    public PanelBuilder setPlacementRight() {
        constraints.anchor = GridBagConstraints.LINE_END;
        return this;
    }

    /**
     * Sets the preferred size of the panel. The size of the panel can only be
     * set to be bigger than the current preferred size, otherwise it might
@@ -264,6 +330,21 @@ public class PanelBuilder {
        return this;
    }

    /**
     * Sets the panel builder to stretch components vertically and horizontally.
     *
     * @return this panel builder
     */
    public PanelBuilder setBothFill() {
        if (subPanelsDepth > 0) {
            subPanel.setBothFill();
            return this;
        }

        this.constraints.fill = GridBagConstraints.BOTH;
        return this;
    }

    /**
     * Sets the Inset we want on the top of components we are adding to the
     * panel.
@@ -427,6 +508,27 @@ public class PanelBuilder {
        return this;
    }

    /**
     * Adds custom button to the builded panel.
     *
     * @param button custom button
     * @return this panel builder
     */
    public PanelBuilder addButton(JButton button) {
        if (subPanelsDepth > 0) {
            subPanel.addButton(button);
            return this;
        }
        updateInsets();

        panel.add(button, constraints);
        constraints.gridx += 1;

        lastComponent = button;

        return this;
    }

    /**
     * Adds RadioButton with given text.
     *
@@ -667,7 +769,6 @@ public class PanelBuilder {
        JTextField field = new JTextField();
        field.setFont(font);

        field.setSize(64, 22);
        field.setPreferredSize(new Dimension(64, 22));

        updateInsets();
@@ -679,6 +780,33 @@ public class PanelBuilder {
        return this;
    }

    /**
     * Adds TextField with given size in the parameters.
     *
     * @param width desired width of the textfield
     * @param height desired height of the textfield
     * @return this panel builder
     */
    public PanelBuilder addTextField(int width, int height) {
        if (subPanelsDepth > 0) {
            subPanel.addTextField(width, height);
            return this;
        }

        JTextField field = new JTextField();
        field.setFont(font);

        field.setPreferredSize(new Dimension(width, height));

        updateInsets();
        panel.add(field, constraints);
        constraints.gridx += 1;

        lastComponent = field;

        return this;
    }

    /**
     * Adds SpinSlider to the panel.
     *
@@ -918,6 +1046,190 @@ public class PanelBuilder {
        return this;
    }

    /**
     * Limits maximum height of the panel to the current height and returns the
     * built panel.
     *
     * @return created panel
     */
    public JPanel build() {
        panel.setMaximumSize(new Dimension(Integer.MAX_VALUE, panel.getPreferredSize().height));

        return panel;
    }

    /**
     * Adds FeaturePointListPanel to the currently builded panel with selected
     * elements.
     *
     * @param action ActionListener for the FeaturePointListPanel
     * @param fpoints DrawableFeaturePoints to be listed
     * @param colorIndicators adds color indicators if set to true
     * @param spinSliders adds color SpinSlider if set to true
     * @param values adds color value if set to true
     * @param info adds info button if set to true
     * @return this panel builder
     */
    public PanelBuilder addFeaturePointListPanel(ActionListener action, DrawableFeaturePoints fpoints, boolean colorIndicators, boolean spinSliders, boolean values, boolean info) {
        if (subPanelsDepth > 0) {
            subPanel.addFeaturePointListPanel(action, fpoints, colorIndicators, spinSliders, values, info);
            return this;
        }

        FeaturePointListPanel fpP = new FeaturePointListPanel();
        fpP.initCustom(action, fpoints, colorIndicators, spinSliders, values, info);

        updateInsets();
        panel.add(fpP, constraints);
        constraints.gridx += 1;

        lastComponent = fpP;

        return this;
    }

    /**
     * Adds sub panel inside a ScrollPane. This scrollpane is set to the size
     * given as a parameter.
     *
     * @param width width of the scroll pane
     * @param height height of the scroll pane
     * @return this panel builder
     */
    public PanelBuilder addScrollSubPanel(int width, int height) {
        if (subPanelsDepth == 0) {
            return this;
        }
        if (subPanelsDepth > 1) {
            subPanel.addScrollSubPanel(width, height);
            subPanelsDepth--;
            return this;
        }
        subPanelsDepth--;

        updateInsets();

        JPanel addedSubPanel = subPanel.build();

        JScrollPane scrollPane = new JScrollPane(addedSubPanel);

        scrollPane.setPreferredSize(new Dimension(width, height));

        panel.add(scrollPane, constraints);

        constraints.gridx += 1;

        lastComponent = addedSubPanel;

        return this;
    }

    /**
     * Adds sub panel inside a ScrollPane. This scrollpane is set to be the same
     * size as the panel inside it. ¨
     *
     * @return this panel builder
     */
    public PanelBuilder addScrollSubPanel() {
        if (subPanelsDepth == 0) {
            return this;
        }
        if (subPanelsDepth > 1) {
            subPanel.addScrollSubPanel();
            subPanelsDepth--;
            return this;
        }
        subPanelsDepth--;

        updateInsets();

        JPanel addedSubPanel = subPanel.build();

        JScrollPane scrollPane = new JScrollPane(addedSubPanel);

        scrollPane.setPreferredSize(new Dimension(subPanel.getPrefferedSize().width
                + scrollPane.getVerticalScrollBar().getPreferredSize().width,
                subPanel.getPrefferedSize().height
                + scrollPane.getVerticalScrollBar().getPreferredSize().height));

        panel.add(scrollPane, constraints);

        constraints.gridx += 1;

        lastComponent = addedSubPanel;

        return this;
    }

    /**
     * Adds custom panel to the currently builded panel.
     *
     * @param panel custom panel
     * @return this panel builder
     */
    public PanelBuilder addPanel(JPanel panel) {
        if (subPanelsDepth > 0) {
            subPanel.addPanel(panel);
            return this;
        }

        updateInsets();
        this.panel.add(panel, constraints);
        constraints.gridx += 1;

        lastComponent = panel;

        return this;
    }

    /**
     * Adds text area to the builded panel spanning given rows and columns.
     *
     * @param rows desired number of rows for the text area
     * @param columns desired number of columns for the text area
     * @return
     */
    public PanelBuilder addTextArea(int rows, int columns) {
        if (subPanelsDepth > 0) {
            subPanel.addTextArea(rows, columns);
            return this;
        }
        JTextArea tArea = new JTextArea(rows, columns);

        updateInsets();

        panel.add(tArea, constraints);
        constraints.gridx += 1;

        lastComponent = tArea;

        return this;
    }

    /**
     * Adds color list panel to the currently builded panel.
     *
     * @param colors map representing description and colors
     * @param panelTitle Title of the panel
     * @return this panel builder
     */
    public PanelBuilder addColorListPanel(Map<String, Color> colors, String panelTitle) {
        if (subPanelsDepth > 0) {
            subPanel.addColorListPanel(colors, panelTitle);
            return this;
        }
        ColorListPanel colorPanel = new ColorListPanel(colors, panelTitle);

        updateInsets();

        panel.add(colorPanel, constraints);
        constraints.gridx += 1;

        lastComponent = colorPanel;

        return this;
    }

    private void updateInsets() {
        if (topPanel) {
            constraints.insets = new Insets(PanelBuilder.SUB_PANEL_INSETS, PanelBuilder.SUB_PANEL_INSETS, 0, 0);
@@ -942,15 +1254,15 @@ public class PanelBuilder {
    }

    /**
     * Limits maximum height of the panel to the current height and returns the
     * built panel.
     * Returns preffered size of the currently builded panel.
     *
     * @return created panel
     * @return preffered size
     */
    public JPanel build() {
        panel.setMaximumSize(new Dimension(Integer.MAX_VALUE, panel.getPreferredSize().height));

        return panel;
    public Dimension getPrefferedSize() {
        if (subPanelsDepth > 0) {
            return subPanel.getPrefferedSize();
        }
        return panel.getPreferredSize();
    }

}
+60 −0
Original line number Diff line number Diff line
package cz.fidentis.analyst.gui.elements;

import cz.fidentis.analyst.gui.builder.PanelBuilder;
import javax.swing.JPanel;
import java.awt.Color;
import java.awt.Dimension;
import java.util.Map;
import javax.swing.BorderFactory;
import javax.swing.JLabel;

/**
 * Simple GUI element for showcase of different colors and information about
 * them.
 *
 * @author Lukas Machalek
 */
public class ColorListPanel extends JPanel {

    /**
     * Constructor
     *
     * @param colors map representing description and colors
     * @param panelTitle Title of the panel
     */
    public ColorListPanel(Map<String, Color> colors, String panelTitle) {

        PanelBuilder builder = new PanelBuilder(this);
        builder.setPanelBorder(panelTitle)
                .setLeftInset(8)
                .setTopInset(4);

        colors.forEach((description, color) -> {
            addRow(builder, color, description);
        });
    }

    /**
     * Adds row with color label and description
     *
     * @param builder builder of this panel
     * @param color color to be shown
     * @param description description of given color
     */
    private void addRow(PanelBuilder builder, Color color, String description) {
        JLabel colorLabel = new JLabel();

        colorLabel.setBorder(BorderFactory.createLineBorder(Color.GRAY, 1));
        colorLabel.setOpaque(true);
        colorLabel.setBackground(color);
        colorLabel.setForeground(Color.GRAY);

        colorLabel.setPreferredSize(new Dimension(15, 15));

        builder.addLabel(colorLabel);

        builder.addLabel(description);
        builder.nextLine();
    }

}
+398 −0

File added.

Preview size limit exceeded, changes collapsed.

+4 −0
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@ import cz.fidentis.analyst.toolbar.SceneToolboxFaceToFace;
import cz.fidentis.analyst.toolbar.SceneToolboxSingleFace;
import cz.fidentis.analyst.gui.task.curvature.CurvatureAction;
import cz.fidentis.analyst.gui.task.distance.DistanceAction;
import cz.fidentis.analyst.gui.task.distance.DistanceActionBuilder;
import cz.fidentis.analyst.gui.task.registration.RegistrationAction;
import cz.fidentis.analyst.rendering.Camera;
import cz.fidentis.analyst.gui.task.symmetry.CuttingPlanesAction;
@@ -13,6 +14,7 @@ import cz.fidentis.analyst.gui.task.symmetry.SymmetryAction;
import cz.fidentis.analyst.gui.task.featurepoints.FeaturePointsAction;
import cz.fidentis.analyst.project.FacesProxy;
import cz.fidentis.analyst.gui.task.faceinfo.FaceOverviewAction;
import cz.fidentis.analyst.gui.task.featurepoints.FeaturePointsActionBuilder;
import cz.fidentis.analyst.gui.task.interactivemask.InteractiveMaskAction;
import cz.fidentis.analyst.rendering.Scene;
import java.awt.event.ActionEvent;
@@ -243,12 +245,14 @@ public class TaskWindow extends TopComponent {
                new SymmetryAction(getCanvas(), faces, controlPanel);
                new CuttingPlanesAction(getCanvas(), faces, controlPanel);
                new FeaturePointsAction(getCanvas(), faces, controlPanel);
                new FeaturePointsActionBuilder(getCanvas(), faces, controlPanel);
                new FaceOverviewAction(getCanvas(), faces, controlPanel, 0);
                new InteractiveMaskAction(getCanvas(), faces, controlPanel);
                break;
            case 2:
                new RegistrationAction(canvas, faces, controlPanel).popup();
                new DistanceAction(canvas, faces, controlPanel);
                new DistanceActionBuilder(canvas, faces, controlPanel);
                new SymmetryAction(canvas, faces, controlPanel);
                new CuttingPlanesAction(canvas, faces, controlPanel);
                new FaceOverviewAction(getCanvas(), faces, controlPanel, 0);
+551 −0

File added.

Preview size limit exceeded, changes collapsed.

Loading