예제 #1
0
 // Makes sure the log is visible.
 private static void displayLog() {
   if (!consoleDisplayed) {
     splitter.add(outputScroll);
     splitter.setDividerLocation(defaultSliderPosition);
     consoleDisplayed = true;
   }
 }
예제 #2
0
 // Makes sure the log is visible.
 private static void displayLog() {
   println("Displayed", warning);
   if (!consoleDisplayed) {
     splitter.add(outputScroll);
     splitter.setDividerLocation(.8);
     consoleDisplayed = true;
   }
 }
예제 #3
0
    public void actionPerformed(ActionEvent a) {
      String command = a.getActionCommand();
      if (command.equals("e")) {
        // Log toggle.
        if (consoleDisplayed = !consoleDisplayed) {
          splitter.add(outputScroll);
          splitter.setDividerLocation(.8);
        } else {
          splitter.remove(outputScroll);
        }
      } else if (command.equals("k")) {
        if (text.getText().contains("class")) {
          // This means we should try to compile this as normal.

          // Pulls out class name
          String code = text.getText();
          int firstPos = code.indexOf("class");
          int secondPos = code.indexOf("{");
          String name = code.substring(firstPos + "class".length() + 1, secondPos).trim();

          compileAndRun(name, text.getText());
        } else {
          // This means we should compile this as a playground.
          String code = text.getText();

          // Common import statements built-in
          String importDump = new String();
          importDump +=
              ("import java.util.*;\n"
                  + "import javax.swing.*;\n"
                  + "import javax.swing.event.*;\n"
                  + "import java.awt.*;\n"
                  + "import java.awt.event.*;\n"
                  + "import java.io.*;\n");

          // Pulls out any "import" statements and appends them to the import dump.
          int i = code.indexOf("import");
          while (i >= 0) {
            String s = code.substring(i, code.indexOf(";", i) + 1);
            code = code.replaceFirst(s, "");
            importDump += s + "\n";
            i = code.indexOf("import", i + 1);
          }

          // Inject the class header and main method
          code =
              "//User and auto-imports pre-defined\n"
                  + importDump
                  + "//Autogenerated class\npublic class Main {\npublic static void main(String[] args) {\n"
                  + code
                  + "\n}\n}";

          compileAndRun("Main", code);
        }
      }
    }
