示例#1
0
  public HelpDialog(JFrame parent) {
    super(parent, ResourceBundle.getBundle(MuViBee.mainBundlePath).getString("helpDialog"), true);
    final JDialog dialog = this;
    setSize(900, 900);

    ResourceBundle bundle = ResourceBundle.getBundle(MuViBee.mainBundlePath);
    String close = bundle.getString("close");

    JPanel panel = new JPanel(new BorderLayout());
    JButton b = new JButton(close);
    final JEditorPane ep = new JEditorPane();
    JScrollPane sb = new JScrollPane(ep);

    ep.setEditable(false);
    getContentPane().add(panel);
    panel.add(b, BorderLayout.SOUTH);
    panel.add(sb);

    b.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent arg0) {
            dialog.setVisible(false);
          }
        });

    try {
      if (Locale.getDefault() == Locale.GERMAN)
        ep.setPage(getClass().getResource("resources/help/help_de.html"));
      else ep.setPage(getClass().getResource("resources/help/help_en.htm"));
    } catch (IOException e) {
      e.printStackTrace();
    }

    ep.addHyperlinkListener(
        new HyperlinkListener() {
          @Override
          public void hyperlinkUpdate(HyperlinkEvent arg0) {
            if (arg0.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
              try {
                ep.setPage(arg0.getURL());
              } catch (IOException e) {
                e.printStackTrace();
              }
            }
          }
        });
  }
示例#2
0
  private static JEditorPane createEditorPane() {
    JEditorPane editorPane = new JEditorPane();
    editorPane.setEditable(false);
    System.setProperty("http.proxyHost", "cache.univ-lille1.fr");
    System.setProperty("http.proxyPort", "3128");
    editorPane.setPreferredSize(new Dimension(300, 200));

    java.net.URL lille1URL = null;
    try {
      lille1URL = new java.net.URL("http://www.google.com");
    } catch (MalformedURLException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    }
    if (lille1URL != null) {
      try {
        editorPane.setPage(lille1URL);
      } catch (IOException e) {
        System.err.println("Attempted to read a bad URL: " + lille1URL);
      }
    } else {
      System.err.println("Couldn't find file: http://www.google.com");
    }

    return editorPane;
  }
  public void displayPage(JEditorPane pane, String text) {
    try {
      File helpFile = new File((String) locations.get(text));
      String loc = "file:" + helpFile.getAbsolutePath();
      URL page = new URL(loc);

      pane.setPage(page);

    } catch (IOException ioe) {
      JOptionPane.showMessageDialog(null, "Help Topic Unavailable");
      pane.getParent().repaint();
    }
  }
示例#4
0
 void setDoc(JEditorPane pane, String doc) {
   if (doc != null) {
     try {
       File file = new File(doc);
       URL url = file.toURI().toURL();
       pane.setPage(url);
     } catch (IOException e) {
       e.printStackTrace();
       System.err.println("Attempted to read a bad file: " + doc);
     }
   } else {
     System.err.println("Couldn't find file: " + doc);
   }
 }
示例#5
0
  public void setBrowserLocation(String locale, boolean cacheLocation) {
    // push old location if one exists AND its specified behavior
    if (cacheLocation && location != null) {
      locationStack.push(location);
      toolBar.getBackButton().setEnabled(true);
    }

    location = locale;
    try {
      browserPane.setPage(location);
    } catch (IOException ioex) {
      String message = "Error loading from location:\n" + ioex.getMessage();
      JOptionPane.showMessageDialog(this, message, "Browser Error", JOptionPane.ERROR_MESSAGE);
      return;
    }
  }
示例#6
0
  /**
   * Creates a JEditorPane (for viewing the web) and puts it in a panel and returns it
   *
   * @param pageURL the URL of the page to open in this text pane
   * @param width, height
   */
  public static JPanel createEditorPane(String pageURL, int width, int height) {
    // build editor pane
    JEditorPane editorPane = new JEditorPane();
    editorPane.setEditable(false);
    editorPane.setFont(FontManager.PREFERRED_FONT);

    // set the page
    java.net.URL url = null;
    try {
      url = new java.net.URL(pageURL);
    } catch (java.net.MalformedURLException m) {
      // bad URL
      System.err.println("Bad url! " + m);
    }
    if (url != null) {
      try {
        editorPane.setPage(url);
      } catch (java.io.IOException io) {
        // error with setting page
        // System.err.println("Error loading page " + url);
      }
    }

    // enable hyperlinks
    editorPane.addHyperlinkListener(
        new HyperlinkListener() {
          public void hyperlinkUpdate(HyperlinkEvent evt) {
            if (evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
              Utils.browse(evt.getURL().toString());
            }
          }
        });

    // put it in a scroll pane
    JScrollPane scrollPane = new JScrollPane(editorPane);
    scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    scrollPane.setHorizontalScrollBarPolicy(
        JScrollPane
            .HORIZONTAL_SCROLLBAR_AS_NEEDED); // mostly for the license, which has preformatted text

    // put it in a JPanel
    JPanel panel = new JPanel(new java.awt.BorderLayout());
    panel.add(scrollPane);
    panel.setPreferredSize(new java.awt.Dimension(width, height));
    return panel;
  }
