Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
GUIUtilities.java
1 
16 package net.squiz.matrix.core;
17 
18 import net.squiz.matrix.matrixtree.*;
19 import net.squiz.matrix.ui.ErrorDialog;
20 import javax.swing.*;
21 import java.awt.*;
22 import java.net.*;
23 import java.util.*;
24 import java.awt.event.*;
25 
26 public class GUIUtilities {
27 
32  private static Map icons = new HashMap();
33  private static JPopupMenu addMenu;
34 
35  // cannot instantiate
36  private GUIUtilities() {}
37 
45  public static void error(Component comp, String message, String title) {
46 
47  MatrixTree tree = MatrixTreeBus.getActiveTree();
48  if (tree == null) {
49  JOptionPane.showMessageDialog(
50  comp,
51  message,
52  title,
53  JOptionPane.ERROR_MESSAGE
54  );
55  return;
56  }
57  ErrorDialog errorDialog = ErrorDialog.getErrorDialog(message, title, tree.getLocationOnScreen(), tree.getSize());
58  errorDialog.show();
59  }
60 
67  public static void error(String message, String title) {
68  // see the JOptionPane docs about using null as a component
69  error(null, message, title);
70  }
71 
88  public static Icon getIcon(String path) {
89  if (!icons.containsKey(path)) {
90  try {
91  Icon icon = new ImageIcon(
92  new URL(Matrix.getProperty("parameter.url.baseurl") + path));
93  icons.put(path, icon);
94  return icon;
95  } catch (MalformedURLException mue) {
96  return null;
97  }
98  }
99  return (Icon) icons.get(path);
100  }
101 
108  public static Icon getAssetMapIcon(String iconName) {
109  return getIcon(Matrix.getProperty("parameter.url.assetmapiconurl") + "/" + iconName);
110  }
111 
117  public static Icon getIconForTypeCode(String typeCode) {
118  return getIcon(Matrix.getProperty("parameter.url.typecodeurl")
119  + "/" + typeCode + "/" + "icon.png");
120  }
121 
126  public static boolean isIconLoaded(String typeCode) {
127  if (icons.containsKey(Matrix.getProperty("parameter.url.typecodeurl") + "/" + typeCode + "/" + "icon.png")) {
128  return true;
129  } else {
130  return false;
131  }
132  }
133 
134  /***
135  * Returns the compound icon for the given type code
136  * @param typeCode the type code of the wanted icon
137  * @param compoundIconName the compound icon name
138  * @return the Icon
139  * @see CompundIcon
140  */
141  public static Icon getCompoundIconForTypeCode(
142  String typeCode,
143  String compoundIconName,
144  String assetId) {
145 
146  String key = "__compound_icon_" + assetId;
147  if (!icons.containsKey(key)) {
148  Icon baseIcon = getIconForTypeCode(typeCode);
149  Icon overlayIcon = getIcon(Matrix.getProperty("parameter.url.iconurl")
150  + "/" + compoundIconName);
151 
152  CompoundIcon icon = new CompoundIcon(
153  baseIcon,
154  overlayIcon,
155  SwingConstants.LEFT,
156  SwingConstants.BOTTOM
157  );
158  icons.put(key, icon);
159  return icon;
160  }
161  return (Icon) icons.get(key);
162  }
163 
169  public static void showInScreenCenter(Component comp) {
170  Dimension size = Toolkit.getDefaultToolkit().getScreenSize();
171  int x = (int) (size.getWidth() - comp.getWidth()) / 2;
172  int y = (int) (size.getHeight() - comp.getHeight()) / 2;
173  comp.setLocation(x, y);
174  comp.setVisible(true);
175  }
176 
183  public static boolean isRightMouseButton(MouseEvent evt) {
184  if ((evt.getModifiers() & MouseEvent.BUTTON3_MASK) == MouseEvent.BUTTON3_MASK)
185  return true;
186  return false;
187  }
188 }