예제 #4
0
  public Browser(CavityNestingDB cndb) throws SQLException {
    super(new BorderLayout());
    setPreferredSize(new Dimension(300, 500));
    db = cndb;
    displayer = new NodeDisplay();

    top = new DefaultMutableTreeNode("CavityNestingDB");
    tree = new JTree(top);
    DefaultTreeSelectionModel selModel = new DefaultTreeSelectionModel();
    selModel.setSelectionMode(DefaultTreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.setSelectionModel(selModel);

    tree.addTreeSelectionListener(
        new TreeSelectionListener() {
          public void valueChanged(TreeSelectionEvent e) {
            if (e.isAddedPath()) {
              TreePath path = e.getPath();
              DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
              Object value = node.getUserObject();

              // System.out.println(String.valueOf(value));
              if (value instanceof CavityDBObject) {
                displayer.display((CavityDBObject) value);
              } else {
                // System.out.println(value.getClass().getSimpleName());
              }
            }
          }
        });

    JSplitPane splitter = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    add(splitter, BorderLayout.CENTER);
    splitter.add(new JScrollPane(tree));
    splitter.add(displayer);

    populate();
  }
예제 #5
0
  void jbInit() throws Exception {
    titledBorder1 =
        new TitledBorder(
            BorderFactory.createLineBorder(new Color(153, 153, 153), 2), "Assembler messages");
    this.getContentPane().setLayout(borderLayout1);

    this.setIconifiable(true);
    this.setMaximizable(true);
    this.setResizable(true);

    this.setTitle("EDIT");

    splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
    splitPane.setDividerLocation(470);
    sourceArea.setFont(new java.awt.Font("Monospaced", 0, 12));
    controlPanel.setLayout(gridBagLayout1);
    controlPanel.setBorder(BorderFactory.createLoweredBevelBorder());
    positionPanel.setLayout(gridBagLayout2);
    fileLabel.setText("Source file:");
    fileText.setEditable(false);
    browseButton.setSelected(false);
    browseButton.setText("Browse ...");
    assembleButton.setEnabled(false);
    assembleButton.setText("Assemble file");
    saveButton.setEnabled(false);
    saveButton.setText("Save file");
    lineLabel.setText("Line:");
    lineText.setMinimumSize(new Dimension(50, 20));
    lineText.setPreferredSize(new Dimension(50, 20));
    lineText.setEditable(false);
    columnLabel.setText("Column:");
    columnText.setMinimumSize(new Dimension(41, 20));
    columnText.setPreferredSize(new Dimension(41, 20));
    columnText.setEditable(false);
    columnText.setText("");
    messageScrollPane.setBorder(titledBorder1);
    messageScrollPane.setMinimumSize(new Dimension(33, 61));
    messageScrollPane.setPreferredSize(new Dimension(60, 90));
    optionsButton.setEnabled(false);
    optionsButton.setText("Assembler options ...");
    messageScrollPane.getViewport().add(messageList, null);
    messageList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    this.getContentPane().add(splitPane, BorderLayout.CENTER);
    splitPane.add(textScrollPane, JSplitPane.TOP);
    splitPane.add(controlPanel, JSplitPane.BOTTOM);
    textScrollPane.getViewport().add(sourceArea, null);

    controlPanel.add(
        fileLabel,
        new GridBagConstraints(
            0,
            0,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 0, 0),
            0,
            0));
    controlPanel.add(
        fileText,
        new GridBagConstraints(
            1,
            0,
            3,
            1,
            1.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.HORIZONTAL,
            new Insets(5, 5, 0, 0),
            0,
            0));
    controlPanel.add(
        browseButton,
        new GridBagConstraints(
            4,
            0,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.HORIZONTAL,
            new Insets(5, 5, 0, 5),
            0,
            0));
    controlPanel.add(
        optionsButton,
        new GridBagConstraints(
            2,
            1,
            1,
            1,
            1.0,
            0.0,
            GridBagConstraints.EAST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 0, 0),
            0,
            0));
    controlPanel.add(
        assembleButton,
        new GridBagConstraints(
            3,
            1,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.EAST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 0, 0),
            0,
            0));
    controlPanel.add(
        saveButton,
        new GridBagConstraints(
            4,
            1,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.HORIZONTAL,
            new Insets(5, 5, 0, 5),
            0,
            0));
    controlPanel.add(
        positionPanel,
        new GridBagConstraints(
            0,
            1,
            2,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.NONE,
            new Insets(5, 5, 0, 0),
            0,
            0));
    positionPanel.add(
        lineLabel,
        new GridBagConstraints(
            0,
            0,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.EAST,
            GridBagConstraints.NONE,
            new Insets(0, 0, 0, 0),
            0,
            0));
    positionPanel.add(
        lineText,
        new GridBagConstraints(
            1,
            0,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.EAST,
            GridBagConstraints.NONE,
            new Insets(0, 5, 0, 0),
            0,
            0));
    positionPanel.add(
        columnLabel,
        new GridBagConstraints(
            2,
            0,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.EAST,
            GridBagConstraints.NONE,
            new Insets(0, 10, 0, 0),
            0,
            0));
    positionPanel.add(
        columnText,
        new GridBagConstraints(
            3,
            0,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.EAST,
            GridBagConstraints.NONE,
            new Insets(0, 5, 0, 0),
            0,
            0));
    controlPanel.add(
        messageScrollPane,
        new GridBagConstraints(
            0,
            2,
            5,
            1,
            1.0,
            1.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.BOTH,
            new Insets(5, 5, 5, 5),
            0,
            0));
  }
  public ListSelectionDemo() {
    super(new BorderLayout());

    String[] listData = {"one", "two", "three", "four", "five", "six", "seven"};
    String[] columnNames = {"French", "Spanish", "Italian"};
    list = new JList(listData);

    listSelectionModel = list.getSelectionModel();
    listSelectionModel.addListSelectionListener(new SharedListSelectionHandler());
    JScrollPane listPane = new JScrollPane(list);

    JPanel controlPane = new JPanel();
    String[] modes = {
      "SINGLE_SELECTION", "SINGLE_INTERVAL_SELECTION", "MULTIPLE_INTERVAL_SELECTION"
    };

    final JComboBox comboBox = new JComboBox(modes);
    comboBox.setSelectedIndex(2);
    comboBox.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            String newMode = (String) comboBox.getSelectedItem();
            if (newMode.equals("SINGLE_SELECTION")) {
              listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            } else if (newMode.equals("SINGLE_INTERVAL_SELECTION")) {
              listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
            } else {
              listSelectionModel.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
            }
            output.append("----------" + "Mode: " + newMode + "----------" + newline);
          }
        });
    controlPane.add(new JLabel("Selection mode:"));
    controlPane.add(comboBox);

    // Build output area.
    output = new JTextArea(1, 10);
    output.setEditable(false);
    JScrollPane outputPane =
        new JScrollPane(
            output,
            ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);

    // Do the layout.
    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    add(splitPane, BorderLayout.CENTER);

    JPanel topHalf = new JPanel();
    topHalf.setLayout(new BoxLayout(topHalf, BoxLayout.LINE_AXIS));
    JPanel listContainer = new JPanel(new GridLayout(1, 1));
    listContainer.setBorder(BorderFactory.createTitledBorder("List"));
    listContainer.add(listPane);

    topHalf.setBorder(BorderFactory.createEmptyBorder(5, 5, 0, 5));
    topHalf.add(listContainer);
    // topHalf.add(tableContainer);

    topHalf.setMinimumSize(new Dimension(100, 50));
    topHalf.setPreferredSize(new Dimension(100, 110));
    splitPane.add(topHalf);

    JPanel bottomHalf = new JPanel(new BorderLayout());
    bottomHalf.add(controlPane, BorderLayout.PAGE_START);
    bottomHalf.add(outputPane, BorderLayout.CENTER);
    // XXX: next line needed if bottomHalf is a scroll pane:
    // bottomHalf.setMinimumSize(new Dimension(400, 50));
    bottomHalf.setPreferredSize(new Dimension(450, 135));
    splitPane.add(bottomHalf);
  }
예제 #7
0
    public void actionPerformed(ActionEvent a) {
      // Note that this only works on *nix OSes.
      // For windows, get the first character of the action command, cast it to int, and compare
      // that on a case-by-case basis.

      String command = a.getActionCommand();
      if (command.equals("e")) {
        // Log toggle.
        if (consoleDisplayed = !consoleDisplayed) {
          splitter.add(outputScroll);
          splitter.setDividerLocation(defaultSliderPosition);
        } else {
          splitter.remove(outputScroll);
        }
      } else if (command.equals("r")) {
        // Gets the code into a string.
        String code = text.getText();

        // Marks certain areas as "dirty".
        // Dirty areas are places that shouldn't be considered for any keywords,
        // including "import", "extend", and so on.
        ArrayList<Integer> dirtyBounds = getDirty(code);

        if (text.getText().contains("class")) {
          // This means we should try to compile this as normal.

          // Pulls out class name
          int firstPos = code.indexOf("public class");
          int secondPos = code.indexOf("{");
          String name = code.substring(firstPos + "public class".length() + 1, secondPos).trim();

          // Just a safety check to make sure you don't try to modify this program while it's
          // running.
          if (name.equals("Playground")) {
            System.out.println(
                "I know what you're doing and I don't approve. I won't even compile that.");
            return;
          }

          compileAndRun(name, code);
        } else {
          // This means we should compile this as a playground.

          // Common import statements built-in
          String importDump = new String();
          importDump +=
              ( // "import java.util.*;\n" +
              "import javax.swing.*;\n"
                  + "import javax.swing.event.*;\n"
                  + "import java.awt.*;\n"
                  + "import java.awt.event.*;\n"
                  + "import java.io.*;\n");

          // User-defined or auto-generated methods
          String methodDump = new String();

          // dirtyBounds.forEach(System.out::println);

          // Pulls out any "import" statements and appends them to the import dump.
          int i = code.indexOf("import");
          while (i >= 0) {
            // Ignores comments and string literals
            if (isDirty(dirtyBounds, i)) {
              i = code.indexOf("import", i + 1);
              continue;
            }

            String s = code.substring(i, code.indexOf(";", i) + 1);
            // System.out.println("Found import: " + s);
            code = code.replaceFirst(s, "");
            importDump += s + "\n";
            i = code.indexOf("import", i + 1);
          }

          // Pulls out methods- these are defined by the keyword "method" until a closing bracket.
          /*
          i = code.indexOf("method");
          while(i >= 0) {
          //Ignores comments and string literals
          if (isDirty(dirtyBounds, i)) {
          i = code.indexOf("method", i+1);
          continue;
          }

          //This scans from the first '{' until the last '}' to pull out the full method declaration.
          char temp = 0;
          int pos = code.indexOf("{", i+1), count = 1;
          if(pos != -1) {
          while(++pos < code.length()) {
          if (count == 0)
          break;

          temp = code.charAt(pos);
          if (temp == '{')
          count++;
          if (temp == '}')
          count--;
          }
          } else {
          //Missing an opening bracket, so just remove "method" and hope it compiles.
          code = code.replaceFirst("method", "");
          i = code.indexOf("method", i+1);
          continue;
          }
          String s = code.substring(i, pos);

          //System.out.println("Found method: " + s);
          code = code.replace(s, "");
          methodDump+=(s.replaceFirst("method ", "static ")) + "\n";

          i = code.indexOf("method", i+1);
          }*/

          // Pulls out all methods
          i = code.indexOf("(");
          while (i >= 0) {
            if (isDirty(dirtyBounds, i)) {
              i = code.indexOf("(", i + 1);
              continue;
            }

            // Move backwards first
            char temp = 0;
            int pos = i;
            boolean shouldSkip = false;
            while (--pos > 0) {
              temp = code.charAt(pos);
              if (temp == '.') {
                shouldSkip = true;
                break;
              } // This is a method call, ie String.charAt();
              if (temp == ';') {
                ++pos;
                break;
              } // This is most likely a method declaration, since we had no errors
              // If we hit the start of the file, that's probable a method dec. too!
            }
            if (shouldSkip || isDirty(dirtyBounds, pos)) {
              i = code.indexOf("(", i + 1);
              continue;
            } // If this def. isn't a method or it's in a comment

            int start = pos;
            temp = 0;
            pos = code.indexOf("{", i + 1);
            int count = 1;
            if (pos != -1) {
              while (++pos < code.length()) {
                if (count == 0) break;

                temp = code.charAt(pos);
                if (temp == '{') count++;
                if (temp == '}') count--;
              }
            } else {
              i = code.indexOf("(", i + 1);
              continue;
            }

            int end = pos;
            String s = code.substring(start, end);
            code = code.replace(s, "");

            // Just to make it look nicer
            s = s.trim();

            System.out.println("Found method: " + s);
            methodDump += (s + "\n");
            i = code.indexOf("(", i + 1);
          }

          // Inject the class header and main method, imports, and methods
          code =
              "//User and auto-imports pre-defined\n"
                  + importDump
                  + "//Autogenerated class\n"
                  + "public class Main {\n"
                  + "public static void main(String[] args) {\n"
                  + code
                  + "}\n"
                  + methodDump
                  + "}";

          // Run as normal
          compileAndRun("Main", code);
        }
      } else if (command.equals("k")) {
        kill();
      } else if (command.equals("o")) {
        new OptionFrame(frame);
      } else if (command.equals("/")) {
        new HelpFrame(frame);
      }
    }
