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); } }
/** * 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(); } }
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; } }
private void resetInterface() { for (JCheckBox b : new JCheckBox[] {crispBox, globalKeyEventsBox, pauseOnBlurBox /*, transparentBox*/}) { b.setSelected(false); } for (JTextField f : new JTextField[] {fontField, preloadField}) { f.setText(""); } }
void initComponents() { JPanel mainPanel = new JPanel(new BorderLayout()); JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS)); Color bgColor = Color.getHSBColor(0.58f, 0.17f, 0.95f); buttonPanel.setBackground(bgColor); Border empty = BorderFactory.createEmptyBorder(5, 5, 5, 5); buttonPanel.setBorder(empty); textField = new JTextField(75); buttonPanel.add(textField); buttonPanel.add(Box.createHorizontalStrut(10)); searchPHI = new JButton("Search PHI"); searchPHI.addActionListener(this); buttonPanel.add(searchPHI); buttonPanel.add(Box.createHorizontalStrut(10)); searchTrial = new JButton("Search Trial IDs"); searchTrial.addActionListener(this); buttonPanel.add(searchTrial); buttonPanel.add(Box.createHorizontalStrut(20)); buttonPanel.add(Box.createHorizontalGlue()); saveAs = new JCheckBox("Save As..."); saveAs.setBackground(bgColor); buttonPanel.add(saveAs); mainPanel.add(buttonPanel, BorderLayout.NORTH); JScrollPane scrollPane = new JScrollPane(); textPane = new ColorPane(); // textPane.setEditable(false); scrollPane.setViewportView(textPane); mainPanel.add(scrollPane, BorderLayout.CENTER); JPanel footerPanel = new JPanel(); footerPanel.setLayout(new BoxLayout(footerPanel, BoxLayout.X_AXIS)); footerPanel.setBackground(bgColor); message = new JLabel("Ready..."); footerPanel.add(message); mainPanel.add(footerPanel, BorderLayout.SOUTH); setTitle(windowTitle); addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent evt) { System.exit(0); } }); getContentPane().add(mainPanel, BorderLayout.CENTER); pack(); centerFrame(); }
/** * 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(); }
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); }