use of java.awt.event.ComponentEvent in project gate-core by GateNLP.
the class MainFrame method initListeners.
protected void initListeners() {
Gate.getCreoleRegister().addCreoleListener(this);
Gate.getCreoleRegister().addPluginListener(this);
resourcesTree.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
// shows in the central tabbed pane, the selected resources
// in the resource tree when the Enter key is pressed
(new ShowSelectedResourcesAction()).actionPerformed(null);
} else if (e.getKeyCode() == KeyEvent.VK_DELETE) {
// close selected resources from GATE
(new CloseSelectedResourcesAction()).actionPerformed(null);
} else if (e.getKeyCode() == KeyEvent.VK_DELETE && e.getModifiers() == InputEvent.SHIFT_DOWN_MASK) {
// close recursively selected resources from GATE
(new CloseRecursivelySelectedResourcesAction()).actionPerformed(null);
}
}
});
resourcesTree.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
TreePath path = resourcesTree.getClosestPathForLocation(e.getX(), e.getY());
if (e.isPopupTrigger() && !resourcesTree.isPathSelected(path)) {
// if right click outside the selection then reset selection
resourcesTree.getSelectionModel().setSelectionPath(path);
}
processMouseEvent(e);
}
@Override
public void mouseReleased(MouseEvent e) {
processMouseEvent(e);
}
@Override
public void mouseClicked(MouseEvent e) {
processMouseEvent(e);
}
protected void processMouseEvent(MouseEvent e) {
// where inside the tree?
int x = e.getX();
int y = e.getY();
TreePath path = resourcesTree.getClosestPathForLocation(x, y);
JPopupMenu popup = null;
Handle handle = null;
if (path != null) {
Object value = path.getLastPathComponent();
if (value == resourcesTreeRoot) {
// no default item for this menu
} else if (value == applicationsRoot) {
appsPopup = new XJPopupMenu();
LiveMenu appsMenu = new LiveMenu(LiveMenu.APP);
appsMenu.setText("Create New Application");
appsMenu.setIcon(MainFrame.getIcon("applications"));
appsPopup.add(appsMenu);
appsPopup.add(new ReadyMadeMenu());
appsPopup.add(new XJMenuItem(new LoadResourceFromFileAction(), MainFrame.this));
RecentAppsMenu recentApps = new RecentAppsMenu();
if (recentApps.getMenuComponentCount() > 0)
appsPopup.add(recentApps);
popup = appsPopup;
} else if (value == languageResourcesRoot) {
popup = lrsPopup;
} else if (value == processingResourcesRoot) {
popup = prsPopup;
} else if (value == datastoresRoot) {
popup = dssPopup;
} else {
value = ((DefaultMutableTreeNode) value).getUserObject();
if (value instanceof Handle) {
handle = (Handle) value;
fileChooser.setResource(handle.getTarget().getClass().getName());
if (e.isPopupTrigger()) {
popup = handle.getPopup();
}
}
}
}
// popup menu
if (e.isPopupTrigger()) {
if (resourcesTree.getSelectionCount() > 1) {
// multiple selection in tree
popup = new XJPopupMenu();
// add a close all action
popup.add(new XJMenuItem(new CloseSelectedResourcesAction(), MainFrame.this));
// add a close recursively all action
TreePath[] selectedPaths = resourcesTree.getSelectionPaths();
for (TreePath selectedPath : selectedPaths) {
Object userObject = ((DefaultMutableTreeNode) selectedPath.getLastPathComponent()).getUserObject();
if (userObject instanceof NameBearerHandle && ((NameBearerHandle) userObject).getTarget() instanceof Controller) {
// there is at least one application
popup.add(new XJMenuItem(new CloseRecursivelySelectedResourcesAction(), MainFrame.this));
break;
}
}
// add a show all action
selectedPaths = resourcesTree.getSelectionPaths();
for (TreePath selectedPath : selectedPaths) {
Object userObject = ((DefaultMutableTreeNode) selectedPath.getLastPathComponent()).getUserObject();
if (userObject instanceof Handle && (!((Handle) userObject).viewsBuilt() || (mainTabbedPane.indexOfComponent(((Handle) userObject).getLargeView()) == -1))) {
// there is at least one resource not shown
popup.add(new XJMenuItem(new ShowSelectedResourcesAction(), MainFrame.this));
break;
}
}
// add a hide all action
selectedPaths = resourcesTree.getSelectionPaths();
for (TreePath selectedPath : selectedPaths) {
Object userObject = ((DefaultMutableTreeNode) selectedPath.getLastPathComponent()).getUserObject();
if (userObject instanceof Handle && ((Handle) userObject).viewsBuilt() && ((Handle) userObject).getLargeView() != null && (mainTabbedPane.indexOfComponent(((Handle) userObject).getLargeView()) != -1)) {
// there is at least one resource shown
popup.add(new XJMenuItem(new CloseViewsForSelectedResourcesAction(), MainFrame.this));
break;
}
}
popup.show(resourcesTree, e.getX(), e.getY());
} else if (popup != null) {
if (handle != null) {
// add a close action
if (handle instanceof NameBearerHandle) {
popup.insert(new XJMenuItem(((NameBearerHandle) handle).getCloseAction(), MainFrame.this), 0);
}
// if application then add a close recursively action
if (handle instanceof NameBearerHandle && handle.getTarget() instanceof Controller) {
popup.insert(new XJMenuItem(((NameBearerHandle) handle).getCloseRecursivelyAction(), MainFrame.this), 1);
}
// add a show/hide action
if (handle.viewsBuilt() && handle.getLargeView() != null && (mainTabbedPane.indexOfComponent(handle.getLargeView()) != -1)) {
popup.insert(new XJMenuItem(new CloseViewAction(handle), MainFrame.this), 2);
} else {
popup.insert(new XJMenuItem(new ShowResourceAction(handle), MainFrame.this), 2);
}
// add a rename action
popup.insert(new XJMenuItem(new RenameResourceAction(path), MainFrame.this), 3);
// add a help action
if (handle instanceof NameBearerHandle) {
popup.insert(new XJMenuItem(new HelpOnItemTreeAction((NameBearerHandle) handle), MainFrame.this), 4);
}
}
popup.show(resourcesTree, e.getX(), e.getY());
}
} else if (e.getID() == MouseEvent.MOUSE_CLICKED && e.getClickCount() == 2 && handle != null) {
// double click - show the resource
select(handle);
}
}
});
resourcesTree.addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
if (!Gate.getUserConfig().getBoolean(MainFrame.class.getName() + ".treeselectview")) {
return;
}
// the resource tree selection
if (resourcesTree.getSelectionPaths() != null && resourcesTree.getSelectionPaths().length == 1) {
Object value = e.getPath().getLastPathComponent();
Object object = ((DefaultMutableTreeNode) value).getUserObject();
if (object instanceof Handle && ((Handle) object).viewsBuilt() && (mainTabbedPane.indexOfComponent(((Handle) object).getLargeView()) != -1)) {
select((Handle) object);
}
}
}
});
// define keystrokes action bindings at the level of the main window
InputMap inputMap = ((JComponent) this.getContentPane()).getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
inputMap.put(KeyStroke.getKeyStroke("control F4"), "Close resource");
inputMap.put(KeyStroke.getKeyStroke("shift F4"), "Close recursively");
inputMap.put(KeyStroke.getKeyStroke("control H"), "Hide");
inputMap.put(KeyStroke.getKeyStroke("control shift H"), "Hide all");
inputMap.put(KeyStroke.getKeyStroke("control S"), "Save As XML");
// TODO: remove when Swing will take care of the context menu key
if (inputMap.get(KeyStroke.getKeyStroke("CONTEXT_MENU")) == null) {
inputMap.put(KeyStroke.getKeyStroke("CONTEXT_MENU"), "Show context menu");
}
ActionMap actionMap = ((JComponent) instance.getContentPane()).getActionMap();
actionMap.put("Show context menu", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
KeyboardFocusManager focusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
// get the current focused component
Component focusedComponent = focusManager.getFocusOwner();
if (focusedComponent != null) {
Point menuLocation = null;
Rectangle selectionRectangle = null;
if (focusedComponent instanceof JTable && ((JTable) focusedComponent).getSelectedRowCount() > 0) {
// selection in a JTable
JTable table = (JTable) focusedComponent;
selectionRectangle = table.getCellRect(table.getSelectionModel().getLeadSelectionIndex(), table.convertColumnIndexToView(table.getSelectedColumn()), false);
} else if (focusedComponent instanceof JTree && ((JTree) focusedComponent).getSelectionCount() > 0) {
// selection in a JTree
JTree tree = (JTree) focusedComponent;
selectionRectangle = tree.getRowBounds(tree.getSelectionModel().getLeadSelectionRow());
} else {
// for other component set the menu location at the top left corner
menuLocation = new Point(focusedComponent.getX() - 1, focusedComponent.getY() - 1);
}
if (menuLocation == null) {
// menu location at the bottom left of the JTable or JTree
menuLocation = new Point(new Double(selectionRectangle.getMinX() + 1).intValue(), new Double(selectionRectangle.getMaxY() - 1).intValue());
}
// generate a right/button 3/popup menu mouse click
focusedComponent.dispatchEvent(new MouseEvent(focusedComponent, MouseEvent.MOUSE_PRESSED, e.getWhen(), MouseEvent.BUTTON3_DOWN_MASK, menuLocation.x, menuLocation.y, 1, true, MouseEvent.BUTTON3));
}
}
});
mainTabbedPane.getModel().addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
// find the handle in the resources tree for the main view
JComponent largeView = (JComponent) mainTabbedPane.getSelectedComponent();
Enumeration<?> nodesEnum = resourcesTreeRoot.preorderEnumeration();
boolean done = false;
DefaultMutableTreeNode node = resourcesTreeRoot;
while (!done && nodesEnum.hasMoreElements()) {
node = (DefaultMutableTreeNode) nodesEnum.nextElement();
done = node.getUserObject() instanceof Handle && ((Handle) node.getUserObject()).viewsBuilt() && ((Handle) node.getUserObject()).getLargeView() == largeView;
}
ActionMap actionMap = ((JComponent) instance.getContentPane()).getActionMap();
if (done) {
Handle handle = (Handle) node.getUserObject();
if (Gate.getUserConfig().getBoolean(MainFrame.class.getName() + ".viewselecttree")) {
// synchronise the selection in the tabbed pane with
// the one in the resources tree
TreePath nodePath = new TreePath(node.getPath());
resourcesTree.setSelectionPath(nodePath);
resourcesTree.scrollPathToVisible(nodePath);
}
lowerScroll.getViewport().setView(handle.getSmallView());
// redefine MainFrame actionMaps for the selected tab
JComponent resource = (JComponent) mainTabbedPane.getSelectedComponent();
actionMap.put("Close resource", resource.getActionMap().get("Close resource"));
actionMap.put("Close recursively", resource.getActionMap().get("Close recursively"));
actionMap.put("Hide", new CloseViewAction(handle));
actionMap.put("Hide all", new HideAllAction());
actionMap.put("Save As XML", resource.getActionMap().get("Save As XML"));
} else {
// the selected item is not a resource (maybe the log area?)
lowerScroll.getViewport().setView(null);
// disabled actions on the selected tabbed pane
actionMap.put("Close resource", null);
actionMap.put("Close recursively", null);
actionMap.put("Hide", null);
actionMap.put("Hide all", null);
actionMap.put("Save As XML", null);
}
}
});
mainTabbedPane.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
processMouseEvent(e);
}
@Override
public void mouseReleased(MouseEvent e) {
processMouseEvent(e);
}
protected void processMouseEvent(MouseEvent e) {
if (e.isPopupTrigger()) {
int index = mainTabbedPane.getIndexAt(e.getPoint());
if (index != -1) {
JComponent view = (JComponent) mainTabbedPane.getComponentAt(index);
Enumeration<?> nodesEnum = resourcesTreeRoot.preorderEnumeration();
boolean done = false;
DefaultMutableTreeNode node = resourcesTreeRoot;
while (!done && nodesEnum.hasMoreElements()) {
node = (DefaultMutableTreeNode) nodesEnum.nextElement();
done = node.getUserObject() instanceof Handle && ((Handle) node.getUserObject()).viewsBuilt() && ((Handle) node.getUserObject()).getLargeView() == view;
}
if (done) {
Handle handle = (Handle) node.getUserObject();
JPopupMenu popup = handle.getPopup();
// add a hide action
CloseViewAction cva = new CloseViewAction(handle);
XJMenuItem menuItem = new XJMenuItem(cva, MainFrame.this);
popup.insert(menuItem, 0);
// add a hide all action
if (mainTabbedPane.getTabCount() > 2) {
HideAllAction haa = new HideAllAction();
menuItem = new XJMenuItem(haa, MainFrame.this);
popup.insert(menuItem, 1);
}
popup.show(mainTabbedPane, e.getX(), e.getY());
}
}
}
}
});
addComponentListener(new ComponentAdapter() {
@Override
public void componentShown(ComponentEvent e) {
leftSplit.setDividerLocation(0.7);
}
@Override
public void componentResized(ComponentEvent e) {
// resize proportionally the status bar elements
int width = MainFrame.this.getWidth();
statusBar.setPreferredSize(new Dimension(width * 65 / 100, statusBar.getPreferredSize().height));
progressBar.setPreferredSize(new Dimension(width * 20 / 100, progressBar.getPreferredSize().height));
progressBar.setMinimumSize(new Dimension(80, 0));
globalProgressBar.setPreferredSize(new Dimension(width * 10 / 100, globalProgressBar.getPreferredSize().height));
globalProgressBar.setMinimumSize(new Dimension(80, 0));
}
});
// blink the messages tab when new information is displayed
logArea.getDocument().addDocumentListener(new javax.swing.event.DocumentListener() {
@Override
public void insertUpdate(javax.swing.event.DocumentEvent e) {
changeOccured();
}
@Override
public void removeUpdate(javax.swing.event.DocumentEvent e) {
changeOccured();
}
@Override
public void changedUpdate(javax.swing.event.DocumentEvent e) {
}
protected void changeOccured() {
logHighlighter.highlight();
}
});
logArea.addPropertyChangeListener("document", new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
// add the document listener
logArea.getDocument().addDocumentListener(new javax.swing.event.DocumentListener() {
@Override
public void insertUpdate(javax.swing.event.DocumentEvent e) {
changeOccured();
}
@Override
public void removeUpdate(javax.swing.event.DocumentEvent e) {
changeOccured();
}
@Override
public void changedUpdate(javax.swing.event.DocumentEvent e) {
changeOccured();
}
protected void changeOccured() {
logHighlighter.highlight();
}
});
}
});
Gate.getListeners().put("gate.event.StatusListener", MainFrame.this);
Gate.getListeners().put("gate.event.ProgressListener", MainFrame.this);
if (Gate.runningOnMac()) {
// mac-specific initialisation
initMacListeners();
}
}
use of java.awt.event.ComponentEvent in project IBMiProgTool by vzupka.
the class MainWindow method createWindow.
/**
* Create window containing trees with initial files in upper part; Left tree
* shows local file system; Right tree shows IBM i file system (IFS).
*/
public void createWindow() {
cont = getContentPane();
globalPanel = new JPanel();
globalPanelLayout = new GroupLayout(globalPanel);
menuBar = new JMenuBar();
helpMenu = new JMenu("Help");
helpMenuItemEN = new JMenuItem("Help English");
helpMenuItemCZ = new JMenuItem("Nápověda česky");
helpMenuItemRPGIII = new JMenuItem("RPG III forms");
helpMenuItemRPGIV = new JMenuItem("RPG IV forms");
helpMenuItemCOBOL = new JMenuItem("COBOL form");
helpMenuItemDDS = new JMenuItem("DDS forms");
helpMenu.add(helpMenuItemEN);
helpMenu.add(helpMenuItemCZ);
helpMenu.add(helpMenuItemRPGIII);
helpMenu.add(helpMenuItemRPGIV);
helpMenu.add(helpMenuItemCOBOL);
helpMenu.add(helpMenuItemDDS);
menuBar.add(helpMenu);
// In macOS on the main system menu bar above, in Windows on the window menu bar
setJMenuBar(menuBar);
panelTop = new JPanel();
panelTopLayout = new GroupLayout(panelTop);
panelTop.setLayout(panelTopLayout);
panelPathLeft = new JPanel();
panelPathLeft.setLayout(new BoxLayout(panelPathLeft, BoxLayout.LINE_AXIS));
scrollPaneLeft = new JScrollPane();
scrollPaneLeft.setBorder(BorderFactory.createEmptyBorder());
panelPathRight = new JPanel();
panelPathRight.setLayout(new BoxLayout(panelPathRight, BoxLayout.LINE_AXIS));
scrollPaneRight = new JScrollPane();
scrollPaneRight.setBorder(BorderFactory.createEmptyBorder());
// Windows: Disks combo box is included in order to choose proper root
// directory (A:\, C:\, ...)
Component diskLabelWin;
Component disksComboBoxWin;
if (operatingSystem.equals(WINDOWS)) {
diskLabelWin = disksLabel;
disksComboBoxWin = disksComboBox;
} else {
//
// Unix (Mac): Empty component instead of combo box
diskLabelWin = new JLabel("");
disksComboBoxWin = new JLabel("");
}
disksComboBox.setToolTipText("List of root directories.");
// Lay out components in panelTop
panelTopLayout.setAutoCreateGaps(false);
panelTopLayout.setAutoCreateContainerGaps(false);
panelTopLayout.setHorizontalGroup(panelTopLayout.createParallelGroup(Alignment.LEADING).addGroup(panelTopLayout.createSequentialGroup().addComponent(userNameLabel).addComponent(userNameTextField).addComponent(hostLabel).addComponent(hostTextField).addComponent(connectReconnectButton).addGap(5).addComponent(libraryPatternLabel).addComponent(libraryPatternTextField).addGap(5).addComponent(filePatternLabel).addComponent(filePatternTextField).addGap(5).addComponent(memberPatternLabel).addComponent(memberPatternTextField).addGap(5).addComponent(sourceTypeLabel).addComponent(sourceTypeComboBox)).addGroup(panelTopLayout.createSequentialGroup().addComponent(pcCharsetLabel).addComponent(pcCharComboBox).addComponent(ibmCcsidLabel).addComponent(ibmCcsidComboBox).addComponent(sourceRecordLengthLabel).addComponent(sourceRecordLengthTextField).addComponent(sourceRecordPrefixLabel).addComponent(sourceRecordPrefixCheckBox).addComponent(overwriteOutputFileLabel).addComponent(overwriteOutputFileCheckBox).addComponent(diskLabelWin).addComponent(disksComboBoxWin)));
panelTopLayout.setVerticalGroup(panelTopLayout.createSequentialGroup().addGroup(panelTopLayout.createParallelGroup(Alignment.CENTER).addComponent(userNameLabel).addComponent(userNameTextField).addComponent(hostLabel).addComponent(hostTextField).addComponent(connectReconnectButton).addGap(5).addComponent(libraryPatternLabel).addComponent(libraryPatternTextField).addGap(5).addComponent(filePatternLabel).addComponent(filePatternTextField).addGap(5).addComponent(memberPatternLabel).addComponent(memberPatternTextField).addGap(5).addComponent(sourceTypeLabel).addComponent(sourceTypeComboBox)).addGroup(panelTopLayout.createParallelGroup(Alignment.CENTER).addComponent(pcCharsetLabel).addComponent(pcCharComboBox).addComponent(ibmCcsidLabel).addComponent(ibmCcsidComboBox).addComponent(sourceRecordLengthLabel).addComponent(sourceRecordLengthTextField).addComponent(sourceRecordPrefixLabel).addComponent(sourceRecordPrefixCheckBox).addComponent(overwriteOutputFileLabel).addComponent(overwriteOutputFileCheckBox).addComponent(diskLabelWin).addComponent(disksComboBoxWin)));
panelTop.setLayout(panelTopLayout);
panelPathLeft.add(leftPathLabel);
leftPathComboBox.setEditable(true);
panelPathLeft.add(leftPathComboBox);
panelPathRight.add(rightPathLabel);
rightPathComboBox.setEditable(true);
panelPathRight.add(rightPathComboBox);
panelLeft = new JPanel();
panelLeft.setLayout(new BorderLayout());
panelLeft.add(panelPathLeft, BorderLayout.NORTH);
panelLeft.add(scrollPaneLeft, BorderLayout.CENTER);
panelRight = new JPanel();
panelRight.setLayout(new BorderLayout());
panelRight.add(panelPathRight, BorderLayout.NORTH);
panelRight.add(scrollPaneRight, BorderLayout.CENTER);
// Split pane inner - divided by horizontal divider
splitPaneInner = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
splitPaneInner.setLeftComponent(panelLeft);
splitPaneInner.setRightComponent(panelRight);
splitPaneInner.setDividerSize(6);
splitPaneInner.setBorder(BorderFactory.createEmptyBorder());
// Scroll pane for message list
scrollMessagePane.setBorder(BorderFactory.createEmptyBorder());
// Split pane outer - divided by vertical divider
splitPaneOuter = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
splitPaneOuter.setTopComponent(splitPaneInner);
splitPaneOuter.setBottomComponent(scrollMessagePane);
splitPaneOuter.setDividerSize(6);
splitPaneOuter.setBorder(BorderFactory.createEmptyBorder());
// This listener keeps the scroll pane at the LAST MESSAGE.
messageScrollPaneAdjustmentListenerMax = new MessageScrollPaneAdjustmentListenerMax();
// List of messages for placing into message scroll pane
messageList = new JList<String>();
// Decision what color the message will get
messageList.setCellRenderer(new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
Component component = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (value.toString().startsWith("Comp")) {
this.setForeground(DIM_BLUE);
} else if (value.toString().startsWith("Err")) {
this.setForeground(DIM_RED);
} else if (value.toString().startsWith("Info")) {
this.setForeground(Color.GRAY);
} else if (value.toString().startsWith("Wait")) {
this.setForeground(DIM_PINK);
} else {
this.setForeground(Color.BLACK);
}
return component;
}
});
// Build messageTable and put it to scrollMessagePane and panelMessages
buildMessageList();
// Create left tree showing local file system
// ----------------
leftRoot = properties.getProperty("LEFT_PATH");
// ----------------------------------------------
// Create new left side
// ----------------------------------------------
// Create split panes containing the PC file tree on the left side of the window
createNewLeftSide(leftRoot);
// Lay out the window components using GroupLayout
// -----------------------------
globalPanelLayout.setAutoCreateGaps(false);
globalPanelLayout.setAutoCreateContainerGaps(false);
globalPanelLayout.setHorizontalGroup(globalPanelLayout.createSequentialGroup().addGroup(globalPanelLayout.createParallelGroup().addComponent(panelTop).addComponent(splitPaneOuter)));
globalPanelLayout.setVerticalGroup(globalPanelLayout.createParallelGroup().addGroup(globalPanelLayout.createSequentialGroup().addComponent(panelTop).addComponent(splitPaneOuter)));
// Create a global panel to wrap the layout
globalPanel.setLayout(globalPanelLayout);
// Set border to the global panel - before it is visible
globalPanel.setBorder(BorderFactory.createLineBorder(globalPanel.getBackground(), borderWidth));
// When the split pane is visible - can divide it by percentage
// 50 %
double splitPaneInnerDividerLoc = 0.50d;
// Percentage to reveal the first message line height when the scroll pane is full
double splitPaneOuterDividerLoc = 0.835d;
splitPaneInner.setDividerLocation(splitPaneInnerDividerLoc);
splitPaneOuter.setDividerLocation(splitPaneOuterDividerLoc);
// Stabilize vertical divider always in the middle
splitPaneInner.setResizeWeight(0.5);
// Register WindowListener for storing X and Y coordinates to properties
addWindowListener(new MainWindowAdapter());
// Register HelpWindow menu item listener
helpMenuItemEN.addActionListener(ae -> {
String command = ae.getActionCommand();
if (command.equals("Help English")) {
if (Desktop.isDesktopSupported()) {
String uri = Paths.get(System.getProperty("user.dir"), "helpfiles", "IBMiProgTool_doc_EN.pdf").toString();
// Replace backslashes by forward slashes in Windows
uri = uri.replace('\\', '/');
uri = uri.replace(" ", "%20");
try {
// Invoke the standard browser in the operating system
Desktop.getDesktop().browse(new URI("file://" + uri));
} catch (Exception exc) {
exc.printStackTrace();
}
}
}
});
// Register HelpWindow menu item listener
helpMenuItemCZ.addActionListener(ae -> {
String command = ae.getActionCommand();
if (command.equals("Nápověda česky")) {
if (Desktop.isDesktopSupported()) {
String uri = Paths.get(System.getProperty("user.dir"), "helpfiles", "IBMiProgTool_doc_CZ.pdf").toString();
// Replace backslashes by forward slashes in Windows
uri = uri.replace('\\', '/');
uri = uri.replace(" ", "%20");
try {
// Invoke the standard browser in the operating system
Desktop.getDesktop().browse(new URI("file://" + uri));
} catch (Exception exc) {
exc.printStackTrace();
}
}
}
});
// Register HelpWindow menu item listener
helpMenuItemRPGIII.addActionListener(ae -> {
String command = ae.getActionCommand();
if (command.equals("RPG III forms")) {
if (Desktop.isDesktopSupported()) {
String uri = Paths.get(System.getProperty("user.dir"), "helpfiles", "RPG_III_forms.pdf").toString();
// Replace backslashes by forward slashes in Windows
uri = uri.replace('\\', '/');
try {
// Invoke the standard browser in the operating system
Desktop.getDesktop().browse(new URI("file://" + uri));
} catch (Exception exc) {
exc.printStackTrace();
}
}
}
});
// Register HelpWindow menu item listener
helpMenuItemRPGIV.addActionListener(ae -> {
String command = ae.getActionCommand();
if (command.equals("RPG IV forms")) {
if (Desktop.isDesktopSupported()) {
String uri = Paths.get(System.getProperty("user.dir"), "helpfiles", "RPG_IV_forms.pdf").toString();
// Replace backslashes by forward slashes in Windows
uri = uri.replace('\\', '/');
uri = uri.replace(" ", "%20");
try {
// Invoke the standard browser in the operating system
Desktop.getDesktop().browse(new URI("file://" + uri));
} catch (Exception exc) {
exc.printStackTrace();
}
}
}
});
// Register HelpWindow menu item listener
helpMenuItemCOBOL.addActionListener(ae -> {
String command = ae.getActionCommand();
if (command.equals("COBOL form")) {
if (Desktop.isDesktopSupported()) {
String uri = Paths.get(System.getProperty("user.dir"), "helpfiles", "COBOL_form.pdf").toString();
// Replace backslashes by forward slashes in Windows
uri = uri.replace('\\', '/');
uri = uri.replace(" ", "%20");
try {
// Invoke the standard browser in the operating system
Desktop.getDesktop().browse(new URI("file://" + uri));
} catch (Exception exc) {
exc.printStackTrace();
}
}
}
});
// Register HelpWindow menu item listener
helpMenuItemDDS.addActionListener(ae -> {
String command = ae.getActionCommand();
if (command.equals("DDS forms")) {
if (Desktop.isDesktopSupported()) {
String uri = Paths.get(System.getProperty("user.dir"), "helpfiles", "DDS_forms.pdf").toString();
// Replace backslashes by forward slashes in Windows
uri = uri.replace('\\', '/');
uri = uri.replace(" ", "%20");
try {
// Invoke the standard browser in the operating system
Desktop.getDesktop().browse(new URI("file://" + uri));
} catch (Exception exc) {
exc.printStackTrace();
}
}
}
});
// Set left path string as selected in the left combo box
leftPathComboBox.setSelectedItem(leftPathString);
// Set also right path string in the right combo box
rightPathComboBox.setSelectedItem(rightPathString);
//
// User name text field action
// ---------------------------
userNameTextField.addActionListener(ae -> {
userNameTextField.setText(userNameTextField.getText().toUpperCase());
// Create the updated text file in directory "paramfiles"
try {
infile = Files.newBufferedReader(parPath, Charset.forName(encoding));
properties.load(infile);
infile.close();
properties.setProperty("USERNAME", userNameTextField.getText());
outfile = Files.newBufferedWriter(parPath, Charset.forName(encoding));
properties.store(outfile, PROP_COMMENT);
outfile.close();
refreshWindow();
} catch (Exception exc) {
exc.printStackTrace();
}
});
//
// Host text field action
// ----------------------
hostTextField.addActionListener(ae -> {
hostTextField.setText(hostTextField.getText());
// Connect or reconnect the server
connectReconnectRefresh();
});
//
// Source Type combo box item listener
// ---------------------
sourceTypeComboBox.addItemListener(il -> {
// JComboBox<String> source = new
// JComboBox<String>((String[])il.getSource());
JComboBox<String[]> source = (JComboBox) il.getSource();
sourceType = (String) source.getSelectedItem();
// Create the updated text file in directory "paramfiles"
try {
infile = Files.newBufferedReader(parPath, Charset.forName(encoding));
properties.load(infile);
infile.close();
properties.setProperty("SOURCE_TYPE", sourceType);
outfile = Files.newBufferedWriter(parPath, Charset.forName(encoding));
properties.store(outfile, PROP_COMMENT);
outfile.close();
} catch (Exception exc) {
exc.printStackTrace();
}
});
//
// Library pattern text field action
// -------------------------
libraryPatternTextField.addActionListener(ae -> {
libraryPatternTextField.setText(libraryPatternTextField.getText().toUpperCase());
// Create the updated text file in directory "paramfiles"
try {
infile = Files.newBufferedReader(parPath, Charset.forName(encoding));
properties.load(infile);
infile.close();
properties.setProperty("LIBRARY_PATTERN", libraryPatternTextField.getText());
outfile = Files.newBufferedWriter(parPath, Charset.forName(encoding));
properties.store(outfile, PROP_COMMENT);
outfile.close();
connectReconnectRefresh();
} catch (Exception exc) {
exc.printStackTrace();
}
});
//
// Source file pattern text field action
// ------------------------------------
filePatternTextField.addActionListener(ae -> {
filePatternTextField.setText(filePatternTextField.getText().toUpperCase());
// Create the updated text file in directory "paramfiles"
try {
infile = Files.newBufferedReader(parPath, Charset.forName(encoding));
properties.load(infile);
infile.close();
properties.setProperty("FILE_PATTERN", filePatternTextField.getText());
outfile = Files.newBufferedWriter(parPath, Charset.forName(encoding));
properties.store(outfile, PROP_COMMENT);
outfile.close();
connectReconnectRefresh();
} catch (Exception exc) {
exc.printStackTrace();
}
});
//
// Member pattern text field action
// -------------------------------
memberPatternTextField.addActionListener(ae -> {
memberPatternTextField.setText(memberPatternTextField.getText().toUpperCase());
// Create the updated text file in directory "paramfiles"
try {
infile = Files.newBufferedReader(parPath, Charset.forName(encoding));
properties.load(infile);
infile.close();
properties.setProperty("MEMBER_PATTERN", memberPatternTextField.getText());
outfile = Files.newBufferedWriter(parPath, Charset.forName(encoding));
properties.store(outfile, PROP_COMMENT);
outfile.close();
connectReconnectRefresh();
} catch (Exception exc) {
exc.printStackTrace();
}
});
//
// Source record length text field action
// --------------------------------------
sourceRecordLengthTextField.addActionListener(ae -> {
String srcRecLen = sourceRecordLengthTextField.getText();
try {
Integer.parseInt(srcRecLen);
} catch (NumberFormatException nfe) {
// If the user enters non-integer text, take default value
srcRecLen = "80";
}
sourceRecordLengthTextField.setText(srcRecLen);
// Create the updated text file in directory "paramfiles"
try {
infile = Files.newBufferedReader(parPath, Charset.forName(encoding));
properties.load(infile);
infile.close();
outfile = Files.newBufferedWriter(parPath, Charset.forName(encoding));
properties.setProperty("SOURCE_RECORD_LENGTH", srcRecLen);
properties.store(outfile, PROP_COMMENT);
outfile.close();
} catch (Exception exc) {
exc.printStackTrace();
}
});
//
// Connect/Reconnect button action
// -------------------------------
connectReconnectButton.addActionListener(ae -> {
connectReconnectRefresh();
});
//
// PC charset combo box
// --------------------
// Select charset name from the list in combo box - listener
pcCharComboBox.addItemListener(il -> {
JComboBox source = (JComboBox) il.getSource();
pcCharset = (String) source.getSelectedItem();
if (!pcCharset.equals("*DEFAULT")) {
// Check if charset is valid
try {
Charset.forName(pcCharset);
} catch (IllegalCharsetNameException | UnsupportedCharsetException charset) {
// If pcCharset is invalid, take ISO-8859-1
pcCharset = "ISO-8859-1";
pcCharComboBox.setSelectedItem(pcCharset);
}
}
// Create the updated text file in directory "paramfiles"
try {
infile = Files.newBufferedReader(parPath, Charset.forName(encoding));
properties.load(infile);
infile.close();
properties.setProperty("PC_CHARSET", pcCharset);
outfile = Files.newBufferedWriter(parPath, Charset.forName(encoding));
properties.store(outfile, PROP_COMMENT);
outfile.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
});
//
// IBM i CCSID combo box item listener
// ---------------------
ibmCcsidComboBox.addItemListener(il -> {
JComboBox source = (JComboBox) il.getSource();
ibmCcsid = (String) source.getSelectedItem();
if (!ibmCcsid.equals("*DEFAULT")) {
try {
ibmCcsidInt = Integer.parseInt(ibmCcsid);
} catch (Exception exc) {
exc.printStackTrace();
ibmCcsid = "37";
ibmCcsidInt = 37;
ibmCcsidComboBox.setSelectedItem(ibmCcsid);
}
}
// Create the updated text file in directory "paramfiles"
try {
infile = Files.newBufferedReader(parPath, Charset.forName(encoding));
properties.load(infile);
infile.close();
outfile = Files.newBufferedWriter(parPath, Charset.forName(encoding));
properties.setProperty("IBM_CCSID", ibmCcsid);
properties.store(outfile, PROP_COMMENT);
outfile.close();
} catch (Exception exc) {
exc.printStackTrace();
}
});
//
// Source record pattern check box - Yes = "Y", No = ""
// ---------------------------------------------------
sourceRecordPrefixCheckBox.addItemListener(il -> {
Object source = il.getSource();
if (source == sourceRecordPrefixCheckBox) {
String check;
if (sourceRecordPrefixCheckBox.isSelected()) {
check = "Y";
} else {
check = "";
}
// Create the updated text file in directory "paramfiles"
try {
infile = Files.newBufferedReader(parPath, Charset.forName(encoding));
properties.load(infile);
infile.close();
outfile = Files.newBufferedWriter(parPath, Charset.forName(encoding));
properties.setProperty("SOURCE_RECORD_PREFIX", check);
properties.store(outfile, PROP_COMMENT);
outfile.close();
} catch (Exception exc) {
exc.printStackTrace();
}
}
});
//
// Overwrite output file(s) check box - Yes = "Y", No = ""
// -------------------------------------------------------
overwriteOutputFileCheckBox.addItemListener(il -> {
Object source = il.getSource();
if (source == overwriteOutputFileCheckBox) {
String check;
if (overwriteOutputFileCheckBox.isSelected()) {
check = "Y";
} else {
check = "";
}
// Create the updated text file in directory "paramfiles"
try {
infile = Files.newBufferedReader(parPath, Charset.forName(encoding));
properties.load(infile);
infile.close();
outfile = Files.newBufferedWriter(parPath, Charset.forName(encoding));
properties.setProperty("OVERWRITE_FILE", check);
properties.store(outfile, PROP_COMMENT);
outfile.close();
} catch (Exception exc) {
exc.printStackTrace();
}
}
});
//
// Left popup menu on Right mouse click
// ====================================
//
// Find text in multiple PC files
//
findInPcFiles.addActionListener(ae -> {
copySourceTree = leftTree;
// Set clipboard path string for find operation
clipboardPathStrings = leftPathStrings;
SearchWindow searchWindow = new SearchWindow(remoteServer, this, "PC");
});
//
// Send to remote server (IBM i)
//
copyFromLeft.addActionListener(ae -> {
copySourceTree = leftTree;
// Set clipboard path string for paste operation
clipboardPathStrings = leftPathStrings;
});
//
// Receive from remote server (IBM i) or PC itself
//
pasteToLeft.addActionListener(ae -> {
if (copySourceTree == rightTree) {
row = "Wait: Copying from IBM i to PC . . .";
msgVector.add(row);
showMessages();
// Paste from IBM i to PC
ParallelCopy_IBMi_PC parallelCopy_IMBI_PC = new ParallelCopy_IBMi_PC(remoteServer, clipboardPathStrings, leftPathStrings[0], null, this);
parallelCopy_IMBI_PC.execute();
} else if (copySourceTree == leftTree) {
row = "Wait: Copying from PC to PC . . .";
msgVector.add(row);
showMessages(nodes);
// Paste from PC to PC
ParallelCopy_PC_PC parallelCopy_PC_PC = new ParallelCopy_PC_PC(clipboardPathStrings, leftPathStrings[0], null, this);
parallelCopy_PC_PC.execute();
}
});
// Insert spooled file that is copied from directory *workfiles* and, renamed,
// into selected directory *targetPathString*
insertSpooledFile.addActionListener(ae -> {
scrollMessagePane.getVerticalScrollBar().addAdjustmentListener(messageScrollPaneAdjustmentListenerMax);
sourcePathString = Paths.get(System.getProperty("user.dir"), "workfiles", "SpooledFile.txt").toString();
targetPathString = leftPathStrings[0];
copyAndRenameFile("SpooledFile.txt");
reloadLeftSide(nodes);
});
// Display PC file
displayPcFile.addActionListener(ae -> {
clipboardPathStrings = leftPathStrings;
// Display all selected files
for (int idx = 0; idx < clipboardPathStrings.length; idx++) {
sourcePathString = clipboardPathStrings[idx];
JTextArea textArea = new JTextArea();
// This is a way to display a PC file directly from Java:
DisplayFile dspf = new DisplayFile(textArea, this);
dspf.displayPcFile(sourcePathString);
}
});
// Edit PC file
editPcFile.addActionListener(ae -> {
clipboardPathStrings = leftPathStrings;
for (int idx = 0; idx < clipboardPathStrings.length; idx++) {
sourcePathString = clipboardPathStrings[idx];
JTextArea textArea = new JTextArea();
JTextArea textArea2 = new JTextArea();
EditFile edtf = new EditFile(remoteServer, this, textArea, textArea2, leftPathString, "rewritePcFile");
}
});
// Rename PC file
renamePcFile.addActionListener(ae -> {
RenamePcObject rnmpf = new RenamePcObject(this, pcFileSep, currentX, currentY);
rnmpf.renamePcObject(leftPathString);
});
// Create PC directory
createPcDirectory.addActionListener(ae -> {
clipboardPathStrings = leftPathStrings;
if (clipboardPathStrings.length > 0) {
leftPathString = clipboardPathStrings[0];
CreateAndDeleteInPC cpcd = new CreateAndDeleteInPC(this, "createPcDirectory", currentX, currentY);
cpcd.createAndDeleteInPC();
reloadLeftSide(nodes);
}
});
// Create PC file
createPcFile.addActionListener(ae -> {
CreateAndDeleteInPC cpcf = new CreateAndDeleteInPC(this, "createPcFile", currentX, currentY);
cpcf.createAndDeleteInPC();
reloadLeftSide(nodes);
});
// Move PC objects to trash
movePcObjectToTrash.addActionListener(ae -> {
scrollMessagePane.getVerticalScrollBar().addAdjustmentListener(messageScrollPaneAdjustmentListenerMax);
// Move selected objects to trash
// ------------------------------
// Set clipboard path strings for paste operation
clipboardPathStrings = leftPathStrings;
for (int idx = 0; idx < clipboardPathStrings.length; idx++) {
// Set path string for the following class
leftPathString = clipboardPathStrings[idx];
// Move one object to trash
CreateAndDeleteInPC dpco = new CreateAndDeleteInPC(this, "movePcObjectToTrash", currentX, currentY);
dpco.createAndDeleteInPC();
}
// Remove selected nodes
TreePath[] paths = leftTree.getSelectionPaths();
for (int indx = 0; indx < paths.length; indx++) {
leftNode = (DefaultMutableTreeNode) (paths[indx].getLastPathComponent());
leftTreeModel.removeNodeFromParent(leftNode);
}
});
//
// Right popup menu on Right mouse click
// =====================================
//
// Find text in multiple IFS files
//
findInIfsFiles.addActionListener(ae -> {
copySourceTree = rightTree;
// Set clipboard path string for find operation
clipboardPathStrings = rightPathStrings;
SearchWindow searchWindow = new SearchWindow(remoteServer, this, "IFS");
});
// Send to PC or IBM i itself
copyFromRight.addActionListener(ae -> {
copySourceTree = rightTree;
// Set clipboard path string for paste operation
clipboardPathStrings = rightPathStrings;
});
// Receive from PC or IBM i itself
// -------------------------------
pasteToRight.addActionListener(ae -> {
// This listener keeps the scroll pane at the LAST MESSAGE.
// It is removed at the end of the method of the background task.
scrollMessagePane.getVerticalScrollBar().addAdjustmentListener(messageScrollPaneAdjustmentListenerMax);
sourcePathString = clipboardPathString;
targetPathString = rightPathStrings[0];
if (copySourceTree == rightTree) {
// Paste from IBM i to IBM i
row = "Wait: Copying from IBM i to IBM i . . .";
msgVector.add(row);
showMessages();
ParallelCopy_IBMi_IBMi parallelCopy_IMBI_IBMI = new ParallelCopy_IBMi_IBMi(remoteServer, clipboardPathStrings, targetPathString, null, this);
parallelCopy_IMBI_IBMI.execute();
} else if (copySourceTree == leftTree) {
// Paste from PC to IBM i
row = "Wait: Copying from PC to IBM i . . .";
msgVector.add(row);
showMessages();
ParallelCopy_PC_IBMi parallelCopy_PC_IBMI = new ParallelCopy_PC_IBMi(remoteServer, clipboardPathStrings, targetPathString, null, this);
parallelCopy_PC_IBMI.execute();
}
});
// Copy library
copyLibrary.addActionListener(ae -> {
scrollMessagePane.getVerticalScrollBar().addAdjustmentListener(messageScrollPaneAdjustmentListenerMax);
ifsFile = new IFSFile(remoteServer, rightPathString);
CreateAndDeleteInIBMi crtdlt = new CreateAndDeleteInIBMi(remoteServer, ifsFile, this, "copyLibrary", currentX, currentY);
crtdlt.createAndDeleteInIBMi(currentX, currentY);
reloadRightSide();
});
// Clear library
clearLibrary.addActionListener(ae -> {
scrollMessagePane.getVerticalScrollBar().addAdjustmentListener(messageScrollPaneAdjustmentListenerMax);
// Set clipboard path strings for paste operation
clipboardPathStrings = rightPathStrings;
for (int idx = 0; idx < clipboardPathStrings.length; idx++) {
rightPathString = clipboardPathStrings[idx];
ifsFile = new IFSFile(remoteServer, rightPathString);
// Clear selected libraries
// ------------------------
CreateAndDeleteInIBMi crtdlt = new CreateAndDeleteInIBMi(remoteServer, ifsFile, this, "clearLibrary", currentX, currentY);
crtdlt.createAndDeleteInIBMi(currentX, currentY);
}
// Reload nodes of cleared libraries
TreePath[] paths = rightTree.getSelectionPaths();
for (int indx = 0; indx < paths.length; indx++) {
rightNode = (DefaultMutableTreeNode) (paths[indx].getLastPathComponent());
reloadRightSide();
}
});
// Delete library
deleteLibrary.addActionListener(ae -> {
scrollMessagePane.getVerticalScrollBar().addAdjustmentListener(messageScrollPaneAdjustmentListenerMax);
// Set clipboard path strings for paste operation
clipboardPathStrings = rightPathStrings;
for (int idx = 0; idx < clipboardPathStrings.length; idx++) {
rightPathString = clipboardPathStrings[idx];
ifsFile = new IFSFile(remoteServer, rightPathString);
// Delete selected libraries
// -------------------------
CreateAndDeleteInIBMi crtdlt = new CreateAndDeleteInIBMi(remoteServer, ifsFile, this, "deleteLibrary", currentX, currentY);
crtdlt.createAndDeleteInIBMi(currentX, currentY);
}
// Remove selected nodes
TreePath[] paths = rightTree.getSelectionPaths();
for (int indx = 0; indx < paths.length; indx++) {
rightNode = (DefaultMutableTreeNode) (paths[indx].getLastPathComponent());
rightTreeModel.removeNodeFromParent(rightNode);
}
});
// Create IFS directory in a parent directory
createIfsDirectory.addActionListener(ae -> {
scrollMessagePane.getVerticalScrollBar().addAdjustmentListener(messageScrollPaneAdjustmentListenerMax);
ifsFile = new IFSFile(remoteServer, rightPathString);
CreateAndDeleteInIBMi crtdlt = new CreateAndDeleteInIBMi(remoteServer, ifsFile, this, "createIfsDirectory", currentX, currentY);
crtdlt.createAndDeleteInIBMi(currentX, currentY);
reloadRightSide();
});
// Create IFS directory in a parent directory
createIfsFile.addActionListener(ae -> {
scrollMessagePane.getVerticalScrollBar().addAdjustmentListener(messageScrollPaneAdjustmentListenerMax);
ifsFile = new IFSFile(remoteServer, rightPathString);
CreateAndDeleteInIBMi crtdlt = new CreateAndDeleteInIBMi(remoteServer, ifsFile, this, "createIfsFile", currentX, currentY);
crtdlt.createAndDeleteInIBMi(currentX, currentY);
reloadRightSide();
});
// Create AS400 Source Physical File
createSourcePhysicalFile.addActionListener(ae -> {
scrollMessagePane.getVerticalScrollBar().addAdjustmentListener(messageScrollPaneAdjustmentListenerMax);
ifsFile = new IFSFile(remoteServer, rightPathString);
CreateAndDeleteInIBMi crtdlt = new CreateAndDeleteInIBMi(remoteServer, ifsFile, this, "createSourcePhysicalFile", currentX, currentY);
crtdlt.createAndDeleteInIBMi(currentX, currentY);
reloadRightSide();
});
// Create AS400 Source Member
createSourceMember.addActionListener(ae -> {
scrollMessagePane.getVerticalScrollBar().addAdjustmentListener(messageScrollPaneAdjustmentListenerMax);
ifsFile = new IFSFile(remoteServer, rightPathString);
CreateAndDeleteInIBMi crtdlt = new CreateAndDeleteInIBMi(remoteServer, ifsFile, this, "createSourceMember", currentX, currentY);
crtdlt.createAndDeleteInIBMi(currentX, currentY);
reloadRightSide();
});
// Create Save File
createSaveFile.addActionListener(ae -> {
scrollMessagePane.getVerticalScrollBar().addAdjustmentListener(messageScrollPaneAdjustmentListenerMax);
ifsFile = new IFSFile(remoteServer, rightPathString);
CreateAndDeleteInIBMi crtdlt = new CreateAndDeleteInIBMi(remoteServer, ifsFile, this, "createSaveFile", currentX, currentY);
crtdlt.createAndDeleteInIBMi(currentX, currentY);
reloadRightSide();
});
// Clear Save File
clearSaveFile.addActionListener(ae -> {
scrollMessagePane.getVerticalScrollBar().addAdjustmentListener(messageScrollPaneAdjustmentListenerMax);
ifsFile = new IFSFile(remoteServer, rightPathString);
CreateAndDeleteInIBMi crtdlt = new CreateAndDeleteInIBMi(remoteServer, ifsFile, this, "clearSaveFile", currentX, currentY);
crtdlt.createAndDeleteInIBMi(currentX, currentY);
});
// Delete IFS object (directory or file)
deleteIfsObject.addActionListener(ae -> {
scrollMessagePane.getVerticalScrollBar().addAdjustmentListener(messageScrollPaneAdjustmentListenerMax);
// Delete selected objects
// -----------------------
// Set clipboard path strings for paste operation
clipboardPathStrings = rightPathStrings;
for (int idx = 0; idx < clipboardPathStrings.length; idx++) {
rightPathString = clipboardPathStrings[idx];
ifsFile = new IFSFile(remoteServer, rightPathString);
CreateAndDeleteInIBMi crtdlt = new CreateAndDeleteInIBMi(remoteServer, ifsFile, this, "deleteIfsObject", currentX, currentY);
crtdlt.createAndDeleteInIBMi(currentX, currentY);
}
// Remove selected nodes
TreePath[] paths = rightTree.getSelectionPaths();
for (int indx = 0; indx < paths.length; indx++) {
rightNode = (DefaultMutableTreeNode) (paths[indx].getLastPathComponent());
rightTreeModel.removeNodeFromParent(rightNode);
}
});
// Delete AS400 Source Member
deleteSourceMember.addActionListener(ae -> {
scrollMessagePane.getVerticalScrollBar().addAdjustmentListener(messageScrollPaneAdjustmentListenerMax);
// Set clipboard path strings for paste operation
clipboardPathStrings = rightPathStrings;
for (int idx = 0; idx < clipboardPathStrings.length; idx++) {
rightPathString = clipboardPathStrings[idx];
ifsFile = new IFSFile(remoteServer, rightPathString);
// Delete selected objects
// -----------------------
CreateAndDeleteInIBMi crtdlt = new CreateAndDeleteInIBMi(remoteServer, ifsFile, this, "deleteSourceMember", currentX, currentY);
crtdlt.createAndDeleteInIBMi(currentX, currentY);
}
// Remove selected nodes
TreePath[] paths = rightTree.getSelectionPaths();
for (int indx = 0; indx < paths.length; indx++) {
rightNode = (DefaultMutableTreeNode) (paths[indx].getLastPathComponent());
rightTreeModel.removeNodeFromParent(rightNode);
}
});
// Delete AS400 Source Physical File
deleteSourcePhysicalFile.addActionListener(ae -> {
scrollMessagePane.getVerticalScrollBar().addAdjustmentListener(messageScrollPaneAdjustmentListenerMax);
// Set clipboard path strings for paste operation
clipboardPathStrings = rightPathStrings;
for (int idx = 0; idx < clipboardPathStrings.length; idx++) {
rightPathString = clipboardPathStrings[idx];
ifsFile = new IFSFile(remoteServer, rightPathString);
// Delete selected objects
// -----------------------
CreateAndDeleteInIBMi crtdlt = new CreateAndDeleteInIBMi(remoteServer, ifsFile, this, "deleteSourcePhysicalFile", currentX, currentY);
crtdlt.createAndDeleteInIBMi(currentX, currentY);
}
// Remove selected nodes
TreePath[] paths = rightTree.getSelectionPaths();
for (int indx = 0; indx < paths.length; indx++) {
rightNode = (DefaultMutableTreeNode) (paths[indx].getLastPathComponent());
rightTreeModel.removeNodeFromParent(rightNode);
}
});
// Delete Save File
deleteSaveFile.addActionListener(ae -> {
scrollMessagePane.getVerticalScrollBar().addAdjustmentListener(messageScrollPaneAdjustmentListenerMax);
// Set clipboard path strings for paste operation
clipboardPathStrings = rightPathStrings;
for (int idx = 0; idx < clipboardPathStrings.length; idx++) {
rightPathString = clipboardPathStrings[idx];
ifsFile = new IFSFile(remoteServer, rightPathString);
// Delete selected objects
// -----------------------
CreateAndDeleteInIBMi crtdlt = new CreateAndDeleteInIBMi(remoteServer, ifsFile, this, "deleteSaveFile", currentX, currentY);
crtdlt.createAndDeleteInIBMi(currentX, currentY);
}
// Remove selected nodes
TreePath[] paths = rightTree.getSelectionPaths();
for (int indx = 0; indx < paths.length; indx++) {
rightNode = (DefaultMutableTreeNode) (paths[indx].getLastPathComponent());
rightTreeModel.removeNodeFromParent(rightNode);
}
});
// Work with spooled files
workWithSpooledFiles.addActionListener(ae -> {
scrollMessagePane.getVerticalScrollBar().addAdjustmentListener(messageScrollPaneAdjustmentListenerMax);
String className = this.getClass().getSimpleName();
// first "false" stands for *ALL users (not *CURRENT user),
// second "true" stands for "create spooled file table".
WrkSplFCall wwsp = new WrkSplFCall(remoteServer, this, rightPathString, // not *CURRENT user
false, currentX, currentY, className, // create spooled file table
true);
wwsp.execute();
});
// Display IFS file
displayIfsFile.addActionListener(ae -> {
scrollMessagePane.getVerticalScrollBar().addAdjustmentListener(messageScrollPaneAdjustmentListenerMax);
JTextArea textArea = new JTextArea();
DisplayFile dspf = new DisplayFile(textArea, this);
dspf.displayIfsFile(remoteServer, rightPathString);
});
// Edit IFS file with source types suffix (e.g. .CLLE, .RPGLE, etc.)
editIfsFile.addActionListener(ae -> {
scrollMessagePane.getVerticalScrollBar().addAdjustmentListener(messageScrollPaneAdjustmentListenerMax);
JTextArea textArea = new JTextArea();
JTextArea textArea2 = new JTextArea();
EditFile edtf = new EditFile(remoteServer, this, textArea, textArea2, rightPathString, "rewriteIfsFile");
});
// Rename IFS file
renameIfsFile.addActionListener(ae -> {
scrollMessagePane.getVerticalScrollBar().addAdjustmentListener(messageScrollPaneAdjustmentListenerMax);
RenameIfsObject rnmifsf = new RenameIfsObject(remoteServer, this, currentX, currentY);
rnmifsf.renameIfsObject(rightPathString);
});
// Compile IFS file
compileIfsFile.addActionListener(ae -> {
scrollMessagePane.getVerticalScrollBar().addAdjustmentListener(messageScrollPaneAdjustmentListenerMax);
if (compile == null) {
compile = new Compile(remoteServer, this, rightPathString, true);
}
// "true" stands for "IFS file" as a source text
compile.compile(rightPathString, true);
// compile = null;
});
// Display IBM i Source Member
displaySourceMember.addActionListener(ae -> {
scrollMessagePane.getVerticalScrollBar().addAdjustmentListener(messageScrollPaneAdjustmentListenerMax);
JTextArea textArea = new JTextArea();
DisplayFile dspf = new DisplayFile(textArea, this);
dspf.displaySourceMember(remoteServer, rightPathString);
});
// Edit IBM i Source Member
editSourceMember.addActionListener(ae -> {
scrollMessagePane.getVerticalScrollBar().addAdjustmentListener(messageScrollPaneAdjustmentListenerMax);
JTextArea textArea = new JTextArea();
JTextArea textArea2 = new JTextArea();
EditFile edtf = new EditFile(remoteServer, this, textArea, textArea2, rightPathString, "rewriteSourceMember");
});
// Compile Source Member
compileSourceMember.addActionListener(ae -> {
scrollMessagePane.getVerticalScrollBar().addAdjustmentListener(messageScrollPaneAdjustmentListenerMax);
if (compile == null) {
compile = new Compile(remoteServer, this, rightPathString, false);
}
// "false" means "IFS file" is NOT a source text
compile.compile(rightPathString, false);
// compile = null;
});
//
// Find text in multiple Source Members
//
findInSourceMembers.addActionListener(ae -> {
copySourceTree = rightTree;
// Set clipboard path string for find operation
clipboardPathStrings = rightPathStrings;
SearchWindow searchWindow = new SearchWindow(remoteServer, this, "MBR");
});
// =================
if (operatingSystem.equals(WINDOWS)) {
// Item listener for DISKS ComboBox reacts on item selection with
// the
// mouse
disksComboBox.addItemListener(il -> {
JComboBox<String> comboBox = (JComboBox) il.getSource();
leftPathString = (String) comboBox.getSelectedItem();
// Remove the old and create a new combo box for left path selection
panelPathLeft.remove(leftPathComboBox);
leftPathComboBox = new JComboBox<>();
leftPathComboBox.setEditable(true);
panelPathLeft.add(leftPathComboBox);
leftPathComboBox.addItem(leftPathString);
leftPathComboBox.setSelectedIndex(0);
// Register a new ActionListener to the new combo box
leftPathComboBox.addActionListener(leftPathActionListener);
// Get the first item (disk symbol or file system root) from the
// combo box and make it leftRoot
leftRoot = leftPathString;
// Make the disk symbol also firstLeftRootSymbol
firstLeftRootSymbol = leftPathString;
// Clear and set the tree map with leftRoot and row number 0
leftTreeMap.clear();
leftTreeMap.put(leftRoot, 0);
// Create a new tree and table on the left side of the window
leftRootChanged = true;
createNewLeftSide(leftPathString);
});
}
// End Windows
// Processing continues for both Windows and Unix:
//
// Register action listener for LEFT PATH ComboBox reacts on text change
// in its input field (first time)
leftPathComboBox.addActionListener(leftPathActionListener);
// Component listener reacting to WINDOW RESIZING
ComponentListener resizingListener = new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent componentEvent) {
windowWidth = componentEvent.getComponent().getWidth();
windowHeight = componentEvent.getComponent().getHeight();
// 50 %
double splitPaneInnerDividerLoc = 0.50d;
// int splitPaneInnerDividerLoc = (windowWidth - (2 * borderWidth + 5)) / 2;
splitPaneInner.setDividerLocation(splitPaneInnerDividerLoc);
}
};
// Register window resizing listener
addComponentListener(resizingListener);
// Add the global panel to the frame, NOT container
cont.add(globalPanel);
add(globalPanel);
// Set initial size and width of the window
setSize(windowWidth, windowHeight);
// Set window coordinates from application properties
setLocation(mainWindowX, mainWindowY);
// Show the window on the screen
setVisible(true);
// Do not pack
pack();
}
use of java.awt.event.ComponentEvent in project gate-core by GateNLP.
the class JFontChooser method showDialog.
// public JFontChooser(Font initialFont)
public static Font showDialog(Component parent, String title, Font initialfont) {
Window windowParent;
if (parent instanceof Window)
windowParent = (Window) parent;
else
windowParent = SwingUtilities.getWindowAncestor(parent);
if (windowParent == null)
throw new IllegalArgumentException("The supplied parent component has no window ancestor");
final JDialog dialog;
if (windowParent instanceof Frame)
dialog = new JDialog((Frame) windowParent, title, true);
else
dialog = new JDialog((Dialog) windowParent, title, true);
dialog.getContentPane().setLayout(new BoxLayout(dialog.getContentPane(), BoxLayout.Y_AXIS));
final JFontChooser fontChooser = new JFontChooser(initialfont);
dialog.getContentPane().add(fontChooser);
JButton okBtn = new JButton("OK");
JButton cancelBtn = new JButton("Cancel");
JPanel buttonsBox = new JPanel();
buttonsBox.setLayout(new BoxLayout(buttonsBox, BoxLayout.X_AXIS));
buttonsBox.add(Box.createHorizontalGlue());
buttonsBox.add(okBtn);
buttonsBox.add(Box.createHorizontalStrut(30));
buttonsBox.add(cancelBtn);
buttonsBox.add(Box.createHorizontalGlue());
dialog.getContentPane().add(buttonsBox);
dialog.pack();
fontChooser.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
dialog.pack();
}
});
okBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dialog.setVisible(false);
}
});
cancelBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dialog.setVisible(false);
fontChooser.setFontValue(null);
}
});
dialog.setVisible(true);
return fontChooser.getFontValue();
}
use of java.awt.event.ComponentEvent in project energy3d by concord-consortium.
the class MainFrame method initialize.
private void initialize() {
JPopupMenu.setDefaultLightWeightPopupEnabled(false);
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
setTitle("Energy3D V" + MainApplication.VERSION);
setJMenuBar(getAppMenuBar());
setContentPane(getMainPanel());
final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
final Preferences pref = Preferences.userNodeForPackage(MainApplication.class);
setSize(Math.min(pref.getInt("window_size_width", Math.max(900, MainPanel.getInstance().getAppToolbar().getPreferredSize().width)), screenSize.width), Math.min(pref.getInt("window_size_height", 600), screenSize.height));
setLocation(pref.getInt("window_location_x", (int) (screenSize.getWidth() - getSize().getWidth()) / 2), pref.getInt("window_location_y", (int) (screenSize.getHeight() - getSize().getHeight()) / 2));
setLocation(MathUtils.clamp(getLocation().x, 0, screenSize.width - getSize().width), MathUtils.clamp(getLocation().y, 0, screenSize.height - getSize().height));
final int windowState = pref.getInt("window_state", JFrame.NORMAL);
if ((windowState & JFrame.ICONIFIED) == 0) {
setExtendedState(windowState);
}
if (Config.isMac()) {
Mac.init();
}
addComponentListener(new ComponentAdapter() {
@Override
public void componentMoved(final ComponentEvent e) {
if (MainFrame.this.getExtendedState() == 0) {
pref.putInt("window_location_x", e.getComponent().getLocation().x);
pref.putInt("window_location_y", e.getComponent().getLocation().y);
}
}
@Override
public void componentResized(final ComponentEvent e) {
if (MainFrame.this.getExtendedState() == 0) {
pref.putInt("window_size_width", e.getComponent().getSize().width);
pref.putInt("window_size_height", e.getComponent().getSize().height);
}
}
});
addWindowStateListener(new WindowStateListener() {
@Override
public void windowStateChanged(final WindowEvent e) {
pref.putInt("window_state", e.getNewState());
SceneManager.getInstance().refresh();
}
});
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(final WindowEvent e) {
exit();
}
@Override
public void windowDeiconified(final WindowEvent e) {
SceneManager.getInstance().refresh();
}
@Override
public void windowActivated(final WindowEvent e) {
// EnergyPanel.getInstance().initJavaFXGUI();
// SceneManager.getInstance().refresh();
}
});
}
use of java.awt.event.ComponentEvent in project bb4-games by bb4.
the class GamePanel method init.
/**
* common initialization in the event that there are multiple constructors.
*/
@Override
public void init(JFrame parent) {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
initGui(parent);
addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent ce) {
GameContext.log(2, "resized");
}
});
}
Aggregations