1 /* 2 * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 */ 24 25 package test.javaclient.shared; 26 27 import com.sun.javafx.application.PlatformImpl; 28 import java.util.logging.Level; 29 import java.util.logging.Logger; 30 import javafx.scene.Scene; 31 import javafx.scene.layout.Pane; 32 import javafx.scene.text.Text; 33 import javafx.stage.Stage; 34 import java.util.concurrent.CountDownLatch; 35 import javafx.application.Platform; 36 import javafx.scene.Group; 37 import javafx.scene.Node; 38 import javafx.scene.control.Button; 39 import javafx.scene.layout.VBox; 40 import javafx.scene.paint.Color; 41 import org.eclipse.swt.widgets.Shell; 42 43 /** 44 * 45 * @author shubov 46 */ 47 public class CombinedTestChooserPresenter implements AbstractTestPresenter, AbstractFailureRegistrator { 48 49 private Pane pageContent; 50 private Node nodeForScreenshot; 51 protected final int width; 52 protected final int height; 53 private Scene scene = null; 54 protected final String title; 55 protected static final int TABS_SPACE = 110; 56 private final Pane buttons; 57 private Text getterNotifier; 58 static final String GETTER_NOTIFIER = "GETTER_NOTIFIER"; 59 static final String FIN_NOTIFIER = "FIN_NOTIFIER"; 60 public static final String PAGE_CONTENT = "AbstractApp.pageContent"; 61 protected boolean mouseTransparent = false; 62 private boolean setPageContentSize = true; 63 private boolean showButtonsPane = true; 64 65 public CombinedTestChooserPresenter(int width, int height, String title, Pane buttonsPane, boolean showButtonsPane) { 66 this.width = width; 67 this.height = height; 68 this.title = title; 69 this.buttons = buttonsPane; 70 this.showButtonsPane = showButtonsPane; 71 } 72 73 protected Scene createSceneForChooserPresenter() { 74 return new Scene(new Group(), width + 50, height + TABS_SPACE + 30); 75 } 76 77 public void avoidSettingPageContentSize() { 78 setPageContentSize = false; 79 } 80 81 public Node getNodeForScreenshot() { 82 return nodeForScreenshot; 83 } 84 85 public void setNodeForScreenshot(Node _node) { 86 nodeForScreenshot = _node; 87 } 88 89 protected void fillScene() { 90 //scene = new Scene(new Group(), width + 50, height + TABS_SPACE + 30); 91 scene = createSceneForChooserPresenter(); 92 93 Utils.addBrowser(scene); 94 95 VBox vBox = new VBox(); 96 97 pageContent = new Pane(); 98 setNodeForScreenshot(pageContent); 99 100 getterNotifier = new Text(""); 101 102 if (showButtonsPane) { 103 vBox.getChildren().add(buttons); 104 }else{ 105 if(!TestUtil.isEmbeddedGraphicsProfile()){ 106 Button button = new Button(); 107 button.setText("This button need to take a focus"); 108 vBox.getChildren().add(button); 109 } 110 111 } 112 113 getterNotifier.setId(GETTER_NOTIFIER); 114 getterNotifier.setFill(Color.RED); 115 vBox.getChildren().add(getterNotifier); 116 117 pageContent.setId(PAGE_CONTENT); 118 if (setPageContentSize) { 119 pageContent.setMinSize(width, height); 120 pageContent.setMaxSize(width, height); 121 pageContent.setPrefSize(width, height); 122 } 123 //LayoutInfo li = new LayoutInfo(); 124 //li.setHshrink(Priority.NEVER); 125 //li.setVshrink(Priority.NEVER); 126 //pageContent.setLayoutInfo(li); 127 pageContent.setMouseTransparent(mouseTransparent); 128 vBox.getChildren().add(pageContent); 129 130 pageContent.setTranslateX(20); 131 pageContent.setTranslateY(20); 132 133 ((Group) scene.getRoot()).getChildren().add(vBox); 134 } 135 136 public void showTestNode(TestNode tn) { 137 138 pageContent.getChildren().clear(); 139 140 if (setPageContentSize) { 141 final int _height = tn.getHeight(); 142 final int _width = tn.getWidth(); 143 pageContent.setMinSize(_width, _height); 144 pageContent.setMaxSize(_width, _height); 145 pageContent.setPrefSize(_width, _height); 146 } 147 //LayoutInfo li = new LayoutInfo(); 148 //li.setHshrink(Priority.NEVER); 149 //li.setVshrink(Priority.NEVER); 150 //pageContent.setLayoutInfo(li); 151 152 tn.drawTo(pageContent); 153 } 154 155 public void registerFailure(final String text) { 156 StringBuilder sb = new StringBuilder(getterNotifier.getText()); 157 if (sb.length() == 0) { 158 sb.append("GETTER FAILURES: "); 159 } else { 160 sb.append(", "); 161 } 162 sb.append(text); 163 getterNotifier.setText(sb.toString()); 164 } 165 166 public void clearFailures() { 167 getterNotifier.setText(""); 168 } 169 170 public String getFailures() { 171 return getterNotifier.getText(); 172 } 173 174 public String getScreenshotPaneName() { 175 return PAGE_CONTENT; 176 } 177 178 public void show(Stage stage) { 179 stage.setX(0); 180 stage.setY(0); 181 stage.setTitle(title); 182 fillScene(); 183 stage.setScene(scene); 184 stage.show(); 185 stage.toFront(); 186 stage.setFocused(true); 187 } 188 189 public void show(final Object frame, final Object panel) { 190 SwingAWTUtils.setJFrameTitle(frame, title); 191 192 final CountDownLatch sync = new CountDownLatch(1); 193 PlatformImpl.runAndWait(new Runnable() { 194 195 public void run() { 196 fillScene(); 197 SwingAWTUtils.setJFXPanelScene(panel, scene); 198 SwingAWTUtils.setJFXPanelSize(panel, (int)scene.getWidth(), (int)scene.getHeight()); 199 sync.countDown(); 200 } 201 }); 202 203 try { 204 sync.await(); 205 } catch (InterruptedException ex) { 206 Logger.getLogger(CombinedTestChooserPresenter.class.getName()).log(Level.SEVERE, null, ex); 207 } 208 SwingAWTUtils.finishShow(frame); 209 } 210 211 public void show(final Shell shell, final Object panel) { 212 shell.setText(title); 213 SwingAWTUtils.setJFXPanelSize(panel, width + 50, height + TABS_SPACE + 30); 214 215 Platform.runLater(new Runnable() { 216 217 public void run() { 218 fillScene(); 219 synchronized (CombinedTestChooserPresenter.this) { 220 CombinedTestChooserPresenter.this.notify(); 221 } 222 SwingAWTUtils.setJFXPanelScene(panel, scene); 223 } 224 }); 225 shell.setLocation(30, 30); 226 } 227 228 public Scene getScene() { 229 return scene; 230 } 231 }