예제 #8
0
  /** Construct a new Help panel */
  public HelpPanel() {
    // Try to build our help tree, keeping an eye out for malformed URLs
    try {
      // root node
      top = new DefaultMutableTreeNode(new HelpItem("MIDIMatrix", "top"));

      // matrices node
      category = new DefaultMutableTreeNode(new HelpItem("Matrices", "matrices"));
      top.add(category);
      category.add(new DefaultMutableTreeNode(new HelpItem("Note Entry", "matrices-noteentry")));
      category.add(
          new DefaultMutableTreeNode(
              new HelpItem("Pitches, volume, and instruments", "matrices-metadata")));
      category.add(new DefaultMutableTreeNode(new HelpItem("Playback", "matrices-playback")));

      // sequences node
      category = new DefaultMutableTreeNode(new HelpItem("Sequences", "sequences"));
      top.add(category);
      category.add(
          new DefaultMutableTreeNode(new HelpItem("Parts of a sequence", "sequences-parts")));
      category.add(
          new DefaultMutableTreeNode(
              new HelpItem("Constructing a sequence", "sequences-construction")));
      category.add(new DefaultMutableTreeNode(new HelpItem("Playback", "sequences-playback")));

      // controls node
      category = new DefaultMutableTreeNode(new HelpItem("Controls", "controls"));
      top.add(category);
      category.add(
          new DefaultMutableTreeNode(new HelpItem("MIDI devices", "controls-mididevices")));
      category.add(new DefaultMutableTreeNode(new HelpItem("Saving", "controls-saving")));

      // about node
      category = new DefaultMutableTreeNode(new HelpItem("About", "about"));
      top.add(category);
      category.add(new DefaultMutableTreeNode(new HelpItem("Author", "about-author")));
      category.add(new DefaultMutableTreeNode(new HelpItem("License", "about-license")));

      // javadoc node
      // category = new DefaultMutableTreeNode(new HelpItem("JavaDoc", base + "javadoc/"));
      // top.add(category);
    } catch (MalformedURLException e) {
      top = new DefaultMutableTreeNode("ERROR");
    }
    helpTree = new JTree(top);
    helpTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    helpTree.addTreeSelectionListener(
        new TreeSelectionListener() {

          public void valueChanged(TreeSelectionEvent e) {
            DefaultMutableTreeNode node =
                (DefaultMutableTreeNode) helpTree.getLastSelectedPathComponent();
            if (node == null) {
              return;
            }
            // try {
            helpPane.scrollToReference(((HelpItem) node.getUserObject()).getHash());
            /*} catch (IOException exc) {

                JOptionPane.showMessageDialog(
                        null,
                        "There was a problem fetching the help page " + exc.getMessage() + "\n" +
                        "Make sure you're connected to the internet before continuing",
                        "Help Oops!",
                        JOptionPane.ERROR_MESSAGE,
                        null);
            }*/
          }
        });

    treePane = new JScrollPane(helpTree);
    treePane.setPreferredSize(new Dimension(200, 750));

    helpPane = new JEditorPane();
    scroller = new JScrollPane(helpPane);
    helpPane.setEditable(false);
    helpPane.setPreferredSize(new Dimension(550, 750));
    helpPane.addHyperlinkListener(
        new HyperlinkListener() {

          public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
              JEditorPane pane = (JEditorPane) e.getSource();
              if (e instanceof HTMLFrameHyperlinkEvent) {
                HTMLFrameHyperlinkEvent evt = (HTMLFrameHyperlinkEvent) e;
                HTMLDocument doc = (HTMLDocument) pane.getDocument();
                doc.processHTMLFrameHyperlinkEvent(evt);
                if (e.getDescription().indexOf("#") != -1) {
                  System.err.println("Found anchor");
                  pane.scrollToReference(
                      e.getDescription().substring(e.getDescription().indexOf("#")));
                }
              } else {
                try {
                  pane.setPage(e.getURL());
                } catch (Throwable t) {
                  t.printStackTrace();
                }
              }
            }
          }
        });
    try {
      helpPane.setPage(HelpPanel.class.getResource("help.xhtml"));
    } catch (IOException e) {
      helpPane.setText("Couldn't fetch help page, sorry!  " + e.getMessage());
    }

    content = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    content.add(treePane);
    content.add(scroller);

    add(content);
  }