16 package net.squiz.matrix.ui;
18 import net.squiz.matrix.plaf.MatrixLookAndFeel;
19 import net.squiz.matrix.matrixtree.*;
20 import net.squiz.matrix.core.*;
22 import javax.swing.border.*;
23 import java.awt.event.*;
34 private static HashMap dialogs =
new HashMap();
35 public Cursor HAND_CURSOR =
new Cursor(Cursor.HAND_CURSOR);
36 public Cursor DEFAULT_CURSOR =
new Cursor(Cursor.DEFAULT_CURSOR);
40 setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
58 dialogs.put(dialog.getClass(), dialog);
66 return dialogs.containsKey(cls);
73 dialogs.remove(getClass());
80 public Point getPrevLoc() {
84 private void setPrevLoc(Point prevLoc) {
85 this.prevLoc = prevLoc;
96 int locX = (int)locationOnScreen.getX()+(int)((treeDimension.getWidth()/2)-(getWidth()/2));
101 setLocation(locX,(
int)(locationOnScreen.getY()+(treeDimension.getHeight()/3)),
false);
104 public JPanel getTopPanel(String dialogTitle) {
105 JPanel topPanel =
new JPanel();
106 topPanel.setBorder(
new EmptyBorder(0, 0, 0, 0));
109 JLabel title =
new JLabel(dialogTitle);
110 title.setFont(MatrixTreeBus.getActiveTree().getFontInUse());
111 title.setHorizontalTextPosition(SwingConstants.CENTER);
112 title.setOpaque(
false);
113 title.setForeground(Color.black);
116 enableDrag(topPanel);
121 public void closeOnClick(
final JLabel component,
final String img_prefix) {
122 component.addMouseListener(
new MouseAdapter(){
123 public void mouseClicked(MouseEvent e){
124 setCursor(DEFAULT_CURSOR);
128 public void mouseExited(MouseEvent e) {
129 component.setIcon(GUIUtilities.getAssetMapIcon(img_prefix +
".png"));
130 setCursor(DEFAULT_CURSOR);
133 public void mouseEntered(MouseEvent e) {
134 setCursor(HAND_CURSOR);
135 component.setIcon(GUIUtilities.getAssetMapIcon(img_prefix +
"_on.png"));
140 public void enableDrag(
final JComponent component) {
141 component.addMouseListener(
new MouseAdapter(){
142 public void mouseReleased(MouseEvent e){
146 public void mousePressed(MouseEvent e){
152 component.addMouseMotionListener(
new MouseMotionAdapter(){
153 public void mouseDragged(MouseEvent e){
154 int posX = getLocationOnScreen().x+(e.getX()-x);
155 int posY = getLocationOnScreen().y+(e.getY()-y);
156 setLocation(posX, posY,
true);
157 setPrevLoc(
new Point(posX, posY));
164 public void setLocation(
int x,
int y,
boolean force) {
165 if (force || (getPrevLoc() == null)) {
166 super.setLocation(x, y);
168 x = (int)getPrevLoc().getX();
169 y = (int)getPrevLoc().getY();
170 super.setLocation(x, y);
172 setPrevLoc(
new Point(x, y));