From 70889ff334002372e84073f843e9b1fae70c0cfb Mon Sep 17 00:00:00 2001 From: jprocter Date: Wed, 24 Aug 2011 15:37:04 +0100 Subject: [PATCH] refactor labelled button creator to JvSwingUtils --- src/jalview/gui/JvSwingUtils.java | 51 +++++++++++++++++++++++++++++++++++ src/jalview/jbgui/GPreferences.java | 28 ++++--------------- 2 files changed, 56 insertions(+), 23 deletions(-) diff --git a/src/jalview/gui/JvSwingUtils.java b/src/jalview/gui/JvSwingUtils.java index 437f430..812353e 100644 --- a/src/jalview/gui/JvSwingUtils.java +++ b/src/jalview/gui/JvSwingUtils.java @@ -19,10 +19,15 @@ package jalview.gui; import java.awt.Color; import java.awt.Font; +import java.awt.Rectangle; import java.awt.event.ActionListener; import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JLabel; import javax.swing.JMenu; +import javax.swing.JPanel; +import javax.swing.JTextArea; import javax.swing.SwingConstants; /** @@ -97,4 +102,50 @@ public final class JvSwingUtils } + /** + * + * @param panel + * @param tooltip + * @param label + * @param valBox + * @return the GUI element created that was added to the layout so it's attributes can be changed. + */ + public static JPanel addtoLayout(JPanel panel, String tooltip, JComponent label, JComponent valBox) + { + JPanel laypanel = new JPanel(),labPanel=new JPanel(), valPanel=new JPanel(); + // laypanel.setSize(panel.getPreferredSize()); + // laypanel.setLayout(null); + labPanel.setBounds(new Rectangle(7, 7, 158, 23)); + valPanel.setBounds(new Rectangle(172, 7, 270,23)); + //labPanel.setLayout(new GridLayout(1,1)); + //valPanel.setLayout(new GridLayout(1,1)); + labPanel.add(label); + valPanel.add(valBox); + laypanel.add(labPanel); + laypanel.add(valPanel); + valPanel.setToolTipText(tooltip); + labPanel.setToolTipText(tooltip); + valBox.setToolTipText(tooltip); + panel.add(laypanel); + panel.validate(); + return laypanel; + } + + public static void mgAddtoLayout(JPanel cpanel, String tooltip, + JLabel jLabel, JComponent name) + { + mgAddtoLayout(cpanel, tooltip, jLabel, name,null); + } + public static void mgAddtoLayout(JPanel cpanel, String tooltip, + JLabel jLabel, JComponent name, String params) + { + cpanel.add(jLabel); + if (params==null) { + cpanel.add(name); + } else {cpanel.add(name, params); + } + name.setToolTipText(tooltip); + jLabel.setToolTipText(tooltip); + } + } diff --git a/src/jalview/jbgui/GPreferences.java b/src/jalview/jbgui/GPreferences.java index 9448065..1a1f9d3 100755 --- a/src/jalview/jbgui/GPreferences.java +++ b/src/jalview/jbgui/GPreferences.java @@ -17,6 +17,8 @@ */ package jalview.jbgui; +import jalview.gui.JvSwingUtils; + import java.awt.*; import java.awt.event.*; @@ -239,26 +241,6 @@ public class GPreferences extends JPanel protected JCheckBox followHighlight = new JCheckBox(); - public void addtoLayout(JPanel panel, String tooltip, JComponent label, JComponent valBox) - { - JPanel laypanel = new JPanel(),labPanel=new JPanel(), valPanel=new JPanel(); - // laypanel.setSize(panel.getPreferredSize()); - // laypanel.setLayout(null); - labPanel.setBounds(new Rectangle(7, 7, 158, 23)); - valPanel.setBounds(new Rectangle(172, 7, 270,23)); - //labPanel.setLayout(new GridLayout(1,1)); - //valPanel.setLayout(new GridLayout(1,1)); - labPanel.add(label); - valPanel.add(valBox); - laypanel.add(labPanel); - laypanel.add(valPanel); - valPanel.setToolTipText(tooltip); - labPanel.setToolTipText(tooltip); - valBox.setToolTipText(tooltip); - panel.add(laypanel); - panel.validate(); - - } /** * Creates a new GPreferences object. */ @@ -727,12 +709,12 @@ public class GPreferences extends JPanel tooltipSettings.add(showNpTooltip); visualTab.add(tooltipSettings); visualTab.add(jPanel2); - addtoLayout(visual2Tab, "Default Colourscheme for alignment", colourLabel, colour); + JvSwingUtils.addtoLayout(visual2Tab, "Default Colourscheme for alignment", colourLabel, colour); JPanel annotationShding=new JPanel(); annotationShding.setBorder(new TitledBorder("Annotation Shading Default")); annotationShding.setLayout(new GridLayout(1,2)); - addtoLayout(annotationShding, "Default Minimum Colour for annotation shading", mincolourLabel,minColour); - addtoLayout(annotationShding,"Default Maximum Colour for annotation shading", maxcolourLabel, maxColour); + JvSwingUtils.addtoLayout(annotationShding, "Default Minimum Colour for annotation shading", mincolourLabel,minColour); + JvSwingUtils.addtoLayout(annotationShding,"Default Maximum Colour for annotation shading", maxcolourLabel, maxColour); visual2Tab.add(annotationShding); // , FlowLayout.LEFT); // visual2panel.add(minColour); -- 1.7.10.2