use of java.awt.datatransfer.DataFlavor in project JMRI by JMRI.
the class ControlPanelEditor method makeDataFlavors.
/**
* ************************** DnD *************************************
*/
protected void makeDataFlavors() {
// _targetPanel.setTransferHandler(new DnDIconHandler(this));
try {
_positionableDataFlavor = new DataFlavor(POSITIONABLE_FLAVOR);
_namedIconDataFlavor = new DataFlavor(ImageIndexEditor.IconDataFlavorMime);
_positionableListDataFlavor = new DataFlavor(List.class, "JComponentList");
} catch (ClassNotFoundException cnfe) {
cnfe.printStackTrace();
}
new DropTarget(this, DnDConstants.ACTION_COPY_OR_MOVE, this);
}
use of java.awt.datatransfer.DataFlavor in project JMRI by JMRI.
the class SignalMastItemPanel method makeDndIconPanel.
@Override
protected void makeDndIconPanel(HashMap<String, NamedIcon> iconMap, String displayKey) {
if (_update) {
return;
}
_dragIconPanel.setToolTipText(Bundle.getMessage("ToolTipDragIcon"));
NamedIcon icon = getDragIcon();
JPanel panel = new JPanel();
String borderName = ItemPalette.convertText("dragToPanel");
panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.black), borderName));
JLabel label;
try {
label = getDragger(new DataFlavor(Editor.POSITIONABLE_FLAVOR), icon);
label.setToolTipText(Bundle.getMessage("ToolTipDragIcon"));
} catch (java.lang.ClassNotFoundException cnfe) {
cnfe.printStackTrace();
label = new JLabel();
}
label.setName(borderName);
panel.add(label);
int width = Math.max(100, panel.getPreferredSize().width);
panel.setPreferredSize(new java.awt.Dimension(width, panel.getPreferredSize().height));
panel.setToolTipText(Bundle.getMessage("ToolTipDragIcon"));
_dragIconPanel.add(panel);
}
use of java.awt.datatransfer.DataFlavor in project JMRI by JMRI.
the class CatalogPanel method setIcons.
/**
* Display the icons in the preview panel
*/
private String setIcons() {
Thread.UncaughtExceptionHandler exceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
resetPanel();
CatalogTreeNode node = getSelectedNode();
if (node == null) {
return null;
}
List<CatalogTreeLeaf> leaves = node.getLeaves();
if (leaves == null) {
return null;
}
int numCol = 1;
while (numCol * numCol < leaves.size()) {
numCol++;
}
if (numCol > 1) {
numCol--;
}
int numRow = leaves.size() / numCol;
boolean newCol = false;
_noMemory = false;
// VM launches another thread to run ImageFetcher.
// This handler will catch memory exceptions from that thread
Thread.setDefaultUncaughtExceptionHandler(new MemoryExceptionHandler());
GridBagLayout gridbag = new GridBagLayout();
_preview.setLayout(gridbag);
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.NONE;
c.anchor = GridBagConstraints.CENTER;
c.weightx = 1.0;
c.weighty = 1.0;
c.gridy = 0;
c.gridx = -1;
for (int i = 0; i < leaves.size(); i++) {
if (_noMemory) {
continue;
}
CatalogTreeLeaf leaf = leaves.get(i);
NamedIcon icon = new NamedIcon(leaf.getPath(), leaf.getName());
double scale = icon.reduceTo(ICON_WIDTH, ICON_HEIGHT, ICON_SCALE);
if (_noMemory) {
continue;
}
if (c.gridx < numCol) {
c.gridx++;
} else if (c.gridy < numRow) {
//start next row
c.gridy++;
if (!newCol) {
c.gridx = 0;
}
} else if (!newCol) {
// start new column
c.gridx++;
numCol++;
c.gridy = 0;
newCol = true;
} else {
// start new row
c.gridy++;
numRow++;
c.gridx = 0;
newCol = false;
}
c.insets = new Insets(5, 5, 0, 0);
JLabel nameLabel;
if (_noDrag) {
nameLabel = new JLabel();
} else {
try {
nameLabel = new DragJLabel(new DataFlavor(ImageIndexEditor.IconDataFlavorMime));
} catch (java.lang.ClassNotFoundException cnfe) {
log.warn("Unable to create drag label", cnfe);
continue;
}
}
// nameLabel.setText(leaf.getName());
nameLabel.setName(leaf.getName());
// nameLabel.setVerticalTextPosition(JLabel.TOP);
nameLabel.setBackground(_currentBackground);
nameLabel.setIcon(icon);
JPanel p = new JPanel();
p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
p.add(nameLabel);
JLabel label = new JLabel(Bundle.getMessage("scale", CatalogPanel.printDbl(scale, 2)));
p.add(label);
label = new JLabel(leaf.getName());
p.add(label);
if (_noDrag) {
p.addMouseListener(this);
}
gridbag.setConstraints(p, c);
_preview.add(p);
if (log.isDebugEnabled()) {
log.debug("{} inserted at ({}, {})", leaf.getName(), c.gridx, c.gridy);
}
}
c.gridy++;
c.gridx++;
JLabel bottom = new JLabel();
gridbag.setConstraints(bottom, c);
_preview.add(bottom);
Thread.setDefaultUncaughtExceptionHandler(exceptionHandler);
return Bundle.getMessage("numImagesInNode", node.getUserObject(), leaves.size());
}
use of java.awt.datatransfer.DataFlavor in project JMRI by JMRI.
the class DnDStringImportHandler method importData.
@Override
public boolean importData(JComponent comp, Transferable tr) {
//if (log.isDebugEnabled()) log.debug("DnDStringImportHandler.importData ");
DataFlavor[] flavors = tr.getTransferDataFlavors();
if (!canImport(comp, flavors)) {
return false;
}
try {
String data = (String) tr.getTransferData(DataFlavor.stringFlavor);
JTextField field = (JTextField) comp;
field.setText(data);
//Notify listeners drop happened
field.firePropertyChange("DnDrop", 0, 1);
return true;
} catch (UnsupportedFlavorException ufe) {
log.warn("DnDStringImportHandler.importData: " + ufe.getMessage());
} catch (IOException ioe) {
log.warn("DnDStringImportHandler.importData: " + ioe.getMessage());
}
return false;
}
use of java.awt.datatransfer.DataFlavor in project JMRI by JMRI.
the class FileDrop method isDragOk.
// end dropListener
/**
* Determine if the dragged data is a file list.
*/
private boolean isDragOk(final java.io.PrintStream out, final java.awt.dnd.DropTargetDragEvent evt) {
boolean ok = false;
// Get data flavors being dragged
java.awt.datatransfer.DataFlavor[] flavors = evt.getCurrentDataFlavors();
// See if any of the flavors are a file list
int i = 0;
while (!ok && i < flavors.length) {
// BEGIN 2007-09-12 Nathan Blomquist -- Linux (KDE/Gnome) support added.
// Is the flavor a file list?
final DataFlavor curFlavor = flavors[i];
if (curFlavor.equals(java.awt.datatransfer.DataFlavor.javaFileListFlavor) || curFlavor.isRepresentationClassReader()) {
ok = true;
}
// END 2007-09-12 Nathan Blomquist -- Linux (KDE/Gnome) support added.
i++;
}
// If logging is enabled, show data flavors
if (out != null) {
if (flavors.length == 0) {
log(out, "FileDrop: no data flavors.");
}
for (i = 0; i < flavors.length; i++) {
log(out, flavors[i].toString());
}
}
return ok;
}
Aggregations