use of au.gov.asd.tac.constellation.utilities.icon.ConstellationIcon in project constellation by constellation-app.
the class IconCriteriaPanel method updateIcon.
/**
* Handles any change to the current icon.
* <p>
* This method handles GUI updates to ensure that the GUI correctly
* represents the current selected icon.
*
* @param icon The name of the new icon to handle.
*/
private void updateIcon(final String icon) {
currentIcon = icon;
if (StringUtils.isNotBlank(currentIcon)) {
lblIconText.setText(currentIcon);
} else {
lblIconText.setText(Bundle.No_Icon());
}
Icon imageIcon = null;
final ConstellationIcon constellationIcon = IconManager.getIcon(currentIcon);
if (constellationIcon != null) {
imageIcon = constellationIcon.buildIcon();
}
// Scale the Icon so that it fits perfectly in the display label:
if (imageIcon != null) {
((ImageIcon) imageIcon).setImage(((ImageIcon) imageIcon).getImage().getScaledInstance(lblIcon.getPreferredSize().width, lblIcon.getPreferredSize().height, 0));
}
lblIcon.setIcon(imageIcon);
// Something has likely changed, so save the state:
parentPanel.saveStateToGraph();
}
use of au.gov.asd.tac.constellation.utilities.icon.ConstellationIcon in project constellation by constellation-app.
the class IconSelector method populateIconsList.
/**
* Populates the Icon list with the icons of the selected category. For
* example electing Flags will populate the list with all the flag icons.
*
* @param categoryName
*/
private void populateIconsList(final String categoryName) {
iconListView.getItems().clear();
/**
* For each of the icons split the extended name at the "." to determine
* what category its in. If its category matches the selected
* categoryName add it to the list of iconNames.
*/
final List<String> iconNames = new ArrayList<>();
for (final ConstellationIcon constellationIcon : IconManager.getIcons()) {
if (constellationIcon.getExtendedName().split("\\.")[0].equals(categoryName)) {
iconNames.add(constellationIcon.getName());
}
}
// sort the icons in alpabetical order
sort(iconNames);
final String[] iconName = icon.getExtendedName().split("\\.");
// for each of those iconNames find the icon and create an IconNode
for (final String name : iconNames) {
IconNode node = new IconNode(IconManager.getIcon(name));
iconListView.getItems().add(node);
if ((iconName.length > 1 && name.equals(iconName[1])) || (iconName.length == 1 && name.equals(iconName[0]))) {
iconListView.getSelectionModel().select(node);
}
}
}
use of au.gov.asd.tac.constellation.utilities.icon.ConstellationIcon in project constellation by constellation-app.
the class AdvancedSearchPlugin method searchAsIcon.
/**
* This function checks to see if a graph elements icon attribute matches
* the criteria specified by the IconCriteriaValues.
*
* @param values the icon criteriaValues
* @param attributeInt the int of the attribute
* @param currElement the currentElement
* @param graph the current graph
* @return
*/
private boolean searchAsIcon(final FindCriteriaValues values, final int attributeInt, final int currElement, final GraphWriteMethods graph) {
final IconCriteriaValues iconValues = (IconCriteriaValues) values;
final ConstellationIcon icon = graph.getObjectValue(attributeInt, currElement);
boolean matches = false;
// if the icon of the attribute matches the users icon matches = true
if (iconValues.getFilter().equals(IS) && iconValues.getIconValue().equals(icon)) {
matches = true;
// if the icon of the attribute does not match the users icon matches = true
} else if (iconValues.getFilter().equals(IS_NOT) && !iconValues.getIconValue().equals(icon)) {
matches = true;
}
return matches;
}
use of au.gov.asd.tac.constellation.utilities.icon.ConstellationIcon in project constellation by constellation-app.
the class IconListCellRenderer method addButtonActionPerformed.
// </editor-fold>//GEN-END:initComponents
private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {
// GEN-FIRST:event_addButtonActionPerformed
// Add an icon to the icon list.
String addedIcon = null;
final FileChooserBuilder fChooser = new FileChooserBuilder(IconChooser.class).setTitle("Add icons").setFileFilter(new FileFilter() {
@Override
public boolean accept(final File pathName) {
final int extlen = 4;
final String name = pathName.getName().toLowerCase();
if (pathName.isFile() && StringUtils.endsWithAny(name, (CharSequence[]) new String[] { FileExtensionConstants.JPG, FileExtensionConstants.PNG })) {
final String label = name.substring(0, name.length() - extlen);
// The name must contain at least one category (a '.' in position 1 or greater).
return label.indexOf('.') > 0;
}
return pathName.isDirectory();
}
@Override
public String getDescription() {
return "Graph Icon";
}
});
final File[] files = fChooser.showMultiOpenDialog();
if (files != null) {
for (File file : files) {
// The name must contain at least one category (a '.' in position 1 or greater).
final int extlen = 4;
final String fnam = file.getName();
final String label = fnam.substring(0, fnam.length() - extlen);
if (label.indexOf('.') < 1) {
final NotifyDescriptor nd = new NotifyDescriptor.Message(String.format("Icon name %s must contain categories separated by '.'", fnam), NotifyDescriptor.ERROR_MESSAGE);
nd.setTitle("Bad icon file name");
DialogDisplayer.getDefault().notify(nd);
} else {
ConstellationIcon customIcon = new ConstellationIcon.Builder(fnam, new FileIconData(file)).build();
if (IconManager.addIcon(customIcon)) {
addedIcon = label;
}
}
}
}
if (addedIcon != null) {
icons.clear();
icons.addAll(IconManager.getIcons());
init(addedIcon);
}
}
use of au.gov.asd.tac.constellation.utilities.icon.ConstellationIcon in project constellation by constellation-app.
the class IconListCellRenderer method init.
/**
* Initialise the icon tree.
*
* @param selectedIconName The initially selected icon.
*/
private void init(final String selectedIconName) {
ArrayList<IconTreeFolder> selectedPath = null;
IconTreeFolder selectedFolder = null;
String selectedPart = null;
final IconFoldersTreeModel treeModel = new IconFoldersTreeModel();
for (ConstellationIcon icon : icons) {
ArrayList<IconTreeFolder> path = new ArrayList<>();
String[] parts = icon.getExtendedName().split("\\.");
IconTreeFolder tf = (IconTreeFolder) treeModel.getRoot();
path.add(tf);
for (int i = 0; i < parts.length - 1; i++) {
final String part = parts[i];
int childIx = treeModel.getIndexOfChild(tf, part);
if (childIx == -1) {
final IconTreeFolder l = new IconTreeFolder(part);
tf.children.add(l);
Collections.sort(tf.children);
}
childIx = treeModel.getIndexOfChild(tf, part);
tf = (IconTreeFolder) treeModel.getChild(tf, childIx);
path.add(tf);
}
tf.icons.put(parts[parts.length - 1], icon);
// the path will end with "."+alias.
if (selectedIconName != null && (icon.getName().equals(selectedIconName) || icon.getExtendedName().endsWith(SeparatorConstants.PERIOD + selectedIconName))) {
selectedPath = path;
selectedFolder = tf;
selectedPart = parts[parts.length - 1];
}
}
iconFolders.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
iconFolders.addTreeSelectionListener(this);
iconFolders.setModel(treeModel);
if (selectedFolder == null) {
selectedFolder = (IconTreeFolder) treeModel.getRoot();
selectedPath = new ArrayList<>();
selectedPath.add(selectedFolder);
}
if (selectedFolder != null && selectedPath != null) {
final TreePath path = new TreePath(selectedPath.toArray(new IconTreeFolder[selectedPath.size()]));
iconFolders.expandPath(path);
iconFolders.scrollPathToVisible(path);
iconFolders.setSelectionPath(path);
iconsList.setModel(new IconListModel(selectedFolder.icons));
iconsList.setSelectedValue(new IconListElement(selectedPart, null), true);
}
}
Aggregations