private void readInFile(String fileName) {
   try {
     FileReader r = new FileReader(fileName);
     area.read(r, null);
     r.close();
     currentFile = fileName;
     setTitle(currentFile + " - CoreyTextEditor");
     changed = false;
   } catch (IOException e) {
     Toolkit.getDefaultToolkit().beep();
     JOptionPane.showMessageDialog(this, "Editor can't find the file called " + fileName);
   }
 }
  /** Creates a ComponentTree, loading the Components from the file at <code>path</code>. */
  public ComponentTree(String path) {
    this.path = path;
    ttCount++;
    jTextArea = new JTextArea();
    textArea = new JTextArea();
    redirectSystemStreams();
    frame = createFrame();
    Container cPane = frame.getContentPane();
    JMenuBar mb = createMenuBar();
    TreeTableModel model = createModel(path);

    cPane.setLayout(new BorderLayout(5, 5));
    Dimension dim = new Dimension(600, 600);
    cPane.setPreferredSize(dim);

    try {
      textArea.read(new FileReader(path), null);
    } catch (IOException e) {
      e.printStackTrace(); // To change body of catch statement use File | Settings | File
      // Templates.
    }
    treeTable = createTreeTable(model);
    textArea.setEditable(false);

    JScrollPane tp =
        new JScrollPane(
            textArea,
            ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    JScrollPane sp =
        new JScrollPane(
            treeTable,
            ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    JScrollPane cp =
        new JScrollPane(
            jTextArea,
            ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    sp.getViewport().setBackground(Color.white);

    Dimension scrDim = new Dimension(300, 600);
    Dimension dime = new Dimension(300, 400);
    Dimension dimc = new Dimension(300, 200);
    sp.setLocation(0, 0);
    sp.setPreferredSize(dime);
    tp.setLocation(300, 0);
    tp.setPreferredSize(scrDim);
    cp.setLocation(0, 400);
    cp.setPreferredSize(dimc);
    cPane.add(sp, BorderLayout.LINE_START);
    cPane.add(tp, BorderLayout.CENTER);
    cPane.add(cp, BorderLayout.PAGE_END);
    cPane.setPreferredSize(dim);

    // frame.add(cPane);
    frame.setJMenuBar(mb);
    // frame.pack();

    frame.setVisible(true);
  }
Beispiel #3
0
  public static void main(String args[]) throws Exception {
    final JFrame frame = new JFrame();
    final JTextArea textArea = new JTextArea(30, 60);
    final JScrollPane scrollPane = new JScrollPane(textArea);
    frame.getContentPane().add(scrollPane);

    JMenuBar menuBar = new JMenuBar();
    frame.setJMenuBar(menuBar);
    JMenu menu = new JMenu("File");
    ScreenCapture.createImage(menu, "menu.jpg");
    menuBar.add(menu);
    JMenuItem menuItem = new JMenuItem("Frame Image");
    menu.add(menuItem);
    menuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            //  Let the menu close and repaint itself before taking the image

            new Thread() {
              public void run() {
                try {
                  Thread.sleep(50);
                  System.out.println("Creating frame.jpg");
                  frame.repaint();
                  ScreenCapture.createImage(frame, "frame.jpg");
                } catch (Exception exc) {
                  System.out.println(exc);
                }
              }
            }.start();
          };
        });

    final JButton button = new JButton("Create Images");
    button.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            try {
              System.out.println("Creating desktop.jpg");
              ScreenCapture.createDesktopImage("desktop.jpg");
              System.out.println("Creating frame.jpg");
              ScreenCapture.createImage(frame, "frame.jpg");
              System.out.println("Creating scrollpane.jpg");
              ScreenCapture.createImage(scrollPane, "scrollpane.jpg");
              System.out.println("Creating textarea.jpg");
              ScreenCapture.createImage(textArea, "textarea.jpg");
              System.out.println("Creating button.jpg");
              ScreenCapture.createImage(button, "button.jpg");
              button.setText("button refreshed");
              button.paintImmediately(button.getBounds());
              System.out.println("Creating refresh.jpg");
              ScreenCapture.createImage(button, "refresh.jpg");
              System.out.println("Creating region.jpg");
              Rectangle r = new Rectangle(0, 0, 100, 16);
              ScreenCapture.createImage(textArea, r, "region.png");
            } catch (Exception exc) {
              System.out.println(exc);
            }
          }
        });
    frame.getContentPane().add(button, BorderLayout.SOUTH);

    try {
      FileReader fr = new FileReader("ScreenCapture.java");
      BufferedReader br = new BufferedReader(fr);
      textArea.read(br, null);
      br.close();
    } catch (Exception e) {
    }

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
  }