Пример #1
0
 @Override
 public void actionPerformed(ActionEvent e) {
   if (td.getTabCount() > 0) {
     TextDocument ta = (TextDocument) td.getComponentAt(td.getSelectedIndex());
     Pattern pn = Pattern.compile(tf1.getText());
     Matcher mt = pn.matcher(ta.getText());
     if (e.getSource() == jb2) { // 取代
       ta.setText(mt.replaceAll(tf2.getText()));
     } else if (e.getSource() == jb1) { // 尋找
       Highlighter hl = ta.getHighlighter();
       hl.removeAllHighlights();
       while (mt.find()) {
         try {
           hl.addHighlight(
               mt.start(), mt.end(), new DefaultHighlighter.DefaultHighlightPainter(null));
         } catch (Exception ex) {
         }
       } // 開啟及關閉介面
     } else if (e.getSource() == replace_searchMenuItem) {
       System.out.println("Replace/Search is show:" + !show);
       if (show) {
         getContentPane().remove(jp);
         show = false;
       } else {
         getContentPane().add(jp, BorderLayout.SOUTH);
         show = true;
       }
       validate(); // 刷新容器
     }
   } else if (e.getSource() == replace_searchMenuItem) {
     JOptionPane.showMessageDialog(
         null, "尚無檔案,無法使用!", "Repace/Search error", JOptionPane.ERROR_MESSAGE);
   }
 }
Пример #2
0
  void applyDirectives() {
    findRemoveDirectives(true);

    StringBuffer buffer = new StringBuffer();
    String head = "", toe = "; \n";

    if (crispBox.isSelected()) buffer.append(head + "crisp=true" + toe);
    if (!fontField.getText().trim().equals(""))
      buffer.append(head + "font=\"" + fontField.getText().trim() + "\"" + toe);
    if (globalKeyEventsBox.isSelected()) buffer.append(head + "globalKeyEvents=true" + toe);
    if (pauseOnBlurBox.isSelected()) buffer.append(head + "pauseOnBlur=true" + toe);
    if (!preloadField.getText().trim().equals(""))
      buffer.append(head + "preload=\"" + preloadField.getText().trim() + "\"" + toe);
    /*if ( transparentBox.isSelected() )
    buffer.append( head + "transparent=true" + toe );*/

    Sketch sketch = editor.getSketch();
    SketchCode code = sketch.getCode(0); // first tab
    if (buffer.length() > 0) {
      code.setProgram("/* @pjs " + buffer.toString() + " */\n\n" + code.getProgram());
      if (sketch.getCurrentCode() == code) // update textarea if on first tab
      {
        editor.setText(sketch.getCurrentCode().getProgram());
        editor.setSelection(0, 0);
      }

      sketch.setModified(false);
      sketch.setModified(true);
    }
  }
Пример #3
0
  void handleScanFiles(JTextField field, String[] extensions) {
    String[] dataFiles = scanDataFolderForFilesByType(extensions);
    if (dataFiles == null || dataFiles.length == 0) return;

    String[] oldFileList = field.getText().trim().split(",");
    ArrayList<String> newFileList = new ArrayList<String>();
    for (String c : oldFileList) {
      c = c.trim();
      if (!c.equals("") && newFileList.indexOf(c) == -1) // TODO check exists() here?
      {
        newFileList.add(c);
      }
    }
    for (String c : dataFiles) {
      c = c.trim();
      if (!c.equals("") && newFileList.indexOf(c) == -1) {
        newFileList.add(c);
      }
    }
    Collections.sort(newFileList);
    String finalFileList = "";
    int i = 0;
    for (String s : newFileList) {
      finalFileList += (i > 0 ? ", " : "") + s;
      i++;
    }
    field.setText(finalFileList);
  }
