Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/* AbstractGraphPanel
*
* created: 2010
*
* This file is part of Artemis
*
* Copyright(C) 2010 Genome Research Limited
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or(at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
package uk.ac.sanger.artemis.components.alignment;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JTextField;
public class AbstractGraphPanel extends JPanel
{
private static final long serialVersionUID = 1L;
protected int start;
protected int end;
protected float pixPerBase;
protected boolean autoWinSize = true;
protected int userWinSize = 1;
protected JPopupMenu popup = new JPopupMenu();
public void initPopupMenu(final JPanel graphPanel)
{
final JMenuItem setScale = new JMenuItem("Set the Window Size...");
setScale.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent _)
{
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
JPanel pane = new JPanel(gridbag);
final JTextField newWinSize = new JTextField(Integer.toString(userWinSize), 10);
final JLabel lab = new JLabel("Window size:");
c.gridy = 0;
pane.add(lab, c);
pane.add(newWinSize, c);
final JCheckBox autoSet = new JCheckBox("Automatically set window size", false);
autoSet.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
lab.setEnabled(!autoSet.isSelected());
newWinSize.setEnabled(!autoSet.isSelected());
}
});
c.gridy = 1;
c.gridwidth = GridBagConstraints.REMAINDER;
pane.add(autoSet, c);
String window_options[] = { "OK", "Cancel" };
int select = JOptionPane.showOptionDialog(null, pane, "Window Size",
JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null,
window_options, window_options[0]);
if (select == 1)
return;
autoWinSize = autoSet.isSelected();
try
{
userWinSize = Integer.parseInt(newWinSize.getText().trim());
}
catch (NumberFormatException nfe)
{
return;
}
graphPanel.repaint();
}
});
popup.add(setScale);
addMouseListener(new PopupListener());
}
protected void setStartAndEnd(int start, int end)
{
this.start = start;
this.end = end;
}
protected void setPixPerBase(float pixPerBase)
{
this.pixPerBase = pixPerBase;
}
/**
* Popup menu listener
*/
class PopupListener extends MouseAdapter
{
JMenuItem gotoMateMenuItem;
JMenuItem showDetails;
public void mouseClicked(MouseEvent e)
{
}
public void mousePressed(MouseEvent e)
{
maybeShowPopup(e);
}
public void mouseReleased(MouseEvent e)
{
maybeShowPopup(e);
}
private void maybeShowPopup(MouseEvent e)
{
if(e.isPopupTrigger())
{
popup.show(e.getComponent(),
e.getX(), e.getY());
}
}
}
}