Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4278846

On Solaris, Graphics.setXORMode() not working correctly

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.3.0
    • client-libs
    • 2d
    • sparc
    • solaris_2.6



      Name: krT82822 Date: 10/06/99


      On Solaris, if you use Graphics.setXORMode() to invert an area,
      then change the background color and use setXORMode() to un-invert
      the inverted area, then the inverted area does not get set back
      to the previous color. It works fine as long as the color does
      not change between the calls to setXORMode(). This only happens on
      Solaris.

      Steps to reproduce:

      1. Compile and run the MyFrame class below.
      2. Click the Select button.
      3. Click the Fill button.
      4. Click the Un-Select button.

      The selected areas are not inverted to the proper colors. Seems
      to be confused with the colors used when first selecting.

      public class MyFrame extends javax.swing.JFrame implements java.awt.event.ActionListener {
          javax.swing.JButton btnSelect;
          javax.swing.JButton btnFill;
          MyPanel panel;
              
          public MyFrame() {
           setTitle("Test Application");
           java.awt.Container pane = getContentPane();
      pane.setLayout(null);
              addWindowListener(new WindowListener());
      setBounds(50, 50, 480, 360);

              btnSelect = new javax.swing.JButton("Select");
      btnSelect.setBounds(10, 10, 100, 20);
              btnSelect.addActionListener(this);
      pane.add(btnSelect);

              btnFill = new javax.swing.JButton("Fill");
      btnFill.setBounds(120, 10, 100, 20);
              btnFill.addActionListener(this);
      pane.add(btnFill);

      panel = new MyPanel();
      panel.setBounds(10, 40, 450, 280);
      panel.setBackground(java.awt.Color.blue);
      pane.add(panel);

              setVisible(true);
          }

      public static void main(String[] args) {
      new MyFrame();
      }

      public void actionPerformed(java.awt.event.ActionEvent e){
      if (e.getSource() == btnFill)
               panel.setColor(randomColor());
      else
      panel.setSelected(!panel.m_bSelected);
      }
          
      class WindowListener extends java.awt.event.WindowAdapter {
      public void windowClosing(java.awt.event.WindowEvent event) {
      System.exit(0);
      }
      }

      class MyPanel extends javax.swing.JPanel {
      java.awt.Color c = java.awt.Color.blue;
      boolean m_bSelected = false;

      public void paint(java.awt.Graphics g) {
      g.setColor(c);
      g.fillRect(0, 0, getWidth(), getHeight());
      if (m_bSelected)
      invert(g);
      }

      void invert(java.awt.Graphics g) {
      if (g == null)
      g = getGraphics();
           g.setColor(java.awt.Color.black);
           g.setXORMode(java.awt.Color.white);
           java.awt.Rectangle r = getBounds();
               g.fillRect(0, 0, 10, 10);
               g.fillRect(r.width - 10, 0, 10, 10);
               g.fillRect(r.width / 2 - 5, r.height / 2 - 5, 10, 10);
               g.fillRect(0, r.height - 10, 10, 10);
               g.fillRect(r.width - 10, r.height - 10, 10, 10);
      g.setPaintMode();
      }

      void setColor(java.awt.Color c) {
      this.c = c;
      repaint();
      }

      void setSelected(boolean b) {
      if (m_bSelected = b)
      btnSelect.setText("Un-Select");
      else
      btnSelect.setText("Select");
      invert(null);
      }
      }

      java.awt.Color randomColor() {
      return new java.awt.Color((int)(Math.random() * 255),
                                 (int)(Math.random() * 255),
                                 (int)(Math.random() * 255));
          }
      }


      JDK Version 1.2.1 on Solaris. When can we expect 1.2.2 for Solaris???

      --------------

      10/6/99 eval1127@eng -- as user notes, works fine under 1.2.2 on win32. On Solaris, fails even under kestrel-beta build O.

      Looks like relative of bug # 4204551 (& possibly to 4265147)
      (Review ID: 96193)
      ======================================================================

            tnguyensunw Thanh Nguyen (Inactive)
            kryansunw Kevin Ryan (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: