-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
atarw
committed
Jun 9, 2018
1 parent
76aa2be
commit 761d071
Showing
14 changed files
with
322 additions
and
107 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package mdlaf; | ||
|
||
import javax.imageio.ImageIO; | ||
import java.awt.image.BufferedImage; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
public class MaterialImages { | ||
|
||
public static final BufferedImage RIGHT_ARROW = loadImg ("/imgs/right_arrow.png"); | ||
public static final BufferedImage DOWN_ARROW = loadImg ("/imgs/down_arrow.png"); | ||
|
||
private static BufferedImage loadImg (String imgPath) { | ||
try (InputStream inputStream = MaterialImages.class.getResourceAsStream (imgPath)) { | ||
return ImageIO.read (inputStream); | ||
} | ||
catch (IOException e) { | ||
e.printStackTrace (); | ||
throw new RuntimeException ("Image " + imgPath + " wasn't loaded"); | ||
} | ||
} | ||
|
||
private MaterialImages () {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package mdlaf.tree; | ||
|
||
import javax.swing.JTextField; | ||
import javax.swing.JTree; | ||
import javax.swing.tree.DefaultTreeCellEditor; | ||
import javax.swing.tree.DefaultTreeCellRenderer; | ||
import javax.swing.tree.TreeCellEditor; | ||
import java.awt.Component; | ||
import java.awt.event.KeyAdapter; | ||
import java.awt.event.KeyEvent; | ||
|
||
public class MaterialTreeCellEditor extends DefaultTreeCellEditor { | ||
|
||
private JTextField textField; | ||
|
||
private void init () { | ||
textField = new JTextField (); | ||
|
||
textField.addKeyListener (new KeyAdapter () { | ||
@Override | ||
public void keyTyped (KeyEvent e) { | ||
if (e.getKeyChar () == KeyEvent.VK_ENTER) | ||
stopCellEditing (); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public Component getTreeCellEditorComponent (JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row) { | ||
textField.setText (value.toString ()); | ||
return textField; | ||
} | ||
|
||
@Override | ||
public Object getCellEditorValue () { | ||
return textField.getText (); | ||
} | ||
|
||
public MaterialTreeCellEditor (JTree tree, DefaultTreeCellRenderer renderer) { | ||
super (tree, renderer); | ||
init (); | ||
} | ||
|
||
public MaterialTreeCellEditor (JTree tree, DefaultTreeCellRenderer renderer, TreeCellEditor editor) { | ||
super (tree, renderer, editor); | ||
init (); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package mdlaf.tree; | ||
|
||
import mdlaf.MaterialColors; | ||
import mdlaf.MaterialFonts; | ||
import mdlaf.MaterialImages; | ||
|
||
import javax.swing.BorderFactory; | ||
import javax.swing.ImageIcon; | ||
import javax.swing.JComponent; | ||
import javax.swing.JTree; | ||
import javax.swing.tree.DefaultTreeCellRenderer; | ||
import java.awt.Color; | ||
import java.awt.Component; | ||
|
||
public class MaterialTreeCellRenderer extends DefaultTreeCellRenderer { | ||
|
||
@Override | ||
public Component getTreeCellRendererComponent (JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row, boolean hasFocus) { | ||
JComponent component = (JComponent) super.getTreeCellRendererComponent (tree, value, isSelected, expanded, leaf, row, hasFocus); | ||
component.setBorder (BorderFactory.createEmptyBorder (5, 2, 5, 2)); | ||
|
||
return component; | ||
} | ||
|
||
public MaterialTreeCellRenderer () { | ||
setTextSelectionColor (Color.BLACK); | ||
setTextNonSelectionColor (Color.BLACK); | ||
|
||
setBackgroundSelectionColor (MaterialColors.LIGHT_GRAY); | ||
setBackgroundNonSelectionColor (Color.WHITE); | ||
|
||
setBorderSelectionColor (null); | ||
|
||
setClosedIcon (new ImageIcon (MaterialImages.RIGHT_ARROW)); | ||
setOpenIcon (new ImageIcon (MaterialImages.DOWN_ARROW)); | ||
|
||
setFont (MaterialFonts.REGULAR); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package mdlaf.tree; | ||
|
||
import mdlaf.MaterialFonts; | ||
|
||
import javax.swing.JComponent; | ||
import javax.swing.JTree; | ||
import javax.swing.plaf.ComponentUI; | ||
import javax.swing.plaf.basic.BasicTreeUI; | ||
import javax.swing.tree.DefaultTreeCellRenderer; | ||
import javax.swing.tree.TreeCellEditor; | ||
|
||
public class MaterialTreeUI extends BasicTreeUI { | ||
|
||
public static ComponentUI createUI (final JComponent c) { | ||
return new MaterialTreeUI (); | ||
} | ||
|
||
@Override | ||
public void installUI (JComponent c) { | ||
super.installUI (c); | ||
JTree tree = (JTree) c; | ||
|
||
DefaultTreeCellRenderer renderer = new MaterialTreeCellRenderer (); | ||
TreeCellEditor editor = new MaterialTreeCellEditor (tree, renderer); | ||
|
||
tree.setCellRenderer (renderer); | ||
tree.setCellEditor (editor); | ||
|
||
tree.setFont (MaterialFonts.REGULAR); | ||
tree.setRowHeight (0); | ||
tree.setInvokesStopCellEditing (true); | ||
|
||
MaterialTreeUI ui = (MaterialTreeUI) tree.getUI (); | ||
ui.setLeftChildIndent (10); | ||
ui.setRightChildIndent (10); | ||
} | ||
} |