use of javax.swing.JComponent in project JMRI by JMRI.
the class RosterFrame method createTop.
JComponent createTop() {
Object selectedRosterGroup = prefsMgr.getProperty(getWindowFrameRef(), SELECTED_ROSTER_GROUP);
groups = new RosterGroupsPanel((selectedRosterGroup != null) ? selectedRosterGroup.toString() : null);
groups.setNewWindowMenuAction(this.getNewWindowAction());
setTitle(groups.getSelectedRosterGroup());
final JPanel rosters = new JPanel();
rosters.setLayout(new BorderLayout());
// set up roster table
rtable = new RosterTable(true, ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
rtable.setRosterGroup(this.getSelectedRosterGroup());
rtable.setRosterGroupSource(groups);
rosters.add(rtable, BorderLayout.CENTER);
// add selection listener
rtable.getTable().getSelectionModel().addListSelectionListener((ListSelectionEvent e) -> {
JTable table = rtable.getTable();
if (!e.getValueIsAdjusting()) {
if (rtable.getSelectedRosterEntries().length == 1 && table.getSelectedRow() >= 0) {
log.debug("Selected row ", table.getSelectedRow());
locoSelected(rtable.getModel().getValueAt(table.getRowSorter().convertRowIndexToModel(table.getSelectedRow()), RosterTableModel.IDCOL).toString());
} else if (rtable.getSelectedRosterEntries().length > 1 || table.getSelectedRow() < 0) {
locoSelected(null);
}
// leave last selected item visible if no selection
}
});
//Set all the sort and width details of the table first.
String rostertableref = getWindowFrameRef() + ":roster";
rtable.getTable().setName(rostertableref);
// Allow only one column to be sorted at a time -
// Java allows multiple column sorting, but to effectly persist that, we
// need to be intelligent about which columns can be meaningfully sorted
// with other columns; this bypasses the problem by only allowing the
// last column sorted to affect sorting
RowSorterUtil.addSingleSortableColumnListener(rtable.getTable().getRowSorter());
// Reset and then persist the table's ui state
JTablePersistenceManager tpm = InstanceManager.getNullableDefault(JTablePersistenceManager.class);
if (tpm != null) {
tpm.resetState(rtable.getTable());
tpm.persist(rtable.getTable());
}
rtable.getTable().setDragEnabled(true);
rtable.getTable().setTransferHandler(new TransferHandler() {
@Override
public int getSourceActions(JComponent c) {
return TransferHandler.COPY;
}
@Override
public Transferable createTransferable(JComponent c) {
JTable table = rtable.getTable();
ArrayList<String> Ids = new ArrayList<>(table.getSelectedRowCount());
for (int i = 0; i < table.getSelectedRowCount(); i++) {
Ids.add(rtable.getModel().getValueAt(table.getRowSorter().convertRowIndexToModel(table.getSelectedRows()[i]), RosterTableModel.IDCOL).toString());
}
return new RosterEntrySelection(Ids);
}
@Override
public void exportDone(JComponent c, Transferable t, int action) {
// nothing to do
}
});
MouseListener rosterMouseListener = new rosterPopupListener();
rtable.getTable().addMouseListener(rosterMouseListener);
try {
clickDelay = ((Integer) Toolkit.getDefaultToolkit().getDesktopProperty("awt.multiClickInterval"));
} catch (RuntimeException e) {
clickDelay = 500;
log.debug("Unable to get the double click speed, Using JMRI default of half a second" + e.toString());
}
// assemble roster/groups splitpane
rosterGroupSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, groups, rosters);
rosterGroupSplitPane.setOneTouchExpandable(true);
// emphasis rosters
rosterGroupSplitPane.setResizeWeight(0);
Object w = prefsMgr.getProperty(getWindowFrameRef(), "rosterGroupPaneDividerLocation");
if (w != null) {
groupSplitPaneLocation = (Integer) w;
rosterGroupSplitPane.setDividerLocation(groupSplitPaneLocation);
}
if (!Roster.getDefault().getRosterGroupList().isEmpty()) {
if (prefsMgr.getSimplePreferenceState(this.getClass().getName() + ".hideGroups")) {
hideGroupsPane(true);
}
} else {
enableRosterGroupMenuItems(false);
}
PropertyChangeListener propertyChangeListener = (PropertyChangeEvent changeEvent) -> {
JSplitPane sourceSplitPane = (JSplitPane) changeEvent.getSource();
String propertyName = changeEvent.getPropertyName();
if (propertyName.equals(JSplitPane.LAST_DIVIDER_LOCATION_PROPERTY)) {
int current = sourceSplitPane.getDividerLocation();
hideGroups = current <= 1;
Integer last = (Integer) changeEvent.getNewValue();
if (current >= 2) {
groupSplitPaneLocation = current;
} else if (last >= 2) {
groupSplitPaneLocation = last;
}
}
};
groups.addPropertyChangeListener(SELECTED_ROSTER_GROUP, new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent pce) {
prefsMgr.setProperty(this.getClass().getName(), SELECTED_ROSTER_GROUP, pce.getNewValue());
setTitle((String) pce.getNewValue());
}
});
rosterGroupSplitPane.addPropertyChangeListener(propertyChangeListener);
Roster.getDefault().addPropertyChangeListener((PropertyChangeEvent e) -> {
if (e.getPropertyName().equals("RosterGroupAdded") && Roster.getDefault().getRosterGroupList().size() == 1) {
// if the pane is hidden, show it when 1st group is created
hideGroupsPane(false);
enableRosterGroupMenuItems(true);
} else if (!rtable.isVisible() && (e.getPropertyName().equals("saved"))) {
if (firstHelpLabel != null) {
firstHelpLabel.setVisible(false);
}
rtable.setVisible(true);
rtable.resetColumnWidths();
}
});
if (Roster.getDefault().numEntries() == 0) {
try {
BufferedImage myPicture = ImageIO.read(FileUtil.findURL(("resources/" + Bundle.getMessage("ThrottleFirstUseImage")), FileUtil.Location.INSTALLED));
//rosters.add(new JLabel(new ImageIcon( myPicture )), BorderLayout.CENTER);
firstHelpLabel = new JLabel(new ImageIcon(myPicture));
rtable.setVisible(false);
rosters.add(firstHelpLabel, BorderLayout.NORTH);
//tableArea.add(firstHelpLabel);
rtable.setVisible(false);
} catch (IOException ex) {
// handle exception...
}
}
return rosterGroupSplitPane;
}
use of javax.swing.JComponent in project JMRI by JMRI.
the class Ds64TabbedPanel method changeGuiElementHighlight.
private void changeGuiElementHighlight(Integer reportedState, Integer reportedIndexToRead) {
log.debug("changedGuiElementHiglight st=" + reportedState + " index=" + reportedIndexToRead);
Color accessColor = Color.blue.brighter();
Color noAccessColor = null;
JComponent jc = null;
if (reportedState == 33) {
jc = whichComponent(reportedState, reportedIndexToRead);
changeComponentBgColor(jc, accessColor);
}
if (reportedState == 48) {
changeGuiElementUnHighlight(33, reportedIndexToRead);
jc = whichComponent(49, reportedIndexToRead);
if (jc != null) {
changeComponentBgColor(jc, accessColor);
}
}
if (reportedState == 64) {
jc = whichComponent(49, reportedIndexToRead);
changeComponentBgColor(jc, noAccessColor);
}
}
use of javax.swing.JComponent in project cytoscape-api by cytoscape.
the class LookAndFeelUtil method equalizeSize.
/**
* Resizes the given components making them equal in size.
*/
public static void equalizeSize(final JComponent... components) {
if (components == null || components.length == 0)
return;
final Dimension prefSize = components[0].getPreferredSize();
final Dimension maxSize = components[0].getMaximumSize();
for (JComponent c : components) {
ensureSize(prefSize, c.getPreferredSize());
ensureSize(maxSize, c.getMaximumSize());
}
for (JComponent c : components) {
c.setPreferredSize(prefSize);
c.setMaximumSize(maxSize);
}
}
use of javax.swing.JComponent in project processdash by dtuma.
the class CustomColumnEditor method showWindow.
private CustomColumn showWindow(Component parent, boolean isAddOperation) {
String title = resources.getString(isAddOperation ? "Add_Title" : "Edit_Title");
JComponent fieldToFocus = isAddOperation ? columnID : columnName;
while (true) {
Object[] message = new Object[] { contents, new JOptionPaneTweaker.GrabFocus(fieldToFocus) };
int userChoice = JOptionPane.showConfirmDialog(parent, message, title, JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null);
if (userChoice != JOptionPane.OK_OPTION)
return null;
try {
return buildColumn(isAddOperation);
} catch (ColumnException ce) {
JOptionPane.showMessageDialog(parent, ce.getMessage(), title, JOptionPane.ERROR_MESSAGE);
if (ce.fieldToFocus != null)
fieldToFocus = ce.fieldToFocus;
}
}
}
use of javax.swing.JComponent in project processdash by dtuma.
the class DefectImportForm method buildAndShowWindow.
private void buildAndShowWindow(Element xml, String windowName) {
frame = new JFrame(windowName) {
public void dispose() {
super.dispose();
disposeForm();
}
};
DashboardIconFactory.setWindowIcon(frame);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.getContentPane().setLayout(new BorderLayout());
((JComponent) getContainer()).setBorder(new EmptyBorder(5, 5, 5, 5));
frame.getContentPane().add(BorderLayout.NORTH, getContainer());
BoundDefectTable defectTable = new BoundDefectTable(this);
defectTable.setBorder(new EmptyBorder(0, 10, 0, 10));
frame.getContentPane().add(BorderLayout.CENTER, defectTable);
frame.getContentPane().add(BorderLayout.SOUTH, createButtonBox());
int width = XMLUtils.getXMLInt(xml, "windowWidth");
if (width <= 0)
width = 600;
int height = XMLUtils.getXMLInt(xml, "windowHeight");
if (height <= 0)
height = 500;
frame.setSize(width, height);
frame.setVisible(true);
}
Aggregations