예제 #1
0
 private void setTestRigTemplateToFile(String testRigFullPath, String text) {
   try {
     XJUtils.writeStringToFile(text, testRigFullPath);
   } catch (IOException ioe) {
     this.debuggerTab.getConsole().println(ioe);
   }
 }
예제 #2
0
  public DialogTestTemplate(DebuggerTab debuggerTab, Container parent) {
    super(parent, true);

    this.debuggerTab = debuggerTab;
    qualifiedFileName = this.debuggerTab.getDelegate().getDocument().getDocumentPath();
    if (qualifiedFileName != null) {
      testRigFullPath =
          XJUtils.getPathByDeletingPathExtension(qualifiedFileName)
              + DBLocal.testRigTemplateSuffix
              + ".st";
      grammarIdentifier = qualifiedFileName.toUpperCase();
    }
    if (this.debuggerTab.getDelegate().getGrammarEngine() != null)
      grammarLanguage = this.debuggerTab.getDelegate().getGrammarEngine().getGrammarLanguage();

    initComponents();

    if (XJSystem.isMacOS()) {
      buttonBar.remove(okButton);
      buttonBar.remove(cancelButton);

      CellConstraints cc = new CellConstraints();
      buttonBar.add(cancelButton, cc.xy(2, 1));
      buttonBar.add(okButton, cc.xy(4, 1));
    }

    setDefaultButton(okButton);
    setOKButton(okButton);
    setCancelButton(cancelButton);

    TextUtils.createTabs(testTextArea);
    TextUtils.setDefaultTextPaneProperties(testTextArea);

    testTextArea.setFont(
        new Font(AWPrefs.getEditorFont(), Font.PLAIN, AWPrefs.getEditorFontSize()));
    testTextArea.setFocusable(true);
    testTextArea.requestFocusInWindow();
    testTextArea.setText(getTestRigTemplateFromFile(testRigFullPath));

    if ("".equals(testTextArea.getText())) {
      if (AWPrefs.TEST_RIG_MODE_DEFAULT.equals(
          AWPrefs.getTestRigTemplateModeByLanguage(grammarLanguage.toUpperCase()))) {
        testTextArea.setText(getDefaultTestRigByLanguage(grammarLanguage));
      } else {
        testTextArea.setText(
            AWPrefs.getTestRigTemplateTextByLanguage(grammarLanguage.toUpperCase()));
      }
    }

    testClassHiddenField.setText(AWPrefs.getTestRigTemplateClass(grammarIdentifier));
    testClassField.setText(testClassHiddenField.getText());
    if ("".equals(testClassField.getText())) {
      testClassField.setForeground(Color.LIGHT_GRAY);
      testClassField.setText(TEXT_FULLY_QUALIFIED_CLASS_NAME);
    }

    textTestRadio.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (textTestRadio.isSelected()) {
              testTextArea.setEnabled(true);
              testClassField.setEnabled(false);
            } else {
              testTextArea.setEnabled(false);
              testClassField.setEnabled(true);
            }
          }
        });

    classTestRadio.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (classTestRadio.isSelected()) {
              testTextArea.setEnabled(false);
              testClassField.setEnabled(true);
            } else {
              testTextArea.setEnabled(true);
              testClassField.setEnabled(false);
            }
          }
        });

    if (AWPrefs.TEST_RIG_MODE_TEXT.equals(AWPrefs.getTestRigTemplateMode(grammarIdentifier))) {
      textTestRadio.setSelected(true);
      testTextArea.setEnabled(true);
      testClassField.setEnabled(false);
    } else {
      classTestRadio.setSelected(true);
      testTextArea.setEnabled(false);
      testClassField.setEnabled(true);
    }
  }
예제 #3
0
  private void initComponents() {
    // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
    // Generated using JFormDesigner Evaluation license - RP Talusan
    dialogPane = new JPanel();
    contentPanel = new JPanel();
    textTestRadio = new JRadioButton();
    scrollPane1 = new JScrollPane();
    testTextArea = new JTextPane();
    classTestRadio = new JRadioButton();
    testClassField = new JTextField();
    buttonBar = new JPanel();
    okButton = new JButton();
    cancelButton = new JButton();
    testClassHiddenField = new JTextField();
    CellConstraints cc = new CellConstraints();

    // ======== this ========
    String title = "Edit Test Rig";
    if (qualifiedFileName != null && !"".equals(qualifiedFileName))
      title = "Edit " + XJUtils.getLastPathComponent(qualifiedFileName) + " Test Rig";
    if (grammarLanguage != null && !"".equals(grammarLanguage)) title += " for " + grammarLanguage;
    setTitle(title);

    Container contentPane = getContentPane();
    contentPane.setLayout(new BorderLayout());

    // ======== dialogPane ========
    {
      dialogPane.setBorder(Borders.DIALOG_BORDER);
      dialogPane.setMinimumSize(new Dimension(340, 250));
      dialogPane.setLayout(new BorderLayout());

      // ======== contentPanel ========
      {
        contentPanel.setLayout(
            new FormLayout(
                new ColumnSpec[] {
                  new ColumnSpec(ColumnSpec.RIGHT, Sizes.DEFAULT, FormSpec.NO_GROW),
                  FormFactory.LABEL_COMPONENT_GAP_COLSPEC,
                  FormFactory.DEFAULT_COLSPEC,
                  FormFactory.LABEL_COMPONENT_GAP_COLSPEC,
                  new ColumnSpec(ColumnSpec.FILL, Sizes.DEFAULT, FormSpec.DEFAULT_GROW)
                },
                new RowSpec[] {
                  FormFactory.DEFAULT_ROWSPEC,
                  FormFactory.LINE_GAP_ROWSPEC,
                  FormFactory.DEFAULT_ROWSPEC,
                  FormFactory.LINE_GAP_ROWSPEC,
                  new RowSpec(RowSpec.FILL, Sizes.DEFAULT, FormSpec.DEFAULT_GROW),
                  FormFactory.LINE_GAP_ROWSPEC,
                  FormFactory.DEFAULT_ROWSPEC
                }));

        // ---- textTestRadio ----
        textTestRadio.setText("Text:");
        contentPanel.add(textTestRadio, cc.xy(1, 1));

        // ======== scrollPane1 ========
        {
          scrollPane1.setPreferredSize(new Dimension(300, 200));
          scrollPane1.setViewportView(testTextArea);
        }
        contentPanel.add(scrollPane1, cc.xywh(3, 1, 3, 5));

        // ---- classTestRadio ----
        classTestRadio.setText("Class:");
        contentPanel.add(classTestRadio, cc.xy(1, 7));

        // ---- testClassField ----
        testClassField.addFocusListener(
            new FocusAdapter() {
              @Override
              public void focusGained(FocusEvent e) {
                if (TEXT_FULLY_QUALIFIED_CLASS_NAME.equals(testClassField.getText())) {
                  testClassField.setForeground(Color.BLACK);
                  testClassField.setText("");
                }
              }

              @Override
              public void focusLost(FocusEvent e) {
                testClassHiddenField.setText(testClassField.getText());
                if ("".equals(testClassField.getText())) {
                  testClassField.setForeground(Color.LIGHT_GRAY);
                  testClassField.setText(TEXT_FULLY_QUALIFIED_CLASS_NAME);
                }
              }
            });
        contentPanel.add(testClassField, cc.xywh(3, 7, 3, 1));
      }
      dialogPane.add(contentPanel, BorderLayout.CENTER);

      // ======== buttonBar ========
      {
        buttonBar.setBorder(Borders.BUTTON_BAR_GAP_BORDER);
        buttonBar.setLayout(
            new FormLayout(
                new ColumnSpec[] {
                  FormFactory.GLUE_COLSPEC,
                  FormFactory.BUTTON_COLSPEC,
                  FormFactory.RELATED_GAP_COLSPEC,
                  FormFactory.BUTTON_COLSPEC
                },
                RowSpec.decodeSpecs("pref")));

        // ---- okButton ----
        okButton.setText("OK");
        buttonBar.add(okButton, cc.xy(2, 1));

        // ---- cancelButton ----
        cancelButton.setText("Cancel");
        buttonBar.add(cancelButton, cc.xy(4, 1));
      }
      dialogPane.add(buttonBar, BorderLayout.SOUTH);
    }
    contentPane.add(dialogPane, BorderLayout.CENTER);
    setSize(625, 395);

    // ---- buttonGroup1 ----
    ButtonGroup buttonGroup1 = new ButtonGroup();
    buttonGroup1.add(textTestRadio);
    buttonGroup1.add(classTestRadio);
    // JFormDesigner - End of component initialization  //GEN-END:initComponents
  }