Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
ErrorDialog.java
1 
16 package net.squiz.matrix.ui;
17 
18 import net.squiz.matrix.matrixtree.*;
19 import net.squiz.matrix.core.*;
20 import net.squiz.matrix.plaf.MatrixLookAndFeel;
21 
22 import java.util.*;
23 import java.io.IOException;
24 import net.squiz.matrix.debug.*;
25 import javax.swing.*;
26 import javax.swing.border.*;
27 
28 import java.awt.BorderLayout;
29 import java.awt.event.*;
30 import java.awt.FontMetrics;
31 import java.awt.*;
32 
39 public class ErrorDialog extends MatrixDialog
40  implements MatrixConstants, KeyListener {
41 
42  private static Point prevScreenLocation = null;
43 
44  private ErrorDialog(String message, String title) {
45  JPanel contentPane = new JPanel(new BorderLayout());
46  setContentPane(contentPane);
47 
48  Border border = new EmptyBorder(1, 1, 1, 1);
49  contentPane.setBorder(border);
50 
51  JPanel midPanel = new JPanel();
52  midPanel.setBackground(MatrixLookAndFeel.PANEL_COLOUR);
53 
54  JLabel label = new JLabel(message);
55  label.setFont(MatrixTreeBus.getActiveTree().getFontInUse());
56  midPanel.add(label);
57 
58  contentPane.add(getTopPanel(title), BorderLayout.NORTH);
59  contentPane.add(midPanel, BorderLayout.CENTER);
60 
61 
62  JPanel bottomPanel = new JPanel();
63  JLabel okButton = new JLabel();
64  okButton.setIcon(GUIUtilities.getAssetMapIcon("ok.png"));
65  closeOnClick(okButton, "ok");
66 
67 
68  /* // mouse events
69  okButton.addMouseListener(new MouseAdapter(){
70  public void mouseClicked(MouseEvent e){
71  setCursor(DEFAULT_CURSOR);
72  dispose();
73  }
74 
75  public void mouseExited(MouseEvent e) {
76  setCursor(DEFAULT_CURSOR);
77  okButton.setIcon(GUIUtilities.getAssetMapIcon("ok.png"));
78  }
79 
80  public void mouseEntered(MouseEvent e) {
81  setCursor(HAND_CURSOR);
82  okButton.setIcon(GUIUtilities.getAssetMapIcon("ok_on.png"));
83  }
84  });*/
85 
86  okButton.setOpaque(false);
87  bottomPanel.add(okButton);
88  bottomPanel.setBackground(MatrixLookAndFeel.PANEL_COLOUR);
89 
90  contentPane.add(bottomPanel, BorderLayout.SOUTH);
91 
92 
93  contentPane.setBackground(MatrixLookAndFeel.PANEL_BORDER_COLOUR);
94  enableDrag(contentPane);
95 
96  FontMetrics fm = getFontMetrics(label.getFont());
97  int textWidth = fm.stringWidth(label.getText());
98  setSize(textWidth + 32, 125);
99  addKeyListener(this);
100 
101  }
102 
103  public void keyTyped(KeyEvent evt) {
104  }
105 
106  public void keyPressed(KeyEvent evt) {
107  if(evt.getKeyCode() == evt.VK_ENTER) {
108  dispose();
109  } else if(evt.getKeyCode() == evt.VK_ESCAPE) {
110  dispose();
111  }
112  }
113 
114  public void keyReleased(KeyEvent evt) {
115  }
116 
117  public void dispose() {
118  prevScreenLocation = getPrevLoc();
119  super.dispose();
120  }
121 
128  public static ErrorDialog getErrorDialog(String message, String title, Point locationOnScreen, Dimension treeDimension) {
129  ErrorDialog ErrorDialog = null;
130 
131  if (MatrixDialog.hasDialog(ErrorDialog.class)) {
132  ErrorDialog = (ErrorDialog) MatrixDialog.getDialog(ErrorDialog.class);
133  ErrorDialog.dispose();
134  }
135 
136  ErrorDialog = new ErrorDialog(message, title);
137  MatrixDialog.putDialog(ErrorDialog);
138 
139  ErrorDialog.pack();
140  ErrorDialog.centerDialogOnTree(locationOnScreen, treeDimension, prevScreenLocation);
141 
142  return ErrorDialog;
143  }
144 
145  /*class ButtonActionListener implements ActionListener {
146  public void actionPerformed(ActionEvent evt) {
147  Object source = evt.getSource();
148 
149  if (source == deleteBtn) {
150  // there can only be on trash folder in the system.
151  String[] assetids = AssetManager.getAssetsOfType("trash_folder");
152  Asset trash = AssetManager.getAsset(assetids[0]);
153  Iterator nodes = trash.getTreeNodes();
154  MatrixTreeNode trashNode = null;
155  while (nodes.hasNext()) {
156  trashNode = (MatrixTreeNode) nodes.next();
157  }
158  MatrixTreeComm.createLink(NewLinkEvent.LINK_TYPE_MOVE, ErrorDialog.this.nodes, trashNode, 0, 0);
159 
160  }
161 
162  //TODO: (MM): need to call super.dispose(), maybe rename dispose() to disposeDialog()
163  // in MatrixDialog and invoke it so it's clear that we are doing something different from dispose
164  dispose();
165  }
166  }//end class ButtonActionListener
167  */
168 
169 }//end class ErrorDialog