use of java.awt.event.WindowEvent in project robo4j by Robo4J.
the class SSD1306DeviceTest method main.
public static void main(String[] args) throws IOException {
final SSD1306Device oled = new SSD1306Device(OLEDVariant.Type128x32, RaspiPin.GPIO_25);
Graphics2D gc = oled.getGraphicsContext();
gc.setColor(Color.white);
gc.setBackground(Color.black);
gc.clearRect(0, 0, 127, 31);
gc.drawLine(0, 0, 127, 31);
gc.drawString("Hello World!", 0, 32);
gc.setBackground(Color.white);
gc.fillOval(127 - 16, -16, 32, 32);
oled.pushImage();
JFrame frame = new JFrame();
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
try {
oled.setEnabled(false);
} catch (IOException e1) {
e1.printStackTrace();
//TODO: is it possible ?
} finally {
System.exit(0);
}
}
});
frame.setSize(256, 256);
frame.getContentPane().add(new JLabel(new ImageIcon(oled.getImage())));
frame.setVisible(true);
}
use of java.awt.event.WindowEvent in project ACS by ACS-Community.
the class Gui method show.
void show(Gen.AnchorNode n) {
DefaultMutableTreeNode r = new DefaultMutableTreeNode(n);
toTreeNode(n, r);
JTree t = new JTree(r);
final JFrame f = new JFrame();
f.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent evt) {
synchronized (Gui.this) {
Gui.this.notify();
}
f.dispose();
}
});
f.getContentPane().add(new JScrollPane(t));
f.pack();
f.setVisible(true);
}
use of java.awt.event.WindowEvent in project ACS by ACS-Community.
the class BeanGrouper method createDelPropWindow.
private void createDelPropWindow() {
if (frame != null) {
return;
}
JLabel delLabel = new JLabel("Select the Component:Property to delete:");
jcombo = new JComboBox();
frame = new JFrame("Delete");
JPanel panel = new JPanel(new BorderLayout(5, 5));
JButton delButton = new JButton("Delete");
for (DataPrinter wp : samplers) {
jcombo.addItem(wp.component + ":" + wp.property);
}
delButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
String[] comProp = new String[2];
comProp = jcombo.getSelectedItem().toString().split(":");
removeSamp(comProp[0], comProp[1]);
jcombo.removeItemAt(jcombo.getSelectedIndex());
addToStatusList(comProp[0] + "#" + comProp[1] + "removed");
}
});
delLabel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
panel.add(delLabel, BorderLayout.NORTH);
jcombo.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
panel.add(jcombo, BorderLayout.CENTER);
delButton.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
panel.add(delButton, BorderLayout.EAST);
//frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
frame.add(panel);
frame.pack();
frame.setVisible(true);
frame.addWindowListener(new java.awt.event.WindowListener() {
@Override
public void windowActivated(WindowEvent e) {
}
@Override
public void windowClosed(WindowEvent e) {
}
@Override
public void windowClosing(WindowEvent e) {
}
@Override
public void windowDeactivated(WindowEvent e) {
frame = null;
}
@Override
public void windowDeiconified(WindowEvent e) {
}
@Override
public void windowIconified(WindowEvent e) {
}
@Override
public void windowOpened(WindowEvent e) {
}
});
}
use of java.awt.event.WindowEvent in project ACS by ACS-Community.
the class StatsDlg method initialize.
/**
* Setup the GUI
*/
private void initialize() {
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Statistics");
this.setBounds(50, 35, 100, 100);
JPanel mainPnl = new JPanel(new BorderLayout());
JPanel valuesPnl = new JPanel(new GridLayout(10, 1));
// Add the num of logs
JPanel numOfLogsPnl = new JPanel(new FlowLayout(FlowLayout.LEFT));
numOfLogsPnl.add(new JLabel("Total logs: "));
numOfLogsPnl.add(totNumOfLogsLbl);
valuesPnl.add(numOfLogsPnl);
// Visible logs
JPanel visibleLogsPnl = new JPanel(new FlowLayout(FlowLayout.LEFT));
visibleLogsPnl.add(new JLabel("Visible logs: "));
visibleLogsPnl.add(visibleLogsLbl);
valuesPnl.add(visibleLogsPnl);
// Hidden logs
JPanel hiddenLogsPnl = new JPanel(new FlowLayout(FlowLayout.LEFT));
hiddenLogsPnl.add(new JLabel("Hidden logs: "));
hiddenLogsPnl.add(hiddenLogsLbl);
valuesPnl.add(hiddenLogsPnl);
// Add the available memory
JPanel availMemPnl = new JPanel(new FlowLayout(FlowLayout.LEFT));
availMemPnl.add(new JLabel("Memory available: "));
availMemPnl.add(availMemLbl);
valuesPnl.add(availMemPnl);
// Add the used memory
JPanel usedMemPnl = new JPanel(new FlowLayout(FlowLayout.LEFT));
usedMemPnl.add(new JLabel("Used memory: "));
usedMemPnl.add(usedMemLbl);
valuesPnl.add(usedMemPnl);
// Add the number of the files of cache
JPanel usedCacheFiles = new JPanel(new FlowLayout(FlowLayout.LEFT));
usedCacheFiles.add(new JLabel("Number of files of cache: "));
usedCacheFiles.add(numOfCacheFiles);
valuesPnl.add(usedCacheFiles);
// Add the disk space used by the files of the cache
JPanel usedDiskSpace = new JPanel(new FlowLayout(FlowLayout.LEFT));
usedDiskSpace.add(new JLabel("Disk space used by the cache: "));
usedDiskSpace.add(diskSpace);
valuesPnl.add(usedDiskSpace);
// Add the time frame
JPanel timeFramePnl = new JPanel(new FlowLayout(FlowLayout.LEFT));
timeFramePnl.add(new JLabel("Time frame: "));
timeFramePnl.add(timeFrameLbl);
valuesPnl.add(timeFramePnl);
// Add the rate from the NC
JPanel inRatePnl = new JPanel(new FlowLayout(FlowLayout.LEFT));
inRatePnl.add(new JLabel("Rate of logs from NC: "));
inRatePnl.add(inRateLbl);
valuesPnl.add(inRatePnl);
// Add the rate to the listeners
JPanel outRatePnl = new JPanel(new FlowLayout(FlowLayout.LEFT));
outRatePnl.add(new JLabel("Rate of logs sent to table: "));
outRatePnl.add(outRateLbl);
valuesPnl.add(outRatePnl);
mainPnl.add(valuesPnl, BorderLayout.CENTER);
// Add the refresh and the close buttons
JPanel buttonPanel = new JPanel(new FlowLayout());
monitorBtn.addActionListener(this);
buttonPanel.add(monitorBtn);
refreshBtn.addActionListener(this);
buttonPanel.add(refreshBtn);
closeBtn.addActionListener(this);
buttonPanel.add(closeBtn);
mainPnl.add(buttonPanel, BorderLayout.SOUTH);
setContentPane(mainPnl);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
enableMonitoring(false);
}
});
}
use of java.awt.event.WindowEvent in project ACS by ACS-Community.
the class SenderPanel method initGUI.
/**
* Initialize the GUI
*/
private void initGUI() {
super.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
addWindowListener(new WindowAdapter() {
@Override
public void windowClosed(WindowEvent e) {
super.windowClosed(e);
close();
}
});
/////////////////////////////////////////////////////////
// The panel to send alarms by triplet or file
//
// This panel contains:
// * one panel to send alarms by triplet
// * one to send alarms by file
// * one to send alarms by CDB
// The user can select only one sending type by means
// of a radio button.
/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
// The panel to send alarm by writing the triplet
//
// The panel has a radio button to select the sending by
// triplet and a panel that contains all the widgets
// needed by this sending mode.
/////////////////////////////////////////////////////////
JPanel tripletPnl = new JPanel(new BorderLayout());
tripletPnl.add(sendFromTripletRB, BorderLayout.WEST);
sendTripletBtn.setEnabled(false);
// The panel with all the widgets to send alarms by triplets
// It has 3 lines: triplet, descriptor and properties
tripletWdgtsPnl.setBorder(BorderFactory.createTitledBorder("Triplet sender"));
BoxLayout tripetWdgtsLayoout = new BoxLayout(tripletWdgtsPnl, BoxLayout.Y_AXIS);
tripletWdgtsPnl.setLayout(tripetWdgtsLayoout);
// Line 1: triplet text field and send button
JPanel sendTripletPnl = new JPanel(new FlowLayout(FlowLayout.LEFT));
sendTripletPnl.add(tripletTF);
tripletTF.setColumns(40);
tripletTF.getDocument().addDocumentListener(this);
tripletTF.setToolTipText("Insert triplet: FaultFamily,FaultMember,1");
sendTripletBtn.setEnabled(false);
sendTripletBtn.addActionListener(this);
sendTripletPnl.add(sendTripletBtn);
// Line 2: the descriptor
JPanel descriptorWdgtPnl = new JPanel(new FlowLayout(FlowLayout.LEFT));
descriptorWdgtPnl.add(new JLabel("Descriptor: "));
activeRB.setName(FaultState.ACTIVE);
terminateRB.setName(FaultState.TERMINATE);
changeRB.setName(FaultState.CHANGE);
instantRB.setName(FaultState.INSTANT);
descriptorWdgtPnl.add(activeRB);
descriptorWdgtPnl.add(terminateRB);
descriptorWdgtPnl.add(changeRB);
descriptorWdgtPnl.add(instantRB);
activeRB.setSelected(true);
// Line 3: the properties
JPanel propsWdgtsPnl = new JPanel(new FlowLayout(FlowLayout.LEFT));
propsWdgtsPnl.add(new JLabel("Properties"));
propsWdgtsPnl.add(propsTF);
propsTF.setColumns(40);
propsTF.setToolTipText("User properties key=val, key2=val2,....");
// Add the three lines of widgets
tripletWdgtsPnl.add(sendTripletPnl);
tripletWdgtsPnl.add(descriptorWdgtPnl);
tripletWdgtsPnl.add(propsWdgtsPnl);
tripletPnl.add(tripletWdgtsPnl, BorderLayout.CENTER);
/////////////////////////////////////////////////////////
// The panel to send alarm by selecting a file
//
// The panel has a radio button to select the sending by
// file and a panel that contains all the widgets
// needed by this sending mode.
/////////////////////////////////////////////////////////
JPanel filePnl = new JPanel(new BorderLayout());
filePnl.add(sendFromFileRB, BorderLayout.WEST);
sendFromFileRB.setPreferredSize(sendFromTripletRB.getPreferredSize());
sendFromFileRB.setMinimumSize(sendFromTripletRB.getMinimumSize());
// The panel with all the widgets to send alarms by file
// It has 2 lines: one to select the file and another one with the control buttons
fileWdgtsPnl.setBorder(BorderFactory.createTitledBorder("File sender"));
BoxLayout fileWdgtsLayoout = new BoxLayout(fileWdgtsPnl, BoxLayout.Y_AXIS);
fileWdgtsPnl.setLayout(fileWdgtsLayoout);
// Line 1: widgets to select the file
JPanel selectFilePnl = new JPanel(new FlowLayout(FlowLayout.RIGHT));
fileNameTF.setColumns(40);
fileNameTF.setEditable(false);
fileNameTF.setText("");
selectFilePnl.add(fileNameTF);
selectFilePnl.add(chooseFiletBtn);
// Line 2: widgets to control the sending mode
JPanel ctrlsFilePnl = new JPanel(new BorderLayout());
JPanel ctrlsButtonsPnl = new JPanel(new FlowLayout(FlowLayout.RIGHT));
ctrlsFilePnl.add(fileTasksPB, BorderLayout.CENTER);
fileTasksPB.setValue(0);
fileTasksPB.setIndeterminate(false);
ctrlsButtonsPnl.add(activateFromFileBtn);
ctrlsButtonsPnl.add(terminateFromFileBtn);
ctrlsButtonsPnl.add(cycleFromFileBtn);
ctrlsFilePnl.add(ctrlsButtonsPnl, BorderLayout.EAST);
// Add the two lines of widgets
fileWdgtsPnl.add(selectFilePnl);
fileWdgtsPnl.add(ctrlsFilePnl);
filePnl.add(fileWdgtsPnl, BorderLayout.CENTER);
/////////////////////////////////////////////////////////
// The panel to send alarm read from TM/CDB
//
// The panel has a radio button to select the sending by
// file and a panel that contains all the widgets
// needed by this sending mode.
/////////////////////////////////////////////////////////
JPanel cdbPnl = new JPanel(new BorderLayout());
cdbPnl.add(sendFromCdbRB, BorderLayout.WEST);
sendFromCdbRB.setPreferredSize(sendFromTripletRB.getPreferredSize());
sendFromCdbRB.setMinimumSize(sendFromTripletRB.getMinimumSize());
// The panel with all the widgets to send alarms by file
// It has 2 lines: one to select the file and another one with the control buttons
cdbWdgtsPnl.setBorder(BorderFactory.createTitledBorder("TM/CDB sender"));
BoxLayout cdbWdgtsLayoout = new BoxLayout(cdbWdgtsPnl, BoxLayout.Y_AXIS);
cdbWdgtsPnl.setLayout(cdbWdgtsLayoout);
// Line 1: widgets to show the number of alarms read from TM/CDB
JPanel showCdbPnl = new JPanel(new FlowLayout(FlowLayout.RIGHT));
cdbAlarmsTF.setColumns(40);
cdbAlarmsTF.setEditable(false);
cdbAlarmsTF.setText("");
showCdbPnl.add(cdbAlarmsTF);
// Line 2: widgets to control the sending mode
JPanel ctrlsCDBPnl = new JPanel(new BorderLayout());
JPanel ctrlsCDBButtonsPnl = new JPanel(new FlowLayout(FlowLayout.RIGHT));
ctrlsCDBPnl.add(cdbTasksPB, BorderLayout.CENTER);
cdbTasksPB.setValue(0);
cdbTasksPB.setIndeterminate(false);
ctrlsCDBButtonsPnl.add(activateFromCdbBtn);
ctrlsCDBButtonsPnl.add(terminateFromCdbBtn);
ctrlsCDBButtonsPnl.add(cycleFromCdbBtn);
ctrlsCDBPnl.add(ctrlsCDBButtonsPnl, BorderLayout.EAST);
// Add the two lines of widgets
cdbWdgtsPnl.add(showCdbPnl);
cdbWdgtsPnl.add(ctrlsCDBPnl);
cdbPnl.add(cdbWdgtsPnl, BorderLayout.CENTER);
// Finally add the triplet, the file and the CDB panels to the alarm sender panel
JPanel alrmSenderPnl = new JPanel(new BorderLayout());
alrmSenderPnl.add(tripletPnl, BorderLayout.NORTH);
JPanel fileAndCDBSenderPnl = new JPanel(new BorderLayout());
fileAndCDBSenderPnl.add(filePnl, BorderLayout.NORTH);
fileAndCDBSenderPnl.add(cdbPnl, BorderLayout.SOUTH);
alrmSenderPnl.add(fileAndCDBSenderPnl, BorderLayout.SOUTH);
alrmSenderPnl.setBorder(BorderFactory.createTitledBorder("Send alarm"));
add(alrmSenderPnl, BorderLayout.NORTH);
/////////////////////////////////////////////////////////
// The panel to clear alarms
/////////////////////////////////////////////////////////
JPanel alarmClearingPnl = new JPanel(new FlowLayout(FlowLayout.LEFT));
alarmClearingPnl.setBorder(BorderFactory.createTitledBorder("Alarm clearing"));
JScrollPane scrollPane = new JScrollPane(alarmsSent);
alarmsSent.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
alarmsSent.getModel().addTableModelListener(this);
alarmClearingPnl.add(scrollPane);
JPanel clearingBtnsPnl = new JPanel();
BoxLayout layout = new BoxLayout(clearingBtnsPnl, BoxLayout.Y_AXIS);
clearingBtnsPnl.setLayout(layout);
clearingBtnsPnl.add(clearAllBtn);
Dimension minSize = new Dimension(5, 10);
Dimension prefSize = new Dimension(5, 10);
Dimension maxSize = new Dimension(Short.MAX_VALUE, 10);
clearingBtnsPnl.add(new Box.Filler(minSize, prefSize, maxSize));
clearingBtnsPnl.add(clearSelectedAlarmsBtn);
clearAllBtn.setEnabled(false);
clearAllBtn.addActionListener(this);
clearSelectedAlarmsBtn.setEnabled(true);
clearSelectedAlarmsBtn.addActionListener(this);
alarmClearingPnl.add(clearingBtnsPnl);
add(alarmClearingPnl, BorderLayout.CENTER);
JPanel donePnl = new JPanel(new FlowLayout(FlowLayout.CENTER));
donePnl.add(closeBtn);
closeBtn.addActionListener(this);
add(donePnl, BorderLayout.SOUTH);
// Add the listeners
sendFromTripletRB.setSelected(true);
sendFromFileRB.addActionListener(this);
sendFromTripletRB.addActionListener(this);
sendFromCdbRB.addActionListener(this);
chooseFiletBtn.addActionListener(this);
activateFromFileBtn.addActionListener(this);
terminateFromFileBtn.addActionListener(this);
cycleFromFileBtn.addActionListener(this);
activateFromCdbBtn.addActionListener(this);
terminateFromCdbBtn.addActionListener(this);
cycleFromCdbBtn.addActionListener(this);
// Set the button groups
sendingBG.add(sendFromTripletRB);
sendingBG.add(sendFromFileRB);
sendingBG.add(sendFromCdbRB);
activationBG.add(activeRB);
activationBG.add(changeRB);
activationBG.add(terminateRB);
activationBG.add(instantRB);
pack();
setVisible(true);
ratioSenderModeButtons();
}
Aggregations