Skip to content

Commit

Permalink
Merge branch 'release/0.6.3'
Browse files Browse the repository at this point in the history
* release/0.6.3:
  0.6.3
  Logging type system loading errors
  fixed file name variable
  log viewer is now scrollable
  Search results are now underlined
  set java version 1.8
  Checking if file exists before trying to load it
  log window view view menu
  log location is now in home directory
  various log and error messages
  for testing, print all log messages
  Test main to use test logging config
  renamed file
  added logging configuration files for test and main
  set java version 1.8
  added log4j2 dependencies
  Loading of external type system via GUI
  0.6.3-SNAPSHOT

# Conflicts:
#	pom.xml
  • Loading branch information
nilsreiter committed Dec 16, 2016
2 parents fc96057 + bc4db7f commit 282f2d5
Show file tree
Hide file tree
Showing 7 changed files with 282 additions and 31 deletions.
21 changes: 15 additions & 6 deletions pom.xml
@@ -1,18 +1,17 @@
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>de.unistuttgart.ims</groupId>
<artifactId>annotationviewer</artifactId>
<version>0.6.2</version>
<version>0.6.3</version>
<packaging>jar</packaging>
<name>SimpleXmiViewer</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<version.dkpro>1.8.0</version.dkpro>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<build>
<plugins>
Expand Down Expand Up @@ -131,5 +130,15 @@
<artifactId>commons</artifactId>
<version>0.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.3</version>
</dependency>
</dependencies>
</project>
103 changes: 101 additions & 2 deletions src/main/java/de/unistuttgart/ims/annotationviewer/SearchPanel.java
@@ -1,9 +1,14 @@
package de.unistuttgart.ims.annotationviewer;

import java.awt.BasicStroke;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.event.ActionEvent;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
Expand All @@ -30,13 +35,16 @@
import javax.swing.text.BadLocationException;
import javax.swing.text.DefaultHighlighter;
import javax.swing.text.Highlighter;
import javax.swing.text.JTextComponent;
import javax.swing.text.Position;
import javax.swing.text.View;

import org.apache.commons.configuration2.Configuration;

import de.unistuttgart.ims.commons.Counter;

public class SearchPanel extends JFrame implements DocumentListener, ListSelectionListener, WindowListener {
final static Color HILIT_COLOR = Color.PINK;
final static Color HILIT_COLOR = Color.black;

private static final long serialVersionUID = 1L;
Highlighter hilit;
Expand All @@ -58,7 +66,8 @@ public SearchPanel(XmiDocumentWindow xdw, Configuration configuration) {
text = xdw.getViewer().getTextPane().getText();

hilit = new DefaultHighlighter();
painter = new DefaultHighlighter.DefaultHighlightPainter(HILIT_COLOR);
painter = new UnderlinePainter(HILIT_COLOR);// new
// DefaultHighlighter.DefaultHighlightPainter(HILIT_COLOR);
xdw.getViewer().getTextPane().setHighlighter(hilit);

lm = new DefaultListModel<SearchResult>();
Expand Down Expand Up @@ -91,27 +100,33 @@ public JPanel createSearchPanel() {
return searchPanel;
}

@Override
public void insertUpdate(DocumentEvent e) {
try {
Pattern.compile(textField.getText());
search(textField.getText());
} catch (PatternSyntaxException ex) {
SimpleXmiViewer.logger.trace(ex.getMessage());
}
}

@Override
public void removeUpdate(DocumentEvent e) {
try {
Pattern.compile(textField.getText());
search(textField.getText());
} catch (PatternSyntaxException ex) {
SimpleXmiViewer.logger.trace(ex.getMessage());
}
}

@Override
public void changedUpdate(DocumentEvent e) {
try {
Pattern.compile(textField.getText());
search(textField.getText());
} catch (PatternSyntaxException ex) {
SimpleXmiViewer.logger.trace(ex.getMessage());
}
}

Expand Down Expand Up @@ -147,6 +162,7 @@ public void search(String s) {
pack();
}

@Override
public void valueChanged(ListSelectionEvent e) {

SearchResult result = lm.getElementAt(((ListSelectionModel) e.getSource()).getMinSelectionIndex());
Expand Down Expand Up @@ -186,6 +202,7 @@ public SearchResultRenderer() {
centerFont = new Font(Font.SANS_SERIF, Font.BOLD, 13);
}

@Override
public Component getListCellRendererComponent(JList<? extends SearchResult> list, SearchResult value, int index,
boolean isSelected, boolean cellHasFocus) {

Expand Down Expand Up @@ -224,6 +241,7 @@ public ShowHistogramAction(Counter<String> c) {
counter = c;
}

@Override
public void actionPerformed(ActionEvent e) {
String[] keys = counter.keySet().toArray(new String[counter.keySet().size()]);
double[] values = new double[keys.length];
Expand All @@ -241,10 +259,12 @@ public void actionPerformed(ActionEvent e) {
}
}

@Override
public void windowOpened(WindowEvent e) {

}

@Override
public void windowClosing(WindowEvent e) {
if (chartFrame != null) {
chartFrame.setVisible(false);
Expand All @@ -254,27 +274,106 @@ public void windowClosing(WindowEvent e) {

}

@Override
public void windowClosed(WindowEvent e) {

}

@Override
public void windowIconified(WindowEvent e) {
// TODO Auto-generated method stub

}

@Override
public void windowDeiconified(WindowEvent e) {
// TODO Auto-generated method stub

}

@Override
public void windowActivated(WindowEvent e) {
// TODO Auto-generated method stub

}

@Override
public void windowDeactivated(WindowEvent e) {
// TODO Auto-generated method stub

}

class UnderlinePainter extends DefaultHighlighter.DefaultHighlightPainter {
public UnderlinePainter(Color color) {
super(color);
}

/**
* Paints a portion of a highlight.
*
* @param g
* the graphics context
* @param offs0
* the starting model offset >= 0
* @param offs1
* the ending model offset >= offs1
* @param bounds
* the bounding box of the view, which is not necessarily the
* region to paint.
* @param c
* the editor
* @param view
* View painting for
* @return region drawing occured in
*/
@Override
public Shape paintLayer(Graphics g, int offs0, int offs1, Shape bounds, JTextComponent c, View view) {
Rectangle r = getDrawingArea(offs0, offs1, bounds, view);

Graphics2D g2 = (Graphics2D) g;

if (r == null)
return null;

// Do your custom painting
Color color = getColor();
g.setColor(color == null ? c.getSelectionColor() : color);

g2.setStroke(new BasicStroke(3));
g2.drawLine(r.x, r.y + r.height, r.x + r.width, r.y + r.height);

return r;
}

private Rectangle getDrawingArea(int offs0, int offs1, Shape bounds, View view) {
// Contained in view, can just use bounds.

if (offs0 == view.getStartOffset() && offs1 == view.getEndOffset()) {
Rectangle alloc;

if (bounds instanceof Rectangle) {
alloc = (Rectangle) bounds;
} else {
alloc = bounds.getBounds();
}

return alloc;
} else {
// Should only render part of View.
try {
// --- determine locations ---
Shape shape = view.modelToView(offs0, Position.Bias.Forward, offs1, Position.Bias.Backward, bounds);
Rectangle r = (shape instanceof Rectangle) ? (Rectangle) shape : shape.getBounds();

return r;
} catch (BadLocationException e) {
// can't render
}
}

// Can't render

return null;
}
}
}

0 comments on commit 282f2d5

Please sign in to comment.