示例#7
0
    TextPanel(String file) {
      super(new BorderLayout());

      JEditorPane text = new JEditorPane();

      try {
        text.setPage(TextPanel.this.getClass().getResource(file));
      } catch (Exception e) {
        text.setText("Error loading '" + file + "'");
        e.printStackTrace();
      }

      text.setEditable(false);

      JScrollPane scrollPane = new JScrollPane(text);
      Dimension dim = new Dimension();
      dim.width = 450;
      dim.height = 200;
      scrollPane.setPreferredSize(dim);
      TextPanel.this.add(BorderLayout.CENTER, scrollPane);
    }
  /** Construct a this GUI object's contents. */
  private void initComponents() {
    htmlWindow = new JEditorPane();
    htmlWindow.setPreferredSize(new Dimension(500, 500));
    htmlWindow.setEditable(false);
    htmlWindow.setContentType("text/html");
    scrollPane =
        new JScrollPane(
            htmlWindow,
            JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    scrollPane.setPreferredSize(new Dimension(500, 500));

    try {
      htmlWindow.setPage("file:./html-docs/index.html");
    } catch (IOException ioe) {
      System.err.println(ioe);
    }
    htmlWindow.addHyperlinkListener(
        new HyperlinkListener() {
          public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
              try {
                htmlWindow.setPage(e.getURL()); // ?????
              } catch (IOException ioe) {
                System.err.println(ioe);
              }
            }
          }
        });

    JButton exitButton = new JButton("Close Help Window");
    exitButton.addActionListener(this);
    mainPanel = new JPanel(new BorderLayout());
    mainPanel.add(exitButton, "North");
    mainPanel.add(scrollPane, "Center");
    getContentPane().add(mainPanel);
  }
示例#9
0
  void doSourceFileUpdate() {
    BufferedReader bufferIn = null;
    String str1 = new String();
    String strContent = new String();
    String sliderValue = new String();
    String newLine = System.getProperty("line.separator");
    StringBuffer strBuf = new StringBuffer();
    RandomAccessFile access = null;
    String tempFile = "temp" + round + ".html";
    File fp = new File(tempFile);
    boolean firstChoice = true;
    int posFound = 0;
    int i = 0;
    PSlider slider;

    // round += 1;
    // Read the original source file to input buffer
    try {
      bufferIn = new BufferedReader(new FileReader(exampleSource));
    } catch (FileNotFoundException fe) {
      System.err.println("Example Source File not found " + fe);
      // System.exit(-1);;
    }
    // get the first line of the buffer.
    try {
      str1 = bufferIn.readLine();
    } catch (IOException ie) {
      System.err.println("Error reading line from the buffer " + ie);
      // System.exit(-1);;
    }
    // Transfer the whole content of the input buffer to the string
    try {
      do strContent += str1 + newLine;
      while ((str1 = bufferIn.readLine()) != null);
    } catch (IOException ie) {
      System.err.println("Error readding content of the input buffer " + ie);
      // System.exit(-1);;
    }
    // do the replacement.
    // First having to update the code part that is active in this section before
    // doing variables updated. Look at the current active radiobutton to make decision
    if (secondBox.isSelected() == true) firstChoice = false;
    if (firstChoice == true) {
      String tempStr = new String();
      strBuf = new StringBuffer(strContent);
      posFound = strContent.indexOf(textStr2);
      tempStr =
          "<font color=blue>/***********" + newLine + textStr2 + newLine + "***********/</font>";
      strBuf.replace(posFound, posFound + textStr2.length(), tempStr);
      strContent = new String(strBuf);
    } else {
      String tempStr = new String();
      strBuf = new StringBuffer(strContent);
      posFound = strContent.indexOf(textStr1);
      tempStr =
          "<font color=blue>/***********" + newLine + textStr1 + newLine + "***********/</font>";
      strBuf.replace(posFound, posFound + textStr1.length(), tempStr);
      strContent = new String(strBuf);
    }
    for (i = COMPONENTS; i > 0; i--) {
      // get the current value of slider
      slider = (PSlider) vSlider.elementAt(i - 1);
      sliderValue = slider.getValue();
      // construct the search string
      str1 = "JPOT$" + i;
      // get the position of the search string in the content string.
      while ((posFound = strContent.indexOf(str1)) != -1) {
        strBuf = new StringBuffer(strContent);
        strBuf.replace(posFound, posFound + str1.length(), sliderValue);
        strContent = new String(strBuf);
      }
    }

    boolean delete = fp.delete();

    try {
      fp.createNewFile();
    } catch (IOException ie) {
      System.err.println("Couldn't create the new file " + ie);
      // System.exit(-1);;
    }

    try {
      access = new RandomAccessFile(fp, "rw");
    } catch (IOException ie) {
      System.err.println("Error in accessing the file " + ie);
      // System.exit(-1);;
    }

    try {
      access.writeBytes(strContent);
      access.close();
    } catch (IOException ie) {
      System.err.println("Error in writing to file " + ie);
      // System.exit(-1);;
    }
    try {
      textPane.getDocument().putProperty(Document.StreamDescriptionProperty, null);
      URL url = new URL("file:" + tempFile + "#gohere");
      textPane.setPage(url);
      delete = fp.delete();
    } catch (IOException ie) {
      System.err.println("Can not get the example html file " + ie);
      // System.exit(-1);;
    }
  }