Пример #4
0
  private void parseDirective(String directive) {
    if (directive == null) {
      System.err.println("Directive is null.");
      return;
    }

    String[] pair = directive.split("=");
    if (pair == null || pair.length != 2) {
      System.err.println("Unable to parse directive: \"" + directive + "\" Ignored.");
      return;
    }

    String key = pair[0].trim(), value = pair[1].trim();

    // clean these, might have too much whitespace around commas
    if (validKeys.indexOf(key) == FONT || validKeys.indexOf(key) == PRELOAD) {
      value = value.replaceAll("[\\s]*,[\\s]*", ",");
    }

    if (validKeys.indexOf(key) == -1) {
      System.err.println("Directive key not recognized: \"" + key + "\" Ignored.");
      return;
    }
    if (value.equals("")) {
      System.err.println("Directive value empty. Ignored.");
      return;
    }

    value = value.replaceAll("^\"|\"$", "").replaceAll("^'|'$", "");

    // System.out.println( key + " = " + value );

    boolean v;
    switch (validKeys.indexOf(key)) {
      case CRISP:
        v = value.toLowerCase().equals("true");
        crispBox.setSelected(v);
        break;
      case FONT:
        fontField.setText(value);
        break;
      case GLOBAL_KEY_EVENTS:
        v = value.toLowerCase().equals("true");
        globalKeyEventsBox.setSelected(v);
        break;
      case PAUSE_ON_BLUR:
        v = value.toLowerCase().equals("true");
        pauseOnBlurBox.setSelected(v);
        break;
      case PRELOAD:
        preloadField.setText(value);
        break;
      case TRANSPARENT:
        v = value.toLowerCase().equals("true");
        // transparentBox.setSelected(v);
        break;
    }
  }
Пример #5
0
 private void resetInterface() {
   for (JCheckBox b :
       new JCheckBox[] {crispBox, globalKeyEventsBox, pauseOnBlurBox /*, transparentBox*/}) {
     b.setSelected(false);
   }
   for (JTextField f : new JTextField[] {fontField, preloadField}) {
     f.setText("");
   }
 }
Пример #6
0
 /**
  * The ActionListener implementation
  *
  * @param event the event.
  */
 public void actionPerformed(ActionEvent event) {
   String searchText = textField.getText().trim();
   if (searchText.equals("") && !saveAs.isSelected() && (fileLength > 10000000)) {
     textPane.setText("Blank search text is not allowed for large IdTables.");
   } else {
     File outputFile = null;
     if (saveAs.isSelected()) {
       outputFile = chooser.getSelectedFile();
       if (outputFile != null) {
         String name = outputFile.getName();
         int k = name.lastIndexOf(".");
         if (k != -1) name = name.substring(0, k);
         name += ".txt";
         File parent = outputFile.getAbsoluteFile().getParentFile();
         outputFile = new File(parent, name);
         chooser.setSelectedFile(outputFile);
       }
       if (chooser.showSaveDialog(this) != JFileChooser.APPROVE_OPTION) System.exit(0);
       outputFile = chooser.getSelectedFile();
     }
     textPane.setText("");
     Searcher searcher = new Searcher(searchText, event.getSource().equals(searchPHI), outputFile);
     searcher.start();
   }
 }
Пример #7
0
 void profileList_mouseClicked(MouseEvent e) {
   JList theList = (JList) e.getSource();
   ListModel aModel = theList.getModel();
   int index = theList.locationToIndex(e.getPoint());
   if (index < 0) return;
   UniProfile aProfile = (UniProfile) aModel.getElementAt(index);
   nameTextField.setText(aProfile.toString());
 }
Пример #8
0
  /**
   * Constructor for FindDialog
   *
   * @param type
   * @param ta Description of the Parameter
   */
  public FindDialog(JFrame parent, JTextComponent ta) {
    super(parent, "Find in Output", true);
    this.textarea = ta;
    textarea.requestFocus();

    JPanel panel = new JPanel();
    KappaLayout layout = new KappaLayout();
    panel.setLayout(layout);
    panel.setBorder(new javax.swing.border.EmptyBorder(11, 11, 11, 11));
    setContentPane(panel);

    JLabel find_label = new JLabel("Find:");
    final JTextField to_find = new JTextField(20);
    JButton find_btn = new JButton("Find");
    JButton find_next_btn = new JButton("Find Next");
    JButton cancel_btn = new JButton("Close");
    final JCheckBox wrap_cb = new JCheckBox("Wrap search");
    wrap_cb.setSelected(true);

    panel.add(find_label, "0, 0, 1, 1, W, w, 3");
    panel.add(to_find, "0, 1, 1, 1, 0, w, 3");
    panel.add(wrap_cb, "0, 2, 1, 1, 0, w, 3");

    JPanel btn_panel = new JPanel(new KappaLayout());
    btn_panel.add(find_btn, "0, 0, 1, 1, 0, w, 3");
    btn_panel.add(find_next_btn, "0, 1, 1, 1, 0, w, 3");
    btn_panel.add(cancel_btn, "0, 2, 1, 1, 0, w, 3");
    panel.add(btn_panel, "1, 0, 1, 3, 0, h, 5");

    find_btn.addActionListener(new Finder(to_find, textarea, false, wrap_cb.isSelected()));
    find_next_btn.addActionListener(new Finder(to_find, textarea, true, wrap_cb.isSelected()));
    cancel_btn.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
            setVisible(false);
            dispose();
          }
        });
    pack();
    to_find.requestFocus();
  }
