public void testFindAncestorTest() throws Exception { Property property = new Property(stack); Form form = new Form(stack, request, response); ActionComponent actionComponent = new ActionComponent(stack, request, response); Anchor anchor = new Anchor(stack, request, response); Form form2 = new Form(stack, request, response); TextField textField = new TextField(stack, request, response); Stack stack = property.getComponentStack(); Iterator i = stack.iterator(); try { // component stack assertEquals(property.getComponentStack().size(), 6); assertEquals(i.next(), property); assertEquals(i.next(), form); assertEquals(i.next(), actionComponent); assertEquals(i.next(), anchor); assertEquals(i.next(), form2); assertEquals(i.next(), textField); // property assertNull(property.findAncestor(Component.class)); // form assertEquals(form.findAncestor(Component.class), property); assertEquals(form.findAncestor(Property.class), property); // action assertEquals(actionComponent.findAncestor(Component.class), form); assertEquals(actionComponent.findAncestor(Property.class), property); assertEquals(actionComponent.findAncestor(Form.class), form); // anchor assertEquals(anchor.findAncestor(Component.class), actionComponent); assertEquals(anchor.findAncestor(ActionComponent.class), actionComponent); assertEquals(anchor.findAncestor(Form.class), form); assertEquals(anchor.findAncestor(Property.class), property); // form2 assertEquals(form2.findAncestor(Component.class), anchor); assertEquals(form2.findAncestor(Anchor.class), anchor); assertEquals(form2.findAncestor(ActionComponent.class), actionComponent); assertEquals(form2.findAncestor(Form.class), form); assertEquals(form2.findAncestor(Property.class), property); // textField assertEquals(textField.findAncestor(Component.class), form2); assertEquals(textField.findAncestor(Form.class), form2); assertEquals(textField.findAncestor(Anchor.class), anchor); assertEquals(textField.findAncestor(ActionComponent.class), actionComponent); assertEquals(textField.findAncestor(Property.class), property); } finally { property.getComponentStack().pop(); property.getComponentStack().pop(); property.getComponentStack().pop(); property.getComponentStack().pop(); property.getComponentStack().pop(); } }
public AnchoredSelection createAnchoredSelection(Position startPos, Position endPos) { Anchor start = Anchor.createAnchor(getSession().getDocument(), startPos.getRow(), startPos.getColumn()); Anchor end = Anchor.createAnchor(getSession().getDocument(), endPos.getRow(), endPos.getColumn()); return new AnchoredSelectionImpl(start, end); }
@Test public void extendedAttributes() { Anchor a = new Anchor(); a.setId("123"); a.setOffset(456.789); a.put("alignmentStatus", 50); assertEquals(new Integer(50), a.get("alignmentStatus")); }
private void showReaction(Reaction r) { this.container.clear(); Anchor anchor = new Anchor( r.getIdentifier(), "http://www.ebi.ac.uk/rhea/reaction.xhtml?id=" + r.getIdentifier(), "_blank"); anchor.setTitle(r.getName()); this.container.add(anchor); this.container.add(new RheaTable(r)); fireEvent(new ReactionStructureLoadedEvent()); }
public AppointmentFormPage() { popupPanel = new PopupPanel(true); popupPanel.add(uiBinder.createAndBindUi(this)); close.addClickHandler(closeHandler()); cancel.addClickHandler(closeHandler()); submit.addClickHandler(createSaveHandler()); }
@Test public void cloning() { Anchor a = new Anchor("123", 99.0, Constants.CONFIDENCE, Constants.CONFIDENCE_AUTOMATIC); a.put("foo", "foo"); Anchor c = (Anchor) a.clone(); assertEquals("123", c.getId()); assertEquals(Constants.CONFIDENCE_AUTOMATIC, c.get(Constants.CONFIDENCE)); assertEquals(new Double(99.0), c.getOffset()); assertFalse(c.containsKey("foo")); }
public static void init() { Add.init(); Address.init(); Align.init(); Alloc.init(); Anchor.init(); And.init(); Bad.init(); Bitcast.init(); Block.init(); Builtin.init(); Call.init(); Cmp.init(); Cond.init(); Confirm.init(); Const.init(); Conv.init(); CopyB.init(); Deleted.init(); Div.init(); Dummy.init(); End.init(); Eor.init(); Free.init(); IJmp.init(); Id.init(); Jmp.init(); Load.init(); Member.init(); Minus.init(); Mod.init(); Mul.init(); Mulh.init(); Mux.init(); NoMem.init(); Not.init(); Offset.init(); Or.init(); Phi.init(); Pin.init(); Proj.init(); Raise.init(); Return.init(); Sel.init(); Shl.init(); Shr.init(); Shrs.init(); Size.init(); Start.init(); Store.init(); Sub.init(); Switch.init(); Sync.init(); Tuple.init(); Unknown.init(); }
// =========================================================== // Methods // =========================================================== protected void setItemsPositions(final float pSize, final float pPositionScale) { final float basePosition = 0; // Log.e("aaa", "W=" + W + "; baseX=" + baseX + "; scale=" + mPositionScale + "; count=" + // mItems.size()); float offset = 0; for (final IEntity item : mItems) { final float pos = basePosition + offset * pPositionScale; offset += getItemSizeMain(item); if (mDirection == eDirection.DIR_HORIZONTAL) { Anchor.setPosCenterLeft(item, pos, getHeight() / 2); } else { Anchor.setPosBottomMiddle(item, getWidth() / 2, pos); } } }
/** * Prepares the GUI * * @param entity PerunEntity GROUP or VO * @param applicationType INITIAL | EXTENSION */ protected void prepareGui(PerunEntity entity, String applicationType) { // trigger email verification as first if present in URL if (Location.getParameterMap().keySet().contains("m") && Location.getParameterMap().keySet().contains("i")) { String verifyI = Location.getParameter("i"); String verifyM = Location.getParameter("m"); if (verifyI != null && !verifyI.isEmpty() && verifyM != null && !verifyM.isEmpty()) { final SimplePanel verifContent = new SimplePanel(); leftMenu.addItem( ApplicationMessages.INSTANCE.emailValidationMenuItem(), SmallIcons.INSTANCE.documentSignatureIcon(), verifContent); ValidateEmail request = new ValidateEmail( verifyI, verifyM, new JsonCallbackEvents() { @Override public void onLoadingStart() { verifContent.clear(); verifContent.add(new AjaxLoaderImage()); } @Override public void onFinished(JavaScriptObject jso) { BasicOverlayType obj = jso.cast(); if (obj.getBoolean() == true) { verifContent.clear(); FlexTable ft = new FlexTable(); ft.setSize("100%", "300px"); ft.setHTML( 0, 0, new Image(LargeIcons.INSTANCE.acceptIcon()) + "<h2>" + ApplicationMessages.INSTANCE.emailValidationSuccess() + "</h2>"); ft.getFlexCellFormatter() .setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER); ft.getFlexCellFormatter() .setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_MIDDLE); verifContent.add(ft); } else { verifContent.clear(); FlexTable ft = new FlexTable(); ft.setSize("100%", "300px"); ft.setHTML( 0, 0, new Image(LargeIcons.INSTANCE.deleteIcon()) + "<h2>" + ApplicationMessages.INSTANCE.emailValidationFail() + "</h2>"); ft.getFlexCellFormatter() .setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER); ft.getFlexCellFormatter() .setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_MIDDLE); verifContent.add(ft); } } @Override public void onError(PerunError error) { ((AjaxLoaderImage) verifContent.getWidget()).loadingError(error); } }); request.retrieveData(); leftMenu.addLogoutItem(); return; } } // group and extension is not allowed if (group != null && applicationType.equalsIgnoreCase("EXTENSION")) { RootLayoutPanel panel = RootLayoutPanel.get(); panel.clear(); FlexTable ft = new FlexTable(); ft.setSize("100%", "300px"); ft.setHTML( 0, 0, new Image(LargeIcons.INSTANCE.errorIcon()) + "<h2>Error: " + ApplicationMessages.INSTANCE.groupMembershipCantBeExtended( group.getName(), vo.getName()) + "</h2>"); ft.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER); ft.getFlexCellFormatter().setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_MIDDLE); panel.add(ft); return; } // application form page ApplicationFormPage formPage = new ApplicationFormPage(vo, group, applicationType); // even user "not yet in perun" can have some applications sent (therefore display by session // info) UsersApplicationsPage appsPage = new UsersApplicationsPage(); // if rt test if ("true".equals(Location.getParameter("rttest"))) { TestRtReportingTabItem tabItem = new TestRtReportingTabItem(); Widget rtTab = tabItem.draw(); leftMenu.addItem("RT test", SmallIcons.INSTANCE.settingToolsIcon(), rtTab); } // proper menu text String appMenuText = ApplicationMessages.INSTANCE.applicationFormForVo(vo.getName()); if (group != null) { appMenuText = ApplicationMessages.INSTANCE.applicationFormForGroup(group.getName()); } if (applicationType.equalsIgnoreCase("EXTENSION")) { appMenuText = ApplicationMessages.INSTANCE.membershipExtensionForVo(vo.getName()); if (group != null) { appMenuText = ApplicationMessages.INSTANCE.membershipExtensionForGroup(group.getName()); } } // load list of applications first if param in session if ("apps".equals(Location.getParameter("page"))) { Anchor a = leftMenu.addItem( ApplicationMessages.INSTANCE.applications(), SmallIcons.INSTANCE.applicationFromStorageIcon(), appsPage); leftMenu.addItem(appMenuText, SmallIcons.INSTANCE.applicationFormIcon(), formPage); a.fireEvent(new ClickEvent() {}); // appsPage.menuClick(); // load list of apps } else { Anchor a = leftMenu.addItem(appMenuText, SmallIcons.INSTANCE.applicationFormIcon(), formPage); leftMenu.addItem( ApplicationMessages.INSTANCE.applications(), SmallIcons.INSTANCE.applicationFromStorageIcon(), appsPage); a.fireEvent(new ClickEvent() {}); // formPage.menuClick(); // load application form } leftMenu.addLogoutItem(); }
private void setInteractions(Anchor anchor) { anchor.setOnMouseEntered(event -> anchor.setStroke(Color.RED)); anchor.setOnMouseExited(event -> anchor.setStroke(Color.TRANSPARENT)); anchor.setOnMouseDragEntered(event -> anchor.setStroke(Color.RED)); anchor.setOnMouseDragExited(event -> anchor.setStroke(Color.TRANSPARENT)); anchor.setOnDragDetected( event -> { WireController wireController = WireController.getInstance(); if (!wireController.active()) { wireController.setActive(); wireController.setStart(anchor); anchor.startFullDrag(); } }); anchor.setOnMouseDragged(Event::consume); anchor.setOnMouseDragReleased( (event) -> { WireController wireController = WireController.getInstance(); if (wireController.active() && wireController.getStartAnchor().getParent() != anchor.getParent() && (anchor.getDirection() == Anchor.Direction.unset || (wireController.getStartAnchor().getParentComponent() instanceof Voltmeter || anchor.getParentComponent() instanceof Voltmeter))) { wireController.completeWire(anchor); wireController.setDormant(); } }); }
/** * XML Circuit constructor * * @param file the file that contains the XML description of the circuit * @param g the graphics that will paint the node * @throws CircuitLoadingException if the internal circuit can not be loaded */ public CircuitUI(File file, Graphics g) throws CircuitLoadingException { this(""); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder; Document doc; Element root; Hashtable<Integer, Link> linkstable = new Hashtable<Integer, Link>(); try { builder = factory.newDocumentBuilder(); doc = builder.parse(file); } catch (SAXException sxe) { throw new CircuitLoadingException("SAX exception raised, invalid XML file."); } catch (ParserConfigurationException pce) { throw new CircuitLoadingException( "Parser exception raised, parser configuration is invalid."); } catch (IOException ioe) { throw new CircuitLoadingException("I/O exception, file cannot be loaded."); } root = (Element) doc.getElementsByTagName("Circuit").item(0); this.setName(root.getAttribute("name")); NodeList nl = root.getElementsByTagName("Node"); Element e; Node n; Class cl; for (int i = 0; i < nl.getLength(); ++i) { e = (Element) nl.item(i); try { cl = Class.forName(e.getAttribute("class")); } catch (Exception exc) { System.err.println(exc.getMessage()); throw new RuntimeException("Circuit creation from xml."); } try { n = ((Node) cl.newInstance()); } catch (Exception exc) { System.err.println(exc.getMessage()); throw new RuntimeException("Circuit creation from xml."); } this.nodes.add(n); n.setLocation(new Integer(e.getAttribute("x")), new Integer(e.getAttribute("y"))); if (n instanceof giraffe.ui.Nameable) ((Nameable) n).setNodeName(e.getAttribute("node_name")); if (n instanceof giraffe.ui.CompositeNode) { try { ((CompositeNode) n) .load(new File(file.getParent() + "/" + e.getAttribute("file_name")), g); } catch (Exception exc) { /* try to load from the lib */ ((CompositeNode) n) .load(new File(giraffe.Giraffe.PATH + "/lib/" + e.getAttribute("file_name")), g); } } NodeList nlist = e.getElementsByTagName("Anchor"); Element el; for (int j = 0; j < nlist.getLength(); ++j) { el = (Element) nlist.item(j); Anchor a = n.getAnchor(new Integer(el.getAttribute("id"))); NodeList linklist = el.getElementsByTagName("Link"); Element link; Link l; for (int k = 0; k < linklist.getLength(); ++k) { link = (Element) linklist.item(k); int id = new Integer(link.getAttribute("id")); int index = new Integer(link.getAttribute("index")); if (id >= this.linkID) linkID = id + 1; if (linkstable.containsKey(id)) { l = linkstable.get(id); l.addLinkedAnchorAt(a, index); a.addLink(l); } else { l = new Link(id); l.addLinkedAnchorAt(a, index); this.links.add(l); linkstable.put(id, l); a.addLink(l); } } } } }
public void stop() { anchor.throwOut(); }
@Override public Anchor createAnchor(Position pos) { return Anchor.createAnchor(getSession().getDocument(), pos.getRow(), pos.getColumn()); }
@Test public void objectAttributes() { Anchor a = new Anchor(); // TODO define before-id hashcode behaviour a.setId("123"); int iStartHashCode = a.hashCode(); a.setOffset(456.789); a.put("foo", "bar"); int iEndHashCode = a.hashCode(); assertEquals("Immutable hashcode:", iStartHashCode, iEndHashCode); assertEquals("456.789", a.toString()); assertTrue("Equality reflexive", a.equals(a)); Anchor a2 = new Anchor(); assertFalse("equals before id set:", a.equals(a2)); a2.setId("123"); a2.setOffset(456.789); // no "foo" attribute, to ensure it doesn't contribute to equality assertTrue("id defines equality:", a.equals(a2)); assertTrue("Equality is symmetric:", a2.equals(a)); assertEquals("Comparable:", 0, a.compareTo(a2)); a2.setOffset(123.456); assertTrue("offset doesn't affect equality:", a.equals(a2)); a2.setId("different id"); assertFalse("Different id:", a.equals(a2)); assertTrue("Compare by offset - 456.123 > 123.456", a.compareTo(a2) > 0); a2.setOffset(a.getOffset()); assertTrue( "Comparable: if offsets are equal, comparison is by ID - \"123\" < \"different id\"", a.compareTo(a2) < 0); a2.setOffset(null); assertTrue( "Comparable: if left offset is null, comparison is by ID - \"123\" < \"different id\"", a.compareTo(a2) < 0); assertTrue( "Comparable: if right offset is null, comparison is by ID - \"different id\" > \"123\"", a2.compareTo(a) > 0); a2.setId(a.getId()); assertTrue("Resetting attribute resets equality:", a.equals(a2)); LinkedHashMap<String, Object> aMap = new LinkedHashMap<String, Object>(); aMap.putAll(a); assertFalse("A map with the same attributes isn't equal:", a.equals(aMap)); }
@Test public void copyConstructor() { Anchor a = new Anchor("123", 456.789); // change offset to generate tracked original a.setOffset(123.456); // set copiable attribute a.put("copy", Boolean.TRUE); // set transient attribute a.put("@dontCopy", Boolean.TRUE); Anchor newA = new Anchor(a); assertNull("id not copied", newA.getId()); assertEquals("offset copied", new Double(123.456), newA.getOffset()); assertNull("originalOffset not copied", newA.get("originalOffset")); assertEquals("originalOffset not copied", new Double(123.456), newA.getOriginalOffset()); assertEquals("other attribute copied", Boolean.TRUE, newA.get("copy")); assertNull("transient attribute not copied", newA.get("@dontCopy")); }
public static FormPanel getLoginPanel() { // Create a FormPanel and point it at a service. final FormPanel form = new FormPanel(); form.setAction("/loginFormHandler"); form.setMethod(FormPanel.METHOD_POST); // Create a panel to hold all of the form widgets. VerticalPanel panel = new VerticalPanel(); form.setWidget(panel); panel.setSpacing(20); final Label emailLabel = new Label("UnityID:"); final TextBox emailBox = new TextBox(); final Label passwordLabel = new Label("Password:"******"Log in", new ClickHandler() { public void onClick(ClickEvent event) { form.submit(); } }); panel.add(loginButton); Anchor signUpLabel = new Anchor("-- New User: Sign up --"); signUpLabel.addStyleName("gwt-RegisterAnchor"); panel.addStyleName("gwt-LoginPanel"); loginButton.addStyleName("gwt-LoginButton"); signUpLabel.addClickHandler( new ClickHandler() { public void onClick(ClickEvent event) { RootPanel.get("leftnav").clear(); RootPanel.get("header").clear(); RootPanel.get("content").clear(); RootPanel.get("content").add(CustomWidgets.getRegisterForm()); final Label titleLabel = new Label("Register"); titleLabel.addStyleName("gwt-Heading"); RootPanel.get("header").add(titleLabel); } }); panel.add(signUpLabel); // Add an event handler to the form. form.addSubmitHandler( new FormPanel.SubmitHandler() { public void onSubmit(FormPanel.SubmitEvent event) { if (emailBox.getText().length() == 0 || passwordBox.getText().length() == 0) { Window.alert("Username and Password must not be empty"); rootLogger.log(Level.SEVERE, "LOGIN ATTEMPT FAIL"); event.cancel(); } } }); form.addSubmitCompleteHandler( new FormPanel.SubmitCompleteHandler() { public void onSubmitComplete(FormPanel.SubmitCompleteEvent event) { final String userid = emailBox.getText(); String password = passwordBox.getText(); loginService.login( userid, password, new AsyncCallback<String>() { public void onFailure(Throwable caught) { rootLogger.log(Level.SEVERE, "LOGIN ATTEMPT FAIL"); } public void onSuccess(String result) { if (result.equals("success")) { RootPanel.get("leftnav").clear(); RootPanel.get("header").clear(); RootPanel.get("content").clear(); dbService.readUserData( "ssharm20", new AsyncCallback<HashMap<String, String>>() { public void onFailure(Throwable caught) { rootLogger.log(Level.SEVERE, "Failed reading data from server"); } public void onSuccess(HashMap<String, String> result) { RootPanel.get("content").add(CustomWidgets.getHomeDataForm(userid)); } }); RootPanel.get("leftnav").add(CustomWidgets.getNavBar(userid)); final Label titleLabel = new Label("Home"); titleLabel.addStyleName("gwt-Heading"); RootPanel.get("header").add(titleLabel); } else { Window.alert(result); rootLogger.log(Level.SEVERE, "LOGIN ATTEMPT FAIL"); } } }); } }); return form; }
@Test public void basicAttributes() { // Default constructor Anchor a = new Anchor(); a.setId("123"); a.setOffset(456.789); assertEquals("123", a.getId()); assertEquals("123", a.get("id")); assertEquals(new Double(456.789), a.getOffset()); assertEquals(new Double(456.789), a.get("offset")); assertEquals("456.789", a.toString()); // Basic constructor a = new Anchor("123", 456.789); assertEquals("123", a.getId()); assertEquals("123", a.get("id")); assertEquals(new Double(456.789), a.getOffset()); assertEquals(new Double(456.789), a.get("offset")); assertEquals("456.789", a.toString()); }
@Test public void offsetMinMaxAndPrecedingFollowing() { Graph g = new Graph(); Anchor a = new Anchor("test", null); g.addAnchor(a); assertNull("offsetMin - null offset, no preceding", a.getOffsetMin()); g.addAnchor(new Anchor("early", null)); g.addAnnotation(new Annotation("toEarly", "direct to early", "layer1", "early", "test")); assertNull("offsetMin - null offsets, one preceding", a.getOffsetMin()); g.addAnchor(new Anchor("earlier", null)); g.addAnnotation( new Annotation("toEarlier", "chained to earlier", "layer1", "earlier", "early")); assertNull("offsetMin - null offsets, chain preceding", a.getOffsetMin()); g.addAnchor(new Anchor("earliest", null)); g.addAnnotation( new Annotation("toEarliest", "direct to earliest", "layer2", "earliest", "test")); assertNull("offsetMin - null offsets, multiple paths preceding", a.getOffsetMin()); g.getAnchor("earliest").setOffset(1.0); assertEquals("offsetMin - earliest", new Double(1.0), a.getOffsetMin()); g.getAnchor("earlier").setOffset(2.0); assertEquals( "offsetMin - chain overrides direct connection", new Double(2.0), a.getOffsetMin()); g.getAnchor("early").setOffset(3.0); assertEquals( "offsetMin - direct connection overrides chain", new Double(3.0), a.getOffsetMin()); assertNull("offsetMax - null offset, no following", a.getOffsetMax()); g.addAnchor(new Anchor("late", null)); g.addAnnotation(new Annotation("toLate", "direct to late", "layer1", "test", "late")); assertNull("offsetMax - null offsets, one following", a.getOffsetMax()); g.addAnchor(new Anchor("later", null)); g.addAnnotation(new Annotation("toLater", "chained to later", "layer1", "late", "later")); assertNull("offsetMax - null offsets, chain following", a.getOffsetMax()); g.addAnchor(new Anchor("latest", null)); g.addAnnotation(new Annotation("toLatest", "direct to latest", "layer2", "test", "latest")); assertNull("offsetMax - null offsets, multiple paths following", a.getOffsetMax()); g.getAnchor("latest").setOffset(7.0); assertEquals("offsetMax - latest", new Double(7.0), a.getOffsetMax()); g.getAnchor("later").setOffset(6.0); assertEquals( "offsetMax - chain overrides direct connection", new Double(6.0), a.getOffsetMax()); g.getAnchor("late").setOffset(5.0); assertEquals( "offsetMax - direct connection overrides chain", new Double(5.0), a.getOffsetMax()); a.setOffset(5.0); assertEquals("offsetMin - offset set", new Double(5.0), a.getOffsetMin()); assertEquals("offsetMax - offset set", new Double(5.0), a.getOffsetMax()); // preceding LinkedHashSet<Anchor> preceding = a.getPreceding(); assertTrue("preceding", preceding.contains(g.getAnchor("earliest"))); assertTrue("preceding", preceding.contains(g.getAnchor("earlier"))); assertTrue("preceding", preceding.contains(g.getAnchor("early"))); assertEquals("preceding size", 3, preceding.size()); // following LinkedHashSet<Anchor> following = a.getFollowing(); assertTrue("following", following.contains(g.getAnchor("late"))); assertTrue("following", following.contains(g.getAnchor("later"))); assertTrue("following", following.contains(g.getAnchor("latest"))); assertEquals("following size", 3, following.size()); // follows assertTrue("follows", a.follows(g.getAnchor("early"))); assertTrue("follows", a.follows(g.getAnchor("earlier"))); assertTrue("follows", a.follows(g.getAnchor("early"))); assertFalse("follows - self", a.follows(a)); assertFalse("follows", a.follows(g.getAnchor("late"))); assertFalse("follows", a.follows(g.getAnchor("later"))); assertFalse("follows", a.follows(g.getAnchor("latest"))); // precedes assertFalse("precedes", a.precedes(g.getAnchor("early"))); assertFalse("precedes", a.precedes(g.getAnchor("earlier"))); assertFalse("precedes", a.precedes(g.getAnchor("early"))); assertFalse("precedes - self", a.precedes(a)); assertTrue("precedes", a.precedes(g.getAnchor("late"))); assertTrue("precedes", a.precedes(g.getAnchor("later"))); assertTrue("precedes", a.precedes(g.getAnchor("latest"))); // add some instants g.addAnnotation( new Annotation("middleInstant", "instant at test anchor", "layer1", "test", "test")); g.addAnnotation( new Annotation("firstInstant", "instant at earliest", "layer2", "earliest", "earliest")); g.addAnnotation( new Annotation("lastInstant", "instant at latest", "layer2", "latest", "latest")); // ending LinkedHashSet<Annotation> ending = a.getEndingAnnotations(); assertTrue("ending", ending.contains(g.getAnnotation("toEarly"))); assertTrue("ending", ending.contains(g.getAnnotation("toEarliest"))); assertTrue("ending", ending.contains(g.getAnnotation("middleInstant"))); assertEquals("ending size", 3, ending.size()); // starting LinkedHashSet<Annotation> starting = a.getStartingAnnotations(); assertTrue("starting", starting.contains(g.getAnnotation("toLate"))); assertTrue("starting", starting.contains(g.getAnnotation("toLatest"))); assertTrue("starting", starting.contains(g.getAnnotation("middleInstant"))); assertEquals("starting size", 3, starting.size()); // linking assertNull("linking - none", a.annotationTo(g.getAnchor("later"))); assertEquals("linking", g.getAnnotation("toLate"), a.annotationTo(g.getAnchor("late"))); assertNull("linking - not symmetric", g.getAnchor("late").annotationTo(a)); }
@Test public void changeTracking() { Anchor a = new Anchor(); a.setId("123"); a.setOffset(456.789); a.put("foo", "bar"); assertEquals(new Double(456.789), a.getOffset()); assertEquals("Offset and original are the same", a.getOriginalOffset(), a.getOffset()); assertEquals(Change.Operation.NoChange, a.getChange()); a.put("foo", "foo"); assertEquals("Only offset affects change:", Change.Operation.NoChange, a.getChange()); a.setOffset(123.456); assertEquals(new Double(123.456), a.getOffset()); assertEquals( "Original offset remembers first offset:", new Double(456.789), a.get("originalOffset")); assertEquals( "Original offset remembers first offset:", new Double(456.789), a.getOriginalOffset()); assertEquals(Change.Operation.Update, a.getChange()); a.setOffset(456.123); assertEquals(new Double(456.123), a.getOffset()); assertEquals("Original offset only set once:", new Double(456.789), a.getOriginalOffset()); assertEquals(Change.Operation.Update, a.getChange()); a.rollback(); assertEquals(new Double(456.789), a.getOffset()); assertEquals("Offset and original are the same", a.getOriginalOffset(), a.getOffset()); assertEquals(Change.Operation.NoChange, a.getChange()); a.destroy(); assertEquals(Change.Operation.Destroy, a.getChange()); a.rollback(); assertEquals(Change.Operation.NoChange, a.getChange()); a.create(); assertEquals(Change.Operation.Create, a.getChange()); a.rollback(); assertEquals("Create cannot be rolled back:", Change.Operation.Create, a.getChange()); }
private void insertRankTableRow(int row, final AccountInfo info) { NumberFormat fmt = NumberFormat.getFormat("#,##0.00"); rankGrid.setWidget(row, 0, new Label(String.valueOf(row))); rankGrid.getCellFormatter().addStyleName(row, 0, "textCell"); rankGrid.setWidget(row, 1, new Label(info.getDisplayName())); rankGrid.getCellFormatter().addStyleName(row, 1, "textCell"); rankGrid.setWidget(row, 2, new Label(fmt.format(info.getIntialPrincipal()))); rankGrid.getCellFormatter().addStyleName(row, 2, "numericCell"); rankGrid.setWidget(row, 3, new Label(fmt.format(info.getLeftCapitical()))); rankGrid.getCellFormatter().addStyleName(row, 3, "numericCell"); rankGrid.setWidget(row, 4, new Label(fmt.format(info.getStockValue()))); rankGrid.getCellFormatter().addStyleName(row, 4, "numericCell"); rankGrid.setWidget(row, 5, new Label(fmt.format(info.getTotalValue()))); rankGrid.getCellFormatter().addStyleName(row, 5, "numericCell"); rankGrid.setWidget(row, 6, new Label(fmt.format(info.getProfit()))); rankGrid.getCellFormatter().addStyleName(row, 6, "numericCell"); rankGrid.setWidget(row, 7, new Label(fmt.format(info.getProfitPct()) + "%")); rankGrid.getCellFormatter().addStyleName(row, 7, "numericCell"); if (info.getProfit() > 0) { rankGrid.getCellFormatter().removeStyleName(row, 7, "negativeChange"); rankGrid.getCellFormatter().addStyleName(row, 7, "positiveChange"); rankGrid.getCellFormatter().removeStyleName(row, 6, "negativeChange"); rankGrid.getCellFormatter().addStyleName(row, 6, "positiveChange"); } else if (info.getProfit() < 0) { rankGrid.getCellFormatter().removeStyleName(row, 7, "positiveChange"); rankGrid.getCellFormatter().addStyleName(row, 7, "negativeChange"); rankGrid.getCellFormatter().removeStyleName(row, 6, "positiveChange"); rankGrid.getCellFormatter().addStyleName(row, 6, "negativeChange"); } else { rankGrid.getCellFormatter().removeStyleName(row, 7, "positiveChange"); rankGrid.getCellFormatter().removeStyleName(row, 7, "negativeChange"); rankGrid.getCellFormatter().removeStyleName(row, 6, "positiveChange"); rankGrid.getCellFormatter().removeStyleName(row, 6, "negativeChange"); } if (info.getTotalValue() != 0) { rankGrid.setWidget( row, 8, new Label(fmt.format(100.0 * info.getStockValue() / info.getTotalValue()) + "%")); } else { rankGrid.setWidget(row, 8, new Label("--")); } rankGrid.getCellFormatter().addStyleName(row, 8, "numericCell"); Anchor link = new Anchor("交易记录"); rankGrid.setWidget(row, 9, link); link.addClickHandler( new ClickHandler() { public void onClick(ClickEvent event) { showTransHistory(info.getUsername(), info.getDisplayName()); } }); rankGrid.getCellFormatter().addStyleName(row, 9, "textCell"); Anchor positionBtn = new Anchor("当前持仓"); rankGrid.setWidget(row, 10, positionBtn); positionBtn.addClickHandler( new ClickHandler() { public void onClick(ClickEvent event) { showPosition(info.getUsername(), info.getDisplayName()); } }); rankGrid.getCellFormatter().addStyleName(row, 10, "textCell"); }