Make first real commit: copy of CaRMetal 4.2.8

This commit is contained in:
Glen Whitney 2018-09-04 22:51:42 -04:00
parent 002acfc88e
commit c312811084
1120 changed files with 226843 additions and 1 deletions

View file

@ -0,0 +1,423 @@
/*
Copyright 2006 Rene Grothmann, modified by Eric Hakenholz
This file is part of C.a.R. software.
C.a.R. is a 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 3 of the License.
C.a.R. 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, see <http://www.gnu.org/licenses/>.
*/
package rene.viewer;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.MenuItem;
import java.awt.PopupMenu;
import java.awt.Scrollbar;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.event.MouseWheelEvent;
import java.io.PrintWriter;
import java.util.Enumeration;
import eric.JEricPanel;
import rene.gui.Global;
import rene.gui.Panel3D;
import rene.util.MyVector;
/**
* An extended Version of the Viewer. It is able to reformat lines, when the
* area is resized. It has no vertical scrollbar. Text is stored into a separate
* string buffer, and will be formatted on repaint.
*/
public class ExtendedViewer extends Viewer implements AdjustmentListener,
MouseListener, MouseMotionListener, ActionListener, KeyListener,
WheelListener {
/**
*
*/
private static final long serialVersionUID = 1L;
TextDisplay TD;
Scrollbar Vertical;
TextPosition Start, End;
PopupMenu PM;
int X, Y;
JEricPanel P3D;
MyVector V; // Vector of lines
StringBuffer B; // Buffer for last line
boolean Changed = false;
public ExtendedViewer() {
TD = new TextDisplay(this);
setLayout(new BorderLayout());
add("Center", P3D = new Panel3D(TD));
add("East", Vertical = new Scrollbar(Scrollbar.VERTICAL, 0, 100, 0,
1100));
Vertical.addAdjustmentListener(this);
TD.addMouseListener(this);
TD.addMouseMotionListener(this);
Start = End = null;
PM = new PopupMenu();
MenuItem mi = new MenuItem(Global.name("block.copy", "Copy"));
mi.addActionListener(this);
PM.add(mi);
PM.addSeparator();
mi = new MenuItem(Global.name("block.begin", "Begin Block"));
mi.addActionListener(this);
PM.add(mi);
mi = new MenuItem(Global.name("block.end", "End Block"));
mi.addActionListener(this);
PM.add(mi);
add(PM);
final Wheel W = new Wheel(this);
addMouseWheelListener(W);
V = new MyVector();
B = new StringBuffer();
}
@Override
public void setFont(final Font f) {
TD.init(f);
}
@Override
public void appendLine(final String s) {
B.append(s);
V.addElement(B.toString());
B.setLength(0);
Changed = true;
}
public void newLine() {
V.addElement(B.toString());
B.setLength(0);
Changed = true;
}
@Override
public void appendLine(final String s, final Color c) {
appendLine(s);
}
@Override
public void append(final String s) {
B.append(s);
}
@Override
public void append(final String s, final Color c) {
append(s);
}
@Override
public void doUpdate(final boolean showlast) {
}
public void update() {
resized();
showFirst();
}
@Override
public void adjustmentValueChanged(final AdjustmentEvent e) {
if (e.getSource() == Vertical) {
switch (e.getAdjustmentType()) {
case AdjustmentEvent.UNIT_INCREMENT:
TD.verticalUp();
break;
case AdjustmentEvent.UNIT_DECREMENT:
TD.verticalDown();
break;
case AdjustmentEvent.BLOCK_INCREMENT:
TD.verticalPageUp();
break;
case AdjustmentEvent.BLOCK_DECREMENT:
TD.verticalPageDown();
break;
default:
final int v = Vertical.getValue();
Vertical.setValue(v);
TD.setVertical(v);
return;
}
setVerticalScrollbar();
}
}
@Override
public void setVerticalScrollbar() {
if (Vertical == null)
return;
final int h = TD.computeVerticalSize();
Vertical.setValues(TD.computeVertical(), h, 0, 1000 + h);
}
@Override
public void setText(final String S) {
TD.unmark();
Start = End = null;
TD.setText(S);
V.removeAllElements();
B.setLength(0);
setVerticalScrollbar();
}
@Override
public void save(final PrintWriter fo) {
TD.save(fo);
}
@Override
public void appendLine0(final String s) {
appendLine(s);
}
@Override
public void appendLine0(final String s, final Color c) {
appendLine(s);
}
boolean Dragging = false;
@Override
public void mouseClicked(final MouseEvent e) {
}
@Override
public void mousePressed(final MouseEvent e) {
if (e.isPopupTrigger() || e.isMetaDown()) {
PM.show(e.getComponent(), e.getX(), e.getY());
X = e.getX();
Y = e.getY();
} else {
TD.unmark(Start, End);
Start = TD.getposition(e.getX(), e.getY());
Start.oneleft();
End = null;
}
}
@Override
public Dimension getPreferredSize() {
return new Dimension(150, 200);
}
@Override
public Dimension getMinimumSize() {
return new Dimension(150, 200);
}
@Override
public void mouseReleased(final MouseEvent e) {
Dragging = false;
}
@Override
public void mouseEntered(final MouseEvent e) {
}
@Override
public void mouseExited(final MouseEvent e) {
}
@Override
public void mouseMoved(final MouseEvent e) {
}
@Override
public void mouseDragged(final MouseEvent e) {
TD.unmark(Start, End);
final TextPosition h = TD.getposition(e.getX(), e.getY());
if (h != null)
End = h;
TD.mark(Start, End);
}
@Override
public void actionPerformed(final ActionEvent e) {
final String o = e.getActionCommand();
if (o.equals(Global.name("block.copy", "Copy")))
TD.copy(Start, End);
else if (o.equals(Global.name("block.begin", "Begin Block"))) {
TD.unmark(Start, End);
Start = TD.getposition(X, Y);
Start.oneleft();
if (End == null && TD.L.last() != null) {
End = TD.lastpos();
}
TD.mark(Start, End);
} else if (o.equals(Global.name("block.end", "End Block"))) {
TD.unmark(Start, End);
End = TD.getposition(X, Y);
if (Start == null && TD.L.first() != null) {
Start = new TextPosition(TD.L.first(), 0, 0);
}
TD.mark(Start, End);
}
}
@Override
public void keyPressed(final KeyEvent e) {
}
@Override
public void keyReleased(final KeyEvent e) {
if (e.isControlDown() && e.getKeyCode() == KeyEvent.VK_C
&& Start != null && End != null) {
TD.copy(Start, End);
}
}
@Override
public void keyTyped(final KeyEvent e) {
}
@Override
public void setTabWidth(final int t) {
TD.setTabWidth(t);
}
@Override
public void showFirst() {
TD.showFirst();
setVerticalScrollbar();
TD.repaint();
}
@Override
public void showLast() {
TD.showlast();
setVerticalScrollbar();
TD.repaint();
}
@Override
public boolean hasFocus() {
return false;
}
@Override
public void setBackground(final Color c) {
TD.setBackground(c);
P3D.setBackground(c);
super.setBackground(c);
}
@Override
public void up(final int n) {
for (int i = 0; i < n; i++)
TD.verticalUp();
setVerticalScrollbar();
}
@Override
public void down(final int n) {
for (int i = 0; i < n; i++)
TD.verticalDown();
setVerticalScrollbar();
}
@Override
public void pageUp() {
TD.verticalPageUp();
setVerticalScrollbar();
}
@Override
public void pageDown() {
TD.verticalPageDown();
setVerticalScrollbar();
}
@Override
public void paint(final Graphics G) {
super.paint(G);
}
public void doAppend(final String s) {
final char a[] = s.toCharArray();
final int w[] = TD.getwidth(a);
int start = 0, end = 0;
final int W = TD.getSize().width;
int goodbreak;
while (start < a.length && a[start] == ' ')
start++;
if (start >= a.length) {
TD.appendLine("");
return;
}
int blanks = 0;
String sblanks = "";
int offset = 0;
if (start > 0) {
blanks = start;
sblanks = new String(a, 0, blanks);
offset = blanks + w[0];
}
while (start < a.length) {
int tw = TD.Offset + offset;
end = start;
goodbreak = start;
while (end < a.length && tw < W) {
tw += w[end];
if (a[end] == ' ')
goodbreak = end;
end++;
}
if (tw < W)
goodbreak = end;
if (goodbreak == start)
goodbreak = end;
if (blanks > 0)
TD
.appendLine(sblanks
+ new String(a, start, goodbreak - start));
else
TD.appendLine(new String(a, start, goodbreak - start));
start = goodbreak;
while (start < a.length && a[start] == ' ')
start++;
}
}
@Override
public synchronized void resized() {
if (TD.getSize().width <= 0)
return;
TD.setText("");
final Enumeration e = V.elements();
while (e.hasMoreElements()) {
final String s = (String) e.nextElement();
doAppend(s);
}
TD.repaint();
}
public void mouseWheelMoved(final MouseWheelEvent arg0) {
}
}

