/** * Returns the value for key in dictionary as a string or null if no value * is defined for the key. * * @param dict * Dictionary that contains the key, value pairs. * @param key * Key whose value should be returned. * @return Returns the string value for key in dict. */ public static String getString(Map<String, Object> dict, String key) { return getString(dict, key, null); }
/** * Returns the value for key in dictionary as a string or null if no value * is defined for the key. * * @param dict * Dictionary that contains the key, value pairs. * @param key * Key whose value should be returned. * @return Returns the string value for key in dict. */ public static String getString(Map<String, Object> dict, String key) { return getString(dict, key, null); }
/** * Gets the image path from the given style. If the path is relative (does * not start with a slash) then it is appended to the imageBasePath. */ public String getImageForStyle(Map<String, Object> style) { String filename = mxUtils.getString(style, mxConstants.STYLE_IMAGE); if (filename != null && !filename.startsWith("/") && !filename.startsWith("file:/")) { filename = imageBasePath + filename; } return filename; }
/** * Gets the image path from the given style. If the path is relative (does * not start with a slash) then it is appended to the imageBasePath. */ public String getImageForStyle(Map<String, Object> style) { String filename = mxUtils.getString(style, mxConstants.STYLE_IMAGE); if (filename != null && !filename.startsWith("/") && !filename.startsWith("file:/")) { filename = imageBasePath + filename; } return filename; }
/** * */ public mxIShape getShape(Map<String, Object> style) { String name = mxUtils.getString(style, mxConstants.STYLE_SHAPE, null); mxIShape shape = shapes.get(name); if (shape == null && name != null) { shape = mxStencilRegistry.getStencil(name); } return shape; }
/** * */ public mxIShape getShape(Map<String, Object> style) { String name = mxUtils.getString(style, mxConstants.STYLE_SHAPE, null); mxIShape shape = shapes.get(name); if (shape == null && name != null) { shape = mxStencilRegistry.getStencil(name); } return shape; }
/** * */ public static Font getFont(Map<String, Object> style, double scale) { String fontFamily = getString(style, mxConstants.STYLE_FONTFAMILY, mxConstants.DEFAULT_FONTFAMILY); int fontSize = getInt(style, mxConstants.STYLE_FONTSIZE, mxConstants.DEFAULT_FONTSIZE); int fontStyle = getInt(style, mxConstants.STYLE_FONTSTYLE); int swingFontStyle = ((fontStyle & mxConstants.FONT_BOLD) == mxConstants.FONT_BOLD) ? Font.BOLD : Font.PLAIN; swingFontStyle += ((fontStyle & mxConstants.FONT_ITALIC) == mxConstants.FONT_ITALIC) ? Font.ITALIC : Font.PLAIN; Map<TextAttribute, Integer> fontAttributes = (fontStyle & mxConstants.FONT_UNDERLINE) == mxConstants.FONT_UNDERLINE ? Collections.singletonMap(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON) : null; return new Font(fontFamily, swingFontStyle, (int) (fontSize * scale)).deriveFont(fontAttributes); }
/** * */ public static Font getFont(Map<String, Object> style, double scale) { String fontFamily = getString(style, mxConstants.STYLE_FONTFAMILY, mxConstants.DEFAULT_FONTFAMILY); int fontSize = getInt(style, mxConstants.STYLE_FONTSIZE, mxConstants.DEFAULT_FONTSIZE); int fontStyle = getInt(style, mxConstants.STYLE_FONTSTYLE); int swingFontStyle = ((fontStyle & mxConstants.FONT_BOLD) == mxConstants.FONT_BOLD) ? Font.BOLD : Font.PLAIN; swingFontStyle += ((fontStyle & mxConstants.FONT_ITALIC) == mxConstants.FONT_ITALIC) ? Font.ITALIC : Font.PLAIN; return new Font(fontFamily, swingFontStyle, (int) (fontSize * scale)); }
/** * Returns the image URL for the given cell state. This implementation * returns the value stored under <mxConstants.STYLE_IMAGE> in the cell * style. * * @param state * @return Returns the image associated with the given cell state. */ public String getImage(mxCellState state) { return (state != null && state.getStyle() != null) ? mxUtils.getString( state.getStyle(), mxConstants.STYLE_IMAGE) : null; }
/** * Returns the image URL for the given cell state. This implementation * returns the value stored under <mxConstants.STYLE_IMAGE> in the cell * style. * * @param state * @return Returns the image associated with the given cell state. */ public String getImage(mxCellState state) { return (state != null && state.getStyle() != null) ? mxUtils.getString( state.getStyle(), mxConstants.STYLE_IMAGE) : null; }
/** * */ protected String createHtmlDocument(Map<String, Object> style, String text, int w, int h) { String overflow = mxUtils.getString(style, mxConstants.STYLE_OVERFLOW, ""); if (overflow.equals("fill")) { return mxUtils.createHtmlDocument(style, text, 1, w, null, "height:" + h + "pt;"); } else if (overflow.equals("width")) { return mxUtils.createHtmlDocument(style, text, 1, w); } else { return mxUtils.createHtmlDocument(style, text); } }
/** * */ protected String createHtmlDocument(Map<String, Object> style, String text, int w, int h) { String overflow = mxUtils.getString(style, mxConstants.STYLE_OVERFLOW, ""); if (overflow.equals("fill")) { return mxUtils.createHtmlDocument(style, text, 1, w, null, "height:" + h + "pt;"); } else if (overflow.equals("width")) { return mxUtils.createHtmlDocument(style, text, 1, w); } else { return mxUtils.createHtmlDocument(style, text); } }
@Override public void paintShape( final mxGraphics2DCanvas canvas, final mxCellState state ) { super.paintShape( canvas, state ); final String imgStr = mxUtils.getString( state.getStyle(), mxConstants.STYLE_IMAGE ); if ( imgStr != null ) { final Image img = canvas.loadImage( mxUtils.getString( state.getStyle(), mxConstants.STYLE_IMAGE ) ); if ( img != null ) { final Rectangle bounds = getImageBounds( state ); final int x = bounds.x; final int y = bounds.y; final int w = bounds.width; final int h = bounds.height; if ( h > 0 && w > 0 ) { final Image scaledImage = img.getScaledInstance( w, h, Image.SCALE_FAST ); canvas.getGraphics().drawImage( scaledImage, x, y, null ); } } } }
@Override public void paintShape( final mxGraphics2DCanvas canvas, final mxCellState state ) { super.paintShape( canvas, state ); final String imgStr = mxUtils.getString( state.getStyle(), mxConstants.STYLE_IMAGE ); if ( imgStr != null ) { final Image img = canvas.loadImage( mxUtils.getString( state.getStyle(), mxConstants.STYLE_IMAGE ) ); if ( img != null ) { final Rectangle bounds = getImageBounds( state ); final int x = bounds.x; final int y = bounds.y; final int w = bounds.width; final int h = bounds.height; if ( h > 0 && w > 0 ) { final Image scaledImage = img.getScaledInstance( w, h, Image.SCALE_FAST ); canvas.getGraphics().drawImage( scaledImage, x, y, null ); } } } }
/** * Draws the given lines as segments between all points of the given list * of mxPoints. * * @param pts List of points that define the line. * @param style Style to be used for painting the line. */ public void drawLine(List<mxPoint> pts, Map<String, Object> style) { String strokeColor = mxUtils.getString(style, mxConstants.STYLE_STROKECOLOR); int strokeWidth = (int) (mxUtils.getInt(style, mxConstants.STYLE_STROKEWIDTH, 1) * scale); if (strokeColor != null && strokeWidth > 0) { mxPoint last = pts.get(0); for (int i = 1; i < pts.size(); i++) { mxPoint pt = pts.get(i); drawSegment((int) last.getX(), (int) last.getY(), (int) pt .getX(), (int) pt.getY(), strokeColor, strokeWidth); last = pt; } } }
/** * Returns true if the overflow portion of labels should be hidden. If this * returns true then vertex labels will be clipped to the size of the vertices. * This implementation returns true if <mxConstants.STYLE_OVERFLOW> in the * style of the given cell is "hidden". * * @param cell Cell whose label should be clipped. * @return Returns true if the cell label should be clipped. */ public boolean isLabelClipped(Object cell) { if (!isLabelsClipped()) { mxCellState state = view.getState(cell); Map<String, Object> style = (state != null) ? state.getStyle() : getCellStyle(cell); return (style != null) ? mxUtils.getString(style, mxConstants.STYLE_OVERFLOW, "").equals("hidden") : false; } return isLabelsClipped(); }
/** * Returns true if the overflow portion of labels should be hidden. If this * returns true then vertex labels will be clipped to the size of the vertices. * This implementation returns true if <mxConstants.STYLE_OVERFLOW> in the * style of the given cell is "hidden". * * @param cell Cell whose label should be clipped. * @return Returns true if the cell label should be clipped. */ public boolean isLabelClipped(Object cell) { if (!isLabelsClipped()) { mxCellState state = view.getState(cell); Map<String, Object> style = (state != null) ? state.getStyle() : getCellStyle(cell); return (style != null) ? mxUtils.getString(style, mxConstants.STYLE_OVERFLOW, "").equals("hidden") : false; } return isLabelsClipped(); }
/** * Returns a cell state that represents the source or target terminal or * port for the given edge. */ public mxCellState getTerminalPort(mxCellState state, mxCellState terminal, boolean source) { String key = (source) ? mxConstants.STYLE_SOURCE_PORT : mxConstants.STYLE_TARGET_PORT; String id = mxUtils.getString(state.style, key); if (id != null && graph.getModel() instanceof mxGraphModel) { mxCellState tmp = getState(((mxGraphModel) graph.getModel()) .getCell(id)); // Only uses ports where a cell state exists if (tmp != null) { terminal = tmp; } } return terminal; }
/** * Returns a cell state that represents the source or target terminal or * port for the given edge. */ public mxCellState getTerminalPort(mxCellState state, mxCellState terminal, boolean source) { String key = (source) ? mxConstants.STYLE_SOURCE_PORT : mxConstants.STYLE_TARGET_PORT; String id = mxUtils.getString(state.style, key); if (id != null && graph.getModel() instanceof mxGraphModel) { mxCellState tmp = getState(((mxGraphModel) graph.getModel()) .getCell(id)); // Only uses ports where a cell state exists if (tmp != null) { terminal = tmp; } } return terminal; }
/** * Returns true if the given cell is a swimlane. This implementation always * returns false. * * @param cell Cell that should be checked. * @return Returns true if the cell is a swimlane. */ public boolean isSwimlane(Object cell) { if (cell != null) { if (model.getParent(cell) != model.getRoot()) { mxCellState state = view.getState(cell); Map<String, Object> style = (state != null) ? state.getStyle() : getCellStyle(cell); if (style != null && !model.isEdge(cell)) { return mxUtils .getString(style, mxConstants.STYLE_SHAPE, "") .equals(mxConstants.SHAPE_SWIMLANE); } } } return false; }