Refactor EmphasizeAwareLabel as HighlightableLabel

This commit is contained in:
robin shine 2016-12-15 21:20:01 +08:00
parent 919c929aba
commit db17dfff7e
9 changed files with 1577 additions and 20 deletions

View File

@ -9,7 +9,7 @@ import org.apache.wicket.request.resource.ResourceReference;
import com.gitplex.commons.lang.extractors.TokenPosition; import com.gitplex.commons.lang.extractors.TokenPosition;
import com.gitplex.commons.lang.extractors.java.icons.Icons; import com.gitplex.commons.lang.extractors.java.icons.Icons;
import com.gitplex.commons.util.Range; import com.gitplex.commons.util.Range;
import com.gitplex.commons.wicket.component.EmphasizeAwareLabel; import com.gitplex.commons.wicket.component.HighlightableLabel;
public class CompilationUnit extends JavaSymbol { public class CompilationUnit extends JavaSymbol {
@ -34,7 +34,7 @@ public class CompilationUnit extends JavaSymbol {
@Override @Override
public Component render(String componentId, Range matchRange) { public Component render(String componentId, Range matchRange) {
return new EmphasizeAwareLabel(componentId, packageName, matchRange); return new HighlightableLabel(componentId, packageName, matchRange);
} }
@Override @Override

View File

@ -4,7 +4,7 @@ import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.panel.Panel; import org.apache.wicket.markup.html.panel.Panel;
import com.gitplex.commons.util.Range; import com.gitplex.commons.util.Range;
import com.gitplex.commons.wicket.component.EmphasizeAwareLabel; import com.gitplex.commons.wicket.component.HighlightableLabel;
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class FieldDefPanel extends Panel { public class FieldDefPanel extends Panel {
@ -23,7 +23,7 @@ public class FieldDefPanel extends Panel {
protected void onInitialize() { protected void onInitialize() {
super.onInitialize(); super.onInitialize();
add(new EmphasizeAwareLabel("name", fieldDef.getName(), matchRange)); add(new HighlightableLabel("name", fieldDef.getName(), matchRange));
add(new Label("type", fieldDef.getType()).setVisible(fieldDef.getType()!=null)); add(new Label("type", fieldDef.getType()).setVisible(fieldDef.getType()!=null));
} }

View File

@ -4,7 +4,7 @@ import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.panel.Panel; import org.apache.wicket.markup.html.panel.Panel;
import com.gitplex.commons.util.Range; import com.gitplex.commons.util.Range;
import com.gitplex.commons.wicket.component.EmphasizeAwareLabel; import com.gitplex.commons.wicket.component.HighlightableLabel;
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class MethodDefPanel extends Panel { public class MethodDefPanel extends Panel {
@ -23,7 +23,7 @@ public class MethodDefPanel extends Panel {
protected void onInitialize() { protected void onInitialize() {
super.onInitialize(); super.onInitialize();
add(new EmphasizeAwareLabel("name", methodDef.getName(), matchRange)); add(new HighlightableLabel("name", methodDef.getName(), matchRange));
add(new Label("params", methodDef.getParams())); add(new Label("params", methodDef.getParams()));
add(new Label("type", methodDef.getType()).setVisible(methodDef.getType()!=null)); add(new Label("type", methodDef.getType()).setVisible(methodDef.getType()!=null));
} }

View File

@ -12,7 +12,7 @@ import com.gitplex.commons.lang.extractors.Symbol;
import com.gitplex.commons.lang.extractors.TokenPosition; import com.gitplex.commons.lang.extractors.TokenPosition;
import com.gitplex.commons.lang.extractors.java.icons.Icons; import com.gitplex.commons.lang.extractors.java.icons.Icons;
import com.gitplex.commons.util.Range; import com.gitplex.commons.util.Range;
import com.gitplex.commons.wicket.component.EmphasizeAwareLabel; import com.gitplex.commons.wicket.component.HighlightableLabel;
public class TypeDef extends JavaSymbol { public class TypeDef extends JavaSymbol {
@ -45,7 +45,7 @@ public class TypeDef extends JavaSymbol {
@Override @Override
public Component render(String componentId, Range matchRange) { public Component render(String componentId, Range matchRange) {
return new EmphasizeAwareLabel(componentId, getName(), matchRange); return new HighlightableLabel(componentId, getName(), matchRange);
} }
public String getPackageName() { public String getPackageName() {

File diff suppressed because it is too large Load Diff

View File

@ -9,18 +9,18 @@ import com.gitplex.commons.util.Range;
import com.gitplex.commons.util.StringUtils; import com.gitplex.commons.util.StringUtils;
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class EmphasizeAwareLabel extends Label { public class HighlightableLabel extends Label {
public EmphasizeAwareLabel(String id, @Nullable String label, @Nullable Range emphasize) { public HighlightableLabel(String id, @Nullable String label, @Nullable Range highlight) {
super(id, new LoadableDetachableModel<String>() { super(id, new LoadableDetachableModel<String>() {
@Override @Override
protected String load() { protected String load() {
if (label != null) { if (label != null) {
if (emphasize != null) { if (highlight != null) {
String prefix = label.substring(0, emphasize.getFrom()); String prefix = label.substring(0, highlight.getFrom());
String middle = label.substring(emphasize.getFrom(), emphasize.getTo()); String middle = label.substring(highlight.getFrom(), highlight.getTo());
String suffix = label.substring(emphasize.getTo()); String suffix = label.substring(highlight.getTo());
return StringUtils.escapeHtml(prefix) return StringUtils.escapeHtml(prefix)
+ "<b>" + "<b>"
+ StringUtils.escapeHtml(middle) + StringUtils.escapeHtml(middle)

View File

@ -8,7 +8,7 @@ import org.apache.wicket.request.resource.PackageResourceReference;
import org.apache.wicket.request.resource.ResourceReference; import org.apache.wicket.request.resource.ResourceReference;
import com.gitplex.commons.util.Range; import com.gitplex.commons.util.Range;
import com.gitplex.commons.wicket.component.EmphasizeAwareLabel; import com.gitplex.commons.wicket.component.HighlightableLabel;
public class FileHit extends QueryHit { public class FileHit extends QueryHit {
@ -32,7 +32,7 @@ public class FileHit extends QueryHit {
if (fileName.contains("/")) if (fileName.contains("/"))
fileName = StringUtils.substringAfterLast(fileName, "/"); fileName = StringUtils.substringAfterLast(fileName, "/");
return new EmphasizeAwareLabel(componentId, fileName, matchRange); return new HighlightableLabel(componentId, fileName, matchRange);
} }
@Override @Override

View File

@ -7,7 +7,7 @@ import org.apache.wicket.request.resource.ResourceReference;
import com.gitplex.commons.lang.extractors.TokenPosition; import com.gitplex.commons.lang.extractors.TokenPosition;
import com.gitplex.commons.util.Range; import com.gitplex.commons.util.Range;
import com.gitplex.commons.wicket.component.EmphasizeAwareLabel; import com.gitplex.commons.wicket.component.HighlightableLabel;
public class TextHit extends QueryHit { public class TextHit extends QueryHit {
@ -38,7 +38,7 @@ public class TextHit extends QueryHit {
@Override @Override
public Component render(String componentId) { public Component render(String componentId) {
return new EmphasizeAwareLabel(componentId, lineContent, getTokenPos().getRange()); return new HighlightableLabel(componentId, lineContent, getTokenPos().getRange());
} }
@Override @Override

View File

@ -33,7 +33,7 @@ import com.gitplex.server.search.hit.TextHit;
import com.gitplex.server.web.component.depotfile.blobview.BlobViewContext; import com.gitplex.server.web.component.depotfile.blobview.BlobViewContext;
import com.gitplex.server.web.page.depot.file.DepotFilePage; import com.gitplex.server.web.page.depot.file.DepotFilePage;
import com.gitplex.commons.git.BlobIdent; import com.gitplex.commons.git.BlobIdent;
import com.gitplex.commons.wicket.component.EmphasizeAwareLabel; import com.gitplex.commons.wicket.component.HighlightableLabel;
import com.gitplex.commons.wicket.component.PreventDefaultAjaxLink; import com.gitplex.commons.wicket.component.PreventDefaultAjaxLink;
@SuppressWarnings("serial") @SuppressWarnings("serial")
@ -400,7 +400,7 @@ public abstract class SearchResultPanel extends Panel {
super.onInitialize(); super.onInitialize();
String blobPath = blobItem.getModelObject().getBlobPath(); String blobPath = blobItem.getModelObject().getBlobPath();
add(new EmphasizeAwareLabel("label", blobPath, blobItem.getModelObject().getMatchRange())); add(new HighlightableLabel("label", blobPath, blobItem.getModelObject().getMatchRange()));
if (activeBlobIndex == blobItem.getIndex() && activeHitIndex == -1) if (activeBlobIndex == blobItem.getIndex() && activeHitIndex == -1)
add(AttributeAppender.append("class", " active")); add(AttributeAppender.append("class", " active"));