[range_selection
douglas@music.columbia.edu**20061202224002
 
 Added a range selection control.
 
 
] {
hunk ./src/com/meapsoft/visualizer/Renderer.java 18
+import javax.swing.JComboBox;
hunk ./src/com/meapsoft/visualizer/Renderer.java 21
+import javax.swing.JTextField;
hunk ./src/com/meapsoft/visualizer/Renderer.java 60
+	
+	JComboBox featureSelector;
+	JTextField rangeInput;
hunk ./src/com/meapsoft/visualizer/Renderer.java 79
-	//String[] optionBoxStrings;
hunk ./src/com/meapsoft/visualizer/Renderer.java 80
-	//boolean linear = true;
-	//boolean sqrt = false;
-	//boolean square = false;
-	
-	final static int LINEAR = 0;
-	final static int SQRT = 1;
-	final static int SQUARE = 2;
-	
-	//static int colorMapType = LINEAR;
+//	final static int LINEAR = 0;
+//	final static int SQRT = 1;
+//	final static int SQUARE = 2;
hunk ./src/com/meapsoft/visualizer/Renderer.java 373
-		selectionPanel.setLayout(new BoxLayout(selectionPanel, BoxLayout.Y_AXIS));
+		//selectionPanel.setLayout(new BoxLayout(selectionPanel, BoxLayout.Y_AXIS));
+		
+		JPanel clickedSelectorPanel = new JPanel();
+		clickedSelectorPanel.setBackground(bgColor);
+		clickedSelectorPanel.setLayout(new BoxLayout(clickedSelectorPanel, BoxLayout.Y_AXIS));
hunk ./src/com/meapsoft/visualizer/Renderer.java 381
-		selectionPanel.add(selectionLabel);
+		clickedSelectorPanel.add(selectionLabel);
hunk ./src/com/meapsoft/visualizer/Renderer.java 387
-		selectionPanel.add(selectAllButton);
+		clickedSelectorPanel.add(selectAllButton);
hunk ./src/com/meapsoft/visualizer/Renderer.java 393
-		selectionPanel.add(selectNoneButton);
+		clickedSelectorPanel.add(selectNoneButton);
hunk ./src/com/meapsoft/visualizer/Renderer.java 397
-		toggleAllButton.setActionCommand("toggleAll");
+		toggleAllButton.setActionCommand("invertAll");
hunk ./src/com/meapsoft/visualizer/Renderer.java 399
-		selectionPanel.add(toggleAllButton);
+		clickedSelectorPanel.add(toggleAllButton);
+		
+		selectionPanel.add(clickedSelectorPanel);
+		
+		JPanel rangeSelectorPanel = new JPanel();
+		rangeSelectorPanel.setBackground(bgColor);
+		rangeSelectorPanel.setLayout(new BoxLayout(rangeSelectorPanel, BoxLayout.Y_AXIS));
+		
+		updateOptionBoxStrings();
+		
+		featureSelector = new JComboBox(optionBoxStrings);
+		featureSelector.setBackground(bgColor);
+		rangeSelectorPanel.add(featureSelector);
+		
+		rangeInput = new JTextField("0.00:1.00");
+		rangeInput.setBackground(bgColor);
+		rangeSelectorPanel.add(rangeInput);
+		
+		JButton selectRangeButton = new JButton("invert range");
+		selectRangeButton.setBackground(bgColor);
+		selectRangeButton.setActionCommand("invertRange");
+		selectRangeButton.addActionListener(this);
+		rangeSelectorPanel.add(selectRangeButton);
+		
+		selectionPanel.add(rangeSelectorPanel);
hunk ./src/com/meapsoft/visualizer/Renderer.java 587
-		else if (command.equals("toggleAll"))
+		else if (command.equals("invertAll"))
hunk ./src/com/meapsoft/visualizer/Renderer.java 596
+		}
+		else if (command.equals("invertRange"))
+		{
+			String[] numbers = rangeInput.getText().split(":");
+			int whichFeature = featureSelector.getSelectedIndex();
+			double low = 0.0;
+			double high = 0.0;
+			
+			try
+			{
+				low = new Double(numbers[0]).doubleValue();
+				high = new Double(numbers[1]).doubleValue();
+			}
+			catch(java.lang.NumberFormatException e)
+			{
+				System.out.println("Please use the form 0.00:1.00 to indicate a selection range.");
+				return;
+			}
+			
+			
+			//System.out.println("range: " + low + " to " + high);
+			
+			//make sure we're in the right order, in case they enter
+			//something like 0.00:-5.0
+			if (low > high)
+			{
+				double tempLow = high;
+				high = low;
+				low = tempLow;
+			}
+			
+			int numEvents = events.size();
+			
+			for (int i = 0; i < numEvents; i++)
+			{
+				ChunkVisInfo cVI = (ChunkVisInfo)events.elementAt(i);
+				if (whichFeature == 0)
+				{
+					if (cVI.startTime >= low && cVI.startTime <= high)
+						cVI.selected = !cVI.selected;
+				}
+				else if (whichFeature == 1)
+				{
+					if (cVI.dstTime >= low && cVI.dstTime <= high)
+						cVI.selected = !cVI.selected;
+				}
+				else if (whichFeature == 2)
+				{
+					if (cVI.length >= low && cVI.length <= high)
+						cVI.selected = !cVI.selected;
+				}
+				else if (whichFeature >= 3)
+				{
+					int which = whichFeature - 3;
+					int featNum[] = {0};
+					
+					for (int j = 0; j < which; j++)
+						featNum[0] += elementsPerFeature[j];
+									
+					double features[] = cVI.getFeatures(featNum);
+					
+					if (features[0] >= low && features[0] <= high)
+						cVI.selected = !cVI.selected;
+				}		
+			
+			}
}
