This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[gui][PATCH] Couple fixes for JColorChooser and JTabbedPane


Hi,

This has a couple fixes for JColorChooser and JTabbedPane. The
JColorChooser's HSB panel should feel much quicker now.

Cheers,

Kim

2004-09-08  Kim Ho  <kho@redhat.com>

	* javax/swing/colorchooser/DefaultHSBChooserPanel.java:
	(stateChanged): Only update the image and the track if
	the values are not being adjusted.
	(updateChooser): Grab the new mouse point from the
	spinner values. Update the image and track only if 
	the values are not being adjusted. 
	(getHSBValues): New method.
	* javax/swing/colorchooser/DefaultRGBChooserPanel.java:
	(SliderHandler::stateChanged): Changed internalChange 
	to updateChange. Set sliderChange.
	(SpinnerHandler::stateChanged): Ditto. Set spinnerChange.
	(spinnerChange): New variable.
	(sliderChange): Ditto.
	(updateChange): Renamed from internalChange.
	(updateChooser): Do not update sliders if the sliders
	were the original source of the change. Ditto for spinners.
	* javax/swing/plaf/basic/BasicTabbedPaneUI.java:
	(mousePress): Don't scroll the JViewport if there will
	be extra space at the end of the run. Change layout() to
	revalidate().
	(calculateSize): Use the component's width/height unless
	it is smaller than the max tab width/height.
	(calculateTabRects): Subtract the tab run overlay.
	(rotateTabRuns): Don't rotate if there's only one run.
	(layoutContainer): Reuse the viewport point.
	(createLayoutManager): Set the viewport to use no layout.
	(paintTabArea): Don't paint the tabs that are not visible
	to the JViewport.
	(paintContentBorderTopEdge): Check for scroll tab layout before
	looking for gap.
	(paintContentBorderLeftEdge): Ditto.
	(paintContentBorderBottomEdge): Ditto.
	(paintContentBorderRightEdge): Ditto.
	

	
? javax/swing/colorchooser/.DefaultHSBChooserPanel.java.swp
? javax/swing/colorchooser/.DefaultRGBChooserPanel.java.swp
? javax/swing/colorchooser/DefaultHSBChooserPanel.java.back
? javax/swing/plaf/basic/.BasicTabbedPaneUI.java.swp
Index: javax/swing/colorchooser/DefaultHSBChooserPanel.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/colorchooser/DefaultHSBChooserPanel.java,v
retrieving revision 1.1.2.1
diff -u -r1.1.2.1 DefaultHSBChooserPanel.java
--- javax/swing/colorchooser/DefaultHSBChooserPanel.java	25 Aug 2004 21:49:48 -0000	1.1.2.1
+++ javax/swing/colorchooser/DefaultHSBChooserPanel.java	9 Sep 2004 02:28:27 -0000
@@ -377,7 +377,7 @@
                                                                          b)));
       spinnerTrigger = false;
 
-      if (! handlingMouse)
+      if (! handlingMouse && slider != null && ! slider.getValueIsAdjusting())
         {
 	  updateImage();
 	  updateTrack();
@@ -419,11 +419,6 @@
 
     internalChange = true;
 
-    // spinnerTrigger, internalChange, and handlingMouse are used because of the
-    // we don't want things like: change spinner -> update chooser -> change spinner
-    // That's because the value from before and after the update can differ
-    // slightly because of the conversion.
-    // FIXME: Think of better way to deal with this.
     if (! spinnerTrigger)
       {
 	hSpinner.setValue(new Integer((int) (hsbVals[0] * 360)));
@@ -438,8 +433,10 @@
 	  slider.setValue(((Number) hSpinner.getValue()).intValue());
 	if (! handlingMouse)
 	  {
-	    gradientPoint.x = (int) ((1 - hsbVals[1]) * imgWidth);
-	    gradientPoint.y = (int) ((1 - hsbVals[2]) * imgHeight);
+	    gradientPoint.x = (int) ((1
+	                      - ((Number) sSpinner.getValue()).intValue() / 100f) * imgWidth);
+	    gradientPoint.y = (int) ((1
+	                      - ((Number) bSpinner.getValue()).intValue() / 100f) * imgHeight);
 	  }
 	break;
       case SLOCKED:
@@ -447,8 +444,9 @@
 	  slider.setValue(((Number) sSpinner.getValue()).intValue());
 	if (! handlingMouse)
 	  {
-	    gradientPoint.x = (int) (hsbVals[0] * imgWidth);
-	    gradientPoint.y = (int) ((1 - hsbVals[2]) * imgHeight);
+	    gradientPoint.x = (int) (((Number) hSpinner.getValue()).intValue() / 360f * imgWidth);
+	    gradientPoint.y = (int) ((1
+	                      - ((Number) bSpinner.getValue()).intValue() / 100f) * imgHeight);
 	  }
 	break;
       case BLOCKED:
@@ -456,15 +454,19 @@
 	  slider.setValue(((Number) bSpinner.getValue()).intValue());
 	if (! handlingMouse)
 	  {
-	    gradientPoint.x = (int) (hsbVals[0] * imgWidth);
-	    gradientPoint.y = (int) ((1 - hsbVals[1]) * imgHeight);
+	    gradientPoint.x = (int) (((Number) hSpinner.getValue()).intValue() / 360f * imgWidth);
+	    gradientPoint.y = (int) ((1
+	                      - ((Number) sSpinner.getValue()).intValue() / 100f) * imgHeight);
 	  }
 	break;
       }
     internalChange = false;
 
-    updateImage();
-    updateTrack();
+    if (! handlingMouse && slider != null && ! slider.getValueIsAdjusting())
+      updateImage();
+
+    if (! handlingMouse || locked != HLOCKED)
+      updateTrack();
     updateTextFields();
   }
 
