[MOBY-guts] biomoby commit
Paul Gordon
gordonp at dev.open-bio.org
Fri Feb 4 18:36:35 UTC 2011
gordonp
Fri Feb 4 13:36:35 EST 2011
Update of /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui
In directory dev.open-bio.org:/tmp/cvs-serv11955/src/main/ca/ucalgary/seahawk/gui
Modified Files:
MobyContentPane.java MobyContentGUI.java
Log Message:
Implemented 'Undo close tab' for Seahawk
moby-live/Java/src/main/ca/ucalgary/seahawk/gui MobyContentPane.java,1.34,1.35 MobyContentGUI.java,1.24,1.25
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobyContentPane.java,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -r1.34 -r1.35
--- /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobyContentPane.java 2011/02/03 21:50:50 1.34
+++ /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobyContentPane.java 2011/02/04 18:36:35 1.35
@@ -243,12 +243,12 @@
tabbedPane.getTabCount() > 1){
try{
if(currentIcon == null){
- tabbedPane.setIconAt(tabIndex, new CloseTabIcon());
+ tabbedPane.setIconAt(tabIndex, (new CloseTabIcon()).addCloseTabListener(getContentGUI()));
return;
}
// If there's a real (non-close-tab) single icon, add the close tab icon
if(!(currentIcon instanceof CloseTabIcon)){
- try{tabbedPane.setIconAt(tabIndex, new CloseTabIcon(currentIcon, TAB_ICON_SPACER));}
+ try{tabbedPane.setIconAt(tabIndex, (new CloseTabIcon(currentIcon, TAB_ICON_SPACER)).addCloseTabListener(getContentGUI()));}
catch(Exception e){e.printStackTrace();}
tabbedPane.setDisabledIconAt(tabIndex, currentIcon);
}
@@ -257,7 +257,7 @@
e.printStackTrace();
}
- } else{
+ } else{ //Don't display X widget (closer) unless it's the active tab
if(currentIcon != null && currentIcon instanceof CloseTabIcon){
tabbedPane.setIconAt(tabIndex, ((CloseTabIcon) currentIcon).getSecondIcon());
tabbedPane.setDisabledIconAt(tabIndex, ((CloseTabIcon) currentIcon).getSecondIcon());
@@ -982,7 +982,7 @@
int tabIndex = tabbedPane.indexOfComponent(this);
if(tabIndex > -1){
try{tabbedPane.setIconAt(tabIndex,
- new CloseTabIcon(failedIcon, TAB_ICON_SPACER));}
+ (new CloseTabIcon(failedIcon, TAB_ICON_SPACER)).addCloseTabListener(getContentGUI()));}
catch(Exception e){e.printStackTrace();
tabbedPane.setIconAt(tabIndex, failedIcon);}
}
@@ -1005,7 +1005,7 @@
int tabIndex = tabbedPane.indexOfComponent(this);
if(tabIndex > -1 && tabbedPane.getTabCount() > 1){
try{tabbedPane.setIconAt(tabIndex,
- new CloseTabIcon(loadedIcon, TAB_ICON_SPACER));}
+ (new CloseTabIcon(loadedIcon, TAB_ICON_SPACER)).addCloseTabListener(getContentGUI()));}
catch(Exception e){e.printStackTrace();
tabbedPane.setIconAt(tabIndex, loadedIcon);}
}
@@ -1476,7 +1476,7 @@
int tabIndex = tabbedPane.indexOfComponent(this);
if(tabIndex > -1){
try{tabbedPane.setIconAt(tabIndex,
- new CloseTabIcon(hourglassIcon, TAB_ICON_SPACER));}
+ (new CloseTabIcon(hourglassIcon, TAB_ICON_SPACER)).addCloseTabListener(getContentGUI()));}
catch(Exception e){e.printStackTrace();
tabbedPane.setIconAt(tabIndex, hourglassIcon);}
}
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobyContentGUI.java,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobyContentGUI.java 2011/02/03 21:47:57 1.24
+++ /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobyContentGUI.java 2011/02/04 18:36:35 1.25
@@ -37,7 +37,7 @@
* @author Paul Gordon (gordonp at ucalgary.ca)
*/
-public class MobyContentGUI extends JFrame implements ActionListener, ComponentListener, KeyListener, MobyRequestEventHandler, MouseListener, FontSizeChangeListener, ArgumentListener{
+public class MobyContentGUI extends JFrame implements ActionListener, ComponentListener, KeyListener, MobyRequestEventHandler, MouseListener, FontSizeChangeListener, ArgumentListener, CloseTabListener{
// Variables used to coordinate component finding with the unit test cases
public final static String BACK_BUTTON_NAME = "MCGbackButton";
@@ -63,9 +63,11 @@
public final static String DEFAULT_XSLT_CONVERTER_URL = "ca/ucalgary/seahawk/resources/moby2HTML.xsl";
public final static int MAX_TAB_NAME_LENGTH = 25;
public final static String CLIPBOARD_TAB_TOOLTIP = "Right-click for clipboard options";
- public final static String TAB_TOOLTIP = "Right-click for tab options, or Ctrl-T for new tab";
+ public final static String TAB_TOOLTIP = "Right-click tabs for options, or Ctrl-T for new tab";
public final static String CLOSE_TAB_OPTION = "Close This Tab";
public final static String CLOSE_OTHERS_OPTION = "Close Other Tabs";
+ public final static String UNDO_CLOSE_TAB_OPTION = "Undo Close Tab";
+ public final static String UNDO_CLOSE_TABS_OPTION = "Undo Close Tabs";
public final static String FILE_OPEN_OPTION = "Open File";
public final static String WEB_OPEN_OPTION = "Open Web Page";
@@ -96,6 +98,9 @@
private MobyContentHelpPane helpPane;
private DataFlowRecorder dataRecorder; // used for workflow export, etc.
private SeahawkOptionsGUI settingsGUI;
+ private java.util.List closedTabs;
+ private java.util.List closedTabTitles;
+ private java.util.List closedTabIcons;
private boolean setup;
private Map<Integer,MobyContentPane> request2tab;
@@ -231,7 +236,7 @@
// See OptionsTabbedPaneUI class definiton at the end of this file (overrides right-click behaviour)
tabbedPane.setUI(new OptionsTabbedPaneUI(this));
tabbedPane.setSize(getContentSize());
- tabbedPane.setToolTipText("Hit <Control-T> to display a new tab");
+ tabbedPane.setToolTipText(TAB_TOOLTIP);
tabbedPane.addKeyListener(this);
try{
@@ -249,6 +254,10 @@
tabbedPane.add(clipboard);
clipboard.init();
+ closedTabs = new ArrayList();
+ closedTabTitles = new ArrayList();
+ closedTabIcons = new ArrayList();
+
settingsGUI = new SeahawkOptionsGUI(this, this); // params are frame owner, font change listener
}
@@ -1015,9 +1024,33 @@
// Don't close clipboard, if somehow we were asked...
}
else{
+ closedTabs.add(tabbedPane.getComponentAt(activeTabIndex));
+ closedTabTitles.add(tabbedPane.getTitleAt(activeTabIndex));
+ closedTabIcons.add(tabbedPane.getIconAt(activeTabIndex));
tabbedPane.remove(activeTabIndex);
}
}
+ else if(UNDO_CLOSE_TAB_OPTION.equals(cmd)){
+ Object lastClose = closedTabs.get(closedTabs.size()-1);
+ if(lastClose instanceof java.util.List){ // Closed more than one tab last time
+ java.util.List tabsList = (java.util.List) lastClose;
+ java.util.List tabTitlesList = (java.util.List) closedTabTitles.get(closedTabTitles.size()-1);
+ java.util.List tabIconsList = (java.util.List) closedTabIcons.get(closedTabIcons.size()-1);
+ for(int i = 0; i < tabsList.size(); i++){
+ tabbedPane.addTab((String) tabTitlesList.get(i),
+ (Icon) tabIconsList.get(i),
+ (Component) tabsList.get(i));
+ }
+ }
+ else{ // Single tab being unclosed
+ tabbedPane.addTab((String) closedTabTitles.get(closedTabTitles.size()-1),
+ (Icon) closedTabIcons.get(closedTabIcons.size()-1),
+ (Component) lastClose);
+ }
+ closedTabs.remove(closedTabs.size()-1); // no longer in close history
+ closedTabTitles.remove(closedTabTitles.size()-1); // no longer in close history
+ closedTabIcons.remove(closedTabIcons.size()-1); // no longer in close history
+ }
else if(MobyContentClipboard.CLEAR_CLIPBOARD_OPTION.equals(cmd)){
clipboard.clearData();
}
@@ -1027,13 +1060,32 @@
return;
}
Component keeper = tabbedPane.getComponentAt(activeTabIndex);
+ ArrayList otherTabs = new ArrayList();
+ ArrayList otherTabTitles = new ArrayList();
+ ArrayList otherTabIcons = new ArrayList();
for(int i = 0; i < tabbedPane.getTabCount(); i++){
Component comp = tabbedPane.getComponentAt(i);
- if(comp != keeper && comp != clipboard){
+ if(comp != keeper && comp != clipboard){
+ // This is slightly lazy, we could actually destroy the component
+ // and save the tab's history rather than put the component in the history.
+ // If memory becomes an issue, this would be a place to start saving...
+ otherTabs.add(comp);
+ otherTabTitles.add(tabbedPane.getTitleAt(i));
+ otherTabIcons.add(tabbedPane.getIconAt(i));
tabbedPane.remove(comp);
i--;
}
}
+ if(otherTabs.size() == 1){ // Was it just one tab?
+ closedTabs.add(otherTabs.get(0));
+ closedTabTitles.add(otherTabTitles.get(0));
+ closedTabIcons.add(otherTabIcons.get(0));
+ }
+ else{
+ closedTabs.add(otherTabs);
+ closedTabTitles.add(otherTabTitles);
+ closedTabIcons.add(otherTabIcons);
+ }
}
else{
logger.warn(getClass().getName() + " ignoring unrecognized action command: " + cmd);
@@ -1139,8 +1191,8 @@
tabOptions.add(item);
}
else if(tabbedPane.getTabCount() > 1){
- item = new JMenuItem(MobyContentGUI.CLOSE_TAB_OPTION);
- item.setActionCommand(MobyContentGUI.CLOSE_TAB_OPTION);
+ item = new JMenuItem(CLOSE_TAB_OPTION);
+ item.setActionCommand(CLOSE_TAB_OPTION);
item.addActionListener(gui);
tabOptions.add(item);
}
@@ -1148,13 +1200,29 @@
if(tabbedPane.getComponentAt(index) == clipboard && tabbedPane.getTabCount() > 1 ||
tabbedPane.getTabCount() > 2 ||
tabbedPane.indexOfComponent(clipboard) == -1 && tabbedPane.getTabCount() >= 2){
- item = new JMenuItem(MobyContentGUI.CLOSE_OTHERS_OPTION);
- item.setActionCommand(MobyContentGUI.CLOSE_OTHERS_OPTION);
+ item = new JMenuItem(CLOSE_OTHERS_OPTION);
+ item.setActionCommand(CLOSE_OTHERS_OPTION);
item.addActionListener(gui);
tabOptions.add(item);
}
-
- tabOptions.show(gui, e.getX(), e.getY());
+ item = new JMenuItem(UNDO_CLOSE_TAB_OPTION);
+ item.setActionCommand(UNDO_CLOSE_TAB_OPTION);
+ if(closedTabs.isEmpty()){
+ item.setEnabled(false); // show just so they know this is an option later...
+ }
+ else{
+ item.addActionListener(gui);
+ // more than one tab closed last time
+ if(closedTabs.get(closedTabs.size()-1) instanceof java.util.List){
+ System.err.println("Set unclose tabS");
+ item.setText(UNDO_CLOSE_TABS_OPTION);
+ }
+ // else nothing more needs to be done, the default menu
+ // label for the task to reopen just one tab
+ }
+ tabOptions.add(item);
+
+ tabOptions.show(gui, e.getX()+7, e.getY()+12);
}
else{
// Otherwise do whatever this handler normally does
@@ -1342,4 +1410,11 @@
((MobyContentPane) tabbedPane.getComponentAt(i)).setFontSize(fontSize);
}
}
+
+ public void tabClosing(Component closingTab){
+ closedTabs.add(closingTab);
+ int closingTabIndex = tabbedPane.indexOfComponent(closingTab);
+ closedTabTitles.add(tabbedPane.getTitleAt(closingTabIndex));
+ closedTabIcons.add(tabbedPane.getIconAt(closingTabIndex));
+ }
}
More information about the MOBY-guts
mailing list