public Component getTableCellRendererComponent(
     JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
   final Color color = UIUtil.getTableFocusCellBackground();
   Component component;
   final Module module = value instanceof Module ? (Module) value : null;
   try {
     UIManager.put(UIUtil.TABLE_FOCUS_CELL_BACKGROUND_PROPERTY, table.getSelectionBackground());
     component =
         super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
     if (module != null) {
       setText(
           module.getName()
               + " ("
               + FileUtil.toSystemDependentName(module.getModuleFilePath())
               + ")");
     }
     if (component instanceof JLabel) {
       ((JLabel) component).setBorder(noFocusBorder);
     }
   } finally {
     UIManager.put(UIUtil.TABLE_FOCUS_CELL_BACKGROUND_PROPERTY, color);
   }
   component.setEnabled(ProcessedModulesTable.this.isEnabled());
   if (component instanceof JLabel) {
     final Icon icon = module != null ? ModuleType.get(module).getIcon() : null;
     JLabel label = (JLabel) component;
     label.setIcon(icon);
     label.setDisabledIcon(icon);
   }
   component.setForeground(isSelected ? table.getSelectionForeground() : table.getForeground());
   return component;
 }
 public Component getTableCellRendererComponent(
     JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
   final Color color = UIUtil.getTableFocusCellBackground();
   Component component;
   T t = (T) value;
   try {
     UIManager.put(UIUtil.TABLE_FOCUS_CELL_BACKGROUND_PROPERTY, table.getSelectionBackground());
     component =
         super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
     setText(t != null ? getItemText(t) : "");
     if (component instanceof JLabel) {
       ((JLabel) component).setBorder(noFocusBorder);
     }
   } finally {
     UIManager.put(UIUtil.TABLE_FOCUS_CELL_BACKGROUND_PROPERTY, color);
   }
   final MyTableModel model = (MyTableModel) table.getModel();
   component.setEnabled(
       ElementsChooser.this.isEnabled()
           && (myColorUnmarkedElements ? model.isElementMarked(row) : true));
   final ElementProperties properties = myElementToPropertiesMap.get(t);
   if (component instanceof JLabel) {
     final Icon icon =
         properties != null ? properties.getIcon() : t != null ? getItemIcon(t) : null;
     JLabel label = (JLabel) component;
     label.setIcon(icon);
     label.setDisabledIcon(icon);
   }
   component.setForeground(
       properties != null && properties.getColor() != null
           ? properties.getColor()
           : (isSelected ? table.getSelectionForeground() : table.getForeground()));
   return component;
 }
 @Override
 protected void installDefaults() {
   UIManager.put("TabbedPane.selected", Color.BLACK);
   UIManager.put("TabbedPane.tabsOverlapBorder", true);
   super.installDefaults();
   tabInsets = new Insets(0, 0, 0, 0);
   contentBorderInsets = new Insets(0, 0, 0, 0);
   tabAreaInsets = new Insets(0, 0, 0, 0);
   selectedTabPadInsets = new Insets(0, 0, 0, 0);
 }
 private ActionMap getActionMap() {
   ActionMap actionMap = (ActionMap) UIManager.get("Grid.actionMap");
   if (actionMap == null) {
     actionMap = createActionMap();
     if (actionMap != null) {
       UIManager.put("Grid.actionMap", actionMap);
     }
   }
   return actionMap;
 }
  public PhoneBookGUI(PhoneBook pb) {
    super("PhoneBook");
    phoneBook = pb;

    setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);

    Locale.setDefault(new Locale("en"));
    /* To avoid hardcoded Swedish text on OptionPane dialogs */
    UIManager.put("OptionPane.cancelButtonText", "Cancel");

    setLayout(new BorderLayout());
    JMenuBar menubar = new JMenuBar();
    setJMenuBar(menubar);

    JMenu editMenu = new JMenu("Edit");
    menubar.add(editMenu);
    editMenu.add(new AddMenu(phoneBook, this));
    editMenu.add(new RemoveMenu(phoneBook, this));
    JMenu findMenu = new JMenu("Find");
    menubar.add(findMenu);
    findMenu.add(new FindNumbersMenu(phoneBook, this));
    findMenu.add(new FindNamesMenu(phoneBook, this));
    JMenu viewMenu = new JMenu("View");
    menubar.add(viewMenu);
    viewMenu.add(new ShowAllMenu(phoneBook, this));

    JPanel southPanel = new JPanel();
    messageArea = new JTextArea(4, 25);
    messageArea.setEditable(false);
    southPanel.add(new JScrollPane(messageArea));
    southPanel.add(new QuitButton(phoneBook));
    add(southPanel, BorderLayout.CENTER);

    pack();
    setVisible(true);

    String fileName = JOptionPane.showInputDialog("Enter file name");
    if (fileName != null) {
      try {
        phoneBook.readFromFile(fileName);
      } catch (Exception e) {
        setText("No such file was found");
      }
    }
  }
Exemplo n.º 6
0
  public static void main(String argv[]) {
    System.setErr(System.out);

    try {

      UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");

    } catch (Exception e) {
      try {

        UIManager.setLookAndFeel("javax.swing.plaf.windows.WindowsLookAndFeel");

      } catch (Exception e1) {
        try {

          UIManager.setLookAndFeel("javax.swing.plaf.motif.MotifLookAndFeel");

        } catch (Exception e2) {
          try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
          } catch (Exception e3) {
          }
        }
      }
    }

    UIManager.put("TextField.background", new Color(255, 255, 255));
    String strCreateTables = null,
        strRunTests = null,
        strCleanUp = null,
        strCreateProc = null,
        strCreateResult = null,
        strDropResult = null,
        strLogLevel = null;
    String strTPCCRun = null, strTPCCLoad = null;
    BenchMain.bench = new BenchMain();
    bench.m_bInApplet = false;

    if (argv.length > 0)
      for (int nArg = 0; nArg < argv.length; nArg++) {
        if (argv[nArg].toUpperCase().startsWith("URL="))
          bench.m_strURL = argv[nArg].substring(argv[nArg].indexOf("=") + 1);
        else if (argv[nArg].toUpperCase().startsWith("USER="******"=") + 1);
        else if (argv[nArg].toUpperCase().startsWith("PASSWORD="******"=") + 1);
        else if (argv[nArg].toUpperCase().startsWith("DRIVER="))
          bench.m_strDriver = argv[nArg].substring(argv[nArg].indexOf("=") + 1);
        else if (argv[nArg].toUpperCase().startsWith("DRIVERTYPE="))
          bench.m_nDriverType =
              Integer.valueOf(argv[nArg].substring(argv[nArg].indexOf("=") + 1)).intValue();
        else if (argv[nArg].toUpperCase().startsWith("CREATETABLES="))
          strCreateTables = argv[nArg].substring(argv[nArg].indexOf("=") + 1);
        else if (argv[nArg].toUpperCase().startsWith("RUNTEST="))
          strRunTests = argv[nArg].substring(argv[nArg].indexOf("=") + 1);
        else if (argv[nArg].toUpperCase().startsWith("CLEANUP")) strCleanUp = argv[nArg];
        else if (argv[nArg].toUpperCase().startsWith("CREATEPROC")) strCreateProc = argv[nArg];
        else if (argv[nArg].toUpperCase().startsWith("CREATERESULT")) strCreateResult = argv[nArg];
        else if (argv[nArg].toUpperCase().startsWith("DROPRESULT")) strDropResult = argv[nArg];
        else if (argv[nArg].toUpperCase().startsWith("LOGLEVEL="))
          strLogLevel = argv[nArg].substring(argv[nArg].indexOf("=") + 1);
        else if (argv[nArg].toUpperCase().startsWith("TPCCRUN="))
          strTPCCRun = argv[nArg].substring(argv[nArg].indexOf("=") + 1);
        else if (argv[nArg].toUpperCase().startsWith("TPCCLOAD="))
          strTPCCLoad = argv[nArg].substring(argv[nArg].indexOf("=") + 1);
      }
    bench.m_bInApplet = false;
    try {
      if (strCreateTables != null
          || strRunTests != null
          || strCleanUp != null
          || strCreateProc != null
          || strCreateResult != null
          || strDropResult != null
          || strTPCCRun != null
          || strTPCCLoad != null) {
        // batch
        TextProgress progress = new TextProgress();
        Bench.BenchPanel pane =
            new Bench.BenchPanel(
                bench.m_strDriver,
                bench.m_strURL,
                bench.m_strUserName,
                bench.m_strPassword,
                bench.m_nDriverType);
        Bench.Logger new_log =
            new Bench.Logger() {
              int m_nLogLevel = 0;

              public synchronized void log(String strMessage, int nLevel) {
                if (nLevel <= m_nLogLevel) System.out.print(strMessage);
              }

              public synchronized void taskDone() {
                notify();
              }

              public synchronized void waitOn() throws InterruptedException {
                wait();
              }

              public synchronized void setLogLevel(int nNewLogLevel) {
                m_nLogLevel = nNewLogLevel;
              }

              public synchronized int getLogLevel() {
                return m_nLogLevel;
              }
            };

        if (strLogLevel != null) new_log.setLogLevel(Integer.valueOf(strLogLevel).intValue());
        pane.setLogger(new_log);
        if (strCreateTables != null) {
          StringTokenizer createTokens = new StringTokenizer(strCreateTables, ",;/");
          int nBranchCount = 10, nTellerCount = 100, nAccountCount = 1000;
          if (createTokens.hasMoreTokens())
            nBranchCount = Integer.valueOf(createTokens.nextToken()).intValue();
          if (createTokens.hasMoreTokens())
            nTellerCount = Integer.valueOf(createTokens.nextToken()).intValue();
          if (createTokens.hasMoreTokens())
            nAccountCount = Integer.valueOf(createTokens.nextToken()).intValue();
          // FIXME               pane.setMaxTableLimits(nBranchCount,nTellerCount,nAccountCount);
          // FIXME               pane.doCreateTables(true,true,true,true,true,true,true,true);
        }
        // FIXME            if(strCreateProc != null)
        // pane.doLoadProcedures(pane.pool.getConnection(0));
        if (strRunTests != null) {
          int nNumThreads = 1, nNumRuns = 100, nTestType = 1, nWaitMinutes = -1;
          boolean bTrans = false, bQuery = true;
          StringTokenizer runTokens = new StringTokenizer(strRunTests, ",;/");
          if (runTokens.hasMoreTokens())
            nNumThreads = Integer.valueOf(runTokens.nextToken()).intValue();
          if (runTokens.hasMoreTokens())
            nNumRuns = Integer.valueOf(runTokens.nextToken()).intValue();
          if (runTokens.hasMoreTokens())
            bTrans = runTokens.nextToken().toUpperCase().equals("TRUE");
          if (runTokens.hasMoreTokens())
            bQuery = runTokens.nextToken().toUpperCase().equals("TRUE");
          if (runTokens.hasMoreTokens())
            nTestType = Integer.valueOf(runTokens.nextToken()).intValue();
          if (runTokens.hasMoreTokens())
            nWaitMinutes = Integer.valueOf(runTokens.nextToken()).intValue();
          // FIXME               pane.doRunTests(nNumThreads,nNumRuns,nWaitMinutes,nTestType ==
          // 1,nTestType == 2,nTestType == 3,bTrans,bQuery);
        }
        // FIXME            if(strCleanUp != null) pane.doCleanUp(pane.pool.getConnection(0),
        // true,true,true,true);
        if (strDropResult != null) pane.doDropResult();
        // FIXME            if(strCreateResult != null) pane.doCreateResult();
        // ========TPCCTest
        //            if(strTPCCLoad != null) {
        //               int n_ware = 1;
        //               StringTokenizer runTokens = new StringTokenizer(strTPCCLoad,",;/");
        //               //					System.out.println("tpcload = " + strTPCCLoad);
        //               if(runTokens.hasMoreTokens()) {
        //                  n_ware = Integer.valueOf(runTokens.nextToken()).intValue();
        //               //						System.out.println("N_ware = " + n_ware);
        //               }
        //               pane.doTpccLoadData(pane.pool.getConnection(0),
        // n_ware,Bench.TPCCBench.DIST_PER_WARE,Bench.TPCCBench.CUST_PER_DIST,Bench.TPCCBench.MAXITEMS,Bench.TPCCBench.ORD_PER_DIST);
        //            }
        //            if(strTPCCRun != null) {
        //               int n_rounds = 1, local_w_id = 1, n_ware = 1, n_threads = 1;
        //               StringTokenizer runTokens = new StringTokenizer(strTPCCRun,",;/");
        //               if(runTokens.hasMoreTokens())
        //                  n_rounds = Integer.valueOf(runTokens.nextToken()).intValue();
        //               if(runTokens.hasMoreTokens())
        //                  local_w_id = Integer.valueOf(runTokens.nextToken()).intValue();
        //               if(runTokens.hasMoreTokens())
        //                  n_ware = Integer.valueOf(runTokens.nextToken()).intValue();
        //               if(runTokens.hasMoreTokens())
        //                  n_threads = Integer.valueOf(runTokens.nextToken()).intValue();
        //               pane.doTpccRun(n_threads, n_rounds,local_w_id,n_ware);
        //            }
        pane.closeConnection(true);
        System.exit(0);
      }
    } catch (Exception e) {
      System.out.println(e.getMessage());
    }
    // go interactive
    JFrame frame = new JFrame("JBench - Generic JDBC Benchmark Utility");
    WindowListener l =
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            BenchMain.bench.m_pane.closeConnection(true);
            System.exit(0);
          }
        };

    frame.addWindowListener(l);
    bench.m_parentFrame = frame;
    bench.init();
    frame.getContentPane().add(bench);
    frame.setSize(675, 400);
    frame.validate();
    frame.setVisible(true);
  }