X-Git-Url: http://www2.svjatoslav.eu/gitweb/?p=sixth-3d.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Fsixth%2Fe3d%2Fgui%2FtextEditorComponent%2FTextEditComponent.java;h=93c05359c3e1086eeed6fcf483aa53034bc59807;hp=9ee9109804c0b98288de5307b8b35fe771159e76;hb=d571801d69962883e194a306ee2b7110d6adc270;hpb=6d38211af83d15953f406f6a6e30f5fa5fc81591 diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/gui/textEditorComponent/TextEditComponent.java b/src/main/java/eu/svjatoslav/sixth/e3d/gui/textEditorComponent/TextEditComponent.java index 9ee9109..93c0535 100755 --- a/src/main/java/eu/svjatoslav/sixth/e3d/gui/textEditorComponent/TextEditComponent.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/gui/textEditorComponent/TextEditComponent.java @@ -10,7 +10,6 @@ import eu.svjatoslav.sixth.e3d.gui.TextPointer; import eu.svjatoslav.sixth.e3d.gui.ViewPanel; import eu.svjatoslav.sixth.e3d.gui.humaninput.KeyboardHelper; import eu.svjatoslav.sixth.e3d.math.Transform; -import eu.svjatoslav.sixth.e3d.renderer.raster.Color; import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.textcanvas.TextCanvas; import java.awt.*; @@ -36,20 +35,23 @@ public class TextEditComponent extends GuiComponent implements ClipboardOwner { public TextPointer selectionEnd = new TextPointer(0, 0); public TextPointer cursorLocation = new TextPointer(0, 0); Page page = new Page(); - ColorConfig colorConfig = new ColorConfig(); + LookAndFeel lookAndFeel; boolean repaintPage = false; public TextEditComponent(final Transform transform, - final ViewPanel viewPanel, final Point2D sizeInWorldCoordinates) { + final ViewPanel viewPanel, + final Point2D sizeInWorldCoordinates, + LookAndFeel lookAndFeel) { super(transform, viewPanel, sizeInWorldCoordinates.to3D()); - // initialize visual panel - + this.lookAndFeel = lookAndFeel; final int columns = (int) (sizeInWorldCoordinates.x / TextCanvas.FONT_CHAR_WIDTH); final int rows = (int) (sizeInWorldCoordinates.y / TextCanvas.FONT_CHAR_HEIGHT); - textCanvas = new TextCanvas(new Transform(), new TextPointer(rows, - columns), Color.WHITE, colorConfig.normalBack); + textCanvas = new TextCanvas( + new Transform(), + new TextPointer(rows, columns), + lookAndFeel.foreground, lookAndFeel.background); textCanvas.setMouseInteractionController(this); @@ -495,7 +497,7 @@ public class TextEditComponent extends GuiComponent implements ClipboardOwner { identSelection: { - // check that identation is possible + // check that indentation is possible for (int y = selectionStart.row; y < selectionEnd.row; y++) { final TextLine textLine = page.getLine(y); @@ -535,44 +537,44 @@ public class TextEditComponent extends GuiComponent implements ClipboardOwner { public void repaintPage() { - final int chXe = textCanvas.getSize().column + 2; - final int chYe = textCanvas.getSize().row + 2; + final int columnCount = textCanvas.getSize().column + 2; + final int rowCount = textCanvas.getSize().row + 2; - for (int cy = 0; cy < chYe; cy++) - for (int cx = 0; cx < chXe; cx++) { - final boolean isTabMargin = ((cx + scrolledCharacters) % 4) == 0; + for (int row = 0; row < rowCount; row++) + for (int column = 0; column < columnCount; column++) { + final boolean isTabMargin = ((column + scrolledCharacters) % 4) == 0; - if ((cx == (cursorLocation.column - scrolledCharacters)) - & (cy == (cursorLocation.row - scrolledLines))) { + if ((column == (cursorLocation.column - scrolledCharacters)) + & (row == (cursorLocation.row - scrolledLines))) { // cursor - textCanvas.setBackgroundColor(colorConfig.cursorBack); - textCanvas.setForegroundColor(colorConfig.cursorText); - } else if (new TextPointer(cy + scrolledLines, cx).isBetween( + textCanvas.setBackgroundColor(lookAndFeel.cursorBackground); + textCanvas.setForegroundColor(lookAndFeel.cursorForeground); + } else if (new TextPointer(row + scrolledLines, column).isBetween( selectionStart, selectionEnd)) { // selected text - textCanvas.setBackgroundColor(colorConfig.selectedBack); - textCanvas.setForegroundColor(colorConfig.selectedText); + textCanvas.setBackgroundColor(lookAndFeel.selectionBackground); + textCanvas.setForegroundColor(lookAndFeel.selectionForeground); } else { // normal text - textCanvas.setBackgroundColor(colorConfig.normalBack); - textCanvas.setForegroundColor(colorConfig.normalText); + textCanvas.setBackgroundColor(lookAndFeel.background); + textCanvas.setForegroundColor(lookAndFeel.foreground); if (isTabMargin) textCanvas - .setBackgroundColor(colorConfig.tabulatorBack); + .setBackgroundColor(lookAndFeel.tabStopBackground); } - final char charUnderCursor = page.getChar(cy + scrolledLines, - cx + scrolledCharacters); + final char charUnderCursor = page.getChar(row + scrolledLines, + column + scrolledCharacters); - textCanvas.putChar(cy, cx, charUnderCursor); + textCanvas.putChar(row, column, charUnderCursor); } } public void repaintRow(final int rowNumber) { - // TODO: fix this + // TODO: Optimize this. No need to repaint entire page. repaintPage(); }