You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
154 lines
3.9 KiB
154 lines
3.9 KiB
package com.jotuntech.sketcher.client;
|
|
|
|
import java.awt.BorderLayout;
|
|
import java.awt.Color;
|
|
import java.awt.Component;
|
|
import java.awt.event.MouseEvent;
|
|
import java.awt.event.MouseListener;
|
|
|
|
import javax.swing.Icon;
|
|
import javax.swing.ImageIcon;
|
|
import javax.swing.JLabel;
|
|
import javax.swing.JPanel;
|
|
import javax.swing.UIManager;
|
|
import javax.swing.border.EmptyBorder;
|
|
|
|
public class JCollapsiblePanel extends JPanel {
|
|
private final static Icon expandedIcon = UIManager.getIcon("Tree.expandedIcon");
|
|
private final static Icon collapsedIcon = UIManager.getIcon("Tree.collapsedIcon");
|
|
private final static Icon pinNormalIcon = new ImageIcon(JCollapsiblePanel.class.getResource("images/pin_normal.png"));
|
|
private final static Icon pinStuckIcon = new ImageIcon(JCollapsiblePanel.class.getResource("images/pin_stuck.png"));
|
|
private JLabel label;
|
|
private JLabel pin;
|
|
private JPanel contentPane;
|
|
private JCollapsiblePanelGroup group;
|
|
private boolean stuck;
|
|
private int id;
|
|
private boolean expandedByDefault, stuckByDefault;
|
|
|
|
public JCollapsiblePanel(int id, String title, boolean expanded, boolean stuckx) {
|
|
super();
|
|
|
|
this.id = id;
|
|
|
|
this.stuck = stuckx;
|
|
this.stuckByDefault = stuckx;
|
|
this.expandedByDefault = expanded;
|
|
|
|
setBorder(new EmptyBorder(0, 0, 1, 0));
|
|
setAlignmentX(Component.LEFT_ALIGNMENT);
|
|
setLayout(new BorderLayout());
|
|
|
|
JPanel topPanel = new JPanel(new BorderLayout());
|
|
topPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
|
|
add(topPanel, BorderLayout.NORTH);
|
|
|
|
label = new JLabel();
|
|
label.setIcon(expanded ? expandedIcon : collapsedIcon);
|
|
label.setText(title);
|
|
label.addMouseListener(new MouseListener() {
|
|
public void mouseClicked(MouseEvent arg0) {
|
|
}
|
|
|
|
public void mouseEntered(MouseEvent arg0) {
|
|
}
|
|
|
|
public void mouseExited(MouseEvent arg0) {
|
|
}
|
|
|
|
public void mousePressed(MouseEvent arg0) {
|
|
}
|
|
|
|
public void mouseReleased(MouseEvent arg0) {
|
|
if(!stuck) {
|
|
setExpanded(!contentPane.isVisible(), true);
|
|
}
|
|
}
|
|
});
|
|
label.setAlignmentX(Component.LEFT_ALIGNMENT);
|
|
label.setBackground(new Color(172, 200, 230));
|
|
label.setOpaque(true);
|
|
topPanel.add(label, BorderLayout.CENTER);
|
|
|
|
pin = new JLabel();
|
|
pin.setIcon(stuck ? pinStuckIcon : pinNormalIcon);
|
|
pin.addMouseListener(new MouseListener() {
|
|
public void mouseClicked(MouseEvent e) {
|
|
}
|
|
|
|
public void mouseEntered(MouseEvent e) {
|
|
}
|
|
|
|
public void mouseExited(MouseEvent e) {
|
|
}
|
|
|
|
public void mousePressed(MouseEvent e) {
|
|
}
|
|
|
|
public void mouseReleased(MouseEvent e) {
|
|
setStuck(!isStuck());
|
|
}
|
|
});
|
|
|
|
pin.setAlignmentX(Component.LEFT_ALIGNMENT);
|
|
pin.setBackground(new Color(172, 200, 230));
|
|
pin.setOpaque(true);
|
|
topPanel.add(pin, BorderLayout.EAST);
|
|
|
|
contentPane = new JPanel();
|
|
contentPane.setVisible(expanded);
|
|
contentPane.setBorder(new EmptyBorder(4, 4, 4, 4));
|
|
add(contentPane, BorderLayout.CENTER);
|
|
}
|
|
|
|
public JPanel getContentPane() {
|
|
return contentPane;
|
|
}
|
|
|
|
public void setExpanded(boolean expanded, boolean interactive) {
|
|
if(interactive && expanded && group != null) {
|
|
for(JCollapsiblePanel panel : group) {
|
|
if(panel == this || panel.isStuck()) {
|
|
continue;
|
|
}
|
|
panel.setExpanded(false, false);
|
|
}
|
|
}
|
|
contentPane.setVisible(expanded);
|
|
label.setIcon(expanded ? expandedIcon : collapsedIcon);
|
|
}
|
|
|
|
public boolean isExpanded() {
|
|
return contentPane.isVisible();
|
|
}
|
|
|
|
public void setGroup(JCollapsiblePanelGroup group) {
|
|
this.group = group;
|
|
group.add(this);
|
|
}
|
|
|
|
public void setStuck(boolean stuck) {
|
|
this.stuck = stuck;
|
|
pin.setIcon(stuck ? pinStuckIcon : pinNormalIcon);
|
|
}
|
|
|
|
public boolean isStuck() {
|
|
return stuck;
|
|
}
|
|
|
|
public void setId(int id) {
|
|
this.id = id;
|
|
}
|
|
|
|
public int getId() {
|
|
return id;
|
|
}
|
|
|
|
public boolean isExpandedByDefault() {
|
|
return expandedByDefault;
|
|
}
|
|
|
|
public boolean isStuckByDefault() {
|
|
return stuckByDefault;
|
|
}
|
|
}
|
|
|