private static void drawSelection(JTable table, int column, Graphics g, final int width) {
   int y = 0;
   final int[] rows = table.getSelectedRows();
   final int height = table.getRowHeight();
   for (int row : rows) {
     final TableCellRenderer renderer = table.getCellRenderer(row, column);
     final Component component =
         renderer.getTableCellRendererComponent(
             table, table.getValueAt(row, column), false, false, row, column);
     g.translate(0, y);
     component.setBounds(0, 0, width, height);
     boolean wasOpaque = false;
     if (component instanceof JComponent) {
       final JComponent j = (JComponent) component;
       if (j.isOpaque()) wasOpaque = true;
       j.setOpaque(false);
     }
     component.paint(g);
     if (wasOpaque) {
       ((JComponent) component).setOpaque(true);
     }
     y += height;
     g.translate(0, -y);
   }
 }
 private static void drawSelection(JTree tree, Graphics g, final int width) {
   int y = 0;
   final int[] rows = tree.getSelectionRows();
   final int height = tree.getRowHeight();
   for (int row : rows) {
     final TreeCellRenderer renderer = tree.getCellRenderer();
     final Object value = tree.getPathForRow(row).getLastPathComponent();
     if (value == null) continue;
     final Component component =
         renderer.getTreeCellRendererComponent(tree, value, false, false, false, row, false);
     if (component.getFont() == null) {
       component.setFont(tree.getFont());
     }
     g.translate(0, y);
     component.setBounds(0, 0, width, height);
     boolean wasOpaque = false;
     if (component instanceof JComponent) {
       final JComponent j = (JComponent) component;
       if (j.isOpaque()) wasOpaque = true;
       j.setOpaque(false);
     }
     component.paint(g);
     if (wasOpaque) {
       ((JComponent) component).setOpaque(true);
     }
     y += height;
     g.translate(0, -y);
   }
 }
Exemplo n.º 3
0
 void decorate(final boolean notified) {
   my(GuiThread.class).assertInGuiThread();
   if (notified) {
     _target.setOpaque(_isOpaque);
     _target.setBackground(_bgColor);
     return;
   }
   _target.setOpaque(true);
 }
Exemplo n.º 4
0
 /*
  *  Create a BufferedImage for Swing components.
  *  All or part of the component can be captured to an image.
  *
  *  @param	 component Swing component to create image from
  *  @param	 region The region of the component to be captured to an image
  *  @param	 fileName name of file to be created or null
  *  @return	image the image for the given region
  *  @exception IOException if an error occurs during writing
  */
 public static BufferedImage createImage(JComponent component, Rectangle region, String fileName)
     throws IOException {
   boolean opaqueValue = component.isOpaque();
   component.setOpaque(true);
   BufferedImage image =
       new BufferedImage(region.width, region.height, BufferedImage.TYPE_INT_RGB);
   Graphics2D g2d = image.createGraphics();
   g2d.setClip(region);
   component.paint(g2d);
   g2d.dispose();
   component.setOpaque(opaqueValue);
   ScreenCapture.writeImage(image, fileName);
   return image;
 }
  /** Adds the overlay panel into the table & converts the button to 'download'. */
  private void setupFakeTable(JPanel overlay) {
    MAIN_PANEL.removeAll();

    // fixes flickering!
    JPanel background =
        new JPanel() {
          public boolean isOptimizedDrawingEnabled() {
            return false;
          }
        };

    background.setLayout(new OverlayLayout(background));

    // overlay.setBorder(BorderFactory.createEmptyBorder(20, 0, 20, 0));

    JPanel overlayPanel = new JPanel();
    overlayPanel.setOpaque(false);
    overlayPanel.setLayout(new MigLayout("fill"));
    overlayPanel.add(overlay, "center");
    JScrollPane scrollPane = new JScrollPane(overlayPanel);
    scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
    scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    scrollPane.getViewport().setBackground(Color.WHITE);
    scrollPane.setBorder(BorderFactory.createEmptyBorder(28, 10, 4, 10));

    JComponent table = getScrolledTablePane();
    table.setOpaque(false);
    background.add(scrollPane);
    background.add(table);

    MAIN_PANEL.add(background);
    addButtonRow();
  }