224
rene/viewer/Line.java Normal file
View file

@ -0,0 +1,224 @@
/*
Copyright 2006 Rene Grothmann, modified by Eric Hakenholz
This file is part of C.a.R. software.
C.a.R. is a 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 3 of the License.
C.a.R. 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, see <http://www.gnu.org/licenses/>.
*/
package rene.viewer;
import java.awt.Color;
import java.awt.Graphics;
public class Line {
TextDisplay TD;
boolean Chosen;
int Pos, Posend;
int Block; // block state
static final int NONE = 0, START = 1, END = 2, FULL = 4; // block states
// (logically
// or'ed)
Color C, IC; // Color of line and high key color of the line
char a[]; // Contains the characters of this line
public Line(final String s, final TextDisplay td) {
this(s, td, Color.black);
}
/**
* Generate a line containing s in the textdisplay td. Display color is c.
*
* @param s
* @param td
* @param c
*/
public Line(final String s, final TextDisplay td, final Color c) {
TD = td;
C = c;
// Create a color that is very bright, but resembles the line color
IC = new Color(C.getRed() / 4 + 192, C.getGreen() / 4 + 192, C
.getBlue() / 4 + 192);
Block = NONE;
a = s.toCharArray();
}
public void expandTabs(final int tabwidth) {
int pos = 0;
for (final char element : a) {
pos++;
if (element == '\t')
pos = (pos / tabwidth + 1) * tabwidth;
}
final char b[] = new char[pos];
pos = 0;
for (final char element : a) {
if (element == '\t') {
final int newpos = ((pos + 1) / tabwidth + 1) * tabwidth;
for (int k = pos; k < newpos; k++)
b[k] = ' ';
pos = newpos;
} else
b[pos++] = element;
}
a = b;
}
int length() {
return a.length;
}
int getpos(final int x, final int offset) {
final int l[] = TD.getwidth(a);
int h = offset - TD.Offset * TD.FM.charWidth(' ');
if (x < h)
return 0;
int i = 0;
while (x > h && i < a.length) {
h += l[i];
i++;
}
return i;
}
/**
* Draw a line. If the line is in a block, draw it white on black or on dark
* gray, depending on the focus. Drawing in blocks does not use antialias.
*
* @param g
* @param x
* @param y
*/
public void draw(final Graphics g, int x, final int y) {
x -= TD.Offset * TD.FM.charWidth(' ');
if (Chosen) // Complete line is chosen (in Lister)
{ // To see, if the display has the focus:
if (TD.hasFocus())
g.setColor(Color.darkGray);
else
g.setColor(Color.gray);
g.fillRect(0, y - TD.Ascent, TD.getSize().width, TD.Height);
g.setColor(IC); // draw in light color
TD.antialias(false);
g.drawChars(a, 0, a.length, x, y);
TD.antialias(true);
} else if ((Block & FULL) != 0) // Line in full block (in Viewer)
{
g.setColor(Color.darkGray);
g.fillRect(x, y - TD.Ascent, TD.FM.charsWidth(a, 0, a.length),
TD.Height);
g.setColor(Color.white);
TD.antialias(false);
g.drawChars(a, 0, a.length, x, y);
TD.antialias(true);
} else if ((Block & START) != 0) {
if (Pos > 0) // Draw text before block
{
g.setColor(C);
g.drawChars(a, 0, Pos, x, y);
x += TD.FM.charsWidth(a, 0, Pos);
}
if ((Block & END) != 0) // draw text in block
{
if (Posend > Pos) {
final int h = TD.FM.charsWidth(a, Pos, Posend - Pos);
g.setColor(Color.darkGray);
g.fillRect(x, y - TD.Ascent, h, TD.Height);
g.setColor(Color.white);
TD.antialias(false);
g.drawChars(a, Pos, Posend - Pos, x, y);
TD.antialias(true);
g.setColor(C);
x += h;
if (a.length > Posend) {
g.drawChars(a, Posend, a.length - Posend, x, y);
}
} else
g.drawChars(a, Pos, a.length - Pos, x, y);
} else // draw the rest of the line in block
{
final int h = TD.FM.charsWidth(a, Pos, a.length - Pos);
g.setColor(Color.darkGray);
g.fillRect(x, y - TD.Ascent, h, TD.Height);
g.setColor(Color.white);
TD.antialias(false);
g.drawChars(a, Pos, a.length - Pos, x, y);
TD.antialias(true);
}
} else if ((Block & END) != 0) {
final int h = TD.FM.charsWidth(a, 0, Posend);
g.setColor(Color.darkGray);
g.fillRect(x, y - TD.Ascent, h, TD.Height);
g.setColor(Color.white);
TD.antialias(false);
g.drawChars(a, 0, Posend, x, y);
TD.antialias(true);
g.setColor(C);
x += h;
if (a.length > Posend) {
g.drawChars(a, Posend, a.length - Posend, x, y);
}
} else {
g.setColor(C);
g.drawChars(a, 0, a.length, x, y);
}
}
void append(final String s) {
a = (new String(a) + s).toCharArray();
}
void chosen(final boolean f) {
Chosen = f;
}
public boolean chosen() {
return Chosen;
}
void block(final int pos, final int mode) {
switch (mode) {
case NONE:
Block = NONE;
break;
case FULL:
Block = FULL;
break;
case START:
Block |= START;
Pos = pos;
break;
case END:
Block |= END;
Posend = pos;
break;
}
}
String getblock() {
if (Block == FULL) {
return new String(a, 0, a.length);
} else if ((Block & START) != 0) {
if ((Block & END) != 0) {
return new String(a, Pos, Posend - Pos);
} else
return new String(a, Pos, a.length - Pos);
} else if ((Block & END) != 0)
return new String(a, 0, Posend);
else
return "";
}
}

