X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=bundles%2Forg.simantics.g2d%2Fsrc%2Forg%2Fsimantics%2Fg2d%2Fexample%2FLoadingMessageDiagram.java;h=e01273049c989c6cf48e5c2b2946035a43c459e1;hb=28438fa467ae60dd63515be2df724c6ff9c299c9;hp=b69938d02f392526e92ad1c2866a2a3b9d5c642f;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/example/LoadingMessageDiagram.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/example/LoadingMessageDiagram.java index b69938d02..e01273049 100644 --- a/bundles/org.simantics.g2d/src/org/simantics/g2d/example/LoadingMessageDiagram.java +++ b/bundles/org.simantics.g2d/src/org/simantics/g2d/example/LoadingMessageDiagram.java @@ -1,96 +1,96 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.g2d.example; - -import java.awt.Color; -import java.awt.geom.Rectangle2D; - -import org.simantics.g2d.canvas.ICanvasContext; -import org.simantics.g2d.diagram.DiagramClass; -import org.simantics.g2d.diagram.DiagramHints; -import org.simantics.g2d.diagram.IDiagram; -import org.simantics.g2d.diagram.impl.Diagram; -import org.simantics.g2d.element.ElementClass; -import org.simantics.g2d.element.ElementUtils; -import org.simantics.g2d.element.IElement; -import org.simantics.g2d.element.handler.Heartbeat; -import org.simantics.g2d.element.handler.Text; -import org.simantics.g2d.element.handler.impl.DefaultTransform; -import org.simantics.g2d.element.handler.impl.FixedSize; -import org.simantics.g2d.element.handler.impl.TextColorImpl; -import org.simantics.g2d.element.handler.impl.TextPainter; -import org.simantics.g2d.element.impl.Element; -import org.simantics.g2d.elementclass.FilmClass; - -/** - * Diagram with LOADING... text - * - * @author Toni Kalajainen - */ -public class LoadingMessageDiagram { - - public static final ElementClass LOADING_CLASS = - ElementClass.compile( - TextColorImpl.WHITE, - DefaultTransform.INSTANCE, - FixedSize.of(30, 20), - Text.INSTANCE, - new TextPainter(), - new LoadingAnimation() - ); - - public static final IDiagram LOADING_DIAGRAM = createLoadingDiagram(); - - /** - * Create diagram where flashing "LOADING" text - * @return - */ - public static IDiagram createLoadingDiagram() - { - String name = "Loading..."; - IDiagram d = Diagram.spawnNew(DiagramClass.DEFAULT); - d.setHint(DiagramHints.KEY_TEXT, name); - - IElement film = Element.spawnNew(FilmClass.FILM_CLASS); - ElementUtils.fitToRectangle(film, new Rectangle2D.Double(0, 4, 40, 30)); - d.addElement(film); - ElementUtils.setFillColor(film, new Color(0.3f, 0.3f, 0.8f, 0.5f)); - - IElement lbl = Element.spawnNew( LOADING_CLASS ); - d.addElement(lbl); - ElementUtils.setPos(lbl, 5,7); - ElementUtils.setText(lbl, "Loading"); - ElementUtils.setTextColor(lbl, Color.WHITE); - - return d; - } - - - - private static class LoadingAnimation implements Heartbeat { - - private static final long serialVersionUID = 2721735864087380222L; - - @Override - public void heartbeat(IElement e, long time, long deltaTime, ICanvasContext ctx) { - int dotCount = (int) ((time % 1000L) / 200L); - String dots = ""; - for (int i=0; i