Exemplo n.º 6
0
  private static Pair<Image, Point> createDragImage(
      final Tree tree, final Component c, Point dragOrigin, boolean adjustToPathUnderDragOrigin) {
    if (c instanceof JComponent) {
      ((JComponent) c).setOpaque(true);
    }

    c.setForeground(tree.getForeground());
    c.setBackground(tree.getBackground());
    c.setFont(tree.getFont());
    c.setSize(c.getPreferredSize());
    final BufferedImage image =
        new BufferedImage(c.getWidth(), c.getHeight(), BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = (Graphics2D) image.getGraphics();
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f));
    c.paint(g2);
    g2.dispose();

    Point point = new Point(-image.getWidth(null) / 2, -image.getHeight(null) / 2);

    if (adjustToPathUnderDragOrigin) {
      TreePath path = tree.getPathForLocation(dragOrigin.x, dragOrigin.y);
      if (path != null) {
        Rectangle bounds = tree.getPathBounds(path);
        point = new Point(bounds.x - dragOrigin.x, bounds.y - dragOrigin.y);
      }
    }

    return new Pair<Image, Point>(image, point);
  }
  public void update(Graphics g, JComponent c) {
    if (c.isOpaque()) {
      AbstractButton b = (AbstractButton) c;
      if (isToolBarButton(b)) {
        c.setOpaque(false);
      } else if (b.isContentAreaFilled()) {
        g.setColor(c.getBackground());
        g.fillRect(0, 0, c.getWidth(), c.getHeight());

        if (is3D(b)) {
          Color color1 = c.getBackground(); // UIManager.getColor("control");
          Color color2 = color1.brighter();

          int x = 0;
          int y = 0;
          int width = c.getWidth();
          int height = c.getHeight();
          GradientPaint gp = new GradientPaint(x, y, color2, width - 2, height - 2, color1, true);
          Graphics2D g2 = (Graphics2D) g;
          g2.setPaint(gp);
          g2.fillRect(x, y, width, height);
        }
      }
    }
    c.setBorder(defaultBorder);
    paint(g, c);
  }
Exemplo n.º 8
0
    public IndicatorToolbox() {
      super(JToolBar.HORIZONTAL);
      setOpaque(false);
      setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));

      indicatorLabel = new JLabel(indicator.getLabel());
      indicatorLabel.setHorizontalTextPosition(SwingConstants.LEFT);
      indicatorLabel.setVerticalTextPosition(SwingConstants.CENTER);
      indicatorLabel.setOpaque(false);
      add(indicatorLabel);

      container = new JPanel();
      container.setOpaque(false);
      container.setLayout(new BoxLayout(container, BoxLayout.X_AXIS));
      add(container);
      update();

      addMouseListener(
          new MouseAdapter() {
            public @Override void mouseEntered(MouseEvent e) {
              mouseOver = true;
              validate();
              repaint();
            }

            public @Override void mouseExited(MouseEvent e) {
              setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
              mouseOver = false;
              validate();
              repaint();
            }
          });
    }
Exemplo n.º 9
0
  /**
   * Create the GUI and show it. For thread safety, this method should be invoked from the
   * event-dispatching thread.
   */
  private static void createAndShowGUI() {
    // Create and set up the window.
    JFrame frame = new JFrame("Automated File Mover");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent we) {
            try {
              FileOutputStream f_out = new FileOutputStream(LOG_DIRECTORY + "save.data");

              // Write object with ObjectOutputStream
              ObjectOutputStream obj_out = new ObjectOutputStream(f_out);

              // Write object out to disk
              obj_out.writeObject(directoryList);
              obj_out.writeObject(ERROR_LOG_NAME);
              obj_out.writeObject(MOVE_LOG_NAME);
              obj_out.flush();
              obj_out.close();
              printer.printError(LOG_DIRECTORY);
            } catch (IOException x) {
              printer.printError(x.toString());
            }
          }
        });

    // Create and set up the content pane.
    JComponent newContentPane = new fileBackupProgram(frame);
    newContentPane.setOpaque(true); // content panes must be opaque
    frame.setContentPane(newContentPane);

    // Display the window.
    frame.pack();
    frame.setVisible(true);
  }
Exemplo n.º 10
0
  /** {@inheritDoc} */
  @Override
  public Component getListCellRendererComponent(
      JList list,
      final Object value,
      final int index,
      boolean isSelected,
      final boolean cellHasFocus) {

    Component label = getObjectComponent(list, value, index, isSelected, cellHasFocus);
    if (label instanceof JComponent) ((JComponent) label).setOpaque(false);

    panel.removeAll();
    panel.add(label);
    panel.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
    panel.restoreBackground();

    if (cellHasFocus)
      if (panel.isBackgroundRestored())
        panel.setBackground(UIUtils.setAlpha(list.getSelectionBackground(), 100));
      else panel.setBorder(BorderFactory.createLineBorder(list.getSelectionBackground()));

    if (isSelected)
      if (panel.isBackgroundRestored())
        panel.setBackground(UIUtils.setAlpha(list.getSelectionBackground(), 200));
      else panel.setBorder(BorderFactory.createLineBorder(list.getSelectionBackground()));

    if (index == hoveredIndex) panel.mouseEntered(null);

    return panel;
  }
