public WhatsNew(AbstractProjectViewer pv, boolean onlyShowCurrentVersion) throws GeneralException { super(pv); String wn = Environment.getProperty(Constants.WHATS_NEW_VERSION_VIEWED_PROPERTY_NAME); if (wn == null) { wn = "0"; } // Get the current whats new version (i.e. old). Version lastWhatsNewVersion = new Version(wn); boolean betasAllowed = Environment.getUserProperties() .getPropertyAsBoolean(Constants.OPTIN_TO_BETA_VERSIONS_PROPERTY_NAME); try { String whatsNew = Environment.getResourceFileAsString(Constants.WHATS_NEW_FILE); // Load up all the whats new for greater versions. Element root = JDOMUtils.getStringAsElement(whatsNew); java.util.List verEls = JDOMUtils.getChildElements(root, XMLConstants.version, false); // Assume they are in the right order // TODO: Enforce the order and/or sort. for (int i = 0; i < verEls.size(); i++) { Element vEl = (Element) verEls.get(i); String id = JDOMUtils.getAttributeValue(vEl, XMLConstants.id, true); Version v = new Version(id); /* if ((v.isBeta ()) && (!betasAllowed) ) { // Ignore, the user isn't interested in betas. continue; } */ if ((lastWhatsNewVersion.isNewer(v)) || ((onlyShowCurrentVersion) && (v.isSame(Environment.getQuollWriterVersion())))) { String c = WhatsNewComponentProvider.class.getName(); int ind = c.lastIndexOf("."); if (ind > 0) { c = c.substring(0, ind); } WhatsNewComponentProvider compProv = null; String cl = JDOMUtils.getAttributeValue(vEl, XMLConstants.clazz, false); if (!cl.equals("")) { Class clz = null; try { clz = Class.forName(cl); if (WhatsNewComponentProvider.class.isAssignableFrom(clz)) { compProv = (WhatsNewComponentProvider) clz.newInstance(); } } catch (Exception e) { } } // This is a version we are interested in. java.util.List itemEls = JDOMUtils.getChildElements(vEl, WhatsNewItem.XMLConstants.root, true); java.util.List<WhatsNewItem> its = new ArrayList(); for (int j = 0; j < itemEls.size(); j++) { Element itEl = (Element) itemEls.get(j); WhatsNewItem it = new WhatsNewItem(itEl, compProv, pv); if (it.onlyIfCurrentVersion) { if (!Environment.getQuollWriterVersion().isSame(v)) { continue; } } if ((it.description == null) && (it.component == null)) { Environment.logMessage( "Whats new item has no description or component, referenced by: " + JDOMUtils.getPath(itEl)); continue; } its.add(it); } if (its.size() > 0) { this.items.put(v, its); } } } } catch (Exception e) { throw new GeneralException("Unable to init whats new", e); } }
public WizardStep getStage(String stage) { final WhatsNew _this = this; WizardStep ws = new WizardStep(); int ind = stage.indexOf(":"); Version v = new Version(stage.substring(0, ind)); int lind = Integer.parseInt(stage.substring(ind + 1)); java.util.List<WhatsNewItem> its = this.items.get(v); if (its == null) { return null; } WhatsNewItem item = its.get(lind); if (item == null) { return null; } ws.title = item.title; ws.helpText = this.getFirstHelpText(); if ((item.description != null) || (item.component != null)) { final Box b = new Box(BoxLayout.Y_AXIS); if (item.description != null) { JTextPane hp = UIUtils.createHelpTextPane(item.description, this.projectViewer); hp.setBorder(null); hp.setSize(new Dimension(UIUtils.getPopupWidth() - 25, 500)); Box hpb = new Box(BoxLayout.Y_AXIS); hpb.add(hp); hpb.setMaximumSize(hpb.getPreferredSize()); hpb.setBorder(UIUtils.createPadding(0, 5, 0, 0)); b.add(hpb); } if (item.component != null) { if (item.description != null) { b.add(Box.createVerticalStrut(5)); } item.component.setAlignmentY(Component.TOP_ALIGNMENT); item.component.setBorder(UIUtils.createPadding(5, 10, 0, 0)); b.add(item.component); } b.add(Box.createVerticalGlue()); ws.panel = b; } return ws; }