View file

@ -0,0 +1,83 @@
/*
Copyright 2006 Rene Grothmann, modified by Eric Hakenholz
This file is part of C.a.R. software.
C.a.R. is a 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 3 of the License.
C.a.R. 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, see <http://www.gnu.org/licenses/>.
*/
package rene.viewer;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.TextArea;
import java.io.PrintWriter;
public class SystemViewer extends Viewer {
/**
*
*/
private static final long serialVersionUID = 1L;
TextArea T;
public SystemViewer() {
super("dummy");
setLayout(new BorderLayout());
add("Center", T = new TextArea());
}
@Override
public void appendLine(final String s) {
T.append(s + "\n");
}
@Override
public void appendLine(final String s, final Color c) {
appendLine(s);
}
@Override
public void append(final String s) {
T.append(s);
}
@Override
public void append(final String s, final Color c) {
append(s);
}
@Override
public void setText(final String s) {
T.setText(s);
}
@Override
public void doUpdate(final boolean showlast) {
T.repaint();
}
@Override
public void setFont(final Font s) {
T.setFont(s);
}
@Override
public void save(final PrintWriter fo) {
fo.print(T.getText());
fo.flush();
}
}

View file

@ -0,0 +1,575 @@
/*
Copyright 2006 Rene Grothmann, modified by Eric Hakenholz
This file is part of C.a.R. software.
C.a.R. is a 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 3 of the License.
C.a.R. 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, see <http://www.gnu.org/licenses/>.
*/
package rene.viewer;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.RenderingHints;
import java.awt.SystemColor;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.ClipboardOwner;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.io.PrintWriter;
import rene.gui.Global;
import rene.util.list.ListClass;
import rene.util.list.ListElement;
class ClipboardCopy extends Thread {
String S;
ClipboardOwner C;
Canvas Cv;
public ClipboardCopy(final ClipboardOwner c, final Canvas cv, final String s) {
S = s;
C = c;
Cv = cv;
start();
}
@Override
public void run() {
final Clipboard clip = Cv.getToolkit().getSystemClipboard();
final StringSelection cont = new StringSelection(S);
clip.setContents(cont, C);
}
}
public class TextDisplay extends Canvas implements ClipboardOwner,
ComponentListener {
/**
*
*/
private static final long serialVersionUID = 1L;
ListClass L;
Font F = null;
FontMetrics FM;
Viewer V;
int Leading, Height, Ascent, Descent;
int LineCount, TopLineCount;
int PageSize;
ListElement TopLine;
Image I;
Graphics IG;
int W, H;
public int Tabsize = 4;
public int Offset;
boolean LineFinished = true;
int Widths[], HW[];
long LastScrollTime;
Color Background;
int TabWidth = 0;
public TextDisplay(final Viewer v) {
L = new ListClass();
F = null;
V = v;
LineCount = 0;
TopLineCount = 0;
TopLine = null;
I = null;
W = H = 0;
PageSize = 10;
HW = new int[1024];
addKeyListener(v);
addComponentListener(this);
}
void init(final Font f) {
F = f;
FM = getFontMetrics(F);
Leading = FM.getLeading()
+ Global.getParameter("fixedfont.spacing", -1);
Height = FM.getHeight();
Ascent = FM.getAscent();
Descent = FM.getDescent();
Widths = FM.getWidths();
}
@Override
public Color getBackground() {
return SystemColor.window;
}
int[] getwidth(final char a[]) {
try {
for (int i = 0; i < a.length; i++) {
if (a[i] < 256)
HW[i] = Widths[a[i]];
else
HW[i] = FM.charWidth(a[i]);
}
} catch (final Exception e) {
return HW;
}
return HW;
}
public synchronized void appendLine0(final String S) {
appendLine0(S, Color.black);
}
public synchronized void appendLine0(final String S, final Color c) {
Line l;
L.append(new ListElement(l = new Line(S, this, c)));
LineCount++;
if (LineCount == 1)
TopLine = L.first();
LineFinished = true;
if (TabWidth > 0)
l.expandTabs(TabWidth);
}
public synchronized void appendLine(final String s) {
appendLine0(s);
V.setVerticalScrollbar();
}
public void append(final String S, final Color c) {
append(S, c, true);
}
public void append(String S, final Color c, final boolean suddenupdate) {
while (true) {
final int p = S.indexOf('\n');
if (p < 0) {
appendlast(S, c);
LineFinished = false;
break;
}
appendlast(S.substring(0, p), c);
LineFinished = true;
S = S.substring(p + 1);
if (S.equals("")) {
break;
}
}
if (suddenupdate)
doUpdate(true);
repaint();
}
public void doUpdate(final boolean showlast) {
if (showlast) {
final long m = System.currentTimeMillis();
if (m - LastScrollTime > 10000)
showlast();
}
repaint();
V.setVerticalScrollbar();
}
public void setText(final String s) {
TopLine = null;
TopLineCount = 0;
LineCount = 0;
L = new ListClass();
if (!s.equals(""))
append(s, Color.black);
repaint();
}
public synchronized void appendlast(final String s, final Color c) {
if (LineFinished || L.last() == null) {
Line l;
L.append(new ListElement(l = new Line(s, this, c)));
LineCount++;
if (LineCount == 1)
TopLine = L.first();
if (TabWidth > 0)
l.expandTabs(TabWidth);
} else {
((Line) L.last().content()).append(s);
}
}
public void showlast() {
ListElement e = L.last();
if (e == null)
return;
TopLineCount = LineCount;
for (int i = 0; i < PageSize - 1; i++) {
if (e.previous() == null)
break;
e = e.previous();
TopLineCount--;
}
TopLine = e;
repaint();
}
public void makeimage() {
final Dimension D = getSize();
if (I == null || D.width != W || D.height != H) {
try {
I = createImage(W = D.width, H = D.height);
IG = I.getGraphics();
} catch (final Exception e) {
}
}
IG.setColor(Color.black);
IG.clearRect(0, 0, W, H);
IG.setFont(F);
try {
PageSize = H / (Height + Leading);
} catch (final Exception e) {
}
}
@Override
public synchronized void paint(final Graphics g) {
if (F == null)
init(getFont());
makeimage();
ListElement e = TopLine;
antialias(true);
int h = Leading + Ascent;
if (Background == null)
Background = getBackground();
IG.setColor(Background);
IG.fillRect(0, 0, W, H);
int lines = 0;
while (lines < PageSize && e != null) {
final Line l = (Line) e.content();
l.draw(IG, 2, h);
h += Leading + Height;
e = e.next();
lines++;
}
g.drawImage(I, 0, 0, this);
}
/**
* Set Anti-Aliasing on or off, if in Java 1.2 or better and the Parameter
* "font.smooth" is switched on.
*
* @param flag
*/
public void antialias(final boolean flag) {
if (Global.getParameter("font.smooth", true)) {
IG = (Graphics2D) IG;
((Graphics2D) IG).setRenderingHint(
RenderingHints.KEY_TEXT_ANTIALIASING,
flag ? RenderingHints.VALUE_TEXT_ANTIALIAS_ON
: RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
}
}
public void showLine(final ListElement line) {
ListElement e = TopLine;
int h = Leading + Ascent;
if (Background == null)
Background = getBackground();
int lines = 0;
while (lines < PageSize && e != null) {
if (e == line)
return;
h += Leading + Height;
e = e.next();
lines++;
}
if (e == line && TopLine.next() != null)
TopLine = TopLine.next();
else
TopLine = line;
}
public ListElement getline(final int y) {
if (TopLine == null)
return null;
ListElement e = TopLine;
int h = Leading + Height;
if (h == 0)
return null;
h = y / h;
for (int i = 0; i < h; i++) {
if (e.next() == null)
return e;
e = e.next();
}
return e;
}
@Override
public void update(final Graphics g) {
paint(g);
}
int computeVertical() {
if (LineCount > 0)
return TopLineCount * 1000 / LineCount;
else
return 0;
}
public int setVertical(final int v) {
if (TopLine == null)
return 0;
final int NewTop = LineCount * v / 1000;
if (NewTop > TopLineCount) {
for (int i = TopLineCount; i < NewTop; i++) {
if (TopLine.next() == null)
break;
TopLine = TopLine.next();
TopLineCount++;
}
repaint();
} else if (NewTop < TopLineCount) {
for (int i = TopLineCount; i > NewTop; i--) {
if (TopLine.previous() == null)
break;
TopLine = TopLine.previous();
TopLineCount--;
}
repaint();
}
LastScrollTime = System.currentTimeMillis();
return v;
}
public void verticalUp() {
if (TopLine == null)
return;
if (TopLine.next() == null)
return;
TopLine = TopLine.next();
TopLineCount++;
repaint();
LastScrollTime = System.currentTimeMillis();
}
public void verticalDown() {
if (TopLine == null)
return;
if (TopLine.previous() == null)
return;
TopLine = TopLine.previous();
TopLineCount--;
repaint();
LastScrollTime = System.currentTimeMillis();
}
public void verticalPageUp() {
if (TopLine == null)
return;
for (int i = 0; i < PageSize - 1; i++) {
if (TopLine.next() == null)
break;
TopLine = TopLine.next();
TopLineCount++;
}
repaint();
LastScrollTime = System.currentTimeMillis();
}
public void verticalPageDown() {
if (TopLine == null)
return;
for (int i = 0; i < PageSize - 1; i++) {
if (TopLine.previous() == null)
break;
TopLine = TopLine.previous();
TopLineCount--;
}
repaint();
LastScrollTime = System.currentTimeMillis();
}
int computeVerticalSize() {
if (LineCount == 0)
return 100;
int h = PageSize * 2000 / LineCount;
if (h < 10)
h = 10;
return h;
}
public int setHorizontal(final int v) {
Offset = v / 5;
repaint();
return v;
}
public void save(final PrintWriter fo) {
ListElement e = L.first();
while (e != null) {
fo.println(new String(((Line) e.content()).a));
e = e.next();
}
}
public TextPosition getposition(final int x, final int y) {
if (L.first() == null)
return null;
if (y < 0)
return new TextPosition(TopLine, TopLineCount, 0);
if (TopLine == null)
return null;
ListElement e = TopLine;
int h = Leading + Height;
if (h == 0)
return null;
h = y / h;
int i;
for (i = 0; i < h; i++) {
if (e.next() == null || i == PageSize - 1)
return new TextPosition(e, TopLineCount + i, ((Line) e
.content()).length());
e = e.next();
}
return new TextPosition(e, TopLineCount + i, ((Line) e.content())
.getpos(x, 2));
}
public void unmark() {
ListElement e = L.first();
while (e != null) {
((Line) e.content()).block(0, Line.NONE);
e = e.next();
}
repaint();
}
public void unmark(final TextPosition Start, final TextPosition End) {
if (Start == null || End == null)
return;
TextPosition P1, P2;
if (Start.before(End)) {
P1 = Start;
P2 = End;
} else if (End.before(Start)) {
P1 = End;
P2 = Start;
} else
return;
ListElement e = P1.L;
while (e != null && e != P2.L) {
((Line) e.content()).block(0, Line.NONE);
e = e.next();
}
if (e != null)
((Line) e.content()).block(0, Line.NONE);
repaint();
}
public void mark(final TextPosition Start, final TextPosition End) {
if (Start == null || End == null)
return;
TextPosition P1, P2;
if (Start.before(End)) {
P1 = Start;
P2 = End;
} else if (End.before(Start)) {
P1 = End;
P2 = Start;
} else
return;
ListElement e = P1.L;
((Line) e.content()).block(P1.LPos, Line.START);
if (e != P2.L)
e = e.next();
while (e != null && e != P2.L) {
((Line) e.content()).block(0, Line.FULL);
e = e.next();
}
if (e != null)
((Line) e.content()).block(P2.LPos, Line.END);
repaint();
requestFocus();
}
void copy(final TextPosition Start, final TextPosition End) {
if (Start == null || End == null)
return;
TextPosition P1, P2;
if (Start.before(End)) {
P1 = Start;
P2 = End;
} else if (End.before(Start)) {
P1 = End;
P2 = Start;
} else
return;
String s = "";
ListElement e = P1.L;
while (e != null && e != P2.L) {
s = s + ((Line) e.content()).getblock() + "\n";
e = e.next();
}
if (e != null)
s = s + ((Line) e.content()).getblock();
new ClipboardCopy(this, this, s);
}
public void showFirst() {
TopLine = L.first();
}
public void lostOwnership(final Clipboard clip, final Transferable cont) {
}
TextPosition lastpos() {
final ListElement e = L.last();
if (e == null)
return null;
final Line l = (Line) e.content();
return new TextPosition(e, LineCount, l.length());
}
public void setTabWidth(final int t) {
TabWidth = t;
}
@Override
public boolean hasFocus() {
return V.hasFocus();
}
@Override
public void setBackground(final Color c) {
Background = c;
super.setBackground(c);
}
public void componentHidden(final ComponentEvent e) {
}
public void componentMoved(final ComponentEvent e) {
}
public void componentResized(final ComponentEvent e) {
V.resized();
}
public void componentShown(final ComponentEvent e) {
}
}

View file

@ -0,0 +1,49 @@
/*
Copyright 2006 Rene Grothmann, modified by Eric Hakenholz
This file is part of C.a.R. software.
C.a.R. is a 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 3 of the License.
C.a.R. 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, see <http://www.gnu.org/licenses/>.
*/
package rene.viewer;
import rene.util.list.ListElement;
class TextPosition {
ListElement L;
int LCount;
int LPos;
public TextPosition(final ListElement l, final int lcount, final int lpos) {
L = l;
LCount = lcount;
LPos = lpos;
}
boolean equal(final TextPosition p) {
return p.LCount == LCount && p.LPos == LPos;
}
boolean before(final TextPosition p) {
return p.LCount > LCount || (p.LCount == LCount && p.LPos > LPos);
}
void oneleft() {
if (LPos > 0)
LPos--;
}
}

339
rene/viewer/Viewer.java Normal file
View file

@ -0,0 +1,339 @@
/*
Copyright 2006 Rene Grothmann, modified by Eric Hakenholz
This file is part of C.a.R. software.
C.a.R. is a 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 3 of the License.
C.a.R. 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, see <http://www.gnu.org/licenses/>.
*/
package rene.viewer;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Frame;
import java.awt.MenuItem;
import java.awt.PopupMenu;
import java.awt.Scrollbar;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.io.PrintWriter;
import eric.JEricPanel;
import rene.gui.Global;
import rene.gui.Panel3D;
/**
* This is a read-only TextArea, removing the memory restriction in some OS's.
* Component usage is like a JPanel. Use appendLine to append a line of text.
* You can give each line a different color. Moreover, you can save the file to
* a PrintWriter. You can mark blocks with the right mouse button. Dragging and
* scrolling is not supported in this version.
*/
public class Viewer extends JEricPanel implements AdjustmentListener,
MouseListener, MouseMotionListener, ActionListener, KeyListener,
WheelListener {
/**
*
*/
private static final long serialVersionUID = 1L;
TextDisplay TD;
Scrollbar Vertical, Horizontal;
TextPosition Start, End;
PopupMenu PM;
int X, Y;
JEricPanel P3D;
public Viewer(final boolean vs, final boolean hs) {
TD = new TextDisplay(this);
setLayout(new BorderLayout());
add("Center", P3D = new Panel3D(TD));
if (vs) {
add("East", Vertical = new Scrollbar(Scrollbar.VERTICAL, 0, 100, 0,
1100));
Vertical.addAdjustmentListener(this);
}
if (hs) {
add("South", Horizontal = new Scrollbar(Scrollbar.HORIZONTAL, 0,
100, 0, 1100));
Horizontal.addAdjustmentListener(this);
}
TD.addMouseListener(this);
TD.addMouseMotionListener(this);
Start = End = null;
PM = new PopupMenu();
MenuItem mi = new MenuItem(Global.name("block.copy", "Copy"));
mi.addActionListener(this);
PM.add(mi);
PM.addSeparator();
mi = new MenuItem(Global.name("block.begin", "Begin Block"));
mi.addActionListener(this);
PM.add(mi);
mi = new MenuItem(Global.name("block.end", "End Block"));
mi.addActionListener(this);
PM.add(mi);
add(PM);
final Wheel W = new Wheel(this);
addMouseWheelListener(W);
}
public Viewer() {
this(true, true);
}
public Viewer(final String dummy) {
}
@Override
public void setFont(final Font f) {
TD.init(f);
}
public void appendLine(final String s) {
TD.appendLine0(s);
}
public void appendLine(final String s, final Color c) {
TD.appendLine0(s, c);
}
public void append(final String s) {
append(s, Color.black);
}
public void append(final String s, final Color c) {
TD.append(s, c);
}
public void doUpdate(final boolean showlast) {
TD.doUpdate(showlast);
setVerticalScrollbar();
}
public void adjustmentValueChanged(final AdjustmentEvent e) {
if (e.getSource() == Vertical) {
switch (e.getAdjustmentType()) {
case AdjustmentEvent.UNIT_INCREMENT:
TD.verticalUp();
break;
case AdjustmentEvent.UNIT_DECREMENT:
TD.verticalDown();
break;
case AdjustmentEvent.BLOCK_INCREMENT:
TD.verticalPageUp();
break;
case AdjustmentEvent.BLOCK_DECREMENT:
TD.verticalPageDown();
break;
default:
final int v = Vertical.getValue();
Vertical.setValue(v);
TD.setVertical(v);
return;
}
setVerticalScrollbar();
} else if (e.getSource() == Horizontal) {
Horizontal.setValue(TD.setHorizontal(Horizontal.getValue()));
}
}
public void setVerticalScrollbar() {
if (Vertical == null)
return;
final int h = TD.computeVerticalSize();
Vertical.setValues(TD.computeVertical(), h, 0, 1000 + h);
}
public void setText(final String S) {
TD.unmark();
Start = End = null;
TD.setText(S);
setVerticalScrollbar();
}
public void save(final PrintWriter fo) {
TD.save(fo);
}
public void appendLine0(final String s) {
TD.appendLine0(s);
}
public void appendLine0(final String s, final Color c) {
TD.appendLine0(s, c);
}
boolean Dragging = false;
public void mouseClicked(final MouseEvent e) {
}
public void mousePressed(final MouseEvent e) {
if (e.isPopupTrigger() || e.isMetaDown()) {
PM.show(e.getComponent(), e.getX(), e.getY());
X = e.getX();
Y = e.getY();
} else {
TD.unmark(Start, End);
Start = TD.getposition(e.getX(), e.getY());
Start.oneleft();
End = null;
}
}
@Override
public Dimension getPreferredSize() {
return new Dimension(150, 200);
}
@Override
public Dimension getMinimumSize() {
return new Dimension(150, 200);
}
public void mouseReleased(final MouseEvent e) {
Dragging = false;
}
public void mouseEntered(final MouseEvent e) {
}
public void mouseExited(final MouseEvent e) {
}
public void mouseMoved(final MouseEvent e) {
}
public void mouseDragged(final MouseEvent e) {
TD.unmark(Start, End);
final TextPosition h = TD.getposition(e.getX(), e.getY());
if (h != null)
End = h;
TD.mark(Start, End);
}
public void actionPerformed(final ActionEvent e) {
final String o = e.getActionCommand();
if (o.equals(Global.name("block.copy", "Copy")))
TD.copy(Start, End);
else if (o.equals(Global.name("block.begin", "Begin Block"))) {
TD.unmark(Start, End);
Start = TD.getposition(X, Y);
Start.oneleft();
if (End == null && TD.L.last() != null) {
End = TD.lastpos();
}
TD.mark(Start, End);
} else if (o.equals(Global.name("block.end", "End Block"))) {
TD.unmark(Start, End);
End = TD.getposition(X, Y);
if (Start == null && TD.L.first() != null) {
Start = new TextPosition(TD.L.first(), 0, 0);
}
TD.mark(Start, End);
}
}
public void keyPressed(final KeyEvent e) {
}
public void keyReleased(final KeyEvent e) {
if (e.isControlDown() && e.getKeyCode() == KeyEvent.VK_C
&& Start != null && End != null) {
TD.copy(Start, End);
}
}
public void keyTyped(final KeyEvent e) {
}
public void setTabWidth(final int t) {
TD.setTabWidth(t);
}
public void showFirst() {
TD.showFirst();
setVerticalScrollbar();
TD.repaint();
}
public void showLast() {
TD.showlast();
setVerticalScrollbar();
TD.repaint();
}
@Override
public boolean hasFocus() {
return false;
}
@Override
public void setBackground(final Color c) {
TD.setBackground(c);
P3D.setBackground(c);
super.setBackground(c);
}
public void up(final int n) {
for (int i = 0; i < n; i++)
TD.verticalUp();
setVerticalScrollbar();
}
public void down(final int n) {
for (int i = 0; i < n; i++)
TD.verticalDown();
setVerticalScrollbar();
}
public void pageUp() {
TD.verticalPageUp();
setVerticalScrollbar();
}
public void pageDown() {
TD.verticalPageDown();
setVerticalScrollbar();
}
public void resized() {
}
public static void main(final String args[]) {
final Frame f = new Frame();
f.setLayout(new BorderLayout());
final Viewer v = new Viewer(true, false);
f.add("Center", v);
f.setSize(300, 300);
f.setVisible(true);
v.append("test test test test test test test");
v.appendLine("test test test test test test test");
v.appendLine("test test test test test test test");
v.appendLine("test test test test test test test");
}
}

48
rene/viewer/Wheel.java Normal file
View file

@ -0,0 +1,48 @@
/*
Copyright 2006 Rene Grothmann, modified by Eric Hakenholz
This file is part of C.a.R. software.
C.a.R. is a 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 3 of the License.
C.a.R. 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, see <http://www.gnu.org/licenses/>.
*/
package rene.viewer;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
class Wheel implements MouseWheelListener {
WheelListener V;
public Wheel(final WheelListener v) {
V = v;
}
public void mouseWheelMoved(final MouseWheelEvent e) {
if (e.getScrollType() == MouseWheelEvent.WHEEL_BLOCK_SCROLL) {
if (e.getWheelRotation() > 0)
V.pageUp();
else
V.pageDown();
} else {
final int n = e.getScrollAmount();
if (e.getWheelRotation() > 0)
V.up(n);
else
V.down(n);
}
}
}

View file

@ -0,0 +1,32 @@
/*
Copyright 2006 Rene Grothmann, modified by Eric Hakenholz
This file is part of C.a.R. software.
C.a.R. is a 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 3 of the License.
C.a.R. 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, see <http://www.gnu.org/licenses/>.
*/
package rene.viewer;
public interface WheelListener {
void up(int n);
void down(int n);
void pageUp();
void pageDown();
}