]> source.dussan.org Git - vaadin-framework.git/commitdiff
View source in subwindow / native window. Fixes #2561
authorMarc Englund <marc.englund@itmill.com>
Thu, 12 Feb 2009 14:51:31 +0000 (14:51 +0000)
committerMarc Englund <marc.englund@itmill.com>
Thu, 12 Feb 2009 14:51:31 +0000 (14:51 +0000)
svn changeset:6821/svn branch:trunk

WebContent/ITMILL/themes/sampler/sampler/styles.css
src/com/itmill/toolkit/demo/sampler/CodeLabel.java
src/com/itmill/toolkit/demo/sampler/FeatureView.java
src/com/itmill/toolkit/demo/sampler/SamplerApplication.java

index 538c7dcf257cb306b0f250ca9d4f808d004e4d9c..083b1b2b3841454b1c8b845c157cb51ee27a6a9d 100644 (file)
        background: transparent url(sample-desc-arrow.png) no-repeat 50% 0;
        margin: -6px 0 13px 0;
 }
-
-.i-app-SamplerApplication .i-button-showcode {
+.i-app-SamplerApplication .i-link-showcode {
+       margin-left: 3px;
+}
+.i-app-SamplerApplication .i-button-showcode,
+.i-app-SamplerApplication .i-link-showcode {
        font-family: helvetica, arial, verdana, sans-serif;
        display: inline;
        font-size: 12px;
        line-height: 20px;
        height: 20px;
 }
-.i-app-SamplerApplication .i-button-showcode span {
+.i-app-SamplerApplication .i-button-showcode span,
+.i-app-SamplerApplication .i-link-showcode span {
        color: #8b8e91;
        text-decoration: none;
 }
-.i-app-SamplerApplication .i-button-showcode:hover span {
+.i-app-SamplerApplication .i-button-showcode:hover span,
+.i-app-SamplerApplication .i-link-showcode:hover span {
        color: #62696f;
+       text-decoration: underline;
 }
 .i-app-SamplerApplication .i-panel-content-source {
        border: 1px solid #eee;
index 67f8875567e5b8acbfd7e828ea35aec755d1b2ad..bc0f0bdf2c1cd30e1b5d2ee598b26e3c1f22ca1c 100644 (file)
@@ -7,7 +7,7 @@ public class CodeLabel extends Label {
     private static final String TAG = "codelabel";
 
     public CodeLabel() {
-        super.setContentMode(CONTENT_PREFORMATTED);
+        setContentMode(CONTENT_PREFORMATTED);
     }
 
     public CodeLabel(String content) {
@@ -21,10 +21,11 @@ public class CodeLabel extends Label {
 
     @Override
     public void setContentMode(int contentMode) {
-        if (contentMode != Label.CONTENT_PREFORMATTED) {
+        if (contentMode != CONTENT_PREFORMATTED) {
             throw new UnsupportedOperationException(
                     "Only preformatted content supported");
         }
+        super.setContentMode(CONTENT_PREFORMATTED);
     }
 
 }
index 8a9fd29ad75b813936b216549fbf2a05cf5baf53..f652f01807c6a8f58d107942a1ed3dfd17f7244b 100644 (file)
@@ -14,21 +14,19 @@ import com.itmill.toolkit.ui.Label;
 import com.itmill.toolkit.ui.Link;
 import com.itmill.toolkit.ui.Panel;
 import com.itmill.toolkit.ui.VerticalLayout;
+import com.itmill.toolkit.ui.Window;
 import com.itmill.toolkit.ui.Button.ClickEvent;
 
 public class FeatureView extends HorizontalLayout {
 
     private static final String MSG_SHOW_SRC = "Show Java™ source »";
-    private static final String MSG_HIDE_SRC = "Hide Java™ source";
 
     private Panel right;
     private VerticalLayout left;
 
     private VerticalLayout controls;
 
-    private Panel sourcePanel;
-    private Label sourceCode;
-    private Button showCode;
+    private ActiveLink srcWin;
 
     private HashMap<Feature, Component> exampleCache = new HashMap<Feature, Component>();
 
@@ -74,36 +72,31 @@ public class FeatureView extends HorizontalLayout {
 
         controlButtons.addComponent(new Label("|"));
 
-        showCode = new Button(MSG_SHOW_SRC, new Button.ClickListener() {
-            public void buttonClick(ClickEvent event) {
-                toggleSource();
+        srcWin = new ActiveLink();
+        srcWin
+                .setDescription("Right / middle / ctrl / shift -click for browser window/tab");
+        srcWin.addListener(new LinkActivatedListener() {
+
+            public void linkActivated(LinkActivatedEvent event) {
+                if (!event.isLinkOpened()) {
+                    Window w = new Window("Java™ source");
+                    ((VerticalLayout) w.getLayout()).setSizeUndefined();
+                    w.setWidth("70%");
+                    w.setHeight("60%");
+                    w.setPositionX(100);
+                    w.setPositionY(100);
+                    w.addComponent(new CodeLabel(currentFeature.getSource()));
+                    getWindow().addWindow(w);
+                }
+
             }
-        });
-        showCode.setStyleName(Button.STYLE_LINK);
-        showCode.addStyleName("showcode");
-        controlButtons.addComponent(showCode);
-
-        sourceCode = new CodeLabel();
-
-        sourcePanel = new Panel();
-        sourcePanel.getLayout().setSizeUndefined();
-        sourcePanel.addStyleName(Panel.STYLE_LIGHT);
-        sourcePanel.addStyleName("source");
-        sourcePanel.addComponent(sourceCode);
-        sourcePanel.setVisible(false);
-        sourcePanel.setWidth("100%");
-        sourcePanel.setHeight("250px");
-
-        controls.addComponent(sourcePanel);
-    }
 
-    private void toggleSource() {
-        showSource(!sourcePanel.isVisible());
-    }
+        });
+        srcWin.setCaption(MSG_SHOW_SRC);
+        srcWin.addStyleName("showcode");
+        srcWin.setTargetBorder(Link.TARGET_BORDER_NONE);
+        controlButtons.addComponent(srcWin);
 
-    private void showSource(boolean show) {
-        showCode.setCaption((show ? MSG_HIDE_SRC : MSG_SHOW_SRC));
-        sourcePanel.setVisible(show);
     }
 
     private void resetExample() {
@@ -120,7 +113,6 @@ public class FeatureView extends HorizontalLayout {
             currentFeature = feature;
             right.removeAllComponents();
             left.removeAllComponents();
-            showSource(false);
 
             left.addComponent(controls);
             controls.setCaption(feature.getName());
@@ -154,7 +146,13 @@ public class FeatureView extends HorizontalLayout {
                 }
             }
 
-            sourceCode.setValue(feature.getSource());
+            { // open src in new window -link
+                String path = SamplerApplication.getPathFor(currentFeature);
+                srcWin.setTargetName(path);
+                srcWin.setResource(new ExternalResource(getApplication()
+                        .getURL()
+                        + "src/" + path));
+            }
 
             NamedExternalResource[] resources = feature.getRelatedResources();
             if (resources != null) {
index f9802d98d28fd31edd39bfaf307ffa1f734305ef..2607d8331027dbd48845bc4b1d7c2dfc4611afee 100644 (file)
@@ -1,6 +1,7 @@
 package com.itmill.toolkit.demo.sampler;
 
 import java.net.URI;
+import java.net.URL;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -15,9 +16,11 @@ import com.itmill.toolkit.demo.sampler.ModeSwitch.ModeSwitchEvent;
 import com.itmill.toolkit.event.ItemClickEvent;
 import com.itmill.toolkit.event.ItemClickEvent.ItemClickListener;
 import com.itmill.toolkit.terminal.ClassResource;
+import com.itmill.toolkit.terminal.DownloadStream;
 import com.itmill.toolkit.terminal.ExternalResource;
 import com.itmill.toolkit.terminal.Resource;
 import com.itmill.toolkit.terminal.ThemeResource;
+import com.itmill.toolkit.terminal.URIHandler;
 import com.itmill.toolkit.ui.Alignment;
 import com.itmill.toolkit.ui.Button;
 import com.itmill.toolkit.ui.ComboBox;
@@ -80,8 +83,13 @@ public class SamplerApplication extends Application {
     public Window getWindow(String name) {
         Window w = super.getWindow(name);
         if (w == null) {
-            w = new SamplerWindow();
-            w.setName(name);
+            if (name.startsWith("src")) {
+                w = new SourceWindow();
+            } else {
+                w = new SamplerWindow();
+                w.setName(name);
+            }
+
             addWindow(w);
         }
         return w;
@@ -500,7 +508,8 @@ public class SamplerApplication extends Application {
                 String current = "";
                 ActiveLink link = null;
                 for (int i = 0; i < parts.length; i++) {
-                    layout.addComponent(new Label("‣"));
+                    layout.addComponent(new Label("&raquo;",
+                            Label.CONTENT_XHTML));
                     current += (i > 0 ? "/" : "") + parts[i];
                     Feature f = FeatureSet.FEATURES.getFeatureByPath(current);
                     link = new ActiveLink(f.getName(), new ExternalResource("#"
@@ -712,4 +721,28 @@ public class SamplerApplication extends Application {
         return allFeatures;
     }
 
+    public class SourceWindow extends Window {
+        public SourceWindow() {
+            addURIHandler(new URIHandler() {
+                public DownloadStream handleURI(URL context, String relativeUri) {
+                    Feature f = FeatureSet.FEATURES
+                            .getFeatureByPath(relativeUri);
+                    if (f != null) {
+                        addComponent(new CodeLabel(f.getSource()));
+                    } else {
+                        addComponent(new Label("Sorry, no source found for "
+                                + relativeUri));
+                    }
+                    return null;
+                }
+
+            });
+
+            addListener(new CloseListener() {
+                public void windowClose(CloseEvent e) {
+                    SamplerApplication.this.removeWindow(SourceWindow.this);
+                }
+            });
+        }
+    }
 }