cfa57c8c89d26fd14cad9575e03bc81d7f9dc899
[jalview.git] / src / jalview / jbgui / GAlignExportSettings.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.jbgui;
22
23 import jalview.io.FileFormatI;
24 import jalview.util.MessageManager;
25
26 import java.awt.BorderLayout;
27 import java.awt.event.ActionEvent;
28 import java.awt.event.ActionListener;
29 import java.awt.event.ItemEvent;
30 import java.awt.event.ItemListener;
31
32 import javax.swing.JButton;
33 import javax.swing.JCheckBox;
34 import javax.swing.JPanel;
35
36 @SuppressWarnings("serial")
37 public abstract class GAlignExportSettings extends JPanel
38 {
39   protected JPanel hiddenRegionConfPanel = new JPanel();
40
41   protected JPanel complexExportPanel = new JPanel();
42
43   protected JPanel optionsPanel = new JPanel();
44
45   protected JPanel actionPanel = new JPanel();
46
47   protected BorderLayout hiddenRegionLayout = new BorderLayout();
48
49   protected BorderLayout complexExportLayout = new BorderLayout();
50
51   protected BorderLayout mainLayout = new BorderLayout();
52
53   protected JCheckBox chkAll = new JCheckBox();
54
55   protected JCheckBox chkHiddenSeqs = new JCheckBox();
56
57   protected JCheckBox chkHiddenCols = new JCheckBox();
58
59   protected JCheckBox chkExportAnnots = new JCheckBox();
60
61   protected JCheckBox chkExportFeats = new JCheckBox();
62
63   protected JCheckBox chkExportGrps = new JCheckBox();
64
65   private boolean hasHiddenSeq, hasHiddenCols, isComplexAlignFile,
66           showDialog;
67
68   public GAlignExportSettings(boolean hasHiddenSeq, boolean hasHiddenCols,
69           FileFormatI format)
70   {
71     this.hasHiddenSeq = hasHiddenSeq;
72     this.hasHiddenCols = hasHiddenCols;
73     this.isComplexAlignFile = format.isComplexAlignFile();
74     if (this.hasHiddenCols || this.hasHiddenSeq || this.isComplexAlignFile)
75     {
76       this.showDialog = true;
77     }
78     init();
79   }
80
81   public void init()
82   {
83     chkHiddenSeqs.setText(
84             MessageManager.getString("action.export_hidden_sequences"));
85     chkHiddenCols.setText(
86             MessageManager.getString("action.export_hidden_columns"));
87     chkExportAnnots
88             .setText(MessageManager.getString("action.export_annotations"));
89     chkExportFeats
90             .setText(MessageManager.getString("action.export_features"));
91     chkExportGrps.setText(MessageManager.getString("action.export_groups"));
92     chkAll.setText(MessageManager.getString("action.select_all"));
93
94     hiddenRegionConfPanel.setLayout(hiddenRegionLayout);
95     complexExportPanel.setLayout(complexExportLayout);
96     setLayout(mainLayout);
97
98     chkAll.addItemListener(new ItemListener()
99     {
100       @Override
101       public void itemStateChanged(ItemEvent e)
102       {
103         checkAllAction();
104       }
105     });
106
107     // hiddenRegionConfPanel.add(chkAll, BorderLayout.NORTH);
108     hiddenRegionConfPanel.add(chkHiddenSeqs, BorderLayout.CENTER);
109     hiddenRegionConfPanel.add(chkHiddenCols, BorderLayout.SOUTH);
110     chkHiddenSeqs.setEnabled(hasHiddenSeq);
111     chkHiddenCols.setEnabled(hasHiddenCols);
112
113     complexExportPanel.add(chkExportAnnots, BorderLayout.NORTH);
114     complexExportPanel.add(chkExportFeats, BorderLayout.CENTER);
115     complexExportPanel.add(chkExportGrps, BorderLayout.SOUTH);
116
117     actionPanel.add(chkAll);
118
119     if (this.isComplexAlignFile)
120     {
121       optionsPanel.add(complexExportPanel);
122     }
123
124     if (hasHiddenSeq || hasHiddenCols)
125     {
126       optionsPanel.add(hiddenRegionConfPanel);
127     }
128
129     add(optionsPanel, BorderLayout.NORTH);
130     add(actionPanel, BorderLayout.SOUTH);
131
132   }
133
134   private void checkAllAction()
135   {
136     boolean isSelected = chkAll.isSelected();
137     chkHiddenSeqs.setSelected(chkHiddenSeqs.isEnabled() && isSelected);
138     chkHiddenCols.setSelected(chkHiddenCols.isEnabled() && isSelected);
139     chkExportAnnots.setSelected(isComplexAlignFile
140             && chkExportAnnots.isEnabled() && isSelected);
141     chkExportFeats.setSelected(
142             isComplexAlignFile && chkExportFeats.isEnabled() && isSelected);
143     chkExportGrps.setSelected(
144             isComplexAlignFile && chkExportGrps.isEnabled() && isSelected);
145   }
146
147   public boolean isShowDialog()
148   {
149     return showDialog;
150   }
151
152   public void setShowDialog(boolean showDialog)
153   {
154     this.showDialog = showDialog;
155   }
156
157   public abstract void ok_actionPerformed(ActionEvent e);
158
159   public abstract void cancel_actionPerformed(ActionEvent e);
160 }