示例#10
0
  public EditorPaneHTMLHelp(String htmlFile) {
    if (GlobalValues.useSystemBrowserForHelp) {
      Desktop d = GlobalValues.desktop;
      try {
        // create a temp file
        GlobalValues.forHTMLHelptempFile = new File("tempHTMLHelpSynthetic.html");
        FileWriter fw = new FileWriter(GlobalValues.forHTMLHelptempFile);

        java.util.List<String> list = readTextFromJar(htmlFile);
        Iterator<String> it = list.iterator();
        while (it.hasNext()) {
          fw.write(it.next() + "\n");
        }

        String canonicalPathOfFile = GlobalValues.forHTMLHelptempFile.getCanonicalPath();
        URL urlFile = new URL("file://" + canonicalPathOfFile);
        URI uriOfFile = urlFile.toURI();

        fw.close();

        d.browse(uriOfFile);

      } catch (Exception e) {
        e.printStackTrace();
      }

    } else {
      URL initialURL = getClass().getResource(htmlFile);

      font = GlobalValues.htmlfont;

      String title = "HTML Help";
      setTitle(title);

      final Stack<String> urlStack = new Stack<String>();
      final JEditorPane editorPane;

      editorPane = new JEditorPane(new HTMLEditorKit().getContentType(), " ");

      editorPane.setOpaque(false);
      editorPane.setBorder(null);
      editorPane.setEditable(false);

      JPanel magPanel = new JPanel();

      magnificationFactor = GlobalValues.helpMagnificationFactor;
      magFactor = new JTextField(Double.toString(magnificationFactor));

      JButton magButton = new JButton("Set Magnification: ");
      magButton.addActionListener(
          new ActionListener() {

            public void actionPerformed(ActionEvent e) {
              magnificationFactor = Double.parseDouble(magFactor.getText());
              GlobalValues.helpMagnificationFactor = magnificationFactor;
            }
          });

      magPanel.setLayout(new GridLayout(1, 2));
      magPanel.add(magButton);
      magPanel.add(magFactor);

      final JTextField url = new JTextField(initialURL.toString());

      // set up hyperlink listener
      editorPane.setEditable(false);

      try {
        // remember URL for back button
        urlStack.push(initialURL.toString());
        // show URL in text field
        url.setText(initialURL.toString());

        // add a CSS rule to force body tags to use the default label font
        // instead of the value in javax.swing.text.html.default.csss

        String bodyRule =
            "body { font-family: "
                + font.getFamily()
                + "; "
                + "font-size: "
                + font.getSize() * GlobalValues.helpMagnificationFactor
                + "pt; }";
        ((HTMLDocument) editorPane.getDocument()).getStyleSheet().addRule(bodyRule);

        editorPane.setPage(initialURL);

        editorPane.firePropertyChange("dummyProp", true, false);

      } catch (IOException e) {
        editorPane.setText("Exception: " + e);
      }

      editorPane.addPropertyChangeListener(
          new PropertyChangeListener() {

            public void propertyChange(PropertyChangeEvent evt) {

              String bodyRule =
                  "body { font-family: "
                      + font.getFamily()
                      + "; "
                      + "font-size: "
                      + font.getSize() * GlobalValues.helpMagnificationFactor
                      + "pt; }";
              ((HTMLDocument) editorPane.getDocument()).getStyleSheet().addRule(bodyRule);
            }
          });

      editorPane.addHyperlinkListener(
          new HyperlinkListener() {
            public void hyperlinkUpdate(HyperlinkEvent event) {
              if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                try {
                  // remember URL for back button
                  urlStack.push(event.getURL().toString());
                  // show URL in text field
                  url.setText(event.getURL().toString());
                  editorPane.setPage(event.getURL());

                  editorPane.firePropertyChange("dummyProp", true, false);

                } catch (IOException e) {
                  editorPane.setText("Exception: " + e);
                }
              }
            }
          });

      // set up checkbox for toggling edit mode
      final JCheckBox editable = new JCheckBox();
      editable.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent event) {
              editorPane.setEditable(editable.isSelected());
            }
          });

      // set up load button for loading URL
      ActionListener listener =
          new ActionListener() {
            public void actionPerformed(ActionEvent event) {
              try {
                // remember URL for back button
                urlStack.push(url.getText());
                editorPane.setPage(url.getText());

                editorPane.firePropertyChange("dummyProp", true, false);

              } catch (IOException e) {
                editorPane.setText("Exception: " + e);
              }
            }
          };

      JButton loadButton = new JButton("Load/Magnify");
      loadButton.addActionListener(listener);
      url.addActionListener(listener);

      // set up back button and button action

      JButton backButton = new JButton("Back");
      backButton.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent event) {
              if (urlStack.size() <= 1) return;
              try {
                // get URL from back button
                urlStack.pop();
                // show URL in text field
                String urlString = urlStack.peek();
                url.setText(urlString);
                editorPane.setPage(urlString);

                editorPane.firePropertyChange("dummyProp", true, false);

              } catch (IOException e) {
                editorPane.setText("Exception: " + e);
              }
            }
          });

      JPanel allPanel = new JPanel(new BorderLayout());

      // put all control components in a panel

      JPanel ctrlPanel = new JPanel(new BorderLayout());
      JPanel urlPanel = new JPanel();
      urlPanel.add(new JLabel("URL"));
      urlPanel.add(url);
      JPanel buttonPanel = new JPanel();
      buttonPanel.add(loadButton);
      buttonPanel.add(backButton);
      buttonPanel.add(new JLabel("Editable"));
      buttonPanel.add(magPanel);
      buttonPanel.add(editable);
      ctrlPanel.add(buttonPanel, BorderLayout.NORTH);
      ctrlPanel.add(urlPanel, BorderLayout.CENTER);

      allPanel.add(ctrlPanel, BorderLayout.NORTH);
      allPanel.add(new JScrollPane(editorPane), BorderLayout.CENTER);

      add(allPanel);
    }
  }
