Пример #1
1
 /**
  * Event.detail line start offset (input) Event.text line text (input) LineStyleEvent.styles
  * Enumeration of StyleRanges, need to be in order. (output) LineStyleEvent.background line
  * background color (output)
  */
 public void lineGetStyle(LineStyleEvent event) {
   Vector styles = new Vector();
   int token;
   StyleRange lastStyle;
   // If the line is part of a block comment, create one style for the entire line.
   if (inBlockComment(event.lineOffset, event.lineOffset + event.lineText.length())) {
     styles.addElement(
         new StyleRange(event.lineOffset, event.lineText.length(), getColor(COMMENT), null));
     event.styles = new StyleRange[styles.size()];
     styles.copyInto(event.styles);
     return;
   }
   Color defaultFgColor = ((Control) event.widget).getForeground();
   scanner.setRange(event.lineText);
   token = scanner.nextToken();
   while (token != EOF) {
     if (token == OTHER) {
       // do nothing for non-colored tokens
     } else if (token != WHITE) {
       Color color = getColor(token);
       // Only create a style if the token color is different than the
       // widget's default foreground color and the token's style is not
       // bold.  Keywords are bolded.
       if ((!color.equals(defaultFgColor)) || (token == KEY)) {
         StyleRange style =
             new StyleRange(
                 scanner.getStartOffset() + event.lineOffset, scanner.getLength(), color, null);
         if (token == KEY) {
           style.fontStyle = SWT.BOLD;
         }
         if (styles.isEmpty()) {
           styles.addElement(style);
         } else {
           // Merge similar styles.  Doing so will improve performance.
           lastStyle = (StyleRange) styles.lastElement();
           if (lastStyle.similarTo(style) && (lastStyle.start + lastStyle.length == style.start)) {
             lastStyle.length += style.length;
           } else {
             styles.addElement(style);
           }
         }
       }
     } else if ((!styles.isEmpty())
         && ((lastStyle = (StyleRange) styles.lastElement()).fontStyle == SWT.BOLD)) {
       int start = scanner.getStartOffset() + event.lineOffset;
       lastStyle = (StyleRange) styles.lastElement();
       // A font style of SWT.BOLD implies that the last style
       // represents a java keyword.
       if (lastStyle.start + lastStyle.length == start) {
         // Have the white space take on the style before it to
         // minimize the number of style ranges created and the
         // number of font style changes during rendering.
         lastStyle.length += scanner.getLength();
       }
     }
     token = scanner.nextToken();
   }
   event.styles = new StyleRange[styles.size()];
   styles.copyInto(event.styles);
 }
  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (!(o instanceof ColorSampleLookupValue)) {
      return false;
    }

    ColorSampleLookupValue value = (ColorSampleLookupValue) o;

    if (myIsStandard != value.myIsStandard) {
      return false;
    }
    if (myColor != null ? !myColor.equals(value.myColor) : value.myColor != null) {
      return false;
    }
    if (myName != null ? !myName.equals(value.myName) : value.myName != null) {
      return false;
    }
    if (myValue != null ? !myValue.equals(value.myValue) : value.myValue != null) {
      return false;
    }

    return true;
  }
Пример #3
0
 // Overridden for performance reasons. ---->
 @Override
 public boolean isOpaque() {
   Color back = getBackground();
   Component p = getParent();
   if (Objects.nonNull(p)) {
     p = p.getParent();
   } // p should now be the JTable.
   boolean colorMatch =
       Objects.nonNull(back)
           && Objects.nonNull(p)
           && back.equals(p.getBackground())
           && p.isOpaque();
   return !colorMatch && super.isOpaque();
 }
  /** {@inheritDoc} */
  public void setBackgroundColor(Color color) {
    if (color == null) {
      String message = Logging.getMessage("nullValue.ColorIsNull");
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

    // Only set the color if it actually changed
    if (!color.equals(this.getBackgroundColor())) {
      this.backgroundColor = color;

      // Convert the color to an RGB hex triplet string that the WebBrowser will understand
      int rgb =
          (color.getRed() & 0xFF) << 16 | (color.getGreen() & 0xFF) << 8 | (color.getBlue() & 0xFF);
      String colorString = String.format("#%06X", rgb);

      WindowsWebViewJNI.setBackgroundColor(this.webViewWindowPtr, colorString);
    }
  }
Пример #5
0
 static void fillRect(
     final Graphics g,
     final Component c,
     final Color color,
     final int x,
     final int y,
     final int w,
     final int h) {
   if (!(g instanceof Graphics2D)) {
     return;
   }
   final Graphics2D cg = (Graphics2D) g.create();
   try {
     if (color instanceof UIResource && isWindowTextured(c) && color.equals(SystemColor.window)) {
       cg.setComposite(AlphaComposite.Src);
       cg.setColor(resetAlpha(color));
     } else {
       cg.setColor(color);
     }
     cg.fillRect(x, y, w, h);
   } finally {
     cg.dispose();
   }
 }
Пример #6
0
  public Component getTableCellRendererComponent(
      JTable table,
      Setting owner,
      Object value,
      boolean isSelected,
      boolean hasFocus,
      boolean isEnabled,
      int row,
      int column) {
    // renderer.setMargin(new Insets(0, 2, 4, 2));

    if (isSelected) {
      renderer.setForeground(table.getSelectionForeground());
      panel.setBackground(table.getSelectionBackground());
      blank1.setBackground(table.getSelectionBackground());
      blank2.setBackground(table.getSelectionBackground());
    } else {
      renderer.setForeground(table.getForeground());
      panel.setBackground(table.getBackground());
      blank1.setBackground(table.getBackground());
      blank2.setBackground(table.getBackground());
    }

    if (hasFocus) {
      panel.setBorder(UIManager.getBorder("Table.focusCellHighlightBorder"));
    } else {
      panel.setBorder(new EmptyBorder(1, 2, 2, 1));
    }

    if (value instanceof Color) {
      Color col = (Color) value;

      // System.out.println("setting background to "+col.toString());

      renderer.setText("[" + col.getRed() + "," + col.getGreen() + "," + col.getBlue() + "]");

      renderer.setEnabled(isEnabled);

      renderer.setFont(font);

      colourPanel.setBackground(col);
    } else if (value instanceof ArrayList) {
      ArrayList values = (ArrayList) value;
      if (values.size() > 0) {
        // if we have multiple properties selected.
        Color last = null;
        boolean allSame = true;
        for (int i = 0; i < values.size(); i++) {
          if (values.get(i) instanceof Color) {
            Color str = (Color) values.get(i);
            if (last != null) {
              if (!str.equals(last)) {
                allSame = false;
                break;
              }
              last = str;
            } else {
              last = str;
            }
          }
        }
        if (allSame) {
          renderer.setText(
              "[" + last.getRed() + "," + last.getGreen() + "," + last.getBlue() + "]");

          renderer.setEnabled(isEnabled);

          renderer.setFont(font);

          colourPanel.setBackground(last);
        } else {
          renderer.setText("(Different values)");

          renderer.setEnabled(isEnabled);

          renderer.setFont(font);

          colourPanel.setBackground(Color.lightGray);
          panel.setBackground(Color.lightGray);
          blank1.setBackground(Color.lightGray);
          blank2.setBackground(Color.lightGray);
        }
      }
    }

    return panel;
  }