| 1 |
/** |
| 2 |
* Copyright (c) 2013-2016 Jens Deters http://www.jensd.de |
| 3 |
* |
| 4 |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 5 |
* use this file except in compliance with the License. You may obtain a copy of |
| 6 |
* the License at |
| 7 |
* |
| 8 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
* |
| 10 |
* Unless required by applicable law or agreed to in writing, software |
| 11 |
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 |
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 |
* License for the specific language governing permissions and limitations under |
| 14 |
* the License. |
| 15 |
* |
| 16 |
*/ |
| 17 |
package de.jensd.fx.glyphs.materialicons; |
| 18 |
|
| 19 |
import de.jensd.fx.glyphs.GlyphIcon; |
| 20 |
import java.io.IOException; |
| 21 |
import java.util.logging.Level; |
| 22 |
import java.util.logging.Logger; |
| 23 |
import javafx.scene.text.Font; |
| 24 |
|
| 25 |
/** |
| 26 |
* |
| 27 |
* @author Jens Deters ([email protected]) |
| 28 |
*/ |
| 29 |
public class MaterialIconView extends GlyphIcon<MaterialIcon> { |
| 30 |
|
| 31 |
public final static String TTF_PATH = "/de/jensd/fx/glyphs/materialicons/MaterialIcons-Regular.ttf"; |
| 32 |
|
| 33 |
static { |
| 34 |
try { |
| 35 |
Font.loadFont(MaterialIconView.class.getResource(TTF_PATH).openStream(), 10.0d); |
| 36 |
} catch (IOException ex) { |
| 37 |
Logger.getLogger(MaterialIconView.class.getName()).log(Level.SEVERE, null, ex); |
| 38 |
} |
| 39 |
|
| 40 |
} |
| 41 |
|
| 42 |
public MaterialIconView(MaterialIcon icon, String iconSize) { |
| 43 |
super(MaterialIcon.class); |
| 44 |
setIcon(icon); |
| 45 |
setStyle(String.format("-fx-font-family: %s; -fx-font-size: %s;", icon.fontFamily(), iconSize)); |
| 46 |
} |
| 47 |
|
| 48 |
public MaterialIconView(MaterialIcon icon) { |
| 49 |
this(icon, "1em"); |
| 50 |
} |
| 51 |
|
| 52 |
public MaterialIconView() { |
| 53 |
this(MaterialIcon.ANDROID); |
| 54 |
} |
| 55 |
|
| 56 |
@Override |
| 57 |
public MaterialIcon getDefaultGlyph() { |
| 58 |
return MaterialIcon.ANDROID; |
| 59 |
} |
| 60 |
|
| 61 |
} |