Exemplo n.º 11
0
  /** Set up component. */
  protected void initialize() {

    JComponent component = getComponent();
    component.setToolTipText(label.getToolTipText());
    component.setEnabled(editable);
    component.setOpaque(false);
  }
 @Override
 protected void addImpl(final Component comp, final Object constraints, final int index) {
   super.addImpl(comp, constraints, index);
   if (comp instanceof JComponent) {
     final JComponent jcomp = (JComponent) comp;
     jcomp.setOpaque(false);
   }
 }
 private static Component setLabelColors(
     final Component label, final JTable table, final boolean isSelected, final int row) {
   if (label instanceof JComponent) {
     ((JComponent) label).setOpaque(true);
   }
   label.setForeground(isSelected ? table.getSelectionForeground() : table.getForeground());
   label.setBackground(isSelected ? table.getSelectionBackground() : table.getBackground());
   return label;
 }
Exemplo n.º 14
0
  private static void createAndShowGUI() {
    JComponent newContentPane = new Splitter();
    newContentPane.setOpaque(true);

    frame = new JFrame("Splitting " + EpubUtils.EPUB.getName());
    frame.setContentPane(newContentPane);
    frame.pack();
    frame.setVisible(true);
  }
Exemplo n.º 15
0
 public ComponentTitledBorder(Component comp, JComponent container, Border border) {
   this.comp = comp;
   this.border = border;
   if (comp instanceof JComponent) {
     ((JComponent) comp).setOpaque(true);
   }
   container.addMouseListener(this);
   container.addMouseMotionListener(this);
 }
 public static void setAllOpaque(Container container, boolean opaque) {
   if (container instanceof JComponent) {
     ((JComponent) container).setOpaque(opaque);
     for (int i = 0; i < container.getComponentCount(); i++) {
       Component component = container.getComponent(i);
       if (component instanceof Container) setAllOpaque((Container) component, opaque);
     }
   }
 }
Exemplo n.º 17
0
  /** Paints the given JTable's table default header background at given x for the given width. */
  private static void paintHeader(Graphics g, JTable table, int x, int width) {
    TableCellRenderer renderer = table.getTableHeader().getDefaultRenderer();
    Component component = renderer.getTableCellRendererComponent(table, "", false, false, -1, 2);

    component.setBounds(0, 0, width, table.getTableHeader().getHeight());

    ((JComponent) component).setOpaque(false);
    CELL_RENDER_PANE.paintComponent(
        g, component, null, x, 0, width, table.getTableHeader().getHeight(), true);
  }
Exemplo n.º 18
0
 /**
  * Installs the UI.
  *
  * @param c
  */
 @Override
 public void installUI(JComponent c) {
   super.installUI(c);
   c.setOpaque(false);
   //  BasicBorders$SplitPaneBorder paints gray border
   //  resulting in a 2pt border for the left/right components
   //  but results in 1pt gray line on top/button of divider.
   //  Still, a 1 pt shaddow light gay line is painted
   c.setBorder(null);
 } //  installUI
Exemplo n.º 19
0
 public void update(Graphics g, JComponent c) {
   if (c.isOpaque()) {
     g.setColor(c.getBackground());
     g.fillRect(0, 0, c.getWidth(), c.getHeight());
     if (isToolBarComboBox(c)) {
       c.setOpaque(false);
     }
   }
   paint(g, c);
 }
Exemplo n.º 20
0
    public static void createAndShowGUI(SimpleGUI sg) {
    JFrame frame = new JFrame("jChat");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JComponent newContentPane = sg;
    newContentPane.setOpaque(true);
    frame.setContentPane(newContentPane);

    frame.pack();
    frame.setVisible(true);
    }
Exemplo n.º 21
0
 @Override
 public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
   Component component = super.prepareRenderer(renderer, row, column);
   // if the rendere is a JComponent and the given row isn't part of a
   // selection, make the renderer non-opaque so that striped rows show
   // through.
   if (component instanceof JComponent) {
     ((JComponent) component).setOpaque(getSelectionModel().isSelectedIndex(row));
   }
   return component;
 }
Exemplo n.º 22
0
    public WrapperContainer(Container c) {
      alpha = 1.0f;
      collapsedState = false;
      setView(c);

      // we must ensure the container is opaque. It is not opaque it introduces
      // painting glitches specially on Linux with JDK 1.5 and GTK look and feel.
      // GTK look and feel calls setOpaque(false)
      if (c instanceof JComponent && !c.isOpaque()) {
        ((JComponent) c).setOpaque(true);
      }
    }
