package com.foo.one;
/*
*
* ATTN: Class org.jdesktop.swingx.JXTaskPane defines non-transient non-serializable instance field icon
*/
import com.foo.defaut.colors.Colors;
import com.foo.defaut.images.Images;
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.LinearGradientPaint;
import javax.swing.*;
import javax.swing.plaf.FontUIResource;
import org.jdesktop.swingx.JXLabel;
import org.jdesktop.swingx.JXTaskPane;
import org.jdesktop.swingx.JXTaskPaneContainer;
import org.jdesktop.swingx.painter.MattePainter;
import org.jdesktop.swingx.painter.Painter;
/**
* TaskPaneExample1
*
* @author Nazmul Idris
* @version 1.0
* @since Jan 28, 2008, 12:49:01 PM
*/
public class MyTaskPaneExample1 {
/** simple main driver for this class */
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new MyTaskPaneExample1();
}
});
}
private JScrollPane _scr_ = null;
/** creates a JFrame and calls {@link #doInit} to create a JXPanel and adds the panel to this frame. */
public MyTaskPaneExample1() {
JFrame frame = new JFrame("TaskPane Example 1");
// add the panel to this frame
Component cmp = doInit();
frame.add(_scr_);
// when you close the frame, the app exits
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// center the frame and show it
frame.setLocationRelativeTo(null);
frame.pack();
frame.setVisible(true);
}
/** creates a JXLabel and attaches a painter to it. */
private Component doInit() {
//JXPanel xpnAll = new JXPanel();
//xpnAll.setLayout(new BorderLayout());
// create a label
final JXLabel _xlb1_ = new JXLabel();
final JXLabel _xlb2_ = new JXLabel();
_xlb1_.setFont(new Font("Segoe UI", Font.BOLD, 14));
_xlb1_.setText("task pane item 1 : a label 1");
_xlb1_.setIcon(Images.NetworkDisconnected.getIcon(32, 32));
_xlb1_.setHorizontalAlignment(JXLabel.LEFT);
//_xlb1_.setBackgroundPainter(getPainter());
// ---
_xlb2_.setFont(new Font("Segoe UI", Font.BOLD, 14));
_xlb2_.setText("task pane item 2 : a label 2");
_xlb2_.setIcon(Images.NetworkDisconnected.getIcon(32, 32));
_xlb2_.setHorizontalAlignment(JXLabel.LEFT);
//_xlb2_.setBackgroundPainter(getPainter());
// ---
// tweak with the UI defaults for the taskpane and taskpanecontainer
_changeUIdefaults_();
// create a taskpanecontainer
JXTaskPaneContainer taskpanecontainer = new JXTaskPaneContainer();
this._scr_ = new JScrollPane(taskpanecontainer);
// create a taskpane, and set it's title and icon
JXTaskPane tsk1 = new JXTaskPane();
tsk1.setTitle("My Tasks 1");
tsk1.setIcon(Images.Quit.getIcon(24, 24));
// add various actions and components to the taskpane
//tsk1.add(_xlb1_);
/*tsk1.add(new AbstractAction() {
{
putValue(Action.NAME, "task pane item 1 : an action");
putValue(Action.SHORT_DESCRIPTION, "perform an action");
putValue(Action.SMALL_ICON, Images.NetworkConnected.getIcon(32, 32));
}
public void actionPerformed(ActionEvent e) {
_xlb1_.setText("an action performed");
}
});*/
// ---
// create a taskpane, and set it's title and icon
JXTaskPane tsk2 = new JXTaskPane();
tsk2.setTitle("My Tasks 2");
tsk2.setIcon(Images.Quit.getIcon(24, 24));
// add various actions and components to the taskpane
JPanel pnl2 = new JPanel();
//JScrollPane scr2 = new JScrollPane(pnl2); // same as scrollPane.setViewportView(table);
tsk2.add(pnl2);
//pnl2.add(_xlb2_);
JButton btn2 = new JButton("btn2");
pnl2.add(btn2);
// ---
// add the task pane to the taskpanecontainer
taskpanecontainer.add(tsk1);
taskpanecontainer.add(tsk2);
// set the transparency of the JXPanel to 50% transparent
//xpnAll.setAlpha(0.7f);
/*xpnAll.add(taskpanecontainer, BorderLayout.CENTER);
xpnAll.setPreferredSize(new Dimension(250, 200));
return xpnAll;*/
return taskpanecontainer;
}
private void _changeUIdefaults_() {
// JXTaskPaneContainer settings (developer defaults)
/* These are all the properties that can be set (may change with new version of SwingX)
"TaskPaneContainer.useGradient",
"TaskPaneContainer.background",
"TaskPaneContainer.backgroundGradientStart",
"TaskPaneContainer.backgroundGradientEnd",
etc.
*/
// setting taskpanecontainer defaults
UIManager.put("TaskPaneContainer.useGradient", Boolean.FALSE);
//UIManager.put("TaskPaneContainer.background", Colors.LightGray.color(0.5f));
UIManager.put("TaskPaneContainer.background", new Color(200, 200, 200, (int) (0.5f * 255f))); // lightgray + alpha
// setting taskpane defaults
//UIManager.put("TaskPane.font", new FontUIResource(new Font("Verdana", Font.BOLD, 16)));
UIManager.put("TaskPane.font", new FontUIResource(new Font("Arial", Font.BOLD, 16)));
//UIManager.put("TaskPane.titleBackgroundGradientStart", Colors.White.color());
UIManager.put("TaskPane.titleBackgroundGradientStart", Color.WHITE);
//UIManager.put("TaskPane.titleBackgroundGradientEnd", Colors.LightBlue.color());
UIManager.put("TaskPane.titleBackgroundGradientEnd", new Color(208, 223, 245)); // lightblue
}
/** this painter draws a gradient fill */
public Painter getPainter() {
int width = 100;
int height = 100;
Color color1 = Colors.White.color(0.5f);
Color color2 = Colors.Gray.color(0.5f);
LinearGradientPaint gradientPaint =
new LinearGradientPaint(0.0f, 0.0f, width, height,
new float[]{0.0f, 1.0f},
new Color[]{color1, color2});
MattePainter mattePainter = new MattePainter(gradientPaint);
return mattePainter;
}
}