Skip to content

Commit

Permalink
Set the font size according to image size.
Browse files Browse the repository at this point in the history
  • Loading branch information
jburel committed Oct 15, 2014
1 parent eedafc3 commit 6eba7b5
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 11 deletions.
Expand Up @@ -27,6 +27,7 @@
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
Expand All @@ -35,6 +36,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
Expand All @@ -47,6 +49,7 @@
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;


//Third-party libraries
import org.jhotdraw.draw.AttributeKey;
import org.jhotdraw.draw.DrawingEditor;
Expand Down Expand Up @@ -210,31 +213,55 @@ private void setUpToggleButton(JToggleButton button)
button.setAction(new DrawingAction(measurementcomponent, button));
button.addMouseListener(this);
}


/** The max plane size.*/
private static final int MAX_SIZE = 512;

private double getDefaultFontSize()
{
int sizeX = model.getSizeX();
int sizeY = model.getSizeY();
double f = ShapeSettingsData.DEFAULT_FONT_SIZE;
if (sizeX <= MAX_SIZE && sizeY <= MAX_SIZE){
return f;
}
double rx = f*(sizeX/MAX_SIZE);
double ry = f*(sizeY/MAX_SIZE);
return Math.floor(Math.max(ry, rx));
}
/** Initializes the component composing the display. */
private void initComponents()
{
showTextButton = new JCheckBox("Show Comment");

lineConnectionProperties = new FigureProperties(
defaultConnectionAttributes);
ellipseTool = new DrawingObjectCreationTool(new MeasureEllipseFigure(
false, true, true, true, true));
rectTool = new DrawingObjectCreationTool(new MeasureRectangleFigure(
false, true, true, true, true));
Map<AttributeKey, Object> p = new HashMap<AttributeKey, Object>();
double value = getDefaultFontSize();
Font font = ROIFigure.DEFAULT_FONT;
font = font.deriveFont((float) value);
p.put(MeasurementAttributes.FONT_SIZE, value);
p.put(MeasurementAttributes.FONT_FACE, font);
Map<AttributeKey, Object> pl = new HashMap<AttributeKey, Object>();
pl.put(MeasurementAttributes.FONT_SIZE, value);
ellipseTool = new DrawingObjectCreationTool(
new MeasureEllipseFigure(false, true, true, true, true), p);
rectTool = new DrawingObjectCreationTool(
new MeasureRectangleFigure(false, true, true, true, true), p);
textTool = new DrawingObjectCreationTool(
new MeasureTextFigure(false, true));
new MeasureTextFigure(false, true), p);
lineTool = new DrawingObjectCreationTool(
new MeasureLineFigure(false, true, true, true, true));
new MeasureLineFigure(false, true, true, true, true), pl);
Map<AttributeKey, Object> m = lineConnectionProperties.getProperties();
m.put(MeasurementAttributes.FONT_SIZE, value);
connectionTool = new DrawingConnectionTool(
new MeasureLineConnectionFigure(),
lineConnectionProperties.getProperties());
new MeasureLineConnectionFigure(), m);
pointTool = new DrawingPointCreationTool(
new MeasurePointFigure(false, true, true, true, true));
polygonTool = new DrawingBezierTool(
new MeasureBezierFigure(true, false, true, true, true, true));
new MeasureBezierFigure(true, false, true, true, true, true), pl);
polylineTool = new DrawingBezierTool(
new MeasureBezierFigure(false, false, true, true, true, true));
new MeasureBezierFigure(false, false, true, true, true, true), pl);

Component component;

Expand Down
Expand Up @@ -35,6 +35,7 @@
import javax.swing.undo.CannotRedoException;
import javax.swing.undo.CannotUndoException;


//Third-party libraries
import org.jhotdraw.draw.AbstractTool;
import org.jhotdraw.draw.AttributeKey;
Expand All @@ -47,6 +48,7 @@
import org.jhotdraw.geom.Geom;
import org.jhotdraw.util.ResourceBundleUtil;

import org.openmicroscopy.shoola.util.roi.model.annotation.MeasurementAttributes;
//Application-internal dependencies
import org.openmicroscopy.shoola.util.ui.drawingtools.figures.BezierTextFigure;

Expand Down Expand Up @@ -141,7 +143,10 @@ public void mousePressed(MouseEvent evt) {
getView().getConstrainer().constrainPoint(
getView().viewToDrawing(anchor)
)));
//work around since the font size is reset when the figure is added.
Object s = createdFigure.getAttribute(MeasurementAttributes.FONT_SIZE);
getDrawing().add(createdFigure);
createdFigure.setAttribute(MeasurementAttributes.FONT_SIZE, s);

nodeCountBeforeDrag = createdFigure.getNodeCount();
} else {
Expand Down
Expand Up @@ -38,6 +38,7 @@
import javax.swing.undo.CannotRedoException;
import javax.swing.undo.CannotUndoException;


//Third-party libraries
import org.jhotdraw.draw.AbstractTool;
import org.jhotdraw.draw.AttributeKey;
Expand All @@ -46,6 +47,7 @@
import org.jhotdraw.draw.DrawingEditor;
import org.jhotdraw.draw.Figure;
import org.jhotdraw.util.ResourceBundleUtil;
import org.openmicroscopy.shoola.util.roi.model.annotation.MeasurementAttributes;

//Application-internal dependencies

Expand Down Expand Up @@ -250,7 +252,10 @@ public void mousePressed(MouseEvent evt)
anchor.x = evt.getX();
anchor.y = evt.getY();
createdFigure.setBounds(p, p);
//work around since the font size is reset when the figure is added.
Object s = createdFigure.getAttribute(MeasurementAttributes.FONT_SIZE);
getDrawing().add(createdFigure);
createdFigure.setAttribute(MeasurementAttributes.FONT_SIZE, s);
}

/**
Expand Down

0 comments on commit 6eba7b5

Please sign in to comment.