示例#1
0
 /** Set selection. */
 public void select() {
   pModel.findSelectionPositions();
   editor.setSelectedTextColor(Color.blue);
   editor.requestFocusInWindow();
   editor.setCaretPosition(pModel.getSelectionStart());
   editor.moveCaretPosition(pModel.getSelectionEnd());
 }
示例#2
0
	public void actionPerformed(ActionEvent e)
	{
		if(e.getSource()==b)
		{
			temp=tf.getText();
			temp1[]=ta.getText().split();
			index=0;
			index=temp1[].indexOf(temp,index);
			ta.select(index, index+temp.length());
			b.setVisible(false);
			b1.setVisible(true);
		}
		if(e.getSource()==b1)
		{
			index=temp1.indexOf(temp,index+temp.length());
			if(index!=-1)
			{
				ta.requestFocusInWindow();
				ta.select(index, index+temp.length());
			}
			else
			{
				b.setVisible(true);
				b1.setVisible(false);
				index=0;
			}
		}
	}	
 private void setScriptArea() {
   String s = null;
   if (pageCheckBox.getAction() != null)
     s = (String) pageCheckBox.getAction().getValue(Action.SHORT_DESCRIPTION);
   if (actionComboBox.getSelectedItem() != null) s = actionComboBox.getSelectedItem().toString();
   if (s == null) return;
   boolean isScriptButton = isScriptActionKey(s);
   scriptAreaSelected.setEnabled(isScriptButton);
   scriptLabelSelected.setEnabled(isScriptButton);
   scriptAreaDeselected.setEnabled(isScriptButton);
   scriptLabelDeselected.setEnabled(isScriptButton);
   scriptAreaSelected.setText(
       isScriptButton ? (String) pageCheckBox.getClientProperty("selection script") : null);
   scriptAreaDeselected.setText(
       isScriptButton ? (String) pageCheckBox.getClientProperty("deselection script") : null);
   if (isScriptButton) {
     scriptAreaSelected.requestFocusInWindow();
     scriptAreaSelected.setCaretPosition(0);
     scriptAreaDeselected.setCaretPosition(0);
   }
 }
