Skip to content

Commit

Permalink
Version 1.2.1
Browse files Browse the repository at this point in the history
Undo and redo options
 - Ctr+Z for undo
 - Ctr+Y for redo
 - Undo and redo for a text in a TextBox
 - Undo and redo for a page editor and for an element editor
  • Loading branch information
Nikola-Mircic committed Jan 28, 2021
1 parent ab8adad commit 5616a81
Show file tree
Hide file tree
Showing 34 changed files with 762 additions and 361 deletions.
Binary file added release/wpc_v1.2.1.rar
Binary file not shown.
Binary file removed release/wpc_v1.2.rar
Binary file not shown.
4 changes: 2 additions & 2 deletions src/com/nm/elems/Page.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@


public class Page {
public AttributeList attrs;

private String TITLE;
private String pageContent;
private String pageHead;
private String pageLocation;

private AttributeList attrs;

private PageElement body;

private PageLoader pl;
Expand Down
11 changes: 8 additions & 3 deletions src/com/nm/elems/PageElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@
*/

public class PageElement {
public AttributeList attributes;

protected Tag elementTag;
protected AttributeList attributes;
protected List<PageElement> childs;

protected PageElement parentElement;
Expand Down Expand Up @@ -100,7 +101,7 @@ protected Tag generateTag(String tagname) {
return temp;
}

protected void drawContent() {
public void drawContent() {
this.width = Math.max(Integer.parseInt(getAttributeValue("width")),30);
this.height = Math.max(Integer.parseInt(getAttributeValue("height")),20);
this.img = new BufferedImage(scale(this.width), scale(this.height), BufferedImage.TYPE_INT_ARGB);
Expand Down Expand Up @@ -343,9 +344,13 @@ public String getContent() {
public List<Attribute> getAttributes() {
return this.attributes.getAttributes();
}

public AttributeList getAttributesList() {
return this.attributes;
}

public void setAttributes(List<Attribute> attributes) {
this.attributes.setAttributes(attributes);;
this.attributes.setAttributes(attributes);
}

public int getX() {
Expand Down
2 changes: 1 addition & 1 deletion src/com/nm/elems/attribute/AttributeList.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import com.nm.wpc.gui.InputField;

public class AttributeList {
protected List<Attribute> attributes;
public List<Attribute> attributes;

public AttributeList() {
this.attributes = new ArrayList<>();
Expand Down
6 changes: 6 additions & 0 deletions src/com/nm/elems/attribute/PageAttributeList.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ public PageAttributeList() {
@Override
public void setAttributeValue(int index,InputField field) {
String newValue = field.getText();

attributes.get(index).setValue(newValue);
}

@Override
public void setAttributeValue(int index, String newValue) {
attributes.get(index).setValue(newValue);
}
}
27 changes: 25 additions & 2 deletions src/com/nm/elems/elements/TextBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.nm.wpc.gui.InputField;

public class TextBox extends PageElement {
protected String lastSavedData;
protected String textData;
protected int ptLenght;
protected int cursorPos;
Expand All @@ -37,9 +38,14 @@ public class TextBox extends PageElement {
protected String fontFamily;
protected int fontSize;

public boolean isChanged;

public TextBox(String tagname) {
super();
setTextData("");
this.textData = "";
this.lastSavedData = "";

this.isChanged = false;

this.childs = new ArrayList<PageElement>();
this.elementTag = generateTag(tagname);
Expand Down Expand Up @@ -145,6 +151,10 @@ else if(pos == 0)
}

public void addLetter(char c) {
if(!isChanged) {
setLastSavedData(this.textData);
isChanged = true;
}
this.textData = insertChar(this.textData, c, cursorPos);
int len = img.getGraphics().getFontMetrics(new Font(fontFamily, Font.PLAIN, fontSize)).stringWidth(textData);
if(len>=lines*(width-15)) {
Expand All @@ -157,6 +167,10 @@ public void addLetter(char c) {
}

public void removeLetter() {
if(!isChanged) {
setLastSavedData(this.textData);
isChanged = true;
}
if(cursorPos==0)
return;
int len = img.getGraphics().getFontMetrics(new Font(fontFamily, Font.PLAIN, (fontSize))).stringWidth(textData);
Expand Down Expand Up @@ -284,8 +298,9 @@ public String getTextData() {
return textData;
}

public void addTextData(String textData) {
public void loadTextData(String textData) {
this.textData += textData;
this.lastSavedData += textData;
int len = img.getGraphics().getFontMetrics(new Font(fontFamily, Font.PLAIN, (fontSize))).stringWidth(textData);
if(len>=lines*((width)-(fontSize)/2)) {
lines++;
Expand All @@ -299,6 +314,14 @@ public void setTextData(String textData) {
this.textData = textData;
}

public String getLastSavedData() {
return lastSavedData;
}

public void setLastSavedData(String lastSavedData) {
this.lastSavedData = lastSavedData;
}

public int getPtLenght() {
return ptLenght;
}
Expand Down
4 changes: 3 additions & 1 deletion src/com/nm/elems/loader/PageLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.nm.elems.elements.Anchor;
import com.nm.elems.elements.TextBox;
import com.nm.elems.tagsystem.Tag;
import com.nm.wpc.editor.changes.Changes;

/*
* Class: com.nm.elems.loader.PageLoader
Expand Down Expand Up @@ -118,7 +119,7 @@ public Page convertToPage(String source) {
String textData = temp.substring(0,temp.indexOf(tag));
textData = textData.replaceAll("&lt;", "<");
textData = textData.replaceAll("&gt;", ">");
((TextBox)elems.peek()).addTextData(textData);
((TextBox)elems.peek()).loadTextData(textData);
start+=temp.indexOf(tag)+4;
}else if(isCloseTag(tag) && s.peek().equals(tag)) {
s.pop();
Expand All @@ -128,6 +129,7 @@ public Page convertToPage(String source) {
tag=findNextTag(start, source);
}

Changes.clearHistory();
return p;
}

Expand Down
16 changes: 13 additions & 3 deletions src/com/nm/wpc/editor/ElementEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,16 @@

import com.nm.elems.PageElement;
import com.nm.elems.attribute.Attribute;
import com.nm.wpc.gui.*;
import com.nm.wpc.screen.*;
import com.nm.wpc.editor.option.*;
import com.nm.wpc.editor.changes.Changes;
import com.nm.wpc.editor.changes.ElementAttributeChange;
import com.nm.wpc.gui.Button;
import com.nm.wpc.gui.ColorField;
import com.nm.wpc.gui.GUIObject;
import com.nm.wpc.gui.InputField;
import com.nm.wpc.gui.NumberField;
import com.nm.wpc.gui.option.Option;
import com.nm.wpc.screen.InputPanel;
import com.nm.wpc.screen.WorkingScreen;

public class ElementEditor extends Editor{
private static final long serialVersionUID = 1L;
Expand Down Expand Up @@ -182,7 +189,10 @@ public void checkValues() {
for(List<GUIObject> list : toShow) {
for(GUIObject field : list) {
if(!((InputField)field).getText().equals(edited.getAttributeValue(idx))) {
String lastData = edited.getAttributeValue(idx);
edited.setAttributeValue(idx,((InputField)field));
String data = ((InputField)field).getText();
Changes.addChange(ElementAttributeChange.makeChange(this.ws, edited, idx, data, lastData));
((InputField)field).setEditing(false);
}
idx++;
Expand Down
2 changes: 1 addition & 1 deletion src/com/nm/wpc/editor/ElementSelector.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import com.nm.wpc.screen.*;
import com.nm.wpc.gui.*;
import com.nm.elems.tagsystem.*;
import com.nm.wpc.editor.option.*;
import com.nm.wpc.gui.option.*;

public class ElementSelector extends Editor{
private static final long serialVersionUID = 1L;
Expand Down
6 changes: 1 addition & 5 deletions src/com/nm/wpc/editor/OptionsBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@
import java.awt.Graphics;
import java.awt.image.BufferedImage;

import com.nm.wpc.editor.option.ContinueRecentOption;
import com.nm.wpc.editor.option.NewProjectOption;
import com.nm.wpc.editor.option.OpenProjectOption;
import com.nm.wpc.editor.option.Option;
import com.nm.wpc.editor.option.SaveProjectOption;
import com.nm.wpc.gui.option.*;
import com.nm.wpc.gui.Button;
import com.nm.wpc.screen.WorkingScreen;

Expand Down
15 changes: 14 additions & 1 deletion src/com/nm/wpc/editor/PageEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
import java.util.List;

import com.nm.elems.Page;
import com.nm.wpc.editor.option.Option;
import com.nm.wpc.gui.option.Option;
import com.nm.wpc.editor.changes.Changes;
import com.nm.wpc.editor.changes.PageAttributeChange;
import com.nm.wpc.gui.*;
import com.nm.wpc.screen.InputPanel;
import com.nm.wpc.screen.WorkingScreen;
Expand Down Expand Up @@ -91,6 +93,8 @@ private void generateObjects() {
if(!toShow.isEmpty() && page.getAttributes().isEmpty())
return;

System.out.println("Generating new editor!!");

controler.setObjects(new ArrayList<GUIObject>());
toShow = new ArrayList<List<GUIObject>>();
int fWidth=this.width,fHeight=80;
Expand Down Expand Up @@ -163,7 +167,10 @@ public void checkValues() {
for(List<GUIObject> list : toShow) {
for(GUIObject field : list) {
if(!((InputField)field).getText().equals(page.getAttributeValue(idx))) {
String lastData = page.getAttributeValue(idx);
page.setAttributeValue(idx,((InputField)field));
String data = ((InputField)field).getText();
Changes.addChange(PageAttributeChange.makeChange(this.ws, page, idx, data, lastData));
((InputField)field).setEditing(false);
}
idx++;
Expand Down Expand Up @@ -202,6 +209,12 @@ public Page getPage() {
public void setPage(Page page) {
this.page = page;
}

public void setPageAttributes(Page element) {
this.setPage(element);
generateObjects();
drawContent(width, height);
}

public List<List<GUIObject>> getToShow() {
return toShow;
Expand Down
10 changes: 9 additions & 1 deletion src/com/nm/wpc/editor/WorkingPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@
import java.io.IOException;

import com.nm.elems.*;
import com.nm.elems.elements.TextBox;
import com.nm.elems.loader.PageLoader;
import com.nm.wpc.editor.changes.Changes;
import com.nm.wpc.editor.changes.TextChange;
import com.nm.wpc.filesystem.ProjectManager;
import com.nm.wpc.screen.WorkingScreen;

Expand Down Expand Up @@ -125,7 +128,12 @@ public void onMousePressed(int x,int y) {
if(newFocused != null) {
this.ws.createEditor(newFocused);
}


if(this.focused instanceof TextBox && this.focused!=newFocused) {
TextChange c = TextChange.makeChange(ws, ((TextBox)focused), ((TextBox) focused).getTextData(), ((TextBox) focused).getLastSavedData());
Changes.addChange(c);
}

setFocused(newFocused);
}

Expand Down
49 changes: 49 additions & 0 deletions src/com/nm/wpc/editor/changes/Change.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* Copyright 2020 Nikola Mircic
This file is part of Web Page Creator.
Web Page Creator 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, either version 3 of the License, or
(at your option) any later version.
Web Page Creator 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 Web Page Creator. If not, see <https://www.gnu.org/licenses/>.
*/

package com.nm.wpc.editor.changes;

import java.lang.reflect.Field;

import com.nm.wpc.screen.WorkingScreen;

public abstract class Change<T, V>{
protected WorkingScreen ws;
protected T changedObject;
protected V data;
protected V lastData;
protected Field field;

public Change(WorkingScreen ws,T changedObject,String field) {
this.ws = ws;
this.changedObject = changedObject;
if(!field.equals("")) {
try {
this.field = changedObject.getClass().getField(field);
} catch (Exception e) {
e.printStackTrace();
}
}
}

protected abstract void changeData(V data, V lastData);

protected abstract void undo();

protected abstract void redo();
}
Loading

0 comments on commit 5616a81

Please sign in to comment.