[MOBY-guts] biomoby commit

Paul Gordon gordonp at dev.open-bio.org
Thu Feb 3 21:52:05 UTC 2011


gordonp
Thu Feb  3 16:52:05 EST 2011
Update of /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui
In directory dev.open-bio.org:/tmp/cvs-serv20606/src/main/ca/ucalgary/seahawk/gui

Modified Files:
	SeahawkOptionsGUI.java 
Log Message:
Added support for disabling highlight-while-typing (may cause freezing), and font resizing
moby-live/Java/src/main/ca/ucalgary/seahawk/gui SeahawkOptionsGUI.java,1.6,1.7
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/SeahawkOptionsGUI.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/SeahawkOptionsGUI.java	2007/12/06 18:47:31	1.6
+++ /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/SeahawkOptionsGUI.java	2011/02/03 21:52:05	1.7
@@ -34,8 +34,12 @@
     private JTextField converterPortTextField;
     private JTextField cacheExpiryTextField;
     private JFileChooser cacheDirFileChooser;
+    private JComboBox fontComboBox;
+    private String[] fontSizes = new String[]{"50%","75%","90%","100%","110%","125%","150%","200%"}; 
+    private FontSizeChangeListener fontSizeChangeListener;
 
     private JCheckBox sendReferrerCheckBox;
+    private JCheckBox filterInteractiveCheckBox;
 
     private JButton resetButton;
     private JButton okButton;
@@ -49,14 +53,15 @@
     /**
      * @param owner the frame that launches this dialog
      */