@@ -857,4 +859,16 @@
     trackImage = createImage(new MemoryImageSource(trackWidth, imgHeight,
                                                    trackPix, 0, trackWidth));
   }
+
+  /**
+   * This method returns the HSB values for the currently selected color.
+   *
+   * @return The HSB values for the currently selected color.
+   */
+  private float[] getHSBValues()
+  {
+    Color c = getColorFromModel();
+    float[] f = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), null);
+    return f;
+  }
 }
Index: javax/swing/colorchooser/DefaultRGBChooserPanel.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/colorchooser/DefaultRGBChooserPanel.java,v
retrieving revision 1.1.2.1
diff -u -r1.1.2.1 DefaultRGBChooserPanel.java
--- javax/swing/colorchooser/DefaultRGBChooserPanel.java	25 Aug 2004 21:49:48 -0000	1.1.2.1
+++ javax/swing/colorchooser/DefaultRGBChooserPanel.java	9 Sep 2004 02:28:29 -0000
@@ -73,11 +73,14 @@
      */
     public void stateChanged(ChangeEvent e)
     {
-      if (internalChange)
+      if (updateChange)
 	return;
+
       int color = R.getValue() << 16 | G.getValue() << 8 | B.getValue();
 
+      sliderChange = true;
       getColorSelectionModel().setSelectedColor(new Color(color));
+      sliderChange = false;
     }
   }
 
@@ -93,23 +96,32 @@
      */
     public void stateChanged(ChangeEvent e)
     {
-      if (internalChange)
+      if (updateChange)
 	return;
+
       int red = ((Number) RSpinner.getValue()).intValue();
       int green = ((Number) GSpinner.getValue()).intValue();
       int blue = ((Number) BSpinner.getValue()).intValue();
 
       int color = red << 16 | green << 8 | blue;
 
+      spinnerChange = true;
       getColorSelectionModel().setSelectedColor(new Color(color));
+      spinnerChange = false;
     }
   }
 
+  /** Whether the color change was initiated by the spinners. */
+  private transient boolean spinnerChange = false;
+
+  /** Whether the color change was initiated by the sliders. */
+  private transient boolean sliderChange = false;
+
   /**
-   * Whether the color change was initiated from the slider or spinner rather
-   * than externally.
+   * Whether the change was forced by the chooser (meaning the color has
+   * already been changed).
    */
-  private transient boolean internalChange = false;
+  private transient boolean updateChange = false;
 
   /** The ChangeListener for the sliders. */
   private transient ChangeListener colorChanger;
@@ -175,22 +187,28 @@
     int green = rgb >> 8 & 0xff;
     int blue = rgb & 0xff;
 
-    internalChange = true;
+    updateChange = true;
 
-    if (R != null)
-      R.setValue(red);
-    if (RSpinner != null)
-      RSpinner.setValue(new Integer(red));
-    if (G != null)
-      G.setValue(green);
-    if (GSpinner != null)
-      GSpinner.setValue(new Integer(green));
-    if (B != null)
-      B.setValue(blue);
-    if (BSpinner != null)
-      BSpinner.setValue(new Integer(blue));
+    if (! sliderChange)
+      {
+	if (R != null)
+	  R.setValue(red);
+	if (G != null)
+	  G.setValue(green);
+	if (B != null)
+	  B.setValue(blue);
+      }
+    if (! spinnerChange)
+      {
+	if (GSpinner != null)
+	  GSpinner.setValue(new Integer(green));
+	if (RSpinner != null)
+	  RSpinner.setValue(new Integer(red));
+	if (BSpinner != null)
+	  BSpinner.setValue(new Integer(blue));
+      }
 
-    internalChange = false;
+    updateChange = false;
 
     revalidate();
     repaint();
