-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[hyperspace-core-gui2] general work on gui2
- Loading branch information
Showing
1 changed file
with
64 additions
and
0 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
...src/main/java/com/idorsia/research/chem/hyperspace/gui2/view/SynthonTreeCellRenderer.java
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,64 @@ | ||
package com.idorsia.research.chem.hyperspace.gui2.view; | ||
|
||
import com.actelion.research.gui.table.ChemistryCellRenderer; | ||
import com.actelion.research.gui.table.ChemistryRenderPanel; | ||
import com.idorsia.research.chem.hyperspace.HyperspaceUtils; | ||
import com.idorsia.research.chem.hyperspace.SynthonSpace; | ||
import com.idorsia.research.chem.hyperspace.tree.SynthonTreeNode; | ||
|
||
import javax.swing.*; | ||
import javax.swing.tree.DefaultTreeCellRenderer; | ||
import java.awt.*; | ||
|
||
public class SynthonTreeCellRenderer extends DefaultTreeCellRenderer { | ||
@Override | ||
public Component getTreeCellRendererComponent(JTree tree, Object value, | ||
boolean selected, boolean expanded, | ||
boolean leaf, int row, boolean hasFocus) { | ||
|
||
if(value instanceof SynthonTreeNode) { | ||
SynthonSpace.FragId node = ((SynthonTreeNode) value).getSynthon(); | ||
// Call super method to ensure default rendering behavior | ||
super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus); | ||
// Customize rendering based on your requirements | ||
// Customize rendering based on the node's properties | ||
setText(node.fragment_id); | ||
|
||
// Custom painting for the icon | ||
ChemistryRenderPanel renderer = new ChemistryRenderPanel(); | ||
renderer.setChemistry(HyperspaceUtils.parseIDCode(node.idcode)); | ||
renderer.setSize(80, 80); | ||
Icon customIcon = new Icon() { | ||
@Override | ||
public void paintIcon(Component c, Graphics g, int x, int y) { | ||
// Custom painting logic using Graphics object 'g' | ||
// For example, draw a rectangle | ||
g.setColor(Color.BLUE); | ||
g.fillRect(x, y, getIconWidth(), getIconHeight()); | ||
renderer.paint(g); | ||
} | ||
|
||
@Override | ||
public int getIconWidth() { | ||
return 20; // Specify the width of the custom icon | ||
} | ||
|
||
@Override | ||
public int getIconHeight() { | ||
return 20; // Specify the height of the custom icon | ||
} | ||
}; | ||
setIcon(customIcon); | ||
|
||
// Apply custom font, color, etc. if needed | ||
setFont(new Font("Arial", Font.BOLD, 12)); | ||
setForeground(Color.RED); | ||
//} | ||
} | ||
else { | ||
super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus); | ||
} | ||
|
||
return this; | ||
} | ||
} |