Skip to content
This repository has been archived by the owner on Apr 6, 2022. It is now read-only.

Commit

Permalink
Cosmetics on code
Browse files Browse the repository at this point in the history
  • Loading branch information
Pascal-Verdier committed Jun 21, 2019
1 parent bd1a939 commit 7d32ae5
Showing 1 changed file with 39 additions and 67 deletions.
106 changes: 39 additions & 67 deletions src/main/java/admin/astor/Astor.java
Expand Up @@ -85,7 +85,7 @@ public class Astor extends JFrame implements AstorDefs {
public static int rwMode = READ_WRITE;
//======================================================================
/**
* Creates new form Astor
* Creates new Astor form
*
* @throws DevFailed in case of database connection failed
*/
Expand Down Expand Up @@ -127,7 +127,6 @@ private void centerWindow() {
p.y = (scrsize.height - appsize.height) / 2;
setLocation(p);
}

//======================================================================
//======================================================================
private void setControlSystemTitle() throws DevFailed {
Expand Down Expand Up @@ -181,21 +180,18 @@ private void buildTree() throws DevFailed {
throw e;
}
}

//======================================================================
//======================================================================
Dimension getTreeSize() {
//return scrollPane.getSize();
return scrollPane.getPreferredSize();
}

//======================================================================
//======================================================================
void setTreeSize(Dimension d) {
scrollPane.setPreferredSize(d);
pack();
}

//======================================================================
//======================================================================
private void customizeMenu() {
Expand Down Expand Up @@ -243,15 +239,13 @@ private void customizeMenu() {

nb_def_tools = toolsMenu.getItemCount();
buildToolsItems();
buildAdditionnalHelps();
buildAdditionalHelps();

expandBtn.setVisible(false);

modeLabel.setText(strMode[rwMode]);
bottomPanel.setVisible(rwMode!=READ_WRITE);
}


//======================================================================
//======================================================================
private void manageAccessControlMenu(boolean isAccessControlled) {
Expand All @@ -264,12 +258,10 @@ private void manageAccessControlMenu(boolean isAccessControlled) {
accessControlBtn.setVisible(false);
}
}

//======================================================================
//======================================================================
private String[] htmlHelps = null;

private void buildAdditionnalHelps() {
private void buildAdditionalHelps() {
htmlHelps = AstorUtil.getHtmlHelps();
if (htmlHelps == null) return;
if (htmlHelps.length == 0) return;
Expand All @@ -279,15 +271,10 @@ private void buildAdditionnalHelps() {
for (int i = 0; i < htmlHelps.length / 2; i++) {
JMenuItem mi = new JMenuItem();
mi.setText(htmlHelps[2 * i]);
mi.addActionListener(new ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
htmlHelpsItemActionPerformed(evt);
}
});
mi.addActionListener(this::htmlHelpsItemActionPerformed);
helpMenu.add(mi);
}
}

//======================================================================
//======================================================================
private void htmlHelpsItemActionPerformed(java.awt.event.ActionEvent evt) {
Expand Down Expand Up @@ -328,11 +315,7 @@ private void buildToolsItems() {
JMenuItem mi = new JMenuItem();
mi.setText(t.name);
ActionListener al;
mi.addActionListener(al = new ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
toolsItemActionPerformed(evt);
}
});
mi.addActionListener(al = this::toolsItemActionPerformed);
tools_al.add(al);
toolsMenu.add(mi);
}
Expand Down Expand Up @@ -774,18 +757,16 @@ private void changeTgHostBtnActionPerformed(java.awt.event.ActionEvent evt) {//G
rights = "-ro";
// Start a new shell because TANGO_HOST is for the JVM
// Start it in a tread to do not block this one
new Thread() {
public void run() {
try {
String cmd = "java -DTANGO_HOST=" + newTangoHost + " admin.astor.Astor " + rights;
//AstorUtil.executeShellCmdAndReturn(cmd);
AstorUtil.executeShellCmd(cmd);
}
catch (IOException | InterruptedException | DevFailed e) {
ErrorPane.showErrorMessage(new JFrame(), "Cannot fork", e);
}
new Thread(() -> {
try {
String cmd = "java -DTANGO_HOST=" + newTangoHost + " admin.astor.Astor " + rights;
//AstorUtil.executeShellCmdAndReturn(cmd);
AstorUtil.executeShellCmd(cmd);
}
catch (IOException | InterruptedException | DevFailed e) {
ErrorPane.showErrorMessage(new JFrame(), "Cannot fork", e);
}
}.start();
}).start();
} catch (Exception e) {
ErrorPane.showErrorMessage(this, "Cannot change TANGO_HOST", e);
}
Expand Down Expand Up @@ -1136,7 +1117,6 @@ private void expandBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIR
else
expandBtn.setText("Expand Tree");
}//GEN-LAST:event_expandBtnActionPerformed

//======================================================================
//======================================================================
@SuppressWarnings({"UnusedDeclaration"})
Expand All @@ -1145,7 +1125,6 @@ private void deviceBrowserBtnActionPerformed(java.awt.event.ActionEvent evt) {//
devBrowser = new DevBrowser(this);
devBrowser.setVisible(true);
}//GEN-LAST:event_deviceBrowserBtnActionPerformed

//======================================================================
//======================================================================
@SuppressWarnings({"UnusedDeclaration"})
Expand All @@ -1156,21 +1135,18 @@ private void refreshBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FI
ErrorPane.showErrorMessage(this, null, e);
}
}//GEN-LAST:event_refreshBtnActionPerformed