Index: javax/swing/plaf/basic/BasicTabbedPaneUI.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/plaf/basic/BasicTabbedPaneUI.java,v
retrieving revision 1.3.16.10
diff -u -r1.3.16.10 BasicTabbedPaneUI.java
--- javax/swing/plaf/basic/BasicTabbedPaneUI.java	16 Jul 2004 22:02:42 -0000	1.3.16.10
+++ javax/swing/plaf/basic/BasicTabbedPaneUI.java	9 Sep 2004 02:28:35 -0000
@@ -56,7 +56,6 @@
 import java.awt.event.MouseListener;
 import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
-
 import javax.swing.Icon;
 import javax.swing.JComponent;
 import javax.swing.JPanel;
@@ -132,11 +131,17 @@
 	    {
 	      if (++currentScrollLocation >= tabCount)
 		currentScrollLocation = tabCount - 1;
-	      if (currentScrollLocation == tabCount - 1)
-		incrButton.setEnabled(false);
+
+	      int width = 0;
+	      for (int i = currentScrollLocation - 1; i < tabCount; i++)
+		width += rects[i].width;
+	      if (width < viewport.getWidth())
+		// FIXME: Still getting mouse events after the button is disabled.
+    //	incrButton.setEnabled(false);
+		currentScrollLocation--;
 	      else if (! decrButton.isEnabled())
 		decrButton.setEnabled(true);
-	      tabPane.layout();
+	      tabPane.revalidate();
 	      tabPane.repaint();
 	      return;
 	    }
@@ -148,7 +153,7 @@
 		decrButton.setEnabled(false);
 	      else if (! incrButton.isEnabled())
 		incrButton.setEnabled(true);
-	      tabPane.layout();
+	      tabPane.revalidate();
 	      tabPane.repaint();
 	      return;
 	    }
@@ -160,7 +165,7 @@
       // e.g. in the inset area.
       if (index != -1 && tabPane.isEnabledAt(index))
 	tabPane.setSelectedIndex(index);
-      tabPane.layout();
+      tabPane.revalidate();
       tabPane.repaint();
     }
   }