Пример #9
0
  private void myInit2(
      SanBootView _view, Backupable _bakable, int _mode, int _type, BootHost host) {
    view = _view;
    bakable = _bakable;
    mode = _mode;
    type = _type;

    setupProfileType();
    setupList();
    setupLanguage();

    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd-hh-mm-ss");
    Date date = new Date();
    String time = df.format(date);
    System.out.println(host.getID() + "-" + time);
    nameTextField.setText(host.getID() + "-" + time);

    if (mode == ProfileChooser.MODE_SAVEAS || mode == ProfileChooser.MODE_SAVE) {
      saveAsProfile = new UniProfile();
      nameTextField.requestFocus();
    }
  }
Пример #10
0
  private void myInit(SanBootView _view, Backupable _bakable, int _mode, int _type) {
    view = _view;
    bakable = _bakable;
    mode = _mode;
    type = _type;

    setupProfileType();
    setupList();
    setupLanguage();

    if (mode == ProfileChooser.MODE_SAVEAS || mode == ProfileChooser.MODE_SAVE) {
      saveAsProfile = new UniProfile();
      nameTextField.requestFocus();
    }
  }
Пример #11
0
 void jbInit() throws Exception {
   border1 = BorderFactory.createEmptyBorder(10, 10, 5, 5);
   panel1.setLayout(borderLayout1);
   jPanel1.setLayout(borderLayout2);
   jScrollPane1.getViewport().setBackground(Color.white);
   jPanel2.setLayout(gridBagLayout1);
   jLabel1.setText("Profile Name : ");
   nameTextField.setMinimumSize(new Dimension(4, 18));
   nameTextField.setPreferredSize(new Dimension(63, 18));
   jLabel2.setText("Profile Type : ");
   openButton.setMaximumSize(new Dimension(73, 24));
   openButton.setMinimumSize(new Dimension(73, 24));
   openButton.setPreferredSize(new Dimension(73, 24));
   openButton.setText("Open");
   openButton.addActionListener(
       new java.awt.event.ActionListener() {
         public void actionPerformed(ActionEvent e) {
           openButton_actionPerformed(e);
         }
       });
   cancelButton.setMaximumSize(new Dimension(73, 24));
   cancelButton.setMinimumSize(new Dimension(73, 24));
   cancelButton.setPreferredSize(new Dimension(73, 24));
   cancelButton.setMargin(new Insets(0, 5, 0, 5));
   cancelButton.setText("Cancel");
   cancelButton.addActionListener(
       new java.awt.event.ActionListener() {
         public void actionPerformed(ActionEvent e) {
           cancelButton_actionPerformed(e);
         }
       });
   profileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
   profileList.addMouseListener(
       new java.awt.event.MouseAdapter() {
         public void mouseClicked(MouseEvent e) {
           profileList_mouseClicked(e);
         }
       });
   jPanel2.setBorder(border1);
   typeComboBox.setMaximumSize(new Dimension(32767, 18));
   typeComboBox.setMinimumSize(new Dimension(122, 18));
   typeComboBox.setPreferredSize(new Dimension(176, 18));
   getContentPane().add(panel1);
   panel1.add(jPanel1, BorderLayout.CENTER);
   jPanel1.add(jScrollPane1, BorderLayout.CENTER);
   panel1.add(jPanel2, BorderLayout.SOUTH);
   jPanel2.add(
       jLabel1,
       new GridBagConstraints(
           0,
           0,
           1,
           1,
           0.0,
           0.0,
           GridBagConstraints.CENTER,
           GridBagConstraints.HORIZONTAL,
           new Insets(0, 0, 7, 0),
           0,
           0));
   jPanel2.add(
       nameTextField,
       new GridBagConstraints(
           1,
           0,
           1,
           1,
           0.0,
           0.0,
           GridBagConstraints.CENTER,
           GridBagConstraints.HORIZONTAL,
           new Insets(0, 11, 7, 0),
           0,
           0));
   jPanel2.add(
       jLabel2,
       new GridBagConstraints(
           0,
           1,
           1,
           1,
           0.0,
           0.0,
           GridBagConstraints.CENTER,
           GridBagConstraints.HORIZONTAL,
           new Insets(0, 0, 17, 0),
           0,
           0));
   jScrollPane1.getViewport().add(profileList, null);
   jPanel2.add(
       openButton,
       new GridBagConstraints(
           3,
           0,
           1,
           1,
           0.0,
           0.0,
           GridBagConstraints.CENTER,
           GridBagConstraints.NONE,
           new Insets(0, 11, 2, 10),
           0,
           0));
   jPanel2.add(
       cancelButton,
       new GridBagConstraints(
           3,
           1,
           1,
           1,
           0.0,
           0.0,
           GridBagConstraints.CENTER,
           GridBagConstraints.NONE,
           new Insets(0, 11, 9, 10),
           0,
           0));
   jPanel2.add(
       typeComboBox,
       new GridBagConstraints(
           1,
           1,
           1,
           1,
           0.0,
           0.0,
           GridBagConstraints.CENTER,
           GridBagConstraints.HORIZONTAL,
           new Insets(0, 11, 17, 0),
           0,
           0));
 }
