|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License Version * 1.0 (the "License"). You may not use this file except in compliance * with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is Terminal Emulator. * The Initial Developer of the Original Code is Sun Microsystems, Inc.. * Portions created by Sun Microsystems, Inc. are Copyright (C) 2001. * All Rights Reserved. * * Contributor(s): Ivan Soleimanipour. */ import java.io.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.*; import org.netbeans.lib.terminalemulator.*; /* * A simple demonstration of using ActiveTerm for highlighting compiler * error output. Most of the machinery in this code is concerened with * starting the build and capturing the output unfortunately. * - The Compiler is started in a separate thread so that we quickly * return from the button action handler. * - We have separate readers for stdout and stderr because alternating * between them in a loop may cause deadlocks, and using Reader.ready() * will cause needless CPU looping. * - Note that since Java provides no facility for merging stdout * and stderr at the origin that by the time the outputs make it * through the OS and BufferedReaders buffers all ordering information * is lost. */ public class BuildTool extends JFrame implements ActionListener { private ActiveTerm term; private JButton b_javac; private JTextField t_files; private Object sync = new Object(); /** * Create a simple red square glyph image */ private Image glyph(int dim) { int xpoints[] = {1, 1, dim-1, dim-1}; int ypoints[] = {1, dim-1, dim-1, 1}; Polygon square = new Polygon(xpoints, ypoints, 4); Image i = term.getTopLevelAncestor().createImage(dim, dim); Graphics g = i.getGraphics(); g.setColor(Color.white); g.fillRect(0, 0, dim, dim); g.setColor(Color.red); g.fillPolygon(square); g.setColor(Color.black); g.drawPolygon(square); g.dispose(); return i; } private void setup_gui() { // Handle quit from WM addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); term = new ActiveTerm(); term.setFont(new Font("Helvetica", Font.PLAIN, 10)); term.setBackground(Color.white); term.setGlyphGutterWidth(20); term.setClickToType(false); term.setHighlightColor(Color.orange); term.setActionListener(new ActiveTermListener() { public void action(ActiveRegion r, InputEvent e) { if (r.isLink()) { String text = term.textWithin(r.begin, r.end); JOptionPane.showMessageDialog(term, "Get the editor to show " + text, "Syntax error", JOptionPane.DEFAULT_OPTION); } } } ); JToolBar toolbar = new JToolBar(); toolbar.setMargin(new Insets(5, 5, 5, 5)); toolbar.setFloatable(false); b_javac = new JButton("Build"); b_javac.addActionListener(this); toolbar.add(b_javac); toolbar.addSeparator(); t_files = new JTextField(); t_files.setColumns(10); t_files.setText(" |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.