use of javax.swing.JComponent in project JMRI by JMRI.
the class PanedInterface method show.
@Override
public void show(jmri.util.swing.JmriPanel child, JmriAbstractAction act, Hint hint) {
JComponent destination;
if (hint == Hint.EXTEND) {
destination = frame.getLowerRight();
} else {
destination = frame.getUpperRight();
}
destination.removeAll();
destination.add(child);
destination.revalidate();
frame.resetRightToPreferredSizes();
if (act != null) {
actions.add(act);
}
}
use of javax.swing.JComponent in project JMRI by JMRI.
the class PositionableLabelTest method getColor.
int getColor(String name) {
flushAWT();
// Find window by name
JmriJFrame frame = JmriJFrame.getFrame(name);
Assert.assertNotNull("frame: " + name, frame);
// find label within that
JLabelFinder finder = new JLabelFinder("....");
// FIXME: finder.findAll returns an untyped list, so we have issues with casting
@SuppressWarnings("rawtypes") java.util.List list = finder.findAll(frame);
Assert.assertNotNull("list: " + name, list);
Assert.assertTrue("length: " + name + ": " + list.size(), list.size() > 0);
JComponent component = (JComponent) list.get(0);
int[] content = getDisplayedContent(component, component.getSize(), new Point(0, 0));
int color = content[0];
// Unless in demo mode, close table window
if (System.getProperty("jmri.demo", "false").equals("false")) {
frame.setVisible(false);
}
return color;
}
use of javax.swing.JComponent in project JMRI by JMRI.
the class PaneProgPaneTest method testVariables.
// test specifying variables in columns
@Test
public void testVariables() {
Assume.assumeFalse(GraphicsEnvironment.isHeadless());
// make sure XML document is ready
setupDoc();
PaneProgFrame pFrame = new PaneProgFrame(null, new RosterEntry(), "test frame", "programmers/Basic.xml", p, false) {
// dummy implementations
@Override
protected JPanel getModePane() {
return null;
}
};
CvTableModel cvModel = new CvTableModel(new JLabel(), p);
IndexedCvTableModel icvModel = new IndexedCvTableModel(new JLabel(), p);
String[] args = { "CV", "Name" };
VariableTableModel varModel = new VariableTableModel(null, args, cvModel, icvModel);
log.debug("VariableTableModel ctor complete");
// create test object with special implementation of the newVariable(String) operation
varCount = 0;
PaneProgPane pane = new PaneProgPane(pFrame, "name", pane1, cvModel, icvModel, varModel, null, null) {
@Override
public void newVariable(Element e, JComponent p, GridBagLayout g, GridBagConstraints c, boolean a) {
varCount++;
}
};
assertNotNull("exists", pane);
assertEquals("variable defn count", 7, varCount);
}
use of javax.swing.JComponent in project jabref by JabRef.
the class FileListEditorTransferHandler method importData.
@Override
public boolean importData(JComponent comp, Transferable t) {
try {
List<Path> files = new ArrayList<>();
// This flavor is used for dragged file links in Windows:
if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
@SuppressWarnings("unchecked") List<Path> transferedFiles = (List<Path>) t.getTransferData(DataFlavor.javaFileListFlavor);
files.addAll(transferedFiles);
}
if (t.isDataFlavorSupported(urlFlavor)) {
URL dropLink = (URL) t.getTransferData(urlFlavor);
LOGGER.debug("URL: " + dropLink);
}
// under Gnome. The data consists of the file paths, one file per line:
if (t.isDataFlavorSupported(stringFlavor)) {
String dropStr = (String) t.getTransferData(stringFlavor);
files.addAll(EntryTableTransferHandler.getFilesFromDraggedFilesString(dropStr));
}
SwingUtilities.invokeLater(() -> {
for (Path file : files) {
// Find the file's extension, if any:
String name = file.toAbsolutePath().toString();
FileHelper.getFileExtension(name).ifPresent(extension -> ExternalFileTypes.getInstance().getExternalFileTypeByExt(extension).ifPresent(fileType -> {
if (droppedFileHandler == null) {
droppedFileHandler = new DroppedFileHandler(frame, frame.getCurrentBasePanel());
}
droppedFileHandler.handleDroppedfile(name, fileType, entryContainer.getEntry());
}));
}
});
if (!files.isEmpty()) {
// Found some files, return
return true;
}
} catch (IOException ioe) {
LOGGER.warn("Failed to read dropped data. ", ioe);
} catch (UnsupportedFlavorException | ClassCastException ufe) {
LOGGER.warn("Drop type error. ", ufe);
}
// all supported flavors failed
StringBuilder logMessage = new StringBuilder("Cannot transfer input:");
DataFlavor[] inflavs = t.getTransferDataFlavors();
for (DataFlavor inflav : inflavs) {
logMessage.append(' ').append(inflav);
}
LOGGER.warn(logMessage.toString());
return false;
}
use of javax.swing.JComponent in project JMRI by JMRI.
the class RosterGroupsPanel method getButtons.
private JToolBar getButtons() {
JToolBar controls = new JToolBar();
controls.setLayout(new GridLayout(1, 0, 0, 0));
controls.setFloatable(false);
final JToggleButton addGroupBtn = new JToggleButton(new ImageIcon(FileUtil.findURL("resources/icons/misc/gui3/Add.png")), false);
final JToggleButton actGroupBtn = new JToggleButton(new ImageIcon(FileUtil.findURL("resources/icons/misc/gui3/Action.png")), false);
addGroupBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
new CreateRosterGroupAction("", scrollPane.getTopLevelAncestor()).actionPerformed(e);
addGroupBtn.setSelected(false);
}
});
actGroupBtn.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent ie) {
if (ie.getStateChange() == ItemEvent.SELECTED) {
TreePath g = new TreePath(_model.getPathToRoot(_groups));
if (_tree.getSelectionPath() != null) {
if (_tree.getSelectionPath().getLastPathComponent().toString().equals(Roster.ALLENTRIES)) {
allEntriesMenu.show((JComponent) ie.getSource(), actGroupBtn.getX() - actGroupBtn.getWidth(), actGroupBtn.getY() - allEntriesMenu.getPreferredSize().height);
} else if (g.isDescendant(_tree.getSelectionPath()) && !_tree.getSelectionPath().isDescendant(g)) {
groupsMenu.show((JComponent) ie.getSource(), actGroupBtn.getX() - actGroupBtn.getWidth(), actGroupBtn.getY() - groupsMenu.getPreferredSize().height);
}
}
}
}
});
PopupMenuListener PML = new PopupMenuListener() {
@Override
public void popupMenuWillBecomeVisible(PopupMenuEvent pme) {
// do nothing
}
@Override
public void popupMenuWillBecomeInvisible(PopupMenuEvent pme) {
actGroupBtn.setSelected(false);
}
@Override
public void popupMenuCanceled(PopupMenuEvent pme) {
actGroupBtn.setSelected(false);
}
};
allEntriesMenu.addPopupMenuListener(PML);
groupsMenu.addPopupMenuListener(PML);
controls.add(addGroupBtn);
controls.add(actGroupBtn);
return controls;
}
Aggregations