Пример #12
0
  void openButton_actionPerformed(ActionEvent e) {
    String name = nameTextField.getText().trim();
    if (mode == ProfileChooser.MODE_OPEN) { // open
      if (name.equals("")) {
        JOptionPane.showMessageDialog(
            this, SanBootView.res.getString("ProfileChooser.errMsg.notSelect"));
        return;
      }

      UniProfile prof = isSameProfile(name);
      if (prof == null) {
        JOptionPane.showMessageDialog(
            this, SanBootView.res.getString("ProfileChooser.errMsg.notExist") + ": " + name);
        return;
      }

      values = new Object[1];
      values[0] = prof;
    } else { // save as 或 save
      if (name.equals("")) {
        JOptionPane.showMessageDialog(
            this, SanBootView.res.getString("ProfileChooser.errMsg.notName"));
        return;
      }

      String tmpName = name;
      Pattern pattern = Pattern.compile(".+\\.prf");
      Matcher matcher = pattern.matcher(tmpName);
      if (!matcher.find()) {
        tmpName += ".prf";
      }

      UniProfile pf = isSameProfile(tmpName);
      if (pf != null) { // 存 在 相 同 的 名 字 的profile ( pf )
        if (view.initor.mdb.getSchNumOnProfName(pf.getProfileName()) > 0) {
          JOptionPane.showMessageDialog(
              this, SanBootView.res.getString("EditProfileDialog.error.hasSch"));
          return;
        }

        if (JOptionPane.showConfirmDialog( // 提示信息更换
                (Dialog) bakable,
                SanBootView.res.getString("ProfileChooser.confirmmsg1"),
                SanBootView.res.getString("common.confirm"),
                JOptionPane.OK_CANCEL_OPTION)
            == JOptionPane.CANCEL_OPTION) {
          return;
        } else {
          values = new Object[2];
          values[0] = pf;
          values[1] = saveAsProfile;
        }
      } else { // 不 存 在 相 同 的 名 字
        String pname = ResourceCenter.PROFILE_DIR + name + ".prf";

        if (pname.indexOf("\"") >= 0
            || pname.indexOf("'") >= 0
            || pname.indexOf(' ') >= 0
            || pname.indexOf('\t') >= 0) {
          JOptionPane.showMessageDialog(
              this, SanBootView.res.getString("ProfileChooser.errmsg.badname"));
          return;
        }

        if (pname.getBytes().length >= 1000) {
          JOptionPane.showMessageDialog(
              this, SanBootView.res.getString("ProfileChooser.errmsg.tooLargePname"));
          return;
        }

        values = new Object[1];
        saveAsProfile.setProfileName(pname);
        values[0] = saveAsProfile;
      }
    }

    dispose();
  }
