diff options
Diffstat (limited to 'javastroke')
-rw-r--r-- | javastroke/Makefile.am | 14 | ||||
-rw-r--r-- | javastroke/Makefile.in | 197 | ||||
-rw-r--r-- | javastroke/Makefile.unix | 20 | ||||
-rw-r--r-- | javastroke/Paint.java | 177 | ||||
-rw-r--r-- | javastroke/README | 6 | ||||
-rw-r--r-- | javastroke/Stroke.java | 264 |
6 files changed, 678 insertions, 0 deletions
diff --git a/javastroke/Makefile.am b/javastroke/Makefile.am new file mode 100644 index 0000000..347a500 --- /dev/null +++ b/javastroke/Makefile.am @@ -0,0 +1,14 @@ + +EXTRA_DIST = \ + README \ + Makefile.unix \ + Paint.java \ + Stroke.java + +.PHONY: files + +files: + @files=`ls $(DISTFILES) 2> /dev/null`; for p in $$files; do \ + echo $$p; \ + done + diff --git a/javastroke/Makefile.in b/javastroke/Makefile.in new file mode 100644 index 0000000..274a843 --- /dev/null +++ b/javastroke/Makefile.in @@ -0,0 +1,197 @@ +# Makefile.in generated automatically by automake 1.4 from Makefile.am + +# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + + +SHELL = @SHELL@ + +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +VPATH = @srcdir@ +prefix = @prefix@ +exec_prefix = @exec_prefix@ + +bindir = @bindir@ +sbindir = @sbindir@ +libexecdir = @libexecdir@ +datadir = @datadir@ +sysconfdir = @sysconfdir@ +sharedstatedir = @sharedstatedir@ +localstatedir = @localstatedir@ +libdir = @libdir@ +infodir = @infodir@ +mandir = @mandir@ +includedir = @includedir@ +oldincludedir = /usr/include + +DESTDIR = + +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ + +top_builddir = .. + +ACLOCAL = @ACLOCAL@ +AUTOCONF = @AUTOCONF@ +AUTOMAKE = @AUTOMAKE@ +AUTOHEADER = @AUTOHEADER@ + +INSTALL = @INSTALL@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS) +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +transform = @program_transform_name@ + +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +host_alias = @host_alias@ +host_triplet = @host@ +AS = @AS@ +CC = @CC@ +DLLTOOL = @DLLTOOL@ +GTK_CFLAGS = @GTK_CFLAGS@ +GTK_CONFIG = @GTK_CONFIG@ +GTK_LIBS = @GTK_LIBS@ +LD = @LD@ +LIBTOOL = @LIBTOOL@ +LN_S = @LN_S@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +NM = @NM@ +PACKAGE = @PACKAGE@ +RANLIB = @RANLIB@ +USE_SYMBOL_UNDERSCORE = @USE_SYMBOL_UNDERSCORE@ +VERSION = @VERSION@ +X_CFLAGS = @X_CFLAGS@ +X_LDFLAGS = @X_LDFLAGS@ + +EXTRA_DIST = README Makefile.unix Paint.java Stroke.java + +mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs +CONFIG_HEADER = ../config.h +CONFIG_CLEAN_FILES = +DIST_COMMON = README Makefile.am Makefile.in + + +DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) + +TAR = gtar +GZIP_ENV = --best +all: all-redirect +.SUFFIXES: +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) + cd $(top_srcdir) && $(AUTOMAKE) --gnu javastroke/Makefile + +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status $(BUILT_SOURCES) + cd $(top_builddir) \ + && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status + +tags: TAGS +TAGS: + + +distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir) + +subdir = javastroke + +distdir: $(DISTFILES) + here=`cd $(top_builddir) && pwd`; \ + top_distdir=`cd $(top_distdir) && pwd`; \ + distdir=`cd $(distdir) && pwd`; \ + cd $(top_srcdir) \ + && $(AUTOMAKE) --include-deps --build-dir=$$here --srcdir-name=$(top_srcdir) --output-dir=$$top_distdir --gnu javastroke/Makefile + @for file in $(DISTFILES); do \ + d=$(srcdir); \ + if test -d $$d/$$file; then \ + cp -pr $$d/$$file $(distdir)/$$file; \ + else \ + test -f $(distdir)/$$file \ + || ln $$d/$$file $(distdir)/$$file 2> /dev/null \ + || cp -p $$d/$$file $(distdir)/$$file || :; \ + fi; \ + done +info-am: +info: info-am +dvi-am: +dvi: dvi-am +check-am: all-am +check: check-am +installcheck-am: +installcheck: installcheck-am +install-exec-am: +install-exec: install-exec-am + +install-data-am: +install-data: install-data-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am +install: install-am +uninstall-am: +uninstall: uninstall-am +all-am: Makefile +all-redirect: all-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install +installdirs: + + +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -rm -f Makefile $(CONFIG_CLEAN_FILES) + -rm -f config.cache config.log stamp-h stamp-h[0-9]* + +maintainer-clean-generic: +mostlyclean-am: mostlyclean-generic + +mostlyclean: mostlyclean-am + +clean-am: clean-generic mostlyclean-am + +clean: clean-am + +distclean-am: distclean-generic clean-am + -rm -f libtool + +distclean: distclean-am + +maintainer-clean-am: maintainer-clean-generic distclean-am + @echo "This command is intended for maintainers to use;" + @echo "it deletes files that may require special tools to rebuild." + +maintainer-clean: maintainer-clean-am + +.PHONY: tags distdir info-am info dvi-am dvi check check-am \ +installcheck-am installcheck install-exec-am install-exec \ +install-data-am install-data install-am install uninstall-am uninstall \ +all-redirect all-am all installdirs mostlyclean-generic \ +distclean-generic clean-generic maintainer-clean-generic clean \ +mostlyclean distclean maintainer-clean + + +.PHONY: files + +files: + @files=`ls $(DISTFILES) 2> /dev/null`; for p in $$files; do \ + echo $$p; \ + done + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/javastroke/Makefile.unix b/javastroke/Makefile.unix new file mode 100644 index 0000000..5ee1537 --- /dev/null +++ b/javastroke/Makefile.unix @@ -0,0 +1,20 @@ + +all:: + "make compile to compile javastroke" + +compile:: + javac Stroke.java + javac Paint.java + +distdir:: + echo "nothing to do" + +test:: + java Paint + +clean:: + rm -f *class + +install:: + echo "Install javastroke by hand, if desired" + diff --git a/javastroke/Paint.java b/javastroke/Paint.java new file mode 100644 index 0000000..0885213 --- /dev/null +++ b/javastroke/Paint.java @@ -0,0 +1,177 @@ +//* Example of Stroke in JAVA * +// by Luciano da Silva Ribas +// license under GNU General Public License + +import java.awt.*; +import java.awt.event.*; +import java.math.*; + +public class Paint extends Frame implements WindowListener, MouseListener,MouseMotionListener, ActionListener { + public static Canvas c; + public static Graphics g; + public static int xp; + public static int yp; + public Color cor = Color.black; + public Stroke MyStroke; + + public static int figura = 1; + public static int rect_lx = 50; + public static int rect_ly = 50; + public static int circ_s = 100; + + public static void main(String args[]){ + Paint i = new Paint("Paint"); + } + + public Paint(String t){ + super(t); + this.setSize(500,500); + this.setLocation(100,100); + this.setVisible(true); + + MyStroke = new Stroke(); + + MenuBar mbar = new MenuBar(); + Menu menuAbout = new Menu("About"); + MenuItem miAbout = new MenuItem("About.."); + miAbout.addActionListener(this); + mbar.add(menuAbout); + menuAbout.add(miAbout); + this.setMenuBar(mbar); + + c = new Canvas(); + this.add(c); + + c.addMouseListener(this); + c.addMouseMotionListener(this); + + this.addWindowListener(this); + this.show(); + + System.out.println("\nLASD/CEFETPR\nTMN Project - Telecommunications Management Network\n\nAuthor: Luciano da Silva Ribas ribas@lasd.cefetpr.br\n"); + System.out.println("Strokes actived."); + System.out.println("\t1 2 3\n\t4 5 6\n\t7 8 9\n"); + System.out.println("to change color:"); + System.out.println("\t456 - Black"); + System.out.println("\t654 - Blue"); + System.out.println("\t258 - Yellow"); + System.out.println("\t852 - Red\n"); + System.out.println("to change draw:"); + System.out.println("\t78963 - Oval"); + System.out.println("\t14789 - Rectangle\n"); + System.out.println("to change size:"); + System.out.println("\t357 - Zoom-in"); + System.out.println("\t753 - Zoom-out\n"); + + System.out.println("detected:"); + + Draw(); + } + + + public void Draw() { + +if( figura==1) { + g=c.getGraphics(); + g.setColor(Color.white); + g.fillRect(0,0,500,500); + g.setColor(cor); + g.fillOval(200,200,circ_s,circ_s); + } + + if( figura==2) { + g=c.getGraphics(); + g.setColor(Color.white); + g.fillRect(0,0,500,500); + g.setColor(cor); + g.fillRect(200-rect_lx,200-rect_ly,200+rect_lx,200+rect_ly); + } + } + + public void actionPerformed( ActionEvent a){ + String comand=a.getActionCommand(); + if(comand.equals("About..")) + System.out.println("\nLASD/CEFETPR\nTMN Project - Telecommunications Management Network\n\nAuthor: Luciano da Silva Ribas ribas@lasd.cefetpr.br\n"); + } + + public void mousePressed(MouseEvent m){ + xp = m.getX(); + yp = m.getY(); + g=c.getGraphics(); + g.setColor(cor); + g.drawLine(xp,yp,xp,yp); + } + + public void mouseReleased(MouseEvent m){ + String Result; + Result = MyStroke.stroke_trans(); + System.out.print("----> ["+Result+"] .. "); + + if (Result.equals("456")) { + cor = Color.black; + System.out.println("color black."); + } else + if (Result.equals("654")) { + cor = Color.blue; + System.out.println("color blue."); + } else + if (Result.equals("258")) { + cor = Color.yellow; + System.out.println("color yellow."); + } else + if (Result.equals("852")) { + cor = Color.red; + System.out.println("color red."); + } else + if (Result.equals("78963")) { + figura = 1; + System.out.println("draw circle."); + } else + if (Result.equals("14789")) { + figura = 2; + System.out.println("draw rectangle."); + } else + if (Result.equals("357")) { + rect_lx *= 2; + rect_ly *= 2; + circ_s *= 2; + System.out.println("ZOOM IN."); + } else + if (Result.equals("753")) { + rect_lx = (int) rect_lx/2; + rect_ly = (int) rect_ly/2; + circ_s = (int) circ_s/2; + System.out.println("ZOOM OUT."); + } else { + System.out.println("stroke not recognizable.");} + + Draw(); + } + + public void mouseEntered(MouseEvent m){} + public void mouseExited(MouseEvent m){} + public void mouseClicked(MouseEvent m){} + + public void mouseDragged(MouseEvent m){ + int x=m.getX(); + int y=m.getY(); + g=c.getGraphics(); + g.setColor(Color.black); + g.drawLine(x,y,xp,yp); + xp=x; + yp=y; + MyStroke.stroke_record( x, y ); + } + + public void mouseMoved(MouseEvent m){} + + public void windowClosing (WindowEvent e){ + System.exit(0);} + public void windowOpened (WindowEvent e){} + public void windowIconified (WindowEvent e){} + public void windowDeiconified (WindowEvent e){} + public void windowClosed (WindowEvent e){} + public void windowActivated (WindowEvent e){} + public void windowDeactivated (WindowEvent e){} +} + diff --git a/javastroke/README b/javastroke/README new file mode 100644 index 0000000..8d3da7a --- /dev/null +++ b/javastroke/README @@ -0,0 +1,6 @@ + +This is a port of the LibStroke library to Java. It is released under the +GPL. It is so cool. + +Author: Luciano da Silva Ribas <ribas@lasd.cefetpr.br> + diff --git a/javastroke/Stroke.java b/javastroke/Stroke.java new file mode 100644 index 0000000..f82274b --- /dev/null +++ b/javastroke/Stroke.java @@ -0,0 +1,264 @@ + +/* + Java Stroke - a Java stroke interface library + Copyright (c) 1996,1997,1998,1999,2000 Mark F. Willey, ETLA Technical + Copyright (c) 1999 Luciano da Silva Ribas, ribas@lasd.cefetpr.br + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software, including the rights to use, copy, + modify, merge, publish, and distribute copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; version 2. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + See the file "LICENSE" for a copy of the GNU GPL terms. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR + OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + OTHER DEALINGS IN THE SOFTWARE. + + Except as contained in this notice, the name of the author shall + name be used in advertising or otherwise to promote the sale, use or + other dealings in this Software without prior written authorization + from the author. + + Non-GPL commercial use licenses are available - contact copyright holder. + + Author: Mark F. Willey -- willey@etla.net + http://www.etla.net/ + + Java Port Author: Luciano da Silva Ribas -- ribas@lasd.cefetpr.br + +*/ + +// version in Java by Luciano da Silve Ribas + +/** Classe de implementacao do Stroke. */ +public class Stroke { + + /** maximo de pontos permitidos por sample*/ + static int MAX_POINTS=10000; + + /** numero minimo de pontos por sample requerido*/ + static int MIN_POINTS=50; + + /** maximo numero de posicoes por stroke*/ + static int MAX_SEQUENCE=20; + + /** threshold do axis*/ + static int SCALE_RATIO=4; + + /** percentagem dos pontos adicionado a sequencia*/ + static double BIN_COUNT_PERCENT=0.07; + + /** Inner Classe para armazenar os pontos do stroke.*/ + class s_point { + int x; + int y; + s_point next; + + public s_point() { + x = 0; y = 0; + } + + public s_point(int a, int b) { + x = a; y = b; + } + } + + /** Variaveis de controle */ + int point_count = 0; + int min_x = -1; + int max_x = 10000; + int min_y = -1; + int max_y = 10000; + + /** Ponteiro para o inicio da lista de pontos */ + s_point point_list_head; + + /** Ponteiro para o fim da lista de pontos */ + s_point point_list_tail; + + /** Verifica se o ponto pertence ao contorno */ + int stroke_bin (s_point point_p, int bound_x_1, int bound_x_2, int bound_y_1, int bound_y_2) { + int bin_num = 1; + if (point_p.x > bound_x_1) bin_num += 1; + if (point_p.x > bound_x_2) bin_num += 1; + if (point_p.y > bound_y_1) bin_num += 3; + if (point_p.y > bound_y_2) bin_num += 3; + return bin_num; + } + + int stroke_init () {return 0;} + + String stroke_trans () { + + int sequence_count = 0; + int prev_bin = 0; + int current_bin = 0; + int bin_count = 0; + int first_bin = 1; + int delta_x, delta_y; + int bound_x_1, bound_x_2; + int bound_y_1, bound_y_2; + + String Result = new String(""); + + delta_x = max_x - min_x; + delta_y = max_y - min_y; + + bound_x_1 = min_x + (delta_x / 3); + bound_x_2 = min_x + 2 * (delta_x / 3); + + bound_y_1 = min_y + (delta_y / 3); + bound_y_2 = min_y + 2 * (delta_y / 3); + + if (delta_x > SCALE_RATIO * delta_y) { + bound_y_1 = (max_y + min_y - delta_x) / 2 + (delta_x / 3); + bound_y_2 = (max_y + min_y - delta_x) / 2 + 2 * (delta_x / 3); + } else if (delta_y > SCALE_RATIO * delta_x) { + bound_x_1 = (max_x + min_x - delta_y) / 2 + (delta_y / 3); + bound_x_2 = (max_x + min_x - delta_y) / 2 + 2 * (delta_y / 3); + } + + while (point_list_head != null) { + + current_bin = stroke_bin(point_list_head,bound_x_1, bound_x_2, bound_y_1, bound_y_2); + prev_bin = (prev_bin == 0) ? current_bin : prev_bin; + + if (prev_bin == current_bin) + bin_count++; + else { + if ((bin_count > (point_count * BIN_COUNT_PERCENT)) || (first_bin == 1)) { + first_bin = 0; + Result = Result + ( (char) (48 + prev_bin) ); + sequence_count++; + } + + bin_count=0; + prev_bin = current_bin; + } + + point_list_tail = point_list_head; + point_list_head = point_list_head.next; + point_list_tail = null; + } + point_list_tail = null; + + Result = Result + ( (char) (48 + prev_bin) ); + sequence_count++; + + if ((point_count < MIN_POINTS) || (sequence_count > MAX_SEQUENCE)) { + point_count = 0; + Result = ""; + return Result; + } + + point_count = 0; + return Result; + + + } + + void stroke_record ( int x, int y) { + + int delx, dely; + double ix, iy; + + + if (point_count < MAX_POINTS) { + + s_point new_point = new s_point(); + + if ( point_list_head == null ) { + point_list_head = point_list_tail = new_point; + min_x = 10000; + min_y = 10000; + max_x = -1; + max_y = -1; + point_count = 0; + } else { + delx = x - point_list_tail.x; + dely = y - point_list_tail.y; + + if (java.lang.Math.abs(delx) > java.lang.Math.abs(dely)) { + iy = point_list_tail.y; + + for (ix = point_list_tail.x; (delx > 0) ? (ix < x) : (ix > x); ix += (delx > 0) ? 1 : -1) { + + iy += java.lang.Math.abs(((float) dely / (float) delx)) * (float) ((dely < 0) ? -1.0 : 1.0); + + s_point new_point_i = new s_point(); + + point_list_tail.next = new_point_i; + point_list_tail = new_point_i; + new_point_i.x = (int) ix; + new_point_i.y = (int) iy; +// new_point.next = null; + + if (((int) ix) < min_x) min_x = (int) ix; + if (((int) ix) > max_x) max_x = (int) ix; + if (((int) iy) < min_y) min_y = (int) iy; + if (((int) iy) > max_y) max_y = (int) iy; + point_count++; + + } + } else { + ix = point_list_tail.x; + + for (iy = point_list_tail.y; (dely > 0) ? (iy < y) : (iy > y); iy += (dely > 0) ? 1 : -1) { + + ix += java.lang.Math.abs(((float) delx / (float) dely)) * (float) ((delx < 0) ? -1.0 : 1.0); + + s_point new_point_i = new s_point(); + + point_list_tail.next = new_point_i; + point_list_tail = new_point_i; + new_point_i.y = (int) iy; + new_point_i.x = (int) ix; +// new_point.next = null; + + if (((int) ix) < min_x) min_x = (int) ix; + if (((int) ix) > max_x) max_x = (int) ix; + if (((int) iy) < min_y) min_y = (int) iy; + if (((int) iy) > max_y) max_y = (int) iy; + point_count++; + + } + } + + point_list_tail.next = new_point; + point_list_tail = new_point; + } + + new_point.x = x; + new_point.y = y; +// new_point.next = null; + + } + + } + + + +} + |