📄 utils.java
字号:
location = pkg; } return location; } public static String getLocString(XMLElement location, XMLElement el) { ActivitySet as = XMLUtil.getActivitySet(el); WorkflowProcess wp = XMLUtil.getWorkflowProcess(el); Package pkg = XMLUtil.getPackage(el); String loc = ResourceManager.getLanguageDependentString("PackageKey") + " '" + pkg.getId() + "'"; if (wp != null) { loc += ", " + ResourceManager.getLanguageDependentString("WorkflowProcessKey") + " '" + wp.getId() + "'"; } if (as != null) { loc += ", " + ResourceManager.getLanguageDependentString("ActivitySetKey") + " '" + as.getId() + "'"; } if (location != as && location != wp && location != pkg) { loc += ", " + ResourceManager.getLanguageDependentString(location.toName() + "Key") + " '" + ((XMLComplexElement) location).get("Id").toValue() + "'"; } if (el != location && el != as && el != wp && el != pkg) { XMLElement parent=el.getParent(); if (parent!=location && !(parent instanceof XMLCollection)) { loc += ", " + ResourceManager.getLanguageDependentString(parent.toName() + "Key"); } loc += " -> " + ResourceManager.getLanguageDependentString(el.toName() + "Key"); } return loc; } public static List makeSearchResultList(List results) { List srl = new ArrayList(); for (int i = 0; i < results.size(); i++) { srl.add(new SearchResult((XMLElement) (results.get(i)))); } return srl; } public static Map loadActions(Properties properties, JaWEComponent comp) { return loadActions(properties, comp, new HashMap()); } public static Map loadActions(Properties properties, JaWEComponent comp, Map defaultActions) { Map componentAction = new HashMap(); // ******** actions Set actions = new HashSet(); List actionsN = ResourceManager.getResourceStrings(properties, "Action.Name.", false); List actionsC = ResourceManager.getResourceStrings(properties, "Action.Class.", false); List actionsI = ResourceManager.getResourceStrings(properties, "Action.Image.", false); actions.addAll(actionsN); actions.addAll(actionsC); actions.addAll(actionsI); for (Iterator it = actions.iterator(); it.hasNext();) { String actionName = (String) it.next(); try { JaWEAction ja; if (defaultActions.containsKey(actionName)) ja = (JaWEAction) defaultActions.get(actionName); else ja = new JaWEAction(); try { // Action Base String className = ResourceManager.getResourceString(properties, "Action.Class." + actionName); Constructor c = Class.forName(className).getConstructor(new Class[] { JaWEComponent.class }); ActionBase action = (ActionBase) c.newInstance(new Object[] { comp }); ja.setAction(action); } catch (Exception e) { } try { // Icon URL url = ResourceManager.getResource(properties, "Action.Image." + actionName); ImageIcon icon = null; if (url != null) icon = new ImageIcon(url); ja.setIcon(icon); } catch (Exception e) { } try { // Language dependent name String langDepName = ResourceManager.getResourceString(properties, "Action.Name." + actionName); ja.setLangDepName(langDepName); } catch (Exception e) { } if (ja.getAction() != null) { componentAction.put(actionName, ja); JaWEManager.getInstance().getLoggingManager().info("Created " + comp.getName() + " action for class " + actionName); } else { JaWEManager.getInstance().getLoggingManager().info("Missing action for " + actionName); } } catch (Throwable thr) { JaWEManager.getInstance().getLoggingManager().error("Can't create " + comp.getName() + " action for class " + actionName); } } return componentAction; } public static Map loadAllMenusAndToolbars(Properties properties) { Map mst = new HashMap(); mst = loadSubMenus(properties); mst.putAll(loadPopups(properties)); mst.putAll(loadToolbars(properties)); return mst; } public static Map loadSubMenus(Properties properties) { Map componentSettings = new HashMap(); List subMenus = ResourceManager.getResourceStrings(properties, "SubMenu.Name.", false); for (int i = 0; i < subMenus.size(); i++) { String aorder = ResourceManager.getResourceString(properties, "SubMenu.ActionOrder." + subMenus.get(i)); String langName = ResourceManager.getResourceString(properties, "SubMenu.Name." + subMenus.get(i)); componentSettings.put(subMenus.get(i) + "Menu", aorder); componentSettings.put(subMenus.get(i) + "LangName", langName); } return componentSettings; } public static Map loadToolbars(Properties properties) { Map componentSettings = new HashMap(); List toolbars = ResourceManager.getResourceStrings(properties, "Toolbar.ActionOrder.", false); for (int i = 0; i < toolbars.size(); i++) { String aorder = ResourceManager.getResourceString(properties, "Toolbar.ActionOrder." + toolbars.get(i)); componentSettings.put(toolbars.get(i) + "Toolbar", aorder); } return componentSettings; } public static Map loadPopups(Properties properties) { Map componentSettings = new HashMap(); List popupMenus = ResourceManager.getResourceStrings(properties, "PopupMenu.ActionOrder.", false); for (int i = 0; i < popupMenus.size(); i++) { String aorder = ResourceManager.getResourceString(properties, "PopupMenu.ActionOrder." + popupMenus.get(i)); componentSettings.put(popupMenus.get(i) + "Menu", aorder); } return componentSettings; } protected static SequencedHashMap actImgResources = null; protected static List actImgResourceNames = null; public static List getActivityIconNamesList() { if (actImgResources == null) { getActivityIconsMap(); } return new ArrayList(actImgResourceNames); } public static SequencedHashMap getOriginalActivityIconsMap() { if (actImgResources == null) { getActivityIconsMap(); } return actImgResources; } public static SequencedHashMap getActivityIconsMap() { if (actImgResources == null) { Map m = new HashMap(); String classPath = System.getProperty("java.class.path"); String[] cps = Utils.tokenize(classPath, File.pathSeparator); String jed = System.getProperty("java.ext.dirs"); String[] jeds = Utils.tokenize(jed, File.pathSeparator); for (int i = 0; i < cps.length; i++) { String cp = cps[i]; if (cp.indexOf("activityicons") >= 0) { m.putAll(Utils.getResourcesForPath(cp, JaWEConstants.JAWE_ACTIVITY_ICONS)); } } for (int i = 0; i < jeds.length; i++) { String jd = jeds[i]; File f = new File(jd); if (f.exists() && f.isDirectory()) { File[] files = f.listFiles(); if (files != null) { for (int j = 0; j < files.length; j++) { if (files[j].isFile() && files[j].getName().indexOf("activityicons") >= 0) { m.putAll(Utils.getResourcesForPath(files[j].getAbsolutePath(), JaWEConstants.JAWE_ACTIVITY_ICONS)); } } } } } actImgResources = new SequencedHashMap(); actImgResourceNames = new ArrayList(m.keySet()); Collections.sort(actImgResourceNames); for (int i = 0; i < actImgResourceNames.size(); i++) { Object key = actImgResourceNames.get(i); actImgResources.put(key, m.get(key)); } } return new SequencedHashMap(actImgResources); } /** * Returns a Map of images from located on given path. */ public static Map getResourcesForPath(String classPath, String prefix) { Map resources = new HashMap(); // case of resources contained in a jar file. if (classPath.endsWith(".jar")) { JarFile jfile = null; try { jfile = new JarFile(classPath, false); } catch (Throwable ex) { ex.printStackTrace(); return resources; } // get all entries Enumeration e = jfile.entries(); // loop through entries and find appropriate ones while (e.hasMoreElements()) { try { ZipEntry entry = (ZipEntry) e.nextElement(); String entryname = entry.getName(); String res = entryname; // removes starting '/' if (res.startsWith("/")) { res = res.substring(1); } // entry must start with prefix if (entryname.startsWith(prefix)) { // checking if resource is image ImageIcon ii = null; try { ii = new ImageIcon(Utils.class.getClassLoader() .getResource(entryname)); } catch (Exception ex) { } if (ii != null) { // removes the prefix res = res.substring(prefix.length()); if (res.startsWith("/")) { res = res.substring(1); } if (res.length() > 0) { resources.put(res, ii); } } } } catch (Throwable thr) { } } } else { // if it is not .jar file, but directory // getting the folder File startingFolder = new File(classPath + "/" + prefix); // if folder exists and realy is a folder but not file if (startingFolder.exists() && startingFolder.isDirectory()) { File[] children = startingFolder.listFiles(); for (int i = 0; i < children.length; i++) { if (children[i].isFile()) { String fileName = children[i].getName(); // checking if resource is image ImageIcon ii = null; try { ii = new ImageIcon(Utils.class.getClassLoader() .getResource(prefix + "/" + fileName)); } catch (Exception ex) { } if (ii != null) { resources.put(fileName, ii); } } } } } return resources; } public static boolean reconfigure(String newConfig) { JaWEController jc = JaWEManager.getInstance().getJaWEController(); String fn = JaWEConstants.JAWE_CONF_HOME + "/defaultconfig"; File file = new File(fn); if (!file.exists()) { return false; } File newFile = new File(JaWEConstants.JAWE_CONF_HOME + "/temp"); WaitScreen ws = new WaitScreen(null); try { newFile.createNewFile(); BufferedReader reader = new BufferedReader(new FileReader(file)); BufferedWriter writer = new BufferedWriter(new FileWriter(newFile)); String line = null; boolean done = false; while ((line = reader.readLine()) != null) { if (!done && (line.startsWith("#" + JaWEConstants.JAWE_CURRENT_CONFIG_HOME) || line.startsWith(JaWEConstants.JAWE_CURRENT_CONFIG_HOME))) { line = JaWEConstants.JAWE_CURRENT_CONFIG_HOME + " = " + newConfig; done = true; } writer.write(line + "\n"); } reader.close(); writer.close(); file.delete(); newFile.renameTo(file); System.setProperty(JaWEConstants.JAWE_CURRENT_CONFIG_HOME, JaWEConstants.JAWE_CONF_HOME + "/" + newConfig); String filename = jc.getPackageFilename(jc.getMainPackageId()); jc.tryToClosePackage(jc.getMainPackageId(), true); ws.show(null, "", jc.getSettings() .getLanguageDependentString("ReconfiguringKey")); JaWEManager.getInstance().restart(filename); ws.setVisible(false); return true; } catch (Throwable e) { e.printStackTrace(); return false; } finally { ws.setVisible(false); } }}class PFFilter implements FilenameFilter { String pfStr = ".properties"; public boolean accept(File dir, String name) { String f = new File(name).getName(); int fi = f.indexOf(Utils.LANG_PROP_PREFIX); int li = f.lastIndexOf(Utils.LANG_PROP_PREFIX); return (fi != -1 && fi == 0 && fi == li && f.endsWith(pfStr)); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -