16 package net.squiz.matrix.assetmap;
19 import javax.swing.tree.*;
20 import net.squiz.matrix.ui.*;
21 import net.squiz.matrix.core.*;
22 import net.squiz.matrix.matrixtree.*;
23 import net.squiz.matrix.plaf.*;
25 import java.awt.event.*;
28 import netscape.javascript.*;
29 import javax.swing.plaf.metal.*;
30 import javax.swing.border.*;
31 import net.squiz.matrix.debug.*;
32 import java.io.IOException;
34 import java.security.AccessControlException;
40 public class AssetMap extends JApplet implements InitialisationListener, KeyListener, ContainerListener {
45 protected static JSObject window;
47 private javax.swing.Timer timer;
48 public static final int POLLING_TIME = 2000;
55 UIManager.setLookAndFeel(
new MatrixLookAndFeel());
56 }
catch (UnsupportedLookAndFeelException ulnfe) {
57 ulnfe.printStackTrace();
61 addKeyAndContainerListenerRecursively(
this);
74 public static void getURL(String url)
throws MalformedURLException {
75 applet.getAppletContext().showDocument(
new URL(url),
"sq_main");
84 public static void openWindow(String url, String title) {
86 window = JSObject.getWindow(applet);
87 window.call(
"open_hipo",
new Object[] { url } );
90 public void initialisationComplete(InitialisationEvent evt) {}
99 window = JSObject.getWindow(
this);
104 addKeyListener(
this);
125 private void javaVersionCheck() {
127 boolean supportedVersion =
false;
129 String version = System.getProperty(
"java.version");
130 String[] supVersions = (Matrix.getProperty(
"parameter.java.supportedversion")).split(
"\\,");
133 for (
int i=0; i< supVersions.length; i++) {
134 if (version.startsWith(supVersions[i])) {
135 supportedVersion =
true;
140 if (!supportedVersion) {
141 Object[] options = { Matrix.translate(
"ok"), Matrix.translate(
"cancel") };
142 Object[] transArgs = {
144 Matrix.getProperty(
"parameter.java.supportedversion").replaceAll(
",",
", ")
147 int ret = JOptionPane.showOptionDialog(null, Matrix.translate(
"asset_map_error_java_version", transArgs),
148 Matrix.translate(
"asset_map_error_java_version_title"),
149 JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]);
154 getAppletContext().showDocument(
new URL(Matrix.getProperty(
"parameter.java.sunurl")),
"_blank");
155 }
catch (java.net.MalformedURLException exp) {
156 System.out.println(exp.getMessage());
170 MatrixStatusBar.setStatus(Matrix.translate(
"asset_map_status_bar_init"));
171 MatrixSwingWorker worker =
new MatrixSwingWorker() {
172 public Object construct() {
173 MatrixTreeNode root = null;
175 root = AssetManager.init();
176 GUIUtilities.getAssetMapIcon(MatrixMenus.DEFAULT_ASSET_ICON);
177 }
catch (IOException ioe) {
183 public void finished() {
186 if (
get instanceof MatrixTreeNode) {
190 String newRoot = Matrix.getProperty(
"parameter.rootlineage");
191 MatrixTreeModelBus.setRoot((MatrixTreeNode)
get());
193 if (newRoot.length() > 0) {
195 String[] info = newRoot.split(
"~");
196 String[] assetIds = info[0].split(
"\\|");
197 String[] sort_orders = info[1].split(
"\\|");
200 Iterator trees = MatrixTreeBus.getTrees();
201 while (trees.hasNext()) {
202 MatrixTree tree = (MatrixTree) trees.next();
204 tree.collapsePath(tree.getPathToRoot((MatrixTreeNode)tree.getModel().getRoot()));
206 tree.loadChildAssets(assetIds, sort_orders,
false,
true);
214 String initial_lineage = Matrix.getProperty(
"parameter.initialselection");
215 if (initial_lineage.length() > 0) {
216 String[] init_info = initial_lineage.split(
"~");
217 String[] init_assetIds = init_info[0].split(
"\\|");
218 String[] init_sort_orders = init_info[1].split(
"\\|");
219 Iterator trees = MatrixTreeBus.getTrees();
220 while (trees.hasNext()) {
221 MatrixTree tree = (MatrixTree) trees.next();
222 tree.loadChildAssets(init_assetIds, init_sort_orders,
true,
false);
225 }
catch (Exception exp) {}
226 MatrixStatusBar.setStatusAndClear(Matrix.translate(
"asset_map_status_bar_success"), 1000);
228 }
else if (
get instanceof IOException) {
229 IOException ioe = (IOException)
get;
231 AssetMap.this, ioe.getMessage(), Matrix.translate(
"asset_map_dialog_title_init_failed"));
232 MatrixStatusBar.setStatusAndClear(Matrix.translate(
"asset_map_status_bar_init_failed"), 1000);
233 Log.log(
"Could not initialise the asset map",
AssetMap.class, ioe);
248 ActionListener taskPerformer =
new ActionListener() {
249 public void actionPerformed(ActionEvent evt) {
253 String assetidsStr = (String) window.getMember(
"SQ_REFRESH_ASSETIDS");
257 if (assetidsStr != null && !assetidsStr.equals(
"")) {
258 String[] assetids = assetidsStr.split(
"\\|");
259 AssetRefreshWorker worker =
new AssetRefreshWorker(assetids,
false) {
261 protected String getStatusBarWaitMessage() {
262 return Matrix.translate(
"asset_map_status_bar_auto_refresh");
267 window.eval(
"SQ_REFRESH_ASSETIDS = '';");
271 timer =
new javax.swing.Timer(POLLING_TIME, taskPerformer);
287 String paramStr = getParameter(
"parameter.params");
288 String[] params = paramStr.split(
",");
290 for (
int i = 0; i < params.length; i++)
291 Matrix.setProperty(params[i], getParameter(params[i]));
299 Document response = null;
302 response = Matrix.doRequest(
"<command action=\"get translations\" />");
303 }
catch (IOException ioe) {
304 ioe.printStackTrace();
307 Element rootElement = response.getDocumentElement();
310 String currentLocale = rootElement.getAttribute(
"locale");
311 Locale availLocales[] = Locale.getAvailableLocales();
312 for (
int j = 0; j < availLocales.length; j++) {
313 if (availLocales[j].toString().equals(currentLocale)) {
315 Locale.setDefault(availLocales[j]);
316 }
catch (AccessControlException ace) {
317 Log.log(
"Error setting locale, invalid permisions",
AssetMap.class, ace);
323 NodeList children = rootElement.getChildNodes();
324 for (
int i = 0; i < children.getLength(); i++) {
325 if (!(children.item(i) instanceof CDATASection))
328 CDATASection cdata = (CDATASection) children.item(i);
329 Matrix.setTranslationFile(cdata.getData());
348 getContentPane().setBackground(
new Color(0x342939));
354 pane.addView(Matrix.translate(
"asset_map_tree1_name"), view1);
355 pane.addView(Matrix.translate(
"asset_map_tree2_name"), view2);
377 if (type.equals(
"asset_finder")) {
378 processAssetFinder(command, params);
379 }
else if (type.equals(
"asset_locator")) {
380 processAssetLocator(params);
384 public void processAssetLocator(String params) {
386 String[] info = params.split(
"~");
387 String[] assetIds = info[0].split(
"\\|");
388 String[] sort_orders = info[1].split(
"\\|");
389 MatrixTreeBus.startAssetLocator(assetIds, sort_orders);
392 private void processAssetFinder(String command, String params) {
393 if (command.equals(
"assetFinderStarted")) {
394 String[] assetTypes = params.split(
"~");
395 MatrixTreeBus.startAssetFinderMode(assetTypes);
396 }
else if (command.equals(
"assetFinderStopped")) {
397 MatrixTreeBus.stopAssetFinderMode();
401 public void keyPressed(KeyEvent e) {
402 if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
403 Iterator trees = MatrixTreeBus.getTrees();
405 while (trees.hasNext()) {
406 MatrixTree tree = (MatrixTree) trees.next();
412 public void keyTyped(KeyEvent e) {}
413 public void keyReleased(KeyEvent e) {}
415 public void componentAdded(ContainerEvent e) {
416 addKeyAndContainerListenerRecursively(e.getChild());
419 public void componentRemoved(ContainerEvent e) {
420 removeKeyAndContainerListenerRecursively(e.getChild());
423 public void addKeyAndContainerListenerRecursively(Component c) {
424 c.addKeyListener(
this);
426 if (c instanceof Container) {
427 Container cont = (Container)c;
428 cont.addContainerListener(
this);
430 Component[] children = cont.getComponents();
431 for (
int i = 0; i < children.length; i++) {
432 addKeyAndContainerListenerRecursively(children[i]);
437 public void removeKeyAndContainerListenerRecursively(Component c) {
438 c.removeKeyListener(
this);
440 if (c instanceof Container) {
441 Container cont = (Container)c;
442 cont.removeContainerListener(
this);
444 Component[] children = cont.getComponents();
445 for (
int i = 0; i < children.length; i++) {
446 removeKeyAndContainerListenerRecursively(children[i]);