示例#11
0
  public BoxOnTable() {
    super(windowTitle);
    int i;

    Runtime program = Runtime.getRuntime();
    Container content = getContentPane();

    /** Get current OS of the system. */
    if (System.getProperty("os.name").startsWith("Windows")) isWindows = true;
    else isWindows = false;
    /** Set interactive buttons for the user interface */
    JButton exitButton = new JButton("Exit");
    exitButton.setToolTipText("Exit the Program");

    JPanel mainPanel = new JPanel();

    content.add(mainPanel, BorderLayout.SOUTH);
    mainPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

    content.add(scrollPane, BorderLayout.CENTER);
    scrollPane.setBorder(BorderFactory.createLoweredBevelBorder());
    scrollPane.getViewport().add(textPane);

    mainPanel.add(exitButton, BorderLayout.CENTER);

    /** Set and view the source code on the frame */
    textPane.setEditable(false);
    textPane.setContentType("text/html; charset=EUC-JP");
    try {
      URL url = new URL("file:" + exampleSource);
      textPane.setPage(url);
    } catch (IOException ie) {
      System.err.println("Error in opening html source file " + ie);
      System.exit(-1);
    }

    exitButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            doExitCommand();
          }
        });

    /** Run the illustrated program */
    try {
      pid = program.exec(cmd);
    } catch (IOException ie) {
      System.err.println("Couldn't run " + ie);
      System.exit(-1);
    }
    /** Set the initial status for the window */
    addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            pid.destroy();
          }
        });
    setSize(WIDTH, HEIGHT);
    setLocation(500, 0);
    setVisible(true);
  }
示例#12
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);
  }