示例#4
0
 /** Place the GUI focus on the text area. */
 public void focusOnTextInput() {
   text_area.requestFocusInWindow();
 }
  /**
   * Constructor for main GUI
   *
   * @param configManager The configuration
   * @param title The titlebar title
   */
  public SQLRunnerGUI(ConfigurationManager configManager, String title) {

    this.configManager = configManager;

    mainWindow = new JFrame(title);

    // XXX DO NOT USE mainWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    // Because the GUI is intended to be embedded in other applications!!
    // They will call SQLRunner.setOkToExit(true) if they want.
    mainWindow.addWindowListener(
        new WindowAdapter() {
          @Override
          public void windowClosing(WindowEvent e) {
            mainWindow.dispose();
            SQLRunner.exit(0);
          }
        });

    final Container controlsArea = new JPanel();
    BoxLayout layout = new BoxLayout(controlsArea, BoxLayout.LINE_AXIS);
    controlsArea.setLayout(layout);
    mainWindow.add(controlsArea, BorderLayout.NORTH);

    configurations = configManager.getConfigurations();
    connectionsList =
        new JComboBox(configurations.toArray(new Configuration[configurations.size()]));
    // when you change to a different database you don't want to remember the "force passwd prompt"
    // setting
    connectionsList.addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent e) {
            passwdPromptCheckBox.setSelected(false);
          }
        });
    controlsArea.add(new JLabel("Connection"));
    controlsArea.add(connectionsList);
    passwdPromptCheckBox = new JCheckBox("Ask for passwd");
    controlsArea.add(passwdPromptCheckBox);

    JButton tb = new JButton("Test");
    controlsArea.add(tb);
    tb.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent evt) {
            // XXX
          }
        });

    final JComboBox inTemplateChoice = new JComboBox();
    // XXX Of course these should be editable...
    inTemplateChoice.addItem("Input Template:");
    for (SQLTemplate t : SQLTemplate.getList()) {
      inTemplateChoice.addItem(t);
    }
    controlsArea.add(inTemplateChoice);

    modeList = new JComboBox();
    for (OutputMode mode : OutputMode.values()) {
      modeList.addItem(mode);
    }

    // If the mode is set to JTable, switch the
    // tab to 1, else reset it to 0 (which is shared
    // by Text, SQL, etc...
    // XXX  should be a third tab for HTML
    modeList.addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent e) {
            mode = (OutputMode) modeList.getSelectedItem();
            switch (mode) {
              case j:
                outputPanel.setSelectedIndex(1);
                break;
              default:
                outputPanel.setSelectedIndex(0);
            }
          }
        });
    controlsArea.add(new JLabel("Output Format:"));
    controlsArea.add(modeList);

    runButton = new JButton(runAction);
    controlsArea.add(runButton);

    JButton clearOutput = new JButton("Clear Output");
    clearOutput.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            textTextArea.setText("");
            resultsStatusBar.reset();
          }
        });
    controlsArea.add(clearOutput);

    // END OF TOP ROW

    // Used by Run...
    busyDialog = new JDialog(mainWindow, "Running...");
    JProgressBar busyIndicator = new JProgressBar();
    busyIndicator.setIndeterminate(true);
    busyDialog.add(busyIndicator, BorderLayout.CENTER);
    JPanel bottomPanel = new JPanel();
    bottomPanel.add(new JButton(cancelAction));
    busyDialog.add(bottomPanel, BorderLayout.SOUTH);
    busyDialog.pack();
    busyDialog.setLocationRelativeTo(mainWindow);

    inputTextArea = new JTextArea(6, DISPLAY_COLUMNS);
    // Switch to monospaced font
    Font msFont = new Font("SansSerif", Font.PLAIN, inputTextArea.getFont().getSize());
    inputTextArea.setFont(msFont);
    JScrollPane inputAreaScrollPane = new JScrollPane(inputTextArea);
    inputAreaScrollPane.setBorder(BorderFactory.createTitledBorder("SQL Command"));

    outputPanel = new JTabbedPane();

    textTextArea = new JTextArea(20, DISPLAY_COLUMNS);
    textTextArea.setFont(msFont);
    JScrollPane outputAreaScrollPane = new JScrollPane(textTextArea);
    String resultTypeName;
    resultTypeName = OutputMode.t.toString();
    outputAreaScrollPane.setBorder(BorderFactory.createTitledBorder(resultTypeName));
    outputPanel.addTab(resultTypeName, outputAreaScrollPane);

    jtable = new JTable();
    resultTypeName = OutputMode.j.toString();
    outputPanel.addTab(resultTypeName, new JScrollPane(jtable));

    inTemplateChoice.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (inTemplateChoice.getSelectedIndex() == 0) {
              return;
            }
            final SQLTemplate selectedItem = (SQLTemplate) inTemplateChoice.getSelectedItem();
            inputTextArea.setText(selectedItem.getTemplate());
          }
        });

    mainWindow.add(
        new JSplitPane(JSplitPane.VERTICAL_SPLIT, inputAreaScrollPane, outputPanel),
        BorderLayout.CENTER);

    out = new PrintWriter(new TextAreaWriter(textTextArea));

    resultsStatusBar = new SuccessFailureBarSwing(mainWindow.getBackground(), 400, 20);
    resultsStatusBar.reset();
    mainWindow.add((JComponent) resultsStatusBar, BorderLayout.SOUTH);

    mainWindow.pack();
    UtilGUI.monitorWindowPosition(mainWindow, prefsNode);
    mainWindow.setVisible(true);
    inputTextArea.requestFocusInWindow();
  }
示例#6
0
 @Override
 public final void run() {
   editorPane.requestFocusInWindow();
 }