Exemplo n.º 23
0
  /**
   * Shows on the right the configuration form given by the given <tt>ConfigFormDescriptor</tt>.
   *
   * @param configForm the configuration form to show
   */
  private void showFormContent(ConfigurationForm configForm) {
    this.centerPanel.removeAll();

    JComponent configFormPanel = (JComponent) configForm.getForm();

    configFormPanel.setOpaque(false);

    this.centerPanel.add(configFormPanel, BorderLayout.CENTER);

    this.centerPanel.revalidate();
    this.centerPanel.repaint();
  }
Exemplo n.º 24
0
    public WrapperContainer(Container c) {
      super(new BorderLayout());
      this.c = c;
      add(c, BorderLayout.CENTER);

      // we must ensure the container is opaque. It is not opaque it introduces
      // painting glitches specially on Linux with JDK 1.5 and GTK look and feel.
      // GTK look and feel calls setOpaque(false)
      if (c instanceof JComponent && !((JComponent) c).isOpaque()) {
        ((JComponent) c).setOpaque(true);
      }
    }
 public void installUI(JComponent jComponent) {
   grid = (JGrid) jComponent;
   rendererPane = new CellRendererPane();
   grid.add(rendererPane);
   gridHeader = (JGrid) jComponent;
   jComponent.setOpaque(false);
   LookAndFeel.installColorsAndFont(
       jComponent, "TableHeader.background", "TableHeader.foreground", "TableHeader.font");
   installDefaults();
   installListeners();
   installKeyboardActions();
 }
Exemplo n.º 26
0
  private static void createAndShowGUI() {
    JFrame frame = new JFrame("Environment Runner");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JComponent newContentPane = new ListDemo();
    newContentPane.setOpaque(true); // content panes must be opaque
    frame.setContentPane(newContentPane);

    frame.setSize(500, 375);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
  }
Exemplo n.º 27
0
  @Override
  public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
    final Component result = super.prepareRenderer(renderer, row, column);
    final boolean selected =
        myExpandableItemsHandler.getExpandedItems().contains(new TableCell(row, column));

    // Fix GTK background
    if (UIUtil.isUnderGTKLookAndFeel()) {
      UIUtil.changeBackGround(this, UIUtil.getTreeTextBackground());
    }

    if (isTableDecorationSupported() && isStriped() && result instanceof JComponent) {
      final Color bg = row % 2 == 1 ? getBackground() : DECORATED_ROW_BG_COLOR;
      final JComponent c = (JComponent) result;
      final boolean cellSelected = isCellSelected(row, column);
      if (!cellSelected || (!hasFocus() && !getSelectionBackground().equals(c.getBackground()))) {
        c.setOpaque(true);
        c.setBackground(bg);
        for (Component child : c.getComponents()) {
          child.setBackground(bg);
        }
      }
    }

    if (!selected) return result;

    return new JComponent() {
      {
        add(result);
        setOpaque(false);
        setLayout(
            new AbstractLayoutManager() {
              @Override
              public Dimension preferredLayoutSize(Container parent) {
                return result.getPreferredSize();
              }

              @Override
              public void layoutContainer(Container parent) {
                Dimension size = parent.getSize();
                Insets i = parent.getInsets();
                Dimension pref = result.getPreferredSize();
                result.setBounds(
                    i.left,
                    i.top,
                    Math.max(pref.width, size.width - i.left - i.right),
                    size.height - i.top - i.bottom);
              }
            });
      }
    };
  }
Exemplo n.º 28
0
 public WidgetPanel(GUIWorkspace workspace) {
   this.workspace = workspace;
   setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.CROSSHAIR_CURSOR));
   setOpaque(true);
   setBackground(java.awt.Color.WHITE);
   addMouseListener(this);
   addMouseMotionListener(this);
   addFocusListener(this);
   setAutoscrolls(true);
   glassPane.setOpaque(false);
   glassPane.setVisible(false);
   add(glassPane, DRAG_LAYER);
 }
Exemplo n.º 29
0
 /** [Internal] */
 public void paintComponent(Graphics g) {
   boolean opq = true;
   if (theOpaque != null) opq = theOpaque;
   super.setOpaque(opq);
   // if(theBackground!=null)super.setBackground(theBackground);
   super.paintComponent(g);
   Graphics2D g2 = (Graphics2D) g;
   Rectangle rt = getBounds();
   rt.x = 0;
   rt.y = 0;
   doBuffer(g2, opq, rt);
   chkFPS();
 }
Exemplo n.º 30
0
  /*
  	create the GUI and show it. for thread safety,
  	this method should be invoke from the event dispacth thread
  */
  private static void createAndShowGUI() {
    // create and setup the window
    JFrame fr = new JFrame("Mouse Event");
    fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // create and setup the content pane
    JComponent newContentPane = new MouseEventDemo();
    newContentPane.setOpaque(true);
    fr.setContentPane(newContentPane);

    fr.pack();
    fr.setVisible(true);
  }