View Javadoc
1   package net.logAnalyzer.utils.gui.quickbar;
2   
3   import java.awt.Color;
4   import java.awt.Dimension;
5   import java.awt.FlowLayout;
6   import java.awt.GradientPaint;
7   import java.awt.Graphics;
8   import java.awt.Graphics2D;
9   
10  import javax.swing.JPanel;
11  
12  import net.logAnalyzer.utils.gui.GraphicsAttributes;
13  
14  public class QuickBar extends JPanel {
15      private static final long serialVersionUID = 1L;
16  
17      /***
18       * Constructs a new QuickBar.
19       * 
20       * @param width
21       */
22      public QuickBar(int width) {
23          super();
24          setLayout(new FlowLayout());
25          setPreferredSize(new Dimension(width, 200));
26      }
27  
28      /***
29       * Paint the background of the component.
30       */
31      public void paintComponent(Graphics g) {
32          Graphics2D gfx = (Graphics2D) g;
33          gfx.setPaint(new GradientPaint(0, 0, GraphicsAttributes.QUICKBAR_GRADIENTSTART_COLOR,
34                  getWidth(), getHeight(), GraphicsAttributes.QUICKBAR_GRADIENTEND_COLOR));
35          gfx.fillRect(0, 0, getWidth(), getHeight());
36      }
37  
38      /***
39       * Add a new {@link QuickPanel}.
40       * 
41       * @param panel
42       *            New {@link QuickPanel}.
43       */
44      public void addPanel(QuickPanel panel) {
45          panel.setPreferredSize(new Dimension((int) (getPreferredSize()
46                  .getWidth() - 20), (int) panel.getPreferredSize().getHeight()));
47          addImpl(panel, null, -1);
48          this.updateUI();
49      }
50      
51      /***
52       * Add a new JPanel.
53       * 
54       * @param panel
55       *          
56       */
57      public void addPanel(JPanel panel) {
58          panel.setPreferredSize(new Dimension((int) (getPreferredSize()
59                  .getWidth() - 20), (int) panel.getPreferredSize().getHeight()));
60          addImpl(panel, null, -1);
61          this.updateUI();
62      }
63      /***
64       * remove a new JPanel.
65       * 
66       * @param panel
67       *          
68       */
69      public void removePanel(JPanel panel) {
70          remove(panel);
71          this.updateUI();
72      }
73  }