Skip to content

Commit

Permalink
Merge pull request #313 from afester/modelPackage
Browse files Browse the repository at this point in the history
Move model classes to model package
  • Loading branch information
TomasMikula authored Jun 10, 2016
2 parents 9bb46ac + 0cdaa23 commit 8459717
Show file tree
Hide file tree
Showing 42 changed files with 155 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import org.fxmisc.flowless.VirtualizedScrollPane;
import org.fxmisc.richtext.CodeArea;
import org.fxmisc.richtext.LineNumberFactory;
import org.fxmisc.richtext.StyleSpans;
import org.fxmisc.richtext.StyleSpansBuilder;
import org.fxmisc.richtext.model.StyleSpans;
import org.fxmisc.richtext.model.StyleSpansBuilder;

public class JavaKeywords extends Application {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import org.fxmisc.flowless.VirtualizedScrollPane;
import org.fxmisc.richtext.CodeArea;
import org.fxmisc.richtext.LineNumberFactory;
import org.fxmisc.richtext.StyleSpans;
import org.fxmisc.richtext.StyleSpansBuilder;
import org.fxmisc.richtext.model.StyleSpans;
import org.fxmisc.richtext.model.StyleSpansBuilder;

public class JavaKeywordsAsync extends Application {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

import org.fxmisc.flowless.VirtualizedScrollPane;
import org.fxmisc.richtext.StyleClassedTextArea;
import org.fxmisc.richtext.StyleSpans;
import org.fxmisc.richtext.StyleSpansBuilder;
import org.fxmisc.richtext.model.StyleSpans;
import org.fxmisc.richtext.model.StyleSpansBuilder;

import javafx.application.Application;
import javafx.scene.Scene;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import org.fxmisc.flowless.VirtualizedScrollPane;
import org.fxmisc.richtext.CodeArea;
import org.fxmisc.richtext.LineNumberFactory;
import org.fxmisc.richtext.StyleSpans;
import org.fxmisc.richtext.StyleSpansBuilder;
import org.fxmisc.richtext.model.StyleSpans;
import org.fxmisc.richtext.model.StyleSpansBuilder;

import javafx.application.Application;
import javafx.scene.Scene;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import javafx.scene.paint.Color;
import javafx.scene.text.TextAlignment;

import org.fxmisc.richtext.Codec;
import org.fxmisc.richtext.model.Codec;

/**
* Holds information about the style of a paragraph.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

package org.fxmisc.richtext.demo.richtext;

import static org.fxmisc.richtext.TwoDimensional.Bias.*;
import static org.fxmisc.richtext.model.TwoDimensional.Bias.*;

import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -34,9 +34,9 @@
import javafx.stage.Stage;

import org.fxmisc.flowless.VirtualizedScrollPane;
import org.fxmisc.richtext.Paragraph;
import org.fxmisc.richtext.StyleSpans;
import org.fxmisc.richtext.StyledTextArea;
import org.fxmisc.richtext.model.Paragraph;
import org.fxmisc.richtext.model.StyleSpans;
import org.reactfx.SuspendableNo;

public class RichText extends Application {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import javafx.scene.paint.Color;

import org.fxmisc.richtext.Codec;
import org.fxmisc.richtext.model.Codec;

/**
* Holds information about the style of a text fragment.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
import javafx.scene.input.ClipboardContent;
import javafx.scene.input.DataFormat;

import org.fxmisc.richtext.model.Codec;
import org.fxmisc.richtext.model.EditActions;
import org.fxmisc.richtext.model.ReadOnlyStyledDocument;
import org.fxmisc.richtext.model.StyledDocument;
import org.fxmisc.richtext.model.TextEditingArea;
import org.reactfx.util.Tuple2;

/**
Expand Down
2 changes: 2 additions & 0 deletions richtextfx/src/main/java/org/fxmisc/richtext/CodeArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

import java.util.Collection;

import org.fxmisc.richtext.model.EditableStyledDocument;

/**
* A convenience subclass of {@link StyleClassedTextArea}
* with fixed-width font and an undo manager that observes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package org.fxmisc.richtext;


import org.fxmisc.richtext.model.Codec;
import org.fxmisc.richtext.model.EditableStyledDocument;
import org.fxmisc.richtext.model.SimpleEditableStyledDocument;

import javafx.scene.text.TextFlow;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
import javafx.scene.control.IndexRange;
import javafx.scene.layout.Region;
import javafx.scene.paint.Paint;

import javafx.scene.text.TextFlow;

import org.fxmisc.richtext.model.Paragraph;
import org.fxmisc.richtext.util.MouseStationaryHelper;
import org.reactfx.EventStream;
import org.reactfx.util.Either;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import javafx.scene.shape.PathElement;
import javafx.scene.shape.StrokeLineCap;

import org.fxmisc.richtext.model.Paragraph;
import org.fxmisc.richtext.model.StyledText;
import org.reactfx.value.Val;
import org.reactfx.value.Var;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import java.util.Collection;
import java.util.Collections;

import org.fxmisc.richtext.model.Codec;
import org.fxmisc.richtext.model.EditableStyledDocument;
import org.fxmisc.richtext.model.SimpleEditableStyledDocument;

/**
* Text area that uses style classes to define style of text segments and paragraph segments.
*/
Expand All @@ -17,8 +21,8 @@ public StyleClassedTextArea(EditableStyledDocument<Collection<String>, Collectio
);

setStyleCodecs(
SuperCodec.upCast(SuperCodec.collectionListCodec(Codec.STRING_CODEC)),
SuperCodec.upCast(SuperCodec.collectionListCodec(Codec.STRING_CODEC))
Codec.collectionCodec(Codec.STRING_CODEC),
Codec.collectionCodec(Codec.STRING_CODEC)
);
}
public StyleClassedTextArea(boolean preserveStyle) {
Expand Down
15 changes: 15 additions & 0 deletions richtextfx/src/main/java/org/fxmisc/richtext/StyledTextArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,21 @@
import org.fxmisc.flowless.Virtualized;
import org.fxmisc.flowless.VirtualizedScrollPane;
import org.fxmisc.richtext.CssProperties.EditableProperty;
import org.fxmisc.richtext.model.Codec;
import org.fxmisc.richtext.model.EditActions;
import org.fxmisc.richtext.model.EditableStyledDocument;
import org.fxmisc.richtext.model.NavigationActions;
import org.fxmisc.richtext.model.SimpleEditableStyledDocument;
import org.fxmisc.richtext.model.Paragraph;
import org.fxmisc.richtext.model.PlainTextChange;
import org.fxmisc.richtext.model.RichTextChange;
import org.fxmisc.richtext.model.StyleSpans;
import org.fxmisc.richtext.model.StyledDocument;
import org.fxmisc.richtext.model.StyledTextAreaModel;
import org.fxmisc.richtext.model.TextEditingArea;
import org.fxmisc.richtext.model.TwoDimensional;
import org.fxmisc.richtext.model.TwoLevelNavigator;
import org.fxmisc.richtext.model.UndoActions;
import org.fxmisc.undo.UndoManager;
import org.fxmisc.undo.UndoManagerFactory;
import org.reactfx.EventStream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import static javafx.scene.input.KeyCode.*;
import static javafx.scene.input.KeyCombination.*;
import static org.fxmisc.richtext.TwoDimensional.Bias.*;
import static org.fxmisc.richtext.model.TwoDimensional.Bias.*;
import static org.fxmisc.wellbehaved.event.EventPattern.*;
import static org.fxmisc.wellbehaved.event.template.InputMapTemplate.consume;
import static org.fxmisc.wellbehaved.event.template.InputMapTemplate.sequence;
Expand All @@ -20,12 +20,12 @@
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;

import org.fxmisc.richtext.NavigationActions.SelectionPolicy;
import org.fxmisc.richtext.TwoDimensional.Position;
import org.fxmisc.richtext.model.StyledTextAreaModel;
import org.fxmisc.richtext.model.NavigationActions.SelectionPolicy;
import org.fxmisc.richtext.model.TwoDimensional.Position;
import org.fxmisc.richtext.ParagraphBox.CaretOffsetX;
import org.fxmisc.wellbehaved.event.EventPattern;
import org.fxmisc.wellbehaved.event.template.InputMapTemplate;

import org.reactfx.EventStream;
import org.reactfx.Subscription;
import org.reactfx.value.Val;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package org.fxmisc.richtext;

import static org.fxmisc.richtext.TwoDimensional.Bias.*;
import static org.fxmisc.richtext.model.TwoDimensional.Bias.*;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

import org.fxmisc.richtext.model.TwoLevelNavigator;

import javafx.scene.shape.PathElement;
import javafx.scene.text.TextFlow;
import javafx.scene.shape.LineTo;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package org.fxmisc.richtext;
package org.fxmisc.richtext.model;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -66,6 +65,10 @@ static <T> Codec<List<T>> listCodec(Codec<T> elemCodec) {
return SuperCodec.collectionListCodec(elemCodec);
}

static <T> Codec<Collection<T>> collectionCodec(Codec<T> elemCodec) {
return SuperCodec.upCast(SuperCodec.collectionListCodec(elemCodec));
}

static <T> Codec<Optional<T>> optionalCodec(Codec<T> elemCodec) {
return new Codec<Optional<T>>() {

Expand Down Expand Up @@ -115,47 +118,4 @@ public E decode(DataInputStream is) throws IOException {

};
}
}

interface SuperCodec<S, T extends S> extends Codec<T> {
void encodeSuper(DataOutputStream os, S s) throws IOException;

@Override
default void encode(DataOutputStream os, T t) throws IOException {
encodeSuper(os, t);
}

@SuppressWarnings("unchecked")
static <S, U extends S, T extends U> SuperCodec<S, U> upCast(SuperCodec<S, T> sc) {
return (SuperCodec<S, U>) sc;
}

static <T> SuperCodec<Collection<T>, List<T>> collectionListCodec(Codec<T> elemCodec) {
return new SuperCodec<Collection<T>, List<T>>() {

@Override
public String getName() {
return "list<" + elemCodec.getName() + ">";
}

@Override
public void encodeSuper(DataOutputStream os, Collection<T> col) throws IOException {
os.writeInt(col.size());
for(T t: col) {
elemCodec.encode(os, t);
}
}

@Override
public List<T> decode(DataInputStream is) throws IOException {
int size = is.readInt();
List<T> elems = new ArrayList<>(size);
for(int i = 0; i < size; ++i) {
T t = elemCodec.decode(is);
elems.add(t);
}
return elems;
}
};
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.fxmisc.richtext;
package org.fxmisc.richtext.model;

import javafx.scene.control.IndexRange;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.fxmisc.richtext;
package org.fxmisc.richtext.model;

import javafx.beans.value.ObservableValue;
import javafx.collections.ObservableList;
Expand All @@ -8,7 +8,7 @@
import org.reactfx.value.Val;

/**
* Content model for {@link StyledTextArea}. Implements edit operations
* Content model for {@link org.fxmisc.richtext.StyledTextArea}. Implements edit operations
* on styled text, but not worrying about additional aspects such as
* caret or selection, which are handled by {@link StyledTextAreaModel}.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.fxmisc.richtext;
package org.fxmisc.richtext.model;

import java.text.BreakIterator;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.fxmisc.richtext;
package org.fxmisc.richtext.model;

import static org.fxmisc.richtext.TwoDimensional.Bias.*;
import static org.fxmisc.richtext.model.TwoDimensional.Bias.*;

import java.util.ArrayList;
import java.util.Collections;
Expand All @@ -9,7 +9,7 @@

import javafx.scene.control.IndexRange;

import org.fxmisc.richtext.TwoDimensional.Position;
import org.fxmisc.richtext.model.TwoDimensional.Position;

public final class Paragraph<PS, S> {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.fxmisc.richtext;
package org.fxmisc.richtext.model;


public class PlainTextChange extends TextChange<String, PlainTextChange> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.fxmisc.richtext;
package org.fxmisc.richtext.model;

import static org.reactfx.util.Either.*;
import static org.reactfx.util.Tuples.*;
Expand Down Expand Up @@ -94,7 +94,7 @@ public static <PS, S> ReadOnlyStyledDocument<PS, S> from(StyledDocument<PS, S> d
}
}

static <PS, S> Codec<StyledDocument<PS, S>> codec(Codec<PS> pCodec, Codec<S> tCodec) {
public static <PS, S> Codec<StyledDocument<PS, S>> codec(Codec<PS> pCodec, Codec<S> tCodec) {
return new Codec<StyledDocument<PS, S>>() {
private final Codec<List<Paragraph<PS, S>>> codec = Codec.listCodec(paragraphCodec(pCodec, tCodec));

Expand Down Expand Up @@ -264,7 +264,7 @@ public StyledDocument<PS, S> subSequence(int start, int end) {
return split(end)._1.split(start)._2;
}

Tuple3<ReadOnlyStyledDocument<PS, S>, RichTextChange<PS, S>, MaterializedListModification<Paragraph<PS, S>>> replace(
public Tuple3<ReadOnlyStyledDocument<PS, S>, RichTextChange<PS, S>, MaterializedListModification<Paragraph<PS, S>>> replace(
int from, int to, ReadOnlyStyledDocument<PS, S> replacement) {
return replace(from, to, x -> replacement);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.fxmisc.richtext;
package org.fxmisc.richtext.model;

public class RichTextChange<PS, S> extends TextChange<StyledDocument<PS, S>, RichTextChange<PS, S>> {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.fxmisc.richtext;
package org.fxmisc.richtext.model;

import static org.fxmisc.richtext.TwoDimensional.Bias.*;
import static org.fxmisc.richtext.model.TwoDimensional.Bias.*;

import java.util.ArrayList;
import java.util.Collections;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.fxmisc.richtext;
package org.fxmisc.richtext.model;

import java.util.Objects;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.fxmisc.richtext;
package org.fxmisc.richtext.model;

import static org.fxmisc.richtext.TwoDimensional.Bias.*;
import static org.fxmisc.richtext.model.TwoDimensional.Bias.*;

import java.util.Iterator;
import java.util.Objects;
Expand Down
Loading

0 comments on commit 8459717

Please sign in to comment.