Пример #13
0
  void createFrame() {
    /* see Preferences.java */
    int GUI_BIG = 13;
    int GUI_BETWEEN = 10;
    int GUI_SMALL = 6;
    int FIELD_SIZE = 30;

    int left = GUI_BIG;
    int top = GUI_BIG;
    int right = 0;

    Dimension d;

    frame = new JFrame("Directives Editor");
    Container pane = frame.getContentPane();
    pane.setLayout(null);

    JLabel label = new JLabel("Click here to read about directives.");
    label.addMouseListener(
        new MouseListener() {
          public void mouseClicked(MouseEvent e) {
            Base.openURL("http://processingjs.org/reference/pjs%20directive");
          }

          public void mouseEntered(MouseEvent e) {}

          public void mouseExited(MouseEvent e) {}

          public void mousePressed(MouseEvent e) {}

          public void mouseReleased(MouseEvent e) {}
        });
    pane.add(label);
    d = label.getPreferredSize();
    label.setBounds(left, top, d.width, d.height);
    top += d.height + GUI_BETWEEN + GUI_BETWEEN;

    // CRISP

    crispBox = new JCheckBox("\"crisp\": disable antialiasing for line(), triangle() and rect()");
    pane.add(crispBox);
    d = crispBox.getPreferredSize();
    crispBox.setBounds(left, top, d.width + 10, d.height);
    right = Math.max(right, left + d.width);
    top += d.height + GUI_BETWEEN;

    // FONTS

    label = new JLabel("\"font\": to load (comma separated)");
    pane.add(label);
    d = label.getPreferredSize();
    label.setBounds(left, top, d.width, d.height);
    top += d.height + GUI_SMALL;

    fontField = new JTextField(FIELD_SIZE);
    pane.add(fontField);
    d = fontField.getPreferredSize();
    fontField.setBounds(left, top, d.width, d.height);

    JButton button = new JButton("scan");
    button.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            handleScanFonts();
          }
        });
    pane.add(button);
    Dimension d2 = button.getPreferredSize();
    button.setBounds(left + d.width + GUI_SMALL, top, d2.width, d2.height);
    right = Math.max(right, left + d.width + GUI_SMALL + d2.width);
    top += d.height + GUI_BETWEEN;

    // GLOBAL_KEY_EVENTS

    globalKeyEventsBox = new JCheckBox("\"globalKeyEvents\": receive global key events");
    pane.add(globalKeyEventsBox);
    d = globalKeyEventsBox.getPreferredSize();
    globalKeyEventsBox.setBounds(left, top, d.width + 10, d.height);
    right = Math.max(right, left + d.width);
    top += d.height + GUI_BETWEEN;

    // PAUSE_ON_BLUR

    pauseOnBlurBox = new JCheckBox("\"pauseOnBlur\": pause if applet loses focus");
    pane.add(pauseOnBlurBox);
    d = pauseOnBlurBox.getPreferredSize();
    pauseOnBlurBox.setBounds(left, top, d.width + 10, d.height);
    right = Math.max(right, left + d.width);
    top += d.height + GUI_BETWEEN;

    // PRELOAD images

    label = new JLabel("\"preload\": images (comma separated)");
    pane.add(label);
    d = label.getPreferredSize();
    label.setBounds(left, top, d.width, d.height);
    top += d.height + GUI_SMALL;

    preloadField = new JTextField(FIELD_SIZE);
    pane.add(preloadField);
    d = preloadField.getPreferredSize();
    preloadField.setBounds(left, top, d.width, d.height);

    button = new JButton("scan");
    button.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            handleScanImages();
          }
        });
    pane.add(button);
    d2 = button.getPreferredSize();
    button.setBounds(left + d.width + GUI_SMALL, top, d2.width, d2.height);
    right = Math.max(right, left + d.width + GUI_SMALL + d2.width);
    top += d.height + GUI_BETWEEN;

    // TRANSPARENT

    /*transparentBox =
         new JCheckBox("\"transparent\": set applet background to be transparent");
       pane.add(transparentBox);
    d = transparentBox.getPreferredSize();
       transparentBox.setBounds(left, top, d.width + 10, d.height);
       right = Math.max(right, left + d.width);
       top += d.height + GUI_BETWEEN;*/

    // APPLY / OK

    button = new JButton("OK");
    button.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            applyDirectives();
            hide();
          }
        });
    pane.add(button);
    d2 = button.getPreferredSize();
    int BUTTON_HEIGHT = d2.height;
    int BUTTON_WIDTH = 80;

    int h = right - (BUTTON_WIDTH + GUI_SMALL + BUTTON_WIDTH);
    button.setBounds(h, top, BUTTON_WIDTH, BUTTON_HEIGHT);
    h += BUTTON_WIDTH + GUI_SMALL;

    button = new JButton("Cancel");
    button.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            hide();
          }
        });
    pane.add(button);
    button.setBounds(h, top, BUTTON_WIDTH, BUTTON_HEIGHT);

    top += BUTTON_HEIGHT + GUI_BETWEEN;

    // frame.getContentPane().add(box);
    frame.pack();
    Insets insets = frame.getInsets();
    frame.setSize(
        right + GUI_BIG + insets.left + insets.right, top + GUI_SMALL + insets.top + insets.bottom);

    // frame.setResizable(false);

    frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    frame.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            frame.setVisible(false);
          }
        });
    Toolkit.registerWindowCloseKeys(
        frame.getRootPane(),
        new ActionListener() {
          public void actionPerformed(ActionEvent actionEvent) {
            frame.setVisible(false);
          }
        });
    Toolkit.setIcon(frame);
  }