]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.graphviz/src/org/simantics/graphviz/internal/xdot/SetStyle.java
Merge "Fix column width issues on HiDPI displays. KeyTiSelection fixes."
[simantics/platform.git] / bundles / org.simantics.graphviz / src / org / simantics / graphviz / internal / xdot / SetStyle.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.graphviz.internal.xdot;
13
14 import java.awt.BasicStroke;
15 import java.awt.Graphics2D;
16
17 public class SetStyle implements DrawCommand {
18
19     private static final BasicStroke SOLID = new BasicStroke(1f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 10.0f, null, 0.0f);
20     private static final BasicStroke DASHED = new BasicStroke(1f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 10.0f, new float[] {5f, 5f}, 0.0f);
21     private static final BasicStroke DOTTED = new BasicStroke(1f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 10.0f, new float[] {0f, 2f}, 0.0f);
22     
23     String styleName;
24     
25         public SetStyle(String styleName) {
26             this.styleName = styleName;
27         }
28
29         @Override
30         public void draw(Graphics2D g) {
31                 if(styleName.equals("solid"))
32                     g.setStroke(SOLID);
33                 else if(styleName.equals("dashed"))
34                     g.setStroke(DASHED);
35                 else if(styleName.equals("dotted"))
36             g.setStroke(DOTTED);
37                 else if(styleName.startsWith("setlinewidth(")) {
38                     double w = Double.parseDouble(styleName.substring(13, styleName.length()-1));
39                     g.setStroke(new BasicStroke((float)w, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 10.0f, ((BasicStroke)g.getStroke()).getDashArray(), 0.0f));
40                 }
41                 else
42                     System.out.println("Unknown style: " + styleName);
43         }
44
45 }