From: <fd...@us...> - 2008-08-11 21:52:05
|
Revision: 4429 http://jnode.svn.sourceforge.net/jnode/?rev=4429&view=rev Author: fduminy Date: 2008-08-11 21:51:41 +0000 (Mon, 11 Aug 2008) Log Message: ----------- removed JTextAreaTextScreen in favor of SwingConsole Modified Paths: -------------- trunk/gui/descriptors/org.jnode.test.gui.xml Removed Paths: ------------- trunk/gui/src/driver/org/jnode/driver/console/swing/JTextAreaTextScreen.java trunk/gui/src/test/org/jnode/test/gui/ConsoleTest2.java Modified: trunk/gui/descriptors/org.jnode.test.gui.xml =================================================================== --- trunk/gui/descriptors/org.jnode.test.gui.xml 2008-08-11 21:03:28 UTC (rev 4428) +++ trunk/gui/descriptors/org.jnode.test.gui.xml 2008-08-11 21:51:41 UTC (rev 4429) @@ -28,7 +28,6 @@ <application name="Swing test" class="org.jnode.test.gui.SwingTest"/> <application name="Swing menu test" class="org.jnode.test.gui.SwingMenuTest"/> <application name="Console" class="org.jnode.test.gui.ConsoleTest"/> - <application name="Console2" class="org.jnode.test.gui.ConsoleTest2"/> <!-- application name="Thinlet" class="thinlet.ThinTest"/ --> <!-- application name="GlyphTest" class="org.jnode.test.gui.GlyphTest"/ --> </extension> Deleted: trunk/gui/src/driver/org/jnode/driver/console/swing/JTextAreaTextScreen.java =================================================================== --- trunk/gui/src/driver/org/jnode/driver/console/swing/JTextAreaTextScreen.java 2008-08-11 21:03:28 UTC (rev 4428) +++ trunk/gui/src/driver/org/jnode/driver/console/swing/JTextAreaTextScreen.java 2008-08-11 21:51:41 UTC (rev 4429) @@ -1,223 +0,0 @@ -/* - * $Id$ - * - * JNode.org - * Copyright (C) 2005 JNode.org - * - * This library is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -package org.jnode.driver.console.swing; - -import java.awt.Color; -import java.awt.Component; -import java.util.Arrays; - -import javax.swing.JTextArea; -import javax.swing.text.AttributeSet; -import javax.swing.text.BadLocationException; -import javax.swing.text.DefaultStyledDocument; -import javax.swing.text.Style; -import javax.swing.text.StyleConstants; -import javax.swing.text.StyleContext; -import javax.swing.text.StyledDocument; -import javax.swing.text.StyleConstants.ColorConstants; - -import org.jnode.driver.textscreen.ScrollableTextScreen; -import org.jnode.driver.textscreen.TextScreen; - -/** - * TODO inherits from AbstractPcTextScreen ? - * - * @author Fabien DUMINY (fduminy at users.sourceforge.net) - * - */ -public class JTextAreaTextScreen implements TextScreen { - private StyledDocument document; - private AttributeSet attributes; - private JTextArea textArea; - private Style style; - private StyleContext context; - - /** - * Initialize this instance. - * @param width - * @param height - */ - public JTextAreaTextScreen(int width, int height) { - context = StyleContext.getDefaultStyleContext(); - style = context.addStyle("defaultStyle", null); - - style.addAttribute(StyleConstants.Foreground, Color.WHITE); - style.addAttribute(StyleConstants.Background, Color.BLACK); - - document = new DefaultStyledDocument(context); - textArea = new JTextArea(document); - textArea.setRows(height); - textArea.setColumns(width); - System.out.println("new JTextAreaTextScreen" + width + "x" + height); - } - - @Override - public char getChar(int offset) { - try { - return document.getText(offset, 1).charAt(0); - } catch (BadLocationException e) { - e.printStackTrace(); - return ' '; - } - } - - @Override - public int getColor(int offset) { - AttributeSet as = document.getCharacterElement(offset).getAttributes(); - return ((Color) as.getAttribute(ColorConstants.Foreground)).getRGB(); - } - - @Override - public void set(int offset, char ch, int count, int color) { - System.out.println("set1 " + offset); - try { - document.remove(offset, count); - - char[] chars = new char[count]; - Arrays.fill(chars, ch); - document.insertString(offset, new String(chars), createAttributes(color)); - } catch (BadLocationException e) { - e.printStackTrace(); - } - } - - @Override - public void set(int offset, char[] ch, int chOfs, int length, int color) { - System.out.println("set2 " + offset); - try { - final AttributeSet as = createAttributes(color); - - document.remove(offset, length); - document.insertString(offset, new String(ch), as); - } catch (BadLocationException e) { - e.printStackTrace(); - } - } - - @Override - public void set(int offset, char[] ch, int chOfs, int length, int[] colors, int colorsOfs) { - System.out.println("set3 " + offset); - try { - // first, replace the characters - document.remove(offset, length); - document.insertString(offset, new String(ch, chOfs, length), style); - - // second, affect the color to the characters - for (int iColor = colorsOfs; iColor < colors.length; iColor++) { - final AttributeSet as = createAttributes(colors[iColor]); - document.setCharacterAttributes(offset, 1, as, false); - offset++; - } - } catch (BadLocationException e) { - e.printStackTrace(); - } - } - - @Override - public void copyContent(int srcOffset, int destOffset, int length) { - // TODO Auto-generated method stub - } - - @Override - public void copyTo(TextScreen dst, int offset, int length) { - // TODO Auto-generated method stub - } - - @Override - public int getHeight() { - return textArea.getRows(); - } - - @Override - public int getWidth() { - return textArea.getColumns(); - } - - /** - * Calculate the offset for a given x,y coordinate. (copied from - * AbstractPcTextScreen) - * - * @param x - * @param y - * @return - */ - @Override - public int getOffset(int x, int y) { - return (y * getWidth()) + x; - } - - public void sync(int offset, int length) { - // TODO Auto-generated method stub - - } - - @Override - public TextScreen createCompatibleBufferScreen() { - // TODO Auto-generated method stub - return null; - } - - @Override - public ScrollableTextScreen createCompatibleScrollableBufferScreen(int height) { - // TODO Auto-generated method stub - return null; - } - - public void ensureVisible(int row, boolean sync) { - } - - @Override - public int setCursor(int x, int y) { - int offset = x + y * textArea.getColumns(); - textArea.setCaretPosition(offset); - return offset; - } - - @Override - public int setCursorVisible(boolean visible) { - textArea.getCaret().setVisible(visible); - return textArea.getCaretPosition(); - } - - // - // Private methods - // - - private AttributeSet createAttributes(int color) { - Color defaultColor = (Color) style.getAttribute(ColorConstants.Foreground); - if (defaultColor.getRGB() == color) { - // default color, use the default attributes - attributes = style; - } else { - // non-default color, create a new AttributeSet - // TODO optimize it by using a cache : Color -> AttributeSet ? - Color foreground = new Color(color); - attributes = context.addAttribute(style, StyleConstants.Foreground, foreground); - } - - return attributes; - } - - public Component getTextArea() { - return textArea; - } -} Deleted: trunk/gui/src/test/org/jnode/test/gui/ConsoleTest2.java =================================================================== --- trunk/gui/src/test/org/jnode/test/gui/ConsoleTest2.java 2008-08-11 21:03:28 UTC (rev 4428) +++ trunk/gui/src/test/org/jnode/test/gui/ConsoleTest2.java 2008-08-11 21:51:41 UTC (rev 4429) @@ -1,153 +0,0 @@ -/* - * $Id$ - * - * JNode.org - * Copyright (C) 2003-2006 JNode.org - * - * This library is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; If not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -package org.jnode.test.gui; - -import java.awt.BorderLayout; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.io.IOException; -import java.io.OutputStream; -import javax.naming.NameNotFoundException; -import javax.swing.JButton; -import javax.swing.JFrame; -import javax.swing.JMenu; -import javax.swing.JMenuBar; -import javax.swing.JMenuItem; -import javax.swing.JTextArea; -import org.jnode.driver.console.ConsoleException; -import org.jnode.driver.console.ConsoleManager; -import org.jnode.driver.console.TextConsole; -import org.jnode.driver.console.swing.JTextAreaTextScreen; -import org.jnode.driver.console.textscreen.TextScreenConsole; -import org.jnode.driver.console.textscreen.TextScreenConsoleManager; -import org.jnode.shell.CommandShell; -import org.jnode.shell.ShellException; -import org.jnode.shell.ShellUtils; - -/** - * @author Ewout Prangsma (ep...@us...) - */ -public class ConsoleTest2 { - - static class ConsoleFrame extends JFrame { - //private PrintStream savedOut; - //private JTextArea textArea; - private JTextAreaTextScreen screen; - private ConsoleManager manager; - private TextConsole console; - - public ConsoleFrame() throws ConsoleException, ShellException, NameNotFoundException { - super("System.out"); - - screen = new JTextAreaTextScreen(80, 24); - manager = new TextScreenConsoleManager(); - console = new TextScreenConsole( - manager, "test", screen, ConsoleManager.CreateOptions.TEXT); - manager.focus(console); - - CommandShell commandShell = new CommandShell(console); - new Thread(commandShell).start(); - ShellUtils.getShellManager().registerShell(commandShell); - - //textArea = new JTextArea( "System.out:" ); - - getContentPane().setLayout(new BorderLayout()); - getContentPane().add(screen.getTextArea(), BorderLayout.CENTER); - //savedOut = new PrintStream( new TextAreaOutputStream( textArea ) ); - } - -// public void show() { -// super.show( ); -// claimPrintStreams(); -// } - -// private void claimPrintStreams() { -// System.out.println( "Claiming print streams." ); -// AccessController.doPrivileged( new PrivilegedAction() { -// public Object run() { -// System.setOut( savedOut ); -// System.setErr( savedOut ); -// return null; -// } -// } ); -// System.out.println( "Claimed print streams." ); -// } - } - - - public static void main(String[] args) { - try { - final ConsoleFrame frame = new ConsoleFrame(); - frame.getRootPane().setDoubleBuffered(false); - frame.setLocation(100, 100); - frame.setSize(400, 400); - JButton button = new JButton("Button"); - button.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent event) { - System.out.println("Button pressed."); - } - }); - frame.getContentPane().add(button, BorderLayout.SOUTH); - JMenuBar mb = new JMenuBar(); - JMenu menu = new JMenu("JMenu test"); - JMenuItem mi = new JMenuItem("JMenuItem test"); - mb.add(menu); - menu.add(mi); - frame.setJMenuBar(mb); - frame.validate(); - frame.show(); - -// int count=0; -// Timer t=new Timer( 1000,new ActionListener() { -// public void actionPerformed( ActionEvent event ) { -// System.out.println( "X" ); -// } -// } ); -// t.start(); -// comp.requestFocus(); - System.out.println("Showed ConsoleTest frame."); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - /** - * @author epr - * @author Levente S\u00e1ntha (ls...@us...) - */ - public static class TextAreaOutputStream extends OutputStream { - - private JTextArea textArea; - - public TextAreaOutputStream(JTextArea console) { - this.textArea = console; - } - - public void write(int b) throws IOException { - textArea.append("" + (char) b); - if (b == '\n') { - textArea.repaint(); - } - } - } - -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |