use of javax.swing.event.InternalFrameAdapter in project mondrian by pentaho.
the class Workbench method openSchemaFrame.
private void openSchemaFrame(File file, boolean newFile) {
try {
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
if (!newFile) {
// check if file not already open
if (checkFileOpen(file)) {
return;
}
// check if schema file exists
if (!file.exists()) {
JOptionPane.showMessageDialog(this, getResourceConverter().getFormattedString("workbench.open.schema.not.found", "{0} File not found.", file.getAbsolutePath()), getResourceConverter().getString("workbench.open.schema.not.found.title", "Alert"), JOptionPane.WARNING_MESSAGE);
return;
}
// check if file is writable
if (!file.canWrite()) {
JOptionPane.showMessageDialog(this, getResourceConverter().getFormattedString("workbench.open.schema.not.writeable", "{0} is not writeable.", file.getAbsolutePath()), getResourceConverter().getString("workbench.open.schema.not.writeable.title", "Alert"), JOptionPane.WARNING_MESSAGE);
return;
}
checkSchemaFile(file);
}
final JInternalFrame schemaFrame = new JInternalFrame();
schemaFrame.setTitle(getResourceConverter().getFormattedString("workbench.open.schema.title", "Schema - {0}", file.getName()));
getNewJdbcMetadata();
schemaFrame.getContentPane().add(new SchemaExplorer(this, file, jdbcMetaData, newFile, schemaFrame));
String errorOpening = ((SchemaExplorer) schemaFrame.getContentPane().getComponent(0)).getErrMsg();
if (errorOpening != null) {
JOptionPane.showMessageDialog(this, getResourceConverter().getFormattedString("workbench.open.schema.error", "Error opening schema - {0}.", errorOpening), getResourceConverter().getString("workbench.open.schema.error.title", "Error"), JOptionPane.ERROR_MESSAGE);
schemaFrame.setClosed(true);
return;
}
schemaFrame.setBounds(0, 0, 1000, 650);
schemaFrame.setClosable(true);
schemaFrame.setIconifiable(true);
schemaFrame.setMaximizable(true);
schemaFrame.setResizable(true);
schemaFrame.setVisible(true);
desktopPane.add(schemaFrame, javax.swing.JLayeredPane.DEFAULT_LAYER);
schemaFrame.show();
schemaFrame.setMaximum(true);
displayWarningOnFailedConnection();
final javax.swing.JMenuItem schemaMenuItem = new javax.swing.JMenuItem();
schemaMenuItem.setText(windowMenuMapIndex++ + " " + file.getName());
schemaMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
try {
if (schemaFrame.isIcon()) {
schemaFrame.setIcon(false);
} else {
schemaFrame.setSelected(true);
}
} catch (Exception ex) {
LOGGER.error("schemaMenuItem", ex);
}
}
});
windowMenu.add(schemaMenuItem, 0);
windowMenu.setEnabled(true);
windowMenu.add(jSeparator3, -1);
windowMenu.add(cascadeMenuItem, -1);
windowMenu.add(tileMenuItem, -1);
windowMenu.add(minimizeMenuItem, -1);
windowMenu.add(maximizeMenuItem, -1);
windowMenu.add(closeAllMenuItem, -1);
// add the file details in menu map
schemaWindowMap.put(schemaFrame, schemaMenuItem);
updateMDXCatalogList();
schemaFrame.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
schemaFrame.addInternalFrameListener(new InternalFrameAdapter() {
public void internalFrameClosing(InternalFrameEvent e) {
if (schemaFrame.getContentPane().getComponent(0) instanceof SchemaExplorer) {
SchemaExplorer se = (SchemaExplorer) schemaFrame.getContentPane().getComponent(0);
int response = confirmFrameClose(schemaFrame, se);
if (response == 3) {
// not dirty
if (se.isNewFile()) {
se.getSchemaFile().delete();
}
// default case for no save and not dirty
schemaWindowMap.remove(schemaFrame);
updateMDXCatalogList();
schemaFrame.dispose();
windowMenu.remove(schemaMenuItem);
}
}
}
});
schemaFrame.setFocusable(true);
schemaFrame.addFocusListener(new FocusAdapter() {
public void focusGained(FocusEvent e) {
if (schemaFrame.getContentPane().getComponent(0) instanceof SchemaExplorer) {
SchemaExplorer se = (SchemaExplorer) schemaFrame.getContentPane().getComponent(0);
// update view menu based on schemaframe who gained
// focus
viewXmlMenuItem.setSelected(se.isEditModeXML());
}
}
public void focusLost(FocusEvent e) {
if (schemaFrame.getContentPane().getComponent(0) instanceof SchemaExplorer) {
SchemaExplorer se = (SchemaExplorer) schemaFrame.getContentPane().getComponent(0);
// update view menu based on
viewXmlMenuItem.setSelected(se.isEditModeXML());
}
}
});
viewXmlMenuItem.setSelected(false);
} catch (Exception ex) {
LOGGER.error("openSchemaFrame", ex);
} finally {
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}
}
use of javax.swing.event.InternalFrameAdapter in project mondrian by pentaho.
the class Workbench method newJDBCExplorerMenuItemActionPerformed.
private void newJDBCExplorerMenuItemActionPerformed(ActionEvent evt) {
try {
if (jdbcMetaData == null) {
getNewJdbcMetadata();
}
final JInternalFrame jf = new JInternalFrame();
jf.setTitle(getResourceConverter().getFormattedString("workbench.new.JDBCExplorer.title", "JDBC Explorer - {0} {1}", jdbcMetaData.getDatabaseProductName(), jdbcMetaData.getJdbcConnectionUrl()));
getNewJdbcMetadata();
JdbcExplorer jdbce = new JdbcExplorer(jdbcMetaData, this);
jf.getContentPane().add(jdbce);
jf.setBounds(0, 0, 500, 480);
jf.setClosable(true);
jf.setIconifiable(true);
jf.setMaximizable(true);
jf.setResizable(true);
jf.setVisible(true);
// create jdbc menu item
final javax.swing.JMenuItem jdbcMenuItem = new javax.swing.JMenuItem();
jdbcMenuItem.setText(getResourceConverter().getFormattedString("workbench.new.JDBCExplorer.menuitem", "{0} JDBC Explorer", Integer.toString(windowMenuMapIndex++)));
jdbcMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
try {
if (jf.isIcon()) {
jf.setIcon(false);
} else {
jf.setSelected(true);
}
} catch (Exception ex) {
LOGGER.error("queryMenuItem", ex);
}
}
});
jf.addInternalFrameListener(new InternalFrameAdapter() {
public void internalFrameClosing(InternalFrameEvent e) {
jdbcWindows.remove(jf);
jf.dispose();
// follow this by removing file from schemaWindowMap
windowMenu.remove(jdbcMenuItem);
return;
}
});
desktopPane.add(jf);
jf.setVisible(true);
jf.show();
try {
jf.setSelected(true);
} catch (Exception ex) {
// do nothing
LOGGER.error("newJDBCExplorerMenuItemActionPerformed.setSelected", ex);
}
jdbcWindows.add(jf);
windowMenu.add(jdbcMenuItem, -1);
windowMenu.add(jSeparator3, -1);
windowMenu.add(cascadeMenuItem, -1);
windowMenu.add(tileMenuItem, -1);
windowMenu.add(minimizeMenuItem, -1);
windowMenu.add(maximizeMenuItem, -1);
windowMenu.add(closeAllMenuItem, -1);
} catch (Exception ex) {
JOptionPane.showMessageDialog(this, getResourceConverter().getFormattedString("workbench.new.JDBCExplorer.exception", "Database connection not successful.\n{0}", ex.getLocalizedMessage()), getResourceConverter().getString("workbench.new.JDBCExplorer.exception.title", "Database Connection Error"), JOptionPane.ERROR_MESSAGE);
LOGGER.error("newJDBCExplorerMenuItemActionPerformed", ex);
}
}
use of javax.swing.event.InternalFrameAdapter in project tetrad by cmu-phil.
the class TimeLagGraphEditor method createEditMenu.
// /**
// * Creates the "file" menu, which allows the user to load, save, and post
// * workbench models.
// *
// * @return this menu.
// */
// private JMenu createFileMenu() {
// JMenu file = new JMenu("File");
//
// file.add(new LoadGraph(this, "Load Graph..."));
// file.add(new SaveGraph(this, "Save Graph..."));
// // file.add(new SaveScreenshot(this, true, "Save Screenshot..."));
// file.add(new SaveComponentImage(getWorkbench(), "Save Graph Image..."));
//
// return file;
// }
/**
* Creates the "file" menu, which allows the user to load, save, and post
* workbench models.
*
* @return this menu.
*/
private JMenu createEditMenu() {
JMenu edit = new JMenu("Edit");
// JMenuItem copy = new JMenuItem(new CopySubgraphAction(this));
// JMenuItem paste = new JMenuItem(new PasteSubgraphAction(this));
//
// copy.setAccelerator(
// KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK));
// paste.setAccelerator(
// KeyStroke.getKeyStroke(KeyEvent.VK_V, ActionEvent.CTRL_MASK));
//
// edit.add(copy);
// edit.add(paste);
edit.addSeparator();
JMenuItem configuration = new JMenuItem("Configuration...");
edit.add(configuration);
configuration.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
final TimeLagGraph graph = (TimeLagGraph) getLayoutEditable().getGraph();
class ConfigurationEditor extends JPanel {
private int maxLag;
private int numInitialLags;
public ConfigurationEditor(final TimeLagGraph graph) {
maxLag = graph.getMaxLag();
numInitialLags = graph.getNumInitialLags();
final SpinnerModel maxLagSpinnerModel = new SpinnerNumberModel(graph.getMaxLag(), 0, 300, 1);
JSpinner maxLagSpinner = new JSpinner(maxLagSpinnerModel);
maxLagSpinner.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
JSpinner spinner = (JSpinner) e.getSource();
SpinnerNumberModel model = (SpinnerNumberModel) spinner.getModel();
int value = (Integer) model.getValue();
setMaxLag(value);
}
});
final SpinnerModel initialLagsSpinnerModel = new SpinnerNumberModel(graph.getNumInitialLags(), 1, 300, 1);
JSpinner initialLagsSpinner = new JSpinner(initialLagsSpinnerModel);
initialLagsSpinner.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
JSpinner spinner = (JSpinner) e.getSource();
SpinnerNumberModel model = (SpinnerNumberModel) spinner.getModel();
int value = (Integer) model.getValue();
setNumInitialLags(value);
}
});
setLayout(new BorderLayout());
Box box = Box.createVerticalBox();
Box b1 = Box.createHorizontalBox();
b1.add(new JLabel("Time lag graph configuration:"));
b1.add(Box.createHorizontalGlue());
box.add(b1);
Box b2 = Box.createHorizontalBox();
b2.add(new JLabel("Maximum Lag = "));
b2.add(Box.createHorizontalGlue());
b2.add(maxLagSpinner);
box.add(b2);
// Box b3 = Box.createHorizontalBox();
// b3.add(new JLabel("# Initial Lags = "));
// b3.add(Box.createHorizontalGlue());
// b3.add(initialLagsSpinner);
// box.add(b3);
box.setBorder(new EmptyBorder(10, 10, 10, 10));
add(box, BorderLayout.CENTER);
}
public int getMaxLag() {
return maxLag;
}
public void setMaxLag(int maxLag) {
this.maxLag = maxLag;
}
public int getNumInitialLags() {
return numInitialLags;
}
public void setNumInitialLags(int numInitialLags) {
this.numInitialLags = numInitialLags;
}
}
final ConfigurationEditor editor = new ConfigurationEditor((TimeLagGraph) getGraph());
EditorWindow editorWindow = new EditorWindow(editor, "Configuration...", "Save", true, TimeLagGraphEditor.this);
DesktopController.getInstance().addEditorWindow(editorWindow, JLayeredPane.PALETTE_LAYER);
editorWindow.pack();
editorWindow.setVisible(true);
editorWindow.addInternalFrameListener(new InternalFrameAdapter() {
public void internalFrameClosed(InternalFrameEvent e) {
EditorWindow window = (EditorWindow) e.getSource();
if (window.isCanceled()) {
return;
}
graph.setMaxLag(editor.getMaxLag());
graph.setNumInitialLags(editor.getNumInitialLags());
LayoutUtils.lastLayout(getLayoutEditable());
}
});
}
});
return edit;
}
use of javax.swing.event.InternalFrameAdapter in project tetrad by cmu-phil.
the class GeneralizedSemImListEditor method beginNodeEdit.
private void beginNodeEdit(final Node node, final JLabel label, JComponent centering) {
if (launchedEditors.keySet().contains(node)) {
launchedEditors.get(node).moveToFront();
return;
}
final GeneralizedExpressionParameterizer paramEditor = new GeneralizedExpressionParameterizer(semIm, node);
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.add(paramEditor, BorderLayout.CENTER);
panel.setBorder(new EmptyBorder(5, 5, 5, 5));
final EditorWindow editorWindow = new EditorWindow(panel, "Parameter Properties", "OK", true, centering);
DesktopController.getInstance().addEditorWindow(editorWindow, JLayeredPane.PALETTE_LAYER);
editorWindow.pack();
editorWindow.setVisible(true);
launchedEditors.put(node, editorWindow);
editorWindow.addInternalFrameListener(new InternalFrameAdapter() {
public void internalFrameClosing(InternalFrameEvent internalFrameEvent) {
if (!editorWindow.isCanceled()) {
semIm.setSubstitutions(paramEditor.getParameterValues());
// if (node.getNodeType() == NodeType.ERROR) {
// label.setText(node + " = " + semIm.getNodeSubstitutedString(node));
// }
// else {
// label.setText(node + " ~ " + semIm.getNodeSubstitutedString(node));
// }
refreshLabels();
launchedEditors.remove(node);
firePropertyChange("modelChanged", null, null);
}
}
});
}
use of javax.swing.event.InternalFrameAdapter in project tetrad by cmu-phil.
the class GeneralizedSemPmGraphicalEditor method beginNodeEdit.
// ========================PRIVATE PROTECTED METHODS======================//
private void beginNodeEdit(final Node node) {
if (launchedEditors.keySet().contains(node)) {
launchedEditors.get(node).moveToFront();
return;
}
final GeneralizedExpressionEditor paramEditor = new GeneralizedExpressionEditor(semPm, node);
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.add(paramEditor, BorderLayout.CENTER);
panel.setBorder(new EmptyBorder(5, 5, 5, 5));
final EditorWindow editorWindow = new EditorWindow(panel, "Edit Expression", "OK", true, this);
DesktopController.getInstance().addEditorWindow(editorWindow, JLayeredPane.PALETTE_LAYER);
editorWindow.pack();
editorWindow.setVisible(true);
launchedEditors.put(node, editorWindow);
editorWindow.addInternalFrameListener(new InternalFrameAdapter() {
public void internalFrameClosing(InternalFrameEvent internalFrameEvent) {
if (!editorWindow.isCanceled()) {
String expressionString = paramEditor.getExpressionString();
try {
semPm.setNodeExpression(node, expressionString);
} catch (ParseException e) {
// This is an expression that's been vetted by the expression editor.
e.printStackTrace();
launchedEditors.remove(node);
throw new RuntimeException("The expression editor returned an unparseable string: " + expressionString, e);
}
refreshLabels();
firePropertyChange("modelChanged", null, null);
}
launchedEditors.remove(node);
}
});
}
Aggregations