View Javadoc
1   package net.logAnalyzer.utils.gui;
2   
3   import java.awt.Component;
4   import java.awt.Dimension;
5   import java.awt.GradientPaint;
6   import java.awt.Graphics;
7   import java.awt.Graphics2D;
8   import java.awt.Insets;
9   
10  import javax.swing.Box;
11  import javax.swing.BoxLayout;
12  import javax.swing.Icon;
13  import javax.swing.JComponent;
14  import javax.swing.JPanel;
15  import javax.swing.border.Border;
16  
17  import net.logAnalyzer.utils.gui.quickbar.QuickTitle;
18  
19  public class GraphicsDecoratorPanel extends JPanel {
20  
21      private static final long serialVersionUID = 1L;
22      
23      private QuickTitle quickTitle = null;
24          
25      private class Graphic2DPanelBorder implements Border {
26  
27          public Insets getBorderInsets(Component c) {
28              return new Insets(0, 10, 10, 10);
29          }
30  
31          public boolean isBorderOpaque() {
32              return false;
33          }
34  
35          public void paintBorder(Component c, Graphics g, int x, int y,
36                  int width, int height) {
37              Graphics2D gfx = (Graphics2D) g;
38              // Actions background
39              gfx.setPaint(GraphicsAttributes.BACKGROUND_COLOR);
40              if (quickTitle != null) {
41                  gfx.fillRect(x, y + 7, x + width, y + height);
42                  // Action border
43                  gfx.setPaint(GraphicsAttributes.QUICKPANEL_BORDER_COLOR);
44                  g.fillRect(x, y + 7, x + 1, y + height);
45                  g.fillRect(x + width - 1, y + 7, x + width, y + height);
46                  g.fillRect(x, y + height - 1, x + width, y + height);
47                  // Title background
48                  gfx.setPaint(new GradientPaint(x + width / 2, y, GraphicsAttributes.QUICKTITLE_GRADIENTSTART_COLOR,
49                          width, y, GraphicsAttributes.QUICKTITLE_GRADIENTEND_COLOR));
50                  gfx.fillRoundRect(x, y, x + width, y + 14, 7, 7);
51              
52                  gfx.fillRect(x, y + 3, x + width, y
53                          + getInsets().top
54                          + (int) (quickTitle.getLocation().getY() + quickTitle
55                                  .getPreferredSize().getHeight()));
56              }else{
57                  gfx.fillRect(x, y , x + width, y + height);
58              }
59          }
60  
61      }
62      
63      
64      public GraphicsDecoratorPanel(JComponent component) {
65          super();
66          createGUI(component);
67      }
68      
69      private void createGUI(JComponent mainComponent){
70          setLayoutBorder();
71          if(mainComponent instanceof IQuickBarComponent){
72              //Add title
73              quickTitle = new QuickTitle(((IQuickBarComponent)mainComponent).getTitle(),((IQuickBarComponent)mainComponent).getIcon());
74              add(quickTitle);
75          }
76          addSeparator();
77          add(mainComponent);
78          
79      }
80      
81      private void setLayoutBorder(){
82          setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
83          setBorder(new Graphic2DPanelBorder());
84      }
85      
86      
87      private void addSeparator(){
88          add(Box.createRigidArea(new Dimension(0,10)));
89      }
90      /***
91       * Paint no background in the component.
92       */
93      public void paintComponent(Graphics g) {
94          // NOP
95      }
96  }