Skip to content

Commit

Permalink
Closes #587
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewhorridge committed Nov 29, 2016
1 parent 3932947 commit 617632b
Show file tree
Hide file tree
Showing 12 changed files with 372 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.protege.editor.core.ui.view;

import javax.annotation.Nonnull;
import java.awt.*;

/**
* Matthew Horridge
* Stanford Center for Biomedical Informatics Research
* 28 Nov 2016
*/
public class CloseIcon extends ViewBarIcon {

private static final BasicStroke STROKE = new BasicStroke(2f);

private static final CloseIcon ICON = new CloseIcon();

private CloseIcon() {
}

/**
* Gets the Close View icon.
* @return The Close View icon.
*/
@Nonnull
public static CloseIcon get() {
return ICON;
}

@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
Graphics2D g2 = (Graphics2D) g.create();
g2.setColor(Color.WHITE);
int width = getIconWidth();
int height = getIconHeight();
g2.drawRect(1, 1, width - 2, height - 2);
g2.setStroke(STROKE);
g2.drawLine(4, 4, width - 4, height - 4);
g2.drawLine(4, height - 4, width - 4, 4);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.protege.editor.core.ui.view;

import javax.annotation.Nonnull;
import java.awt.*;

/**
* Matthew Horridge
* Stanford Center for Biomedical Informatics Research
* 28 Nov 2016
*/
public class FloatIcon extends ViewBarIcon {

public static final FloatIcon ICON = new FloatIcon();

private FloatIcon() {
}

/**
* Gets the Float View Icon.
* @return The Float View Icon.
*/
@Nonnull
public static FloatIcon get() {
return ICON;
}

@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
Graphics2D g2 = (Graphics2D) g.create();
g2.setColor(Color.WHITE);
int width = getIconWidth();
int height = getIconHeight();
g2.drawRect(1, 1, width - 2, height - 2);
g2.fillRect(3, 3, width - 6, height - 6);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package org.protege.editor.core.ui.view;

import javax.swing.*;
import java.awt.*;
import java.awt.geom.Rectangle2D;

import static java.awt.RenderingHints.KEY_ANTIALIASING;
import static java.awt.RenderingHints.VALUE_ANTIALIAS_ON;

/**
* Matthew Horridge
* Stanford Center for Biomedical Informatics Research
* 28 Nov 2016
*/
public class HelpIcon extends ViewBarIcon {


private static final String HELP_STRING = "?";

private static final HelpIcon ICON = new HelpIcon();

private final Font font;

public HelpIcon() {
this.font = new Font("Verdana", Font.BOLD, 9);
}

public static HelpIcon get() {
return ICON;
}


@Override
public void paintIcon(Component c, Graphics graphics, int x, int y) {
Graphics2D g2 = (Graphics2D) graphics.create();
g2.setColor(Color.WHITE);
int width = getIconWidth();
int height = getIconHeight();
g2.drawRect(1, 1, width - 2, height - 2);

g2.setFont(font);
g2.setRenderingHint(KEY_ANTIALIASING, VALUE_ANTIALIAS_ON);

FontMetrics fm = g2.getFontMetrics();
Rectangle2D bounds = fm.getStringBounds(HELP_STRING, g2);

float xPos = (float) ((width - bounds.getWidth()) / 2);
int ascent = fm.getAscent();
int descent = fm.getDescent();
float yPos = ((height + 1) / 2 - (ascent + descent) / 2 + ascent - 1);
g2.drawString(HELP_STRING,
xPos,
yPos);
g2.translate(-x, -y);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.protege.editor.core.ui.view;

import javax.swing.*;
import java.awt.*;

import static java.awt.Color.WHITE;
import static java.awt.RenderingHints.KEY_ANTIALIASING;
import static java.awt.RenderingHints.VALUE_ANTIALIAS_ON;

/**
* Matthew Horridge
* Stanford Center for Biomedical Informatics Research
* 28 Nov 2016
*/
public class HorizontalMoreIcon implements Icon {

public static final int DOT_SIZE = 4;

private final int WIDTH = 18;

private final int HEIGHT = 8;

@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
Graphics2D g2 = (Graphics2D) g.create();
g2.setRenderingHint(KEY_ANTIALIASING, VALUE_ANTIALIAS_ON);
g2.setColor(WHITE);
g2.translate(0, HEIGHT / 2 - DOT_SIZE / 2);
g2.fillOval(0, 0, DOT_SIZE, DOT_SIZE);
g2.translate(5, 0);
g2.fillOval(0, 0, DOT_SIZE, DOT_SIZE);
g2.translate(5, 0);
g2.fillOval(0, 0, DOT_SIZE, DOT_SIZE);
}

@Override
public int getIconWidth() {
return WIDTH;
}

@Override
public int getIconHeight() {
return HEIGHT;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.protege.editor.core.ui.view;

import javax.annotation.Nonnull;
import java.awt.*;

/**
* Matthew Horridge
* Stanford Center for Biomedical Informatics Research
* 28 Nov 2016
*/
public class SplitHorizontallyIcon extends ViewBarIcon {

private static final SplitHorizontallyIcon ICON = new SplitHorizontallyIcon();

private SplitHorizontallyIcon() {
}

/**
* Gets the Split Horizontall Icon.
* @return The Split Horizontally Icon.
*/
@Nonnull
public static SplitHorizontallyIcon get() {
return ICON;
}

@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
Graphics2D g2 = (Graphics2D) g.create();
g2.setColor(Color.WHITE);
int width = getIconWidth();
int height = getIconHeight();
g2.drawRect(1, 1, width - 2, height - 2);
g2.drawLine(1, height / 2 - 1, width - 1, height / 2 - 1);
g2.drawLine(1, height / 2 , width - 1, height / 2 );
g2.drawLine(1, height / 2 + 1, width - 1, height / 2 + 1);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.protege.editor.core.ui.view;

import javax.annotation.Nonnull;
import java.awt.*;

/**
* Matthew Horridge
* Stanford Center for Biomedical Informatics Research
* 28 Nov 2016
*/
public class SplitVerticallyIcon extends ViewBarIcon {

private static final SplitVerticallyIcon ICON = new SplitVerticallyIcon();

private SplitVerticallyIcon() {
}

/**
* Gets the Split Vertically Icon.
* @return The Split Vertically Icon.
*/
@Nonnull
public static SplitVerticallyIcon get() {
return ICON;
}

@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
Graphics2D g2 = (Graphics2D) g.create();
g2.setColor(Color.WHITE);
int width = getIconWidth();
int height = getIconHeight();
g2.drawRect(1, 1, width - 2, height - 2);
g2.drawLine(width / 2 - 1, 1, width / 2 - 1, height - 1);
g2.drawLine(width / 2, 1, width / 2, height - 1);
g2.drawLine(width / 2 + 1, 1, width / 2 + 1, height - 1);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.IOException;
import java.util.*;


Expand Down Expand Up @@ -335,40 +336,14 @@ public String getGroupIndex() {

private void addViewManipulationActions() {
// View manipulation toolbar
viewBarComponent.getViewBar().getViewBanner().addAction(new AbstractAction("Split vertically",
Icons.getIcon(
SPLIT_VERTICALLY_ICON_NAME)) {

public void actionPerformed(ActionEvent e) {
splitVertically();
}
});
viewBarComponent.getViewBar().getViewBanner().addAction(new AbstractAction("Split horizontally",
Icons.getIcon(
SPLIT_HORIZONTALLY_ICON_NAME)) {


public void actionPerformed(ActionEvent e) {
splitHorizontally();
}
});
viewBarComponent.getViewBar().getViewBanner().addAction(new AbstractAction("Float",
Icons.getIcon(FLOAT_ICON_NAME)) {

public void actionPerformed(ActionEvent e) {
copyAndFloatView();
}
});
viewBarComponent.getViewBar().getViewBanner().addAction(new AbstractAction("Close",
Icons.getIcon(CLOSE_ICON_NAME)) {

public void actionPerformed(ActionEvent e) {
closeView();
}
});
ViewBanner viewBanner = viewBarComponent.getViewBar().getViewBanner();
plugin.getHelpLink().ifPresent(u -> viewBanner.addAction("Help", HelpIcon.get(), this::showHelpIfPresent));
viewBanner.addAction("Split vertically", SplitVerticallyIcon.get(), this::splitVertically);
viewBanner.addAction("Split horizontally", SplitHorizontallyIcon.get(), this::splitHorizontally);
viewBanner.addAction("Float", FloatIcon.get(), this::copyAndFloatView);
viewBanner.addAction("Close", CloseIcon.get(), this::closeView);
}


private NodePanel getNodePanel() {
return (NodePanel) SwingUtilities.getAncestorOfClass(NodePanel.class, this);
}
Expand Down Expand Up @@ -417,6 +392,18 @@ else if (getParent() instanceof ViewContainer) {
}
}

private void showHelpIfPresent() {
plugin.getHelpLink().ifPresent(l -> {
try {
Desktop.getDesktop().browse(l);
} catch (IOException e1) {
logger.warn("An error occurred whilst navigating to the help for the {} view. URL: {}",
plugin.getLabel(),
l);
}
});
}


private void createContent() {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import org.protege.editor.core.ui.view.button.ViewButtonUI;

import javax.annotation.Nonnull;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.ArrayList;
Expand Down Expand Up @@ -123,23 +125,33 @@ public void removeAllActions() {
toolBar.removeAll();
}

/**
* Adds an action to the view header.
* @param name The name of the action.
* @param icon An icon to display in the view header for the action.
* @param runnable The code that should be called when the action is executed.
*/
public void addAction(@Nonnull String name,
@Nonnull Icon icon,
@Nonnull final Runnable runnable) {
addAction(new AbstractAction(name, icon) {
@Override
public void actionPerformed(ActionEvent e) {
runnable.run();
}
});
}

/**
* Adds an action to the view header.
* @param action The action to be added.
*/
public void addAction(Action action) {
public void addAction(@Nonnull Action action) {
String name = (String) action.getValue(Action.NAME);
action.putValue(Action.NAME, "");
action.putValue(Action.SHORT_DESCRIPTION, name);
JButton button = new JButton(action) {
/**
*
*/
private static final long serialVersionUID = -5577350824168578334L;

public void updateUI() {
// super.updateUI();
}
};
button.setFocusable(false);
Expand Down
Loading

0 comments on commit 617632b

Please sign in to comment.