-    public SeahawkOptionsGUI(Frame owner){
+    public SeahawkOptionsGUI(Frame owner, FontSizeChangeListener listener){
         super(owner, DIALOG_TITLE, DIALOG_MODAL);
 
         // Custom handling of window close operation
         setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
         addWindowListener(this);
+	fontSizeChangeListener = listener;
 
-        // The dreaded GridBagLayout...
+        // The dreaded GridBagLayout...see http://madbean.com/anim/totallygridbag/
         GridBagLayout gridbag = new GridBagLayout();
         GridBagConstraints c = new GridBagConstraints();
         c.fill = GridBagConstraints.BOTH;
@@ -72,6 +77,16 @@
         registryNames[i] = CUSTOM_REGISTRY_SYNONYM;
 
         c.insets = new Insets(3,2,3,2);
+
+	// Font size widget
+	
+        //........................................
+	//c.gridx = 0;
+        //c.gridy = 4;
+        //c.gridwidth = 5;
+        //JSeparator line = new JSeparator();
+        //add(line, c);
+
         //........................................
         
         c.gridwidth = 2;
@@ -185,20 +200,50 @@
         //........................................
         c.gridx = 0;
         c.gridy = 7;
-        c.gridwidth = 4;
+        c.gridwidth = 2;
         c.gridheight = 1;
         sendReferrerCheckBox = new JCheckBox("Send referrer data to services");
         add(sendReferrerCheckBox, c);
+	c.gridx = 2;
+        c.gridwidth = 2;
+        c.gridheight = 1;
+        filterInteractiveCheckBox = new JCheckBox("Highlight filter matches while typing");
+        add(filterInteractiveCheckBox, c);
 
         //........................................
+	c.gridx = 0;
         c.gridy = 8;
         c.gridwidth = 5;
         line = new JSeparator();
         add(line, c);
 
-        //........................................
+        c.gridx = 0;
         c.gridy = 9;
         c.gridwidth = 2;
+        c.weightx = 0.0;
+        c.weighty = 0.0;
+        c.fill = GridBagConstraints.HORIZONTAL;
+        label = new JLabel("Document Font Size:", JLabel.RIGHT);
+        add(label, c);
+	c.gridx = 2;
+	c.gridwidth = 1;
+
+	adjustFontSizesIfNecessary();
+        fontComboBox = new JComboBox(fontSizes);
+	fontComboBox.setSelectedItem(SeahawkOptions.getFontSize()); // do this here to avoid unnecessary callback
+        fontComboBox.addActionListener(this);
+        add(fontComboBox, c);	
+
+        //........................................
+        c.gridx = 0;
+	c.gridy = 10;
+	c.gridwidth = 5;
+        line = new JSeparator();
+        add(line, c);
+
+	c.gridy = 11;
+	c.gridx = 0;
+        c.gridwidth = 2;
         label = new JLabel("Cache expiry (in hours)", JLabel.RIGHT);
         add(label, c);
 
@@ -232,10 +277,54 @@
 	pack();
     }
 
+    // If the value of the user preferred font size is not one of the standard presets 
+    // (e.g. they set it manually in the config file), 
+    // add that custom value to the list of options.
+    private void adjustFontSizesIfNecessary(){
+	String currentFontSize = SeahawkOptions.getFontSize();
+	double currentSizeDouble = convertFontSizeToDouble(currentFontSize);
+	for(String presetChoice: fontSizes){
+	    if(convertFontSizeToDouble(presetChoice) == currentSizeDouble){
+		SeahawkOptions.setFontSize(presetChoice); // avoids confusion in parts of app looking for 100%, not 100.000% etc.
+		return; // it's an existing choice
+	    }
+	}
+
+	// If we got here, it's a custom value
+	System.err.println("Inserting custom value (" + currentFontSize + ") into font size choices");
+	String[] newFontSizes = new String[fontSizes.length+1];
+	// Insertion of custom value into ordered presets list assumes existing font sizes and ordered small to large
+	boolean customValuePlaced = false;
+	for(int i = 0; i < fontSizes.length; i++){
+	    if(customValuePlaced){
+		newFontSizes[i+1] = fontSizes[i];
+	    }
+	    else if(currentSizeDouble < convertFontSizeToDouble(fontSizes[i])){
+		newFontSizes[i] = currentFontSize;
+		customValuePlaced = true;
+		i--;
+	    }
+	    else{
+		newFontSizes[i] = fontSizes[i];  // verbatim 'cause custom value not encountered yet
+	    }
+	}
+	// Bigger than any preset? append to new list
+	if(!customValuePlaced){
+	    newFontSizes[fontSizes.length] = currentFontSize;
+	}
+	fontSizes = newFontSizes;
+    }
+
+    // "100%" -> 100.0
+    private double convertFontSizeToDouble(String fontSize){
+	return Double.parseDouble(fontSize.substring(0, fontSize.length()-1)); // lop off % sign
+    }
+
     public void actionPerformed(ActionEvent event){
 	Object source = event.getSource();
 	if(source == cancelButton){
 	    setCurrentValues();
+	    updateDocumentFont(SeahawkOptions.getFontSize());
 	    setVisible(false);
 	}
 	else if(source == okButton){
@@ -257,6 +346,9 @@
 	else if(source == registryComboBox){
 	    updateRegistryFields();
 	}
+	else if(source == fontComboBox){
+	    updateDocumentFont(fontComboBox.getSelectedItem().toString());
+	}
     }
     
     /**
@@ -279,8 +371,9 @@
 	converterHostTextField.setText(""+SeahawkOptions.getDocConverterHost());
 	converterPortTextField.setText(""+SeahawkOptions.getDocConverterPort());
 	sendReferrerCheckBox.setSelected(SeahawkOptions.getSendReferrerPolicy());
+	filterInteractiveCheckBox.setSelected(SeahawkOptions.isFilterInteractive());
 	cacheExpiryTextField.setText(""+SeahawkOptions.getCacheExpiry());
-	cacheDirFileChooser.setSelectedFile(SeahawkOptions.getTempDir());
+	cacheDirFileChooser.setSelectedFile(SeahawkOptions.getTempDir());	
     }
 
     private void saveSettings(){
@@ -350,6 +443,15 @@
 	SeahawkOptions.setDocConverterHost(converterHostTextField.getText().trim());
 	SeahawkOptions.setSendReferrerPolicy(sendReferrerCheckBox.isSelected());
 	SeahawkOptions.setCacheExpiry(expiry);
+	if(filterInteractiveCheckBox.isSelected() != SeahawkOptions.isFilterInteractive()){
+	    JOptionPane.showMessageDialog(null, 
+					  "Please restart Seahawk to fully apply the filter behaviour change.", 
+					  "Filter behaviour change requires restart", 
+					  JOptionPane.INFORMATION_MESSAGE);
+	}
+	SeahawkOptions.setFilterInteractive(filterInteractiveCheckBox.isSelected());
+	SeahawkOptions.setFontSize(fontComboBox.getSelectedItem().toString());
+	updateDocumentFont(fontComboBox.getSelectedItem().toString());
 
 	// Saves the new values to a file, so they will perpetuate themselves between sessions
 	if(!SeahawkOptions.saveSettings()){
@@ -377,6 +479,12 @@
 	setVisible(false);
     }
 
+    private void updateDocumentFont(String fontSize){
+	if(fontSizeChangeListener != null){
+	    fontSizeChangeListener.fontSizeChanged(fontSize);
+	}
+    }
+
     private void updateRegistryFields(){
 	// Update all the registry fields if the name switches
 	String selectedRegistryName = registryComboBox.getSelectedItem().toString();
@@ -446,7 +554,7 @@
       JFrame frame = new JFrame("test");
       frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
       
-      SeahawkOptionsGUI dialog = new SeahawkOptionsGUI(frame);
+      SeahawkOptionsGUI dialog = new SeahawkOptionsGUI(frame, null);
       
       frame.pack();
       frame.setVisible(true);




More information about the MOBY-guts mailing list