nl.cloudfarming.client.util.swing.ASBodyPanel Maven / Gradle / Ivy
/**
* Copyright (C) 2010-2012 Agrosense [email protected]
*
* Licensed under the Eclipse Public License - v 1.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.eclipse.org/legal/epl-v10.html
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.cloudfarming.client.util.swing;
import java.awt.*;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import net.miginfocom.swing.MigLayout;
import org.openide.util.ImageUtilities;
/**
* Panel which contains AgroSense header background.
* The constructor needs a LayoutManger for the body area of this panel.
* there are two areas which can be manipulated.
* The Title area: use setTitle to add a title
* The body area: use the default add methods of component to add components to it
* @author monezz & Merijn Zengers
*/
public class ASBodyPanel extends JPanel {
private AgroSenseHeader header;
private LayoutManager bodyLayoutManager;
private JPanel bodyPanel;
private static final int PANEL_HEIGHT = 400;
/**
* Creates new form ASPanel
* Needs a LayoutManager to use for the body area of this panel.
* Use this manager to manipulate the components added too this panel.
*/
public ASBodyPanel(LayoutManager bodyLayoutManager) {
this.bodyLayoutManager = bodyLayoutManager;
initComponents();
}
private void initComponents() {
this.setLayout(new MigLayout("wrap 1, insets 0 0 0 0"));
setBackground(Color.white);
this.bodyPanel = new JPanel(bodyLayoutManager);
bodyPanel.setBackground(Color.white);
header = new AgroSenseHeader();
Dimension size = new Dimension(header.getWidth(), PANEL_HEIGHT);
setPreferredSize(size);
setMinimumSize(size);
setMaximumSize(size);
setSize(size);
super.add(header);
super.add(bodyPanel);
}
/**
* Sets the title of this panel.
* This will be displayed in the title area of the panel
* @param title the title to set.
*/
public void setTitle(String title){
header.setTitle(title);
}
/**
* Set the icon for this panel
* Will place this icon before the title
* @param icon the icon to set
*/
public void setIcon(ImageIcon icon){
header.setIcon(icon);
}
@Override
public Component add(Component component){
return bodyPanel.add(component);
}
@Override
public void add(Component component, Object constraints){
bodyPanel.add(component, constraints);
}
private class AgroSenseHeader extends AgroSenseImage{
private JLabel title;
private JLabel iconLabel;
public AgroSenseHeader(){
init();
}
private void init(){
this.setLayout(new MigLayout("wrap 2, insets 0 0 0 0"));
iconLabel = new JLabel();
iconLabel.setPreferredSize(new Dimension(0, 0));
title = new JLabel();
title.setFont(new java.awt.Font("DejaVu Sans", 0, 24));
this.add(iconLabel, "gap top 40, gap left 12");
this.add(title, "gap top 40, gap left 5");
}
void setIcon(ImageIcon icon){
iconLabel.setPreferredSize(new Dimension(icon.getIconWidth(),icon.getIconHeight()));
iconLabel.setIcon(icon);
this.repaint();
}
void setTitle(String title){
this.title.setText(title);
this.repaint();
}
}
private class AgroSenseImage extends JPanel {
private Image background = ImageUtilities.loadImage("nl/cloudfarming/client/util/swing/background-base600.png");
public AgroSenseImage() {
Dimension size = new Dimension(background.getWidth(null), background.getHeight(null));
setPreferredSize(size);
setMinimumSize(size);
setMaximumSize(size);
setSize(size);
}
@Override
protected void paintComponent(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
g2d.setPaint(getBackground());
g2d.fillRect(0, 0, getWidth(), getHeight());
g.drawImage(background, 0, 0, getWidth(), background.getHeight(this), null);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy