Example #1
0
 private static boolean isWindows(LookAndFeel laf) {
   if (laf.getID() == "Windows") {
     return true;
   }
   if (!checkedForWindows) {
     try {
       WINDOWS_CLASS = Class.forName("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
     } catch (ClassNotFoundException e) {
     }
     checkedForWindows = true;
   }
   return (WINDOWS_CLASS != null && WINDOWS_CLASS.isInstance(laf));
 }
  private void copyFile() throws Exception {
    // Load the JDBC driver
    Class.forName(((String) jcboDriver.getSelectedItem()).trim());
    System.out.println("Driver loaded");

    // Establish a connection
    Connection conn =
        DriverManager.getConnection(
            ((String) jcboURL.getSelectedItem()).trim(),
            jtfUsername.getText().trim(),
            String.valueOf(jtfPassword.getPassword()).trim());
    System.out.println("Database connected");

    // Read each line from the text file and insert it to the table
    insertRows(conn);
  }
Example #3
0
  private Object getResource(String key) {

    URL url = null;
    String name = key;

    if (name != null) {

      try {
        Class c = Class.forName("content.AdvancedPanel");
        url = c.getResource(name);
      } catch (ClassNotFoundException cnfe) {
        System.err.println("Unable to find Main class");
      }
      return url;
    } else return null;
  }
Example #4
0
 private static boolean isXP() {
   if (!checkedForClassic) {
     try {
       CLASSIC_WINDOWS =
           Class.forName("com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel");
     } catch (ClassNotFoundException e) {
     }
     checkedForClassic = true;
   }
   if (CLASSIC_WINDOWS != null && CLASSIC_WINDOWS.isInstance(UIManager.getLookAndFeel())) {
     return false;
   }
   Toolkit toolkit = Toolkit.getDefaultToolkit();
   Boolean themeActive = (Boolean) toolkit.getDesktopProperty("win.xpstyle.themeActive");
   if (themeActive == null) {
     themeActive = Boolean.FALSE;
   }
   return themeActive.booleanValue();
 }
Example #5
0
  // event handling
  public void actionPerformed(ActionEvent e) {
    if (e.getSource() == btnok) {
      PreparedStatement pstm;
      ResultSet rs;
      String sql;
      // if no entries has been made and hit ok button throw an error
      // you can do this step using try clause as well
      if ((tf1.getText().equals("") && (tf2.getText().equals("")))) {
        lblmsg.setText("Enter your details ");
        lblmsg.setForeground(Color.magenta);
      } else {

        try {
          Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
          Connection connect = DriverManager.getConnection("jdbc:odbc:student_base");
          System.out.println("Connected to the database");
          pstm = connect.prepareStatement("insert into student_base values(?,?)");
          pstm.setString(1, tf1.getText());
          pstm.setString(2, tf2.getText());
          // execute method to execute the query
          pstm.executeUpdate();
          lblmsg.setText("Details have been added to database");

          // closing the prepared statement  and connection object
          pstm.close();
          connect.close();
        } catch (SQLException sqe) {
          System.out.println("SQl error");
        } catch (ClassNotFoundException cnf) {
          System.out.println("Class not found error");
        }
      }
    }
    // upon clickin button addnew , your textfield will be empty to enternext record
    if (e.getSource() == btnaddnew) {
      tf1.setText("");
      tf2.setText("");
    }

    if (e.getSource() == btnexit) {
      System.exit(1);
    }
  }
Example #6
0
 static {
   Method componentBaselineMethod = null;
   Method componentBRBMethod = null;
   Method componentBRBIMethod = null;
   Object brbCenterOffset = null;
   Object brbConstantAscent = null;
   Object brbConstantDescent = null;
   Object brbOther = null;
   try {
     componentBaselineMethod =
         Component.class.getMethod("getBaseline", new Class[] {int.class, int.class});
     componentBRBMethod = Component.class.getMethod("getBaselineResizeBehavior", new Class[] {});
     Class brbClass = Class.forName("java.awt.Component$BaselineResizeBehavior");
     brbCenterOffset = getFieldValue(brbClass, "CENTER_OFFSET");
     brbConstantAscent = getFieldValue(brbClass, "CONSTANT_ASCENT");
     brbConstantDescent = getFieldValue(brbClass, "CONSTANT_DESCENT");
     brbOther = getFieldValue(brbClass, "OTHER");
   } catch (NoSuchMethodException nsme) {
   } catch (ClassNotFoundException cnfe) {
   } catch (NoSuchFieldException nsfe) {
   } catch (IllegalAccessException iae) {
   }
   if (componentBaselineMethod == null
       || componentBRBMethod == null
       || brbCenterOffset == null
       || brbConstantDescent == null
       || brbConstantAscent == null
       || brbOther == null) {
     componentBaselineMethod = componentBRBMethod = null;
     brbCenterOffset = brbConstantAscent = brbConstantDescent = brbOther = null;
   }
   COMPONENT_BASELINE_METHOD = componentBaselineMethod;
   COMPONENT_BRB_METHOD = componentBRBMethod;
   ENUM_BRB_CENTER_OFFSET = brbCenterOffset;
   ENUM_BRB_CONSTANT_ASCENT = brbConstantAscent;
   ENUM_BRB_CONSTANT_DESCENT = brbConstantDescent;
   ENUM_BRB_OTHER = brbOther;
 }
Example #7
0
  public WhatsNew(AbstractProjectViewer pv, boolean onlyShowCurrentVersion)
      throws GeneralException {

    super(pv);

    String wn = Environment.getProperty(Constants.WHATS_NEW_VERSION_VIEWED_PROPERTY_NAME);

    if (wn == null) {

      wn = "0";
    }

    // Get the current whats new version (i.e. old).
    Version lastWhatsNewVersion = new Version(wn);

    boolean betasAllowed =
        Environment.getUserProperties()
            .getPropertyAsBoolean(Constants.OPTIN_TO_BETA_VERSIONS_PROPERTY_NAME);

    try {

      String whatsNew = Environment.getResourceFileAsString(Constants.WHATS_NEW_FILE);

      // Load up all the whats new for greater versions.
      Element root = JDOMUtils.getStringAsElement(whatsNew);

      java.util.List verEls = JDOMUtils.getChildElements(root, XMLConstants.version, false);

      // Assume they are in the right order
      // TODO: Enforce the order and/or sort.
      for (int i = 0; i < verEls.size(); i++) {

        Element vEl = (Element) verEls.get(i);

        String id = JDOMUtils.getAttributeValue(vEl, XMLConstants.id, true);

        Version v = new Version(id);
        /*
                      if ((v.isBeta ())
                          &&
                          (!betasAllowed)
                         )
                      {

                          // Ignore, the user isn't interested in betas.
                          continue;

                      }
        */
        if ((lastWhatsNewVersion.isNewer(v))
            || ((onlyShowCurrentVersion) && (v.isSame(Environment.getQuollWriterVersion())))) {

          String c = WhatsNewComponentProvider.class.getName();

          int ind = c.lastIndexOf(".");

          if (ind > 0) {

            c = c.substring(0, ind);
          }

          WhatsNewComponentProvider compProv = null;

          String cl = JDOMUtils.getAttributeValue(vEl, XMLConstants.clazz, false);

          if (!cl.equals("")) {

            Class clz = null;

            try {

              clz = Class.forName(cl);

              if (WhatsNewComponentProvider.class.isAssignableFrom(clz)) {

                compProv = (WhatsNewComponentProvider) clz.newInstance();
              }

            } catch (Exception e) {

            }
          }

          // This is a version we are interested in.
          java.util.List itemEls =
              JDOMUtils.getChildElements(vEl, WhatsNewItem.XMLConstants.root, true);

          java.util.List<WhatsNewItem> its = new ArrayList();

          for (int j = 0; j < itemEls.size(); j++) {

            Element itEl = (Element) itemEls.get(j);

            WhatsNewItem it = new WhatsNewItem(itEl, compProv, pv);

            if (it.onlyIfCurrentVersion) {

              if (!Environment.getQuollWriterVersion().isSame(v)) {

                continue;
              }
            }

            if ((it.description == null) && (it.component == null)) {

              Environment.logMessage(
                  "Whats new item has no description or component, referenced by: "
                      + JDOMUtils.getPath(itEl));

              continue;
            }

            its.add(it);
          }

          if (its.size() > 0) {

            this.items.put(v, its);
          }
        }
      }

    } catch (Exception e) {

      throw new GeneralException("Unable to init whats new", e);
    }
  }