1 /*
   2  * $Id$
   3  *
   4  * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
   5  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   6  *
   7  * This code is free software; you can redistribute it and/or modify it
   8  * under the terms of the GNU General Public License version 2 only, as
   9  * published by the Free Software Foundation.  Oracle designates this
  10  * particular file as subject to the "Classpath" exception as provided
  11  * by Oracle in the LICENSE file that accompanied this code.
  12  *
  13  * This code is distributed in the hope that it will be useful, but WITHOUT
  14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  16  * version 2 for more details (a copy is included in the LICENSE file that
  17  * accompanied this code).
  18  *
  19  * You should have received a copy of the GNU General Public License version
  20  * 2 along with this work; if not, write to the Free Software Foundation,
  21  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  22  *
  23  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  24  * or visit www.oracle.com if you need additional information or have any
  25  * questions.
  26  */
  27 package com.sun.javatest.exec;
  28 
  29 import java.awt.GridBagConstraints;
  30 import java.awt.GridBagLayout;
  31 import java.util.Map;
  32 
  33 import javax.swing.BorderFactory;
  34 import javax.swing.Box;
  35 import javax.swing.ButtonGroup;
  36 import javax.swing.JCheckBox;
  37 import javax.swing.JLabel;
  38 import javax.swing.JPanel;
  39 import javax.swing.JRadioButton;
  40 import javax.swing.JTextArea;
  41 import javax.swing.JTextField;
  42 
  43 import com.sun.javatest.report.ReportManager;
  44 import com.sun.javatest.tool.Preferences;
  45 import com.sun.javatest.tool.PreferencesPane;
  46 import com.sun.javatest.tool.UIFactory;
  47 import com.sun.javatest.tool.jthelp.HelpBroker;
  48 
  49 import java.awt.Font;
  50 
  51 
  52 
  53 class PrefsPane extends PreferencesPane
  54 {
  55     PrefsPane(HelpBroker helpBroker) {
  56         uif = new UIFactory(this, helpBroker);
  57         initGUI();
  58     }
  59 
  60     @Override
  61     public PreferencesPane[] getChildPanes() {
  62         if (configEditorPane == null) {
  63             configEditorPane = new ConfigEditorPane();
  64         }
  65 
  66         if (reportingPane == null) {
  67             reportingPane = new ReportingPane();
  68         }
  69 
  70         if (runPane == null) {
  71             runPane = new RunPane();
  72         }
  73 
  74         if (childPanes == null)
  75             childPanes = new PreferencesPane[] { configEditorPane, reportingPane, runPane };
  76         return childPanes;
  77     }
  78 
  79     public String getText() {
  80         return uif.getI18NString("ep.title");
  81     }
  82 
  83     @Override
  84     public void load(Map<?, ?> m) {
  85         super.load(m);
  86         String p = (String) (m.get(ExecTool.TOOLBAR_PREF));
  87         toolBarChk.setSelected(p == null || p.equals("true"));
  88         p = (String) (m.get(ExecTool.FILTER_WARN_PREF));
  89         filterWarnChk.setSelected(p == null || p.equals("true"));
  90         p = (String) (m.get(TP_OutputSubpanel.LINE_WRAP_PREF));
  91         // selected by default
  92         wrapResChk.setSelected((p == null ? true : p.equals("true")));
  93     }
  94 
  95     @Override
  96     public void save(Map<String, String> m) {
  97         super.save(m);
  98         m.put(ExecTool.TOOLBAR_PREF, String.valueOf(toolBarChk.isSelected()));
  99         m.put(ExecTool.FILTER_WARN_PREF, String.valueOf(filterWarnChk.isSelected()));
 100         m.put(TP_OutputSubpanel.LINE_WRAP_PREF, String.valueOf(wrapResChk.isSelected()));
 101     }
 102 
 103     private void initGUI() {
 104         setLayout(new GridBagLayout());
 105 
 106         GridBagConstraints c = new GridBagConstraints();
 107         c.fill = GridBagConstraints.HORIZONTAL;
 108         c.gridwidth = GridBagConstraints.REMAINDER;
 109         c.weightx = 1;
 110 
 111         add(createToolBarPanel(), c);
 112         add(createFilterPanel(), c);
 113         add(createTestRunMsgPanel(), c);
 114 
 115         c.weighty = 1;
 116         add(Box.createVerticalGlue(), c);
 117 
 118     }
 119 
 120     private JPanel createToolBarPanel() {
 121         JPanel p = uif.createPanel("exec.prefs", new GridBagLayout(), false);
 122         GridBagConstraints c = new GridBagConstraints();
 123         c.anchor = GridBagConstraints.WEST;
 124         c.weightx = 1;
 125         p.setBorder(uif.createTitledBorder("ep.toolbar"));
 126         toolBarChk = uif.createCheckBox("ep.toolbar", true);
 127         // override default a11y name
 128         uif.setAccessibleName(toolBarChk, "ep.toolbar");
 129         p.add(toolBarChk, c);
 130         return p;
 131     }
 132 
 133     private JPanel createFilterPanel() {
 134         // could have setting to ask user what the default filter to use is
 135         JPanel p = uif.createPanel("exec.prefs.filter", new GridBagLayout(), false);
 136         GridBagConstraints c = new GridBagConstraints();
 137         c.anchor = GridBagConstraints.WEST;
 138         c.weightx = 1;
 139         p.setBorder(uif.createTitledBorder("ep.filt"));
 140         filterWarnChk= uif.createCheckBox("ep.filt", true);
 141         // override default a11y name
 142         uif.setAccessibleName(filterWarnChk, "ep.filt");
 143         p.add(filterWarnChk, c);
 144         return p;
 145     }
 146 
 147     private JPanel createTestRunMsgPanel() {
 148         JPanel p = uif.createPanel("exec.prefs.testrun", new GridBagLayout(), false);
 149         GridBagConstraints c = new GridBagConstraints();
 150         c.anchor = GridBagConstraints.WEST;
 151         c.weightx = 1;
 152         p.setBorder(uif.createTitledBorder("ep.testrun"));
 153         wrapResChk= uif.createCheckBox("ep.wrapres", true);
 154         uif.setAccessibleName(wrapResChk, "ep.wrapres");
 155         p.add(wrapResChk, c);
 156         return p;
 157     }
 158 
 159 
 160     private UIFactory uif;
 161     private JCheckBox toolBarChk;
 162     private JCheckBox filterWarnChk;
 163     private JCheckBox wrapResChk;
 164     private ConfigEditorPane configEditorPane;
 165     private ReportingPane reportingPane;
 166     private RunPane runPane;
 167     private PreferencesPane[] childPanes;
 168 
 169     private class ConfigEditorPane extends PreferencesPane {
 170         ConfigEditorPane() {
 171             initGUI();
 172         }
 173 
 174         public String getText() {
 175             return uif.getI18NString("ep.ce.title");
 176         }
 177 
 178         @Override
 179         public void load(Map<?, ?> m) {
 180             String mp = (String) m.get(InterviewEditor.MORE_INFO_PREF);
 181             moreInfoChk.setSelected(mp == null || mp.equals("true"));
 182         }
 183 
 184         @Override
 185         public void save(Map<String, String> m) {
 186             m.put(InterviewEditor.MORE_INFO_PREF, String.valueOf(moreInfoChk.isSelected()));
 187         }
 188 
 189         private void initGUI() {
 190             setLayout(new GridBagLayout());
 191 
 192             GridBagConstraints c = new GridBagConstraints();
 193             c.fill = GridBagConstraints.HORIZONTAL;
 194             c.gridwidth = GridBagConstraints.REMAINDER;
 195             c.weightx = 1;
 196 
 197             add(createDefaultViewPanel(), c);
 198 
 199             c.weighty = 1;
 200             add(Box.createVerticalGlue(), c);
 201         }
 202 
 203         private JPanel createDefaultViewPanel() {
 204             GridBagConstraints c = new GridBagConstraints();
 205             c.anchor = GridBagConstraints.WEST;
 206             c.gridwidth = GridBagConstraints.REMAINDER;
 207             c.insets.left = 10;
 208             c.weightx = 1;
 209             c.weighty = 0;
 210 
 211             JPanel p = new JPanel(new GridBagLayout());
 212 
 213             JTextArea infoTa = uif.createMessageArea("ep.ce.info");
 214             infoTa.setOpaque(false);
 215             add(infoTa, c);
 216 
 217             p.setBorder(uif.createTitledBorder("ep.ce.defView"));
 218             moreInfoChk = uif.createCheckBox("ep.ce.moreInfo", true);
 219             // override default a11y name
 220             uif.setAccessibleName(moreInfoChk, "ep.ce.moreInfo");
 221 
 222             c.insets.top = 10;
 223             p.add(moreInfoChk, c);
 224             return p;
 225         }
 226 
 227         private JCheckBox moreInfoChk;
 228     }
 229 
 230     private class ReportingPane extends PreferencesPane {
 231         ReportingPane() {
 232             initGUI();
 233         }
 234 
 235         public String getText() {
 236             return uif.getI18NString("ep.rpt.title");
 237         }
 238 
 239         @Override
 240         public void load(Map<?, ?> m) {
 241             String mp = (String) (m.get(ReportManager.BUGRPT_URL_PREF));
 242             bugUrlTf.setText(mp);
 243         }
 244 
 245         @Override
 246         public void save(Map<String, String> m) {
 247             m.put(ReportManager.BUGRPT_URL_PREF, bugUrlTf.getText());
 248         }
 249 
 250         private void initGUI() {
 251             setLayout(new GridBagLayout());
 252 
 253             GridBagConstraints c = new GridBagConstraints();
 254             c.fill = GridBagConstraints.HORIZONTAL;
 255             c.gridwidth = GridBagConstraints.REMAINDER;
 256             c.weightx = 1;
 257 
 258             add(createDefaultViewPanel(), c);
 259 
 260             c.weighty = 1;
 261             add(Box.createVerticalGlue(), c);
 262         }
 263 
 264         private JPanel createDefaultViewPanel() {
 265             GridBagConstraints c = new GridBagConstraints();
 266             c.anchor = GridBagConstraints.BASELINE_LEADING;
 267             c.gridwidth = 1;
 268             //c.insets.left = 10;
 269             c.gridx = GridBagConstraints.RELATIVE;
 270             c.gridy = 0;
 271             c.weighty = c.weightx = 1;
 272 
 273             JPanel p = new JPanel(new GridBagLayout());
 274             JLabel lbl = uif.createLabel("ep.rpt.url");
 275             p.add(lbl, c);
 276 
 277             bugUrlTf = uif.createInputField("ep.rpt.url", lbl);
 278             bugUrlTf.setColumns(30);
 279             // override default a11y name
 280             uif.setAccessibleName(bugUrlTf, "ep.rpt.url");
 281 
 282             //c.insets.top = 10;
 283             c.gridwidth = GridBagConstraints.REMAINDER;
 284             c.weightx = 5;
 285             p.add(bugUrlTf, c);
 286 
 287             JTextArea hint = uif.createMessageArea("ep.rpt.url");
 288             hint.setFont(hint.getFont().deriveFont(Font.ITALIC));
 289             hint.setBorder(BorderFactory.createEmptyBorder());
 290             c.gridy = c.gridx = 1;    // under bugUrlTf
 291             c.weightx = 1;
 292             p.add(hint, c);
 293 
 294             return p;
 295         }
 296 
 297         private JTextField bugUrlTf;
 298     }
 299 
 300     private class RunPane extends PreferencesPane {
 301         RunPane() {
 302             initGUI();
 303         }
 304 
 305         public String getText() {
 306             return uif.getI18NString("ep.run.title");
 307         }
 308 
 309         @Override
 310         public void load(Map<?, ?> m) {
 311             String mp = (String)m.get("javatest.executionOrder");
 312             if (mp == null) {
 313                 mp = "default";
 314             }
 315 
 316             if (mp.equals("reverse")) {
 317                 reverseRadio.setSelected(true);
 318             }
 319             else if (mp.equals("random")) {
 320                 randomRadio.setSelected(true);
 321             }
 322             else {
 323                 defaultRadio.setSelected(true);
 324             }
 325 
 326             mp = (String) (m.get(ExecTool.TESTS2RUN_PREF));
 327             tests2RunChk.setSelected((mp == null ? false : mp.equals("true")));
 328             mp = (String) (m.get("javatest.sortExecution"));
 329             testSortingChk.setSelected((mp == null ? false : mp.equals("false")));
 330         }
 331 
 332         @Override
 333         public void save(Map<String, String> m) {
 334             m.put(ExecTool.TESTS2RUN_PREF, String.valueOf(tests2RunChk.isSelected()));
 335             m.put("javatest.sortExecution", Boolean.toString(!testSortingChk.isSelected()));
 336 
 337             String sequence = ".default";
 338             if (reverseRadio.isSelected()) {
 339                 sequence = reverseRadio.getName();
 340             }
 341             else if (randomRadio.isSelected()) {
 342                 sequence = randomRadio.getName();
 343             }
 344             else {
 345                 sequence = defaultRadio.getName();
 346             }
 347 
 348             m.put("javatest.executionOrder", sequence.substring(sequence.lastIndexOf(".") + 1));
 349         }
 350 
 351         private void initGUI() {
 352             setLayout(new GridBagLayout());
 353 
 354             GridBagConstraints c = new GridBagConstraints();
 355             c.fill = GridBagConstraints.HORIZONTAL;
 356             c.gridwidth = GridBagConstraints.REMAINDER;
 357             c.weightx = 1;
 358 
 359             add(createExecutionPanel(), c);
 360             add(createOrderPanel(), c);
 361 
 362             c.weighty = 1;
 363             add(Box.createVerticalGlue(), c);
 364         }
 365 
 366         private JPanel createExecutionPanel() {
 367             JPanel p = uif.createPanel("exec.prefs.run", new GridBagLayout(), false);
 368             GridBagConstraints c = new GridBagConstraints();
 369             c.anchor = GridBagConstraints.WEST;
 370             c.weightx = 1;
 371             p.setBorder(uif.createTitledBorder("ep.exec"));
 372 
 373             tests2RunChk = uif.createCheckBox("ep.tests2run", true);
 374             // override default a11y name
 375             uif.setAccessibleName(tests2RunChk, "ep.tests2run");
 376             p.add(tests2RunChk, c);
 377 
 378             testSortingChk = uif.createCheckBox("ep.sorttests", true);
 379             c.gridy = GridBagConstraints.PAGE_END;
 380             p.add(testSortingChk, c);
 381             return p;
 382         }
 383 
 384         private JPanel createOrderPanel() {
 385             GridBagConstraints c = new GridBagConstraints();
 386             c.anchor = GridBagConstraints.LINE_START;
 387             c.gridwidth = 1;
 388             c.weighty = c.weightx = 1;
 389             JPanel p = uif.createPanel("exec.prefs.exec", new GridBagLayout(), false);
 390             p.setBorder(uif.createTitledBorder("ep.run"));
 391 
 392             sequenceButtons = new ButtonGroup();
 393 
 394             defaultRadio = uif.createRadioButton("ep.run.order.default", sequenceButtons);
 395             randomRadio = uif.createRadioButton("ep.run.order.random", sequenceButtons);
 396             reverseRadio = uif.createRadioButton("ep.run.order.reverse", sequenceButtons);
 397 
 398             p.add(defaultRadio, c);
 399             p.add(randomRadio, c);
 400             p.add(reverseRadio, c);
 401             return p;
 402         }
 403 
 404         private JTextField bugUrlTf;
 405         private JCheckBox tests2RunChk;
 406         private JCheckBox testSortingChk;   // deceptive name, see i18n description
 407         private JRadioButton defaultRadio;
 408         private JRadioButton reverseRadio;
 409         private JRadioButton randomRadio;
 410         private ButtonGroup sequenceButtons;
 411     }
 412 }