//======================================================================
//======================================================================
@SuppressWarnings({"UnusedDeclaration"})
private void exitBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitBtnActionPerformed
doExit();
}//GEN-LAST:event_exitBtnActionPerformed

//======================================================================
//======================================================================
@SuppressWarnings({"UnusedDeclaration"})
private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm
doExit();
}//GEN-LAST:event_exitForm

//======================================================================
//======================================================================
private WideSearchDialog wide_search_dlg = null;
Expand All @@ -1183,7 +1159,6 @@ private void findObjectByFilterItemActionPerformed(java.awt.event.ActionEvent ev
wide_search_dlg.setVisible(true);

}//GEN-LAST:event_findObjectByFilterItemActionPerformed

//======================================================================
//======================================================================
@SuppressWarnings({"UnusedDeclaration"})
Expand All @@ -1197,7 +1172,6 @@ private void multiServersCmdItemActionPerformed(java.awt.event.ActionEvent evt)
ErrorPane.showErrorMessage(this, null, e);
}
}//GEN-LAST:event_multiServersCmdItemActionPerformed

//======================================================================
//======================================================================
@SuppressWarnings({"UnusedDeclaration"})
Expand All @@ -1206,7 +1180,6 @@ private void statisticsBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN
statisticsPanel.readAndDisplayStatistics(null); // On all Servers
statisticsPanel.setVisible(true);
}//GEN-LAST:event_statisticsBtnActionPerformed

//======================================================================
//======================================================================
@SuppressWarnings({"UnusedDeclaration"})
Expand All @@ -1217,7 +1190,6 @@ private void serverUsageMenuItemActionPerformed(java.awt.event.ActionEvent evt)
ErrorPane.showErrorMessage(this, null, e);
}
}//GEN-LAST:event_serverUsageMenuItemActionPerformed

//======================================================================
//======================================================================
@SuppressWarnings({"UnusedDeclaration"})
Expand All @@ -1236,10 +1208,8 @@ private void faultyListItemhelpActionPerformed(java.awt.event.ActionEvent evt) {
popupText.setVisible(true);

}//GEN-LAST:event_faultyListItemhelpActionPerformed

//======================================================================
//======================================================================
@SuppressWarnings({"ConstantConditions"})
private void stopThreads() {
System.out.println("Astor exiting....");
// Stop all host controlled
Expand All @@ -1254,9 +1224,8 @@ private void stopThreads() {
}
}
}
System.out.println(" ");
System.out.println();
}

//======================================================================
//======================================================================
public void doExit() {
Expand All @@ -1268,6 +1237,11 @@ public void doExit() {
System.exit(0);
}
}
//======================================================================
//======================================================================




//======================================================================
// Variables declaration - do not modify//GEN-BEGIN:variables
Expand Down Expand Up @@ -1308,7 +1282,7 @@ public void doExit() {
* @param args the command line arguments
*/
//======================================================================
public static void main(String args[]) {
public static void main(String[] args) {

// Check if line command
if (args.length > 0) {
Expand Down Expand Up @@ -1339,27 +1313,25 @@ public static void main(String args[]) {
}
// Else start application

SwingUtilities.invokeLater(new Runnable() {
public void run() {
long t0 = System.currentTimeMillis();
// First time, Open a simple Tango window
try {
Astor astor = new Astor();
astor.setVisible(true);
} catch (DevFailed e) {
System.err.println(e.errors[0].desc);
if (e.errors[0].desc.indexOf("Controlled access service defined in Db but unreachable") > 0)
e.errors[0].desc = "Controlled access service defined in Db but unreachable\n" +
"Astor cannot be configured from database !";

ErrorPane.showErrorMessage(new JFrame(), null, e);
System.exit(-1);
} catch (java.lang.InternalError| java.awt.HeadlessException e) {
System.err.println(e.getMessage());
}
long t1 = System.currentTimeMillis();
System.out.println("Build GUI :" + (t1 - t0) + " ms");
SwingUtilities.invokeLater(() -> {
long t0 = System.currentTimeMillis();
// First time, Open a simple Tango window
try {
Astor astor = new Astor();
astor.setVisible(true);
} catch (DevFailed e) {
System.err.println(e.errors[0].desc);
if (e.errors[0].desc.indexOf("Controlled access service defined in Db but unreachable") > 0)
e.errors[0].desc = "Controlled access service defined in Db but unreachable\n" +
"Astor cannot be configured from database !";

ErrorPane.showErrorMessage(new JFrame(), null, e);
System.exit(-1);
} catch (InternalError| HeadlessException e) {
System.err.println(e.getMessage());
}
long t1 = System.currentTimeMillis();
System.out.println("Build GUI :" + (t1 - t0) + " ms");
});
}
//===============================================================
Expand Down

0 comments on commit 7d32ae5

Please sign in to comment.