[MOBY-guts] biomoby commit
Paul Gordon
gordonp at dev.open-bio.org
Sat Jun 16 00:27:44 UTC 2007
gordonp
Fri Jun 15 20:27:44 EDT 2007
Update of /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/util
In directory dev.open-bio.org:/tmp/cvs-serv29229/src/main/ca/ucalgary/seahawk/util
Modified Files:
CloseTabIcon.java
Log Message:
Changed code to ensure close action is only active when the close icon is displayed
moby-live/Java/src/main/ca/ucalgary/seahawk/util CloseTabIcon.java,1.1,1.2
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/util/CloseTabIcon.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/util/CloseTabIcon.java 2007/04/03 02:18:46 1.1
+++ /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/util/CloseTabIcon.java 2007/06/16 00:27:44 1.2
@@ -34,6 +34,10 @@
super(getIcon(), otherIcon, spacerWidth, orient);
}
+ public Rectangle getCloseIconArea(){
+ return closeIconArea;
+ }
+
public static Icon getIcon() throws Exception{
if(closeIcon == null){
URL u = Thread.currentThread().getContextClassLoader().getResource(CLOSE_TAB_ICON_RESOURCE);
@@ -57,19 +61,51 @@
return;
}
tabbedPane = (JTabbedPane) c;
- tabbedPane.addMouseListener(new MouseAdapter(){
- public void mouseReleased(MouseEvent e){
- // Did the user click in the close icon area?
- if(!e.isConsumed() && closeIconArea.contains(e.getX(), e.getY())){
- int tabIndex = tabbedPane.getSelectedIndex();
- tabbedPane.remove(tabIndex);
- e.consume(); // so other tabs aren't closed by mistake
- }
- }
- });
+ tabbedPane.addMouseListener(new Closer(this, tabbedPane));
}
// The close Icon is the first of the two. Note its area so we can check for mouse clicks later
closeIconArea = new Rectangle(x, y, getFirstIcon().getIconWidth(), getFirstIcon().getIconHeight());
}
+
+ class Closer extends MouseAdapter{
+ private CloseTabIcon icon;
+ private JTabbedPane tabbedPane;
+ private boolean active;
+
+ public Closer(CloseTabIcon cti, JTabbedPane tp){
+ icon = cti;
+ tabbedPane = tp;
+ active = false;
+ }
+
+ public void mousePressed(MouseEvent e){
+ if(!e.isConsumed() && getCloseIconArea() != null &&
+ getCloseIconArea().contains(e.getX(), e.getY()) &&
+ tabbedPane.getIconAt(tabbedPane.getSelectedIndex()) == icon){
+ active = true;
+ }
+ else{
+ active = false;
+ }
+ }
+
+ public void mouseReleased(MouseEvent e){
+ // Did the user click in the close icon area, when the icon was being displayed?
+ if(active && !e.isConsumed() && getCloseIconArea() != null &&
+ getCloseIconArea().contains(e.getX(), e.getY())){
+ int tabIndex = tabbedPane.getSelectedIndex();
+ if(tabIndex < 0){
+ return;
+ }
+ if(tabbedPane.getIconAt(tabIndex) != icon){
+ // Don't respond unless the close tab icon is actually showing
+ return;
+ }
+ tabbedPane.remove(tabIndex);
+ e.consume(); // so other tabs aren't closed by mistake
+ tabbedPane.removeMouseListener(this);
+ }
+ }
+ }
}
More information about the MOBY-guts
mailing list