import jalview.api.analysis.SimilarityParamsI;
import jalview.util.MessageManager;
+import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
+import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridLayout;
+import java.awt.Insets;
import java.awt.event.ActionEvent;
-import java.awt.event.ItemEvent;
-import java.awt.event.ItemListener;
+import java.awt.event.ActionListener;
+import java.awt.event.FocusEvent;
+import java.awt.event.FocusListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.beans.PropertyVetoException;
import java.util.ArrayList;
import java.util.List;
+import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JLayeredPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
+import javax.swing.event.InternalFrameAdapter;
+import javax.swing.event.InternalFrameEvent;
/**
* A dialog where a user can choose and action Tree or PCA calculation options
JRadioButton pca;
- JRadioButton tree;
-
JRadioButton neighbourJoining;
JRadioButton averageDistance;
JComboBox<String> modelNames;
- private JInternalFrame frame;
+ JButton ok;
- private ButtonGroup treeTypes;
+ private JInternalFrame frame;
private JCheckBox includeGaps;
{
this.af = alignFrame;
init();
+ af.alignPanel.setCalculationDialog(this);
}
/**
*/
void init()
{
+ setLayout(new BorderLayout());
frame = new JInternalFrame();
frame.setContentPane(this);
this.setBackground(Color.white);
/*
- * Layout consists of 4 or 5 panels:
- * - first with choice of Tree or PCA
- * - second with choice of tree method NJ or AV
- * - third with choice of score model
- * - fourth with score model parameter options [suppressed]
- * - fifth with OK and Cancel
+ * Layout consists of 3 or 4 panels:
+ * - first with choice of PCA or tree method NJ or AV
+ * - second with choice of score model
+ * - third with score model parameter options [suppressed]
+ * - fourth with OK and Cancel
*/
- tree = new JRadioButton(MessageManager.getString("label.tree"));
- tree.setOpaque(false);
pca = new JRadioButton(
MessageManager.getString("label.principal_component_analysis"));
pca.setOpaque(false);
MessageManager.getString("label.tree_calc_nj"));
averageDistance = new JRadioButton(
MessageManager.getString("label.tree_calc_av"));
- ItemListener listener = new ItemListener()
+ neighbourJoining.setOpaque(false);
+
+ JPanel calcChoicePanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
+ calcChoicePanel.setOpaque(false);
+
+ // first create the Tree calculation's border panel
+ JPanel treePanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
+ treePanel.setOpaque(false);
+
+ treePanel.setBorder(BorderFactory.createTitledBorder(MessageManager
+ .getString("label.tree")));
+
+ // then copy the inset dimensions for the border-less PCA panel
+ JPanel pcaBorderless = new JPanel(new FlowLayout(FlowLayout.LEFT));
+ Insets b = treePanel.getBorder().getBorderInsets(treePanel);
+ pcaBorderless.setBorder(BorderFactory.createEmptyBorder(2, b.left, 2,
+ b.right));
+ pcaBorderless.setOpaque(false);
+
+ pcaBorderless.add(pca, FlowLayout.LEFT);
+ calcChoicePanel.add(pcaBorderless, FlowLayout.LEFT);
+
+
+ treePanel.add(neighbourJoining);
+ treePanel.add(averageDistance);
+
+ calcChoicePanel.add(treePanel);
+
+ ButtonGroup calcTypes = new ButtonGroup();
+ calcTypes.add(pca);
+ calcTypes.add(neighbourJoining);
+ calcTypes.add(averageDistance);
{
@Override
public void itemStateChanged(ItemEvent e)
averageDistance.setEnabled(tree.isSelected());
}
};
- pca.addItemListener(listener);
- tree.addItemListener(listener);
- ButtonGroup calcTypes = new ButtonGroup();
- calcTypes.add(pca);
- calcTypes.add(tree);
- JPanel calcChoicePanel = new JPanel();
- calcChoicePanel.setOpaque(false);
- tree.setSelected(true);
- calcChoicePanel.add(tree);
- calcChoicePanel.add(pca);
-
- neighbourJoining.setOpaque(false);
- treeTypes = new ButtonGroup();
- treeTypes.add(neighbourJoining);
- treeTypes.add(averageDistance);
- neighbourJoining.setSelected(true);
- JPanel treeChoicePanel = new JPanel();
- treeChoicePanel.setOpaque(false);
- treeChoicePanel.add(neighbourJoining);
- treeChoicePanel.add(averageDistance);
/*
* score models drop-down - with added tooltips!
*/
modelNames = buildModelOptionsList();
- JPanel scoreModelPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
+ JPanel scoreModelPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
scoreModelPanel.setOpaque(false);
- scoreModelPanel.add(modelNames, FlowLayout.LEFT);
+ scoreModelPanel.add(modelNames);
/*
* score model parameters
actionPanel.add(cancel);
boolean includeParams = false;
- this.add(calcChoicePanel);
- this.add(treeChoicePanel);
- this.add(scoreModelPanel);
+ this.add(calcChoicePanel, BorderLayout.CENTER);
+ calcChoicePanel.add(scoreModelPanel);
if (includeParams)
{
- this.add(paramsPanel);
+ scoreModelPanel.add(paramsPanel);
}
- this.add(actionPanel);
+ this.add(actionPanel, BorderLayout.SOUTH);
int width = 350;
- int height = includeParams ? 400 : 220;
+ int height = includeParams ? 420 : 240;
+
+ setMinimumSize(new Dimension(325, height - 10));
+ String title = MessageManager.getString("label.choose_calculation");
+ if (af.getViewport().viewName != null)
+ {
+ title = title + " (" + af.getViewport().viewName + ")";
+ }
+
Desktop.addInternalFrame(frame,
- MessageManager.getString("label.choose_calculation"), width,
+ title, width,
height, false);
+ calcChoicePanel.doLayout();
+ revalidate();
+ /*
+ * null the AlignmentPanel's reference to the dialog when it is closed
+ */
+ frame.addInternalFrameListener(new InternalFrameAdapter()
+ {
+ @Override
+ public void internalFrameClosed(InternalFrameEvent evt)
+ {
+ af.alignPanel.setCalculationDialog(null);
+ };
+ });
frame.setLayer(JLayeredPane.PALETTE_LAYER);
}
}
/**
- * Open and calculate the selected tree on 'OK'
+ * Open and calculate the selected tree or PCA on 'OK'
*/
protected void ok_actionPerformed()
{
boolean doPCA = pca.isSelected();
- ScoreModelI sm = ScoreModels.getInstance().forName(
- modelNames.getSelectedItem().toString());
+ String modelName = modelNames.getSelectedItem().toString();
SimilarityParamsI params = getSimilarityParameters(doPCA);
if (doPCA)
{
- openPcaPanel(sm, params);
+ openPcaPanel(modelName, params);
}
else
{
- openTreePanel(sm, params);
+ openTreePanel(modelName, params);
}
// closeFrame();
/**
* Open a new Tree panel on the desktop
*
- * @param sm
+ * @param modelName
* @param params
*/
- protected void openTreePanel(ScoreModelI sm, SimilarityParamsI params)
+ protected void openTreePanel(String modelName, SimilarityParamsI params)
{
String treeType = neighbourJoining.isSelected() ? TreeBuilder.NEIGHBOUR_JOINING
: TreeBuilder.AVERAGE_DISTANCE;
- af.newTreePanel(treeType, sm, params);
+ af.newTreePanel(treeType, modelName, params);
}
/**
* Open a new PCA panel on the desktop
*
- * @param sm
+ * @param modelName
* @param params
*/
- protected void openPcaPanel(ScoreModelI sm, SimilarityParamsI params)
+ protected void openPcaPanel(String modelName, SimilarityParamsI params)
{
AlignViewport viewport = af.getViewport();
if (((viewport.getSelectionGroup() != null)
JvOptionPane.WARNING_MESSAGE);
return;
}
- new PCAPanel(af.alignPanel, sm, params);
+ new PCAPanel(af.alignPanel, modelName, params);
}
/**