@@ -269,18 +274,16 @@
       if (tabPlacement == SwingConstants.TOP
           || tabPlacement == SwingConstants.BOTTOM)
         {
-	  width = calculateMaxTabWidth(tabPlacement) * tabPane.getTabCount();
-	  calcRect = tabPane.getParent().getBounds();
-	  width = Math.max(width, componentWidth);
+	  int min = calculateMaxTabWidth(tabPlacement);
+	  width = Math.max(min, componentWidth);
 
 	  int tabAreaHeight = preferredTabAreaHeight(tabPlacement, width);
 	  height = tabAreaHeight + componentHeight;
         }
       else
         {
-	  height = calculateMaxTabHeight(tabPlacement) * tabPane.getTabCount();
-	  calcRect = tabPane.getParent().getBounds();
-	  height = Math.max(height, componentHeight);
+	  int min = calculateMaxTabHeight(tabPlacement);
+	  height = Math.max(min, componentHeight);
 
 	  int tabAreaWidth = preferredTabAreaWidth(tabPlacement, height);
 	  width = tabAreaWidth + componentWidth;
@@ -454,7 +457,7 @@
 	    {
 	      for (int j = first; j <= last; j++)
 		rects[j].y += (runCount - i) * maxTabHeight
-		+ (runCount - i) * tabRunOverlay;
+		- (runCount - i) * tabRunOverlay;
 	    }
 
 	  if (tabPlacement == SwingConstants.BOTTOM)
@@ -810,7 +813,7 @@
      */
     protected void rotateTabRuns(int tabPlacement, int selectedRun)
     {
-      if (selectedRun == 1 || selectedRun == -1)
+      if (runCount == 1 || selectedRun == 1 || selectedRun == -1)
 	return;
       int[] newTabRuns = new int[tabRuns.length];
       int currentRun = selectedRun;
@@ -1025,6 +1028,7 @@
     {
       super.layoutContainer(pane);
       int tabCount = tabPane.getTabCount();
+      Point p = null;
       if (tabCount == 0)
 	return;
       int tabPlacement = tabPane.getTabPlacement();
@@ -1083,13 +1087,14 @@
         {
 	  int w = Math.max(rects[tabC].width + rects[tabC].x, tabAreaRect.width);
 	  int h = Math.max(rects[tabC].height, tabAreaRect.height);
-	  Point p = findPointForIndex(currentScrollLocation);
+	  p = findPointForIndex(currentScrollLocation);
 
 	  // we want to cover that entire space so that borders that run under
 	  // the tab area don't show up when we move the viewport around.
 	  panel.setSize(w + p.x, h + p.y);
         }
-      viewport.setViewPosition(findPointForIndex(currentScrollLocation));
+      viewport.setViewPosition(p);
+      viewport.repaint();
     }
   }
 
@@ -1445,6 +1450,7 @@
 	incrButton = createIncreaseButton();
 	decrButton = createDecreaseButton();
 	viewport = new ScrollingViewport();
+	viewport.setLayout(null);
 	panel = new ScrollingPanel();
 	viewport.setView(panel);
 	tabPane.add(incrButton);
@@ -1689,6 +1695,8 @@
     Rectangle ir = new Rectangle();
     Rectangle tr = new Rectangle();
 
+    boolean isScroll = tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT;
+
     // Please note: the ordering of the painting is important. 
     // we WANT to paint the outermost run first and then work our way in.
     int tabCount = tabPane.getTabCount();
@@ -1701,17 +1709,33 @@
     for (int i = 0; i < runCount; i++)
       {
 	int first = lastTabInRun(tabCount, getPreviousTabRun(currRun)) + 1;
-	if (first == tabCount)
+	if (isScroll)
+	  first = currentScrollLocation;
+	else if (first == tabCount)
 	  first = 0;
 	int last = lastTabInRun(tabCount, currRun);
+	if (isScroll)
+	  {
+	    for (int k = first; k < tabCount; k++)
+	      {
+		if (rects[k].x + rects[k].width - rects[first].x > viewport
+		                                                   .getWidth())
+		  {
+		    last = k;
+		    break;
+		  }
+	      }
+	  }
+
 	for (int j = first; j <= last; j++)
 	  {
-	    if (j != selectedIndex)
+	    if (j != selectedIndex || isScroll)
 	      paintTab(g, tabPlacement, rects, j, ir, tr);
 	  }
-	currRun = getNextTabRun(currRun);
+	currRun = getPreviousTabRun(currRun);
       }
-    paintTab(g, tabPlacement, rects, selectedIndex, ir, tr);
+    if (! isScroll)
+      paintTab(g, tabPlacement, rects, selectedIndex, ir, tr);
   }
 
   /**
@@ -1974,7 +1998,7 @@
                                 int x, int y, int w, int h, boolean isSelected)
   {
     Color saved = g.getColor();
-    
+
     if (! isSelected || tabPlacement != SwingConstants.TOP)
       {
 	g.setColor(shadow);
@@ -2029,7 +2053,7 @@
       {
 	Color bg = tabPane.getBackgroundAt(tabIndex);
 	if (bg == null)
-	  bg = tabPane.getBackground();
+	  bg = Color.GRAY;
 	g.setColor(bg);
       }
 
@@ -2082,14 +2106,14 @@
 
     int diff = 0;
 
-    if (tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT)
-      {
-	Point p = findPointForIndex(currentScrollLocation);
-	diff = p.x;
-      }
-
     if (tabPlacement == SwingConstants.TOP)
       {
+	if (tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT)
+	  {
+	    Point p = findPointForIndex(currentScrollLocation);
+	    diff = p.x;
+	  }
+
 	g.drawLine(x, y, startgap - diff, y);
 	g.drawLine(endgap - diff, y, x + w, y);
       }
@@ -2122,14 +2146,14 @@
 
     int diff = 0;
 
-    if (tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT)
-      {
-	Point p = findPointForIndex(currentScrollLocation);
-	diff = p.y;
-      }
-
     if (tabPlacement == SwingConstants.LEFT)
       {
+	if (tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT)
+	  {
+	    Point p = findPointForIndex(currentScrollLocation);
+	    diff = p.y;
+	  }
+
 	g.drawLine(x, y, x, startgap - diff);
 	g.drawLine(x, endgap - diff, x, y + h);
       }
@@ -2161,14 +2185,14 @@
 
     int diff = 0;
 
-    if (tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT)
-      {
-	Point p = findPointForIndex(currentScrollLocation);
-	diff = p.x;
-      }
-
     if (tabPlacement == SwingConstants.BOTTOM)
       {
+	if (tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT)
+	  {
+	    Point p = findPointForIndex(currentScrollLocation);
+	    diff = p.x;
+	  }
+
 	g.setColor(shadow);
 	g.drawLine(x + 1, y + h - 1, startgap - diff, y + h - 1);
 	g.drawLine(endgap - diff, y + h - 1, x + w - 1, y + h - 1);
@@ -2208,14 +2232,15 @@
     int endgap = rects[selectedIndex].y + rects[selectedIndex].height;
 
     int diff = 0;
-    if (tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT)
-      {
-	Point p = findPointForIndex(currentScrollLocation);
-	diff = p.y;
-      }
 
     if (tabPlacement == SwingConstants.RIGHT)
       {
+	if (tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT)
+	  {
+	    Point p = findPointForIndex(currentScrollLocation);
+	    diff = p.y;
+	  }
+
 	g.setColor(shadow);
 	g.drawLine(x + w - 1, y + 1, x + w - 1, startgap - diff);
 	g.drawLine(x + w - 1, endgap - diff, x + w - 1, y + h - 1);

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]