@Override protected void paintComponent(Graphics g) { super.paintComponent(g); if (UIUtil.isUnderAquaLookAndFeel()) { return; } switch (getState()) { case DONT_CARE: Icon icon = getIcon(); if (icon == null) { icon = UIManager.getIcon("CheckBox.icon"); } if (UIUtil.isUnderDarcula() || UIUtil.isUnderIntelliJLaF()) { icon = EmptyIcon.create(20, 18); } if (icon != null) { final Insets i = getInsets(); final Rectangle r = getBounds(); final Rectangle r1 = new Rectangle(); r1.x = i.left; r1.y = i.top; r1.width = r.width - (i.right + r1.x); r1.height = r.height - (i.bottom + r1.y); final Rectangle r2 = new Rectangle(); final Rectangle r3 = new Rectangle(); SwingUtilities.layoutCompoundLabel( this, getFontMetrics(getFont()), getText(), icon, getVerticalAlignment(), getHorizontalAlignment(), getVerticalTextPosition(), getHorizontalTextPosition(), r1, r2, r3, getText() == null ? 0 : getIconTextGap()); // selected table cell: do not paint white on white g.setColor(UIUtil.getTreeForeground()); int height = r2.height / 10; int width = r2.width / 3; g.fillRect( r2.x + r2.width / 2 - width / 2, r2.y + r2.height / 2 - height / 2, width, height); } break; default: break; } }
@Override public Component prepareRenderer(TableCellRenderer renderer, int row, int column) { final Component result = super.prepareRenderer(renderer, row, column); final boolean selected = myExpandableItemsHandler.getExpandedItems().contains(new TableCell(row, column)); // Fix GTK background if (UIUtil.isUnderGTKLookAndFeel()) { UIUtil.changeBackGround(this, UIUtil.getTreeTextBackground()); } if (isTableDecorationSupported() && isStriped() && result instanceof JComponent) { final Color bg = row % 2 == 1 ? getBackground() : DECORATED_ROW_BG_COLOR; final JComponent c = (JComponent) result; final boolean cellSelected = isCellSelected(row, column); if (!cellSelected || (!hasFocus() && !getSelectionBackground().equals(c.getBackground()))) { c.setOpaque(true); c.setBackground(bg); for (Component child : c.getComponents()) { child.setBackground(bg); } } } if (!selected) return result; return new JComponent() { { add(result); setOpaque(false); setLayout( new AbstractLayoutManager() { @Override public Dimension preferredLayoutSize(Container parent) { return result.getPreferredSize(); } @Override public void layoutContainer(Container parent) { Dimension size = parent.getSize(); Insets i = parent.getInsets(); Dimension pref = result.getPreferredSize(); result.setBounds( i.left, i.top, Math.max(pref.width, size.width - i.left - i.right), size.height - i.top - i.bottom); } }); } }; }
public void openChangelog(Component parent) { JPanel p = new JPanel(new GridBagLayout()); p.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); GridBagConstraints gBC = new GridBagConstraints(); gBC.anchor = GridBagConstraints.CENTER; gBC.fill = GridBagConstraints.HORIZONTAL; gBC.insets = new Insets(1, 1, 1, 1); JLabel a = new JLabel(getApplicationName()); a.setFont(a.getFont().deriveFont(24f)); UIUtil.jGridBagAdd(p, a, gBC, GridBagConstraints.REMAINDER); String changelog = ""; try { BufferedReader br = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("/changelog"))); String line = br.readLine(); while (line != null) { changelog += line + "\n"; line = br.readLine(); } br.close(); } catch (Exception e) { changelog = "<Error opening changelog>\n"; } javax.swing.JTextArea message = new javax.swing.JTextArea(changelog); message.setEditable(false); message.setBorder(javax.swing.BorderFactory.createEmptyBorder(4, 4, 4, 4)); javax.swing.JLabel jl = new javax.swing.JLabel(); message.setFont(jl.getFont()); message.setBackground(jl.getBackground()); // MultilineLabel x = new MultilineLabel(changelog); // x.setBorder(BorderFactory.createEmptyBorder(8, 0, 8, 0)); // x.setFont(x.getFont().deriveFont(12f)); javax.swing.JScrollPane scrollPane = new javax.swing.JScrollPane(); scrollPane.getViewport().add(message); scrollPane.setSize(400, 200); scrollPane.setPreferredSize(new java.awt.Dimension(400, 200)); UIUtil.jGridBagAdd(p, scrollPane, gBC, GridBagConstraints.REMAINDER); JOptionPane.showMessageDialog( parent, p, "Change log", JOptionPane.PLAIN_MESSAGE, getApplicationLargeIcon()); }
/** Show an 'About' dialog */ public void showAbout(final Component parent) { JPanel p = new JPanel(new GridBagLayout()); p.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); GridBagConstraints gBC = new GridBagConstraints(); gBC.anchor = GridBagConstraints.CENTER; gBC.fill = GridBagConstraints.HORIZONTAL; gBC.insets = new Insets(1, 1, 1, 1); JLabel a = new JLabel(getApplicationName()); a.setFont(a.getFont().deriveFont(24f)); UIUtil.jGridBagAdd(p, a, gBC, GridBagConstraints.REMAINDER); MultilineLabel v = new MultilineLabel(getApplicationName() + " " + getApplicationVersion()); v.setFont(v.getFont().deriveFont(10f)); UIUtil.jGridBagAdd(p, v, gBC, GridBagConstraints.REMAINDER); MultilineLabel x = new MultilineLabel(getAboutAuthors()); x.setBorder(BorderFactory.createEmptyBorder(8, 0, 8, 0)); x.setFont(x.getFont().deriveFont(12f)); UIUtil.jGridBagAdd(p, x, gBC, GridBagConstraints.REMAINDER); MultilineLabel c = new MultilineLabel(getAboutLicenseDetails()); c.setFont(c.getFont().deriveFont(10f)); UIUtil.jGridBagAdd(p, c, gBC, GridBagConstraints.REMAINDER); final JLabel h = new JLabel(getAboutURL()); h.setForeground(Color.blue); h.setFont(new Font(h.getFont().getName(), Font.BOLD, 10)); h.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); h.addMouseListener( new MouseAdapter() { public void mouseClicked(MouseEvent evt) { try { BrowserLauncher.openURL(getAboutURL()); } catch (IOException ioe) { ioe.printStackTrace(); } } }); UIUtil.jGridBagAdd(p, h, gBC, GridBagConstraints.REMAINDER); JOptionPane.showMessageDialog( parent, p, "About", JOptionPane.PLAIN_MESSAGE, getApplicationLargeIcon()); }
public void actionPerformed(ActionEvent e) { mFileChooser.setDialogTitle("Predictions CSV"); mFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); mFileChooser.setSelectedFile(new File("predictions.csv")); mFileChooser.setFileFilter(null); if (UIUtil.runFileChooser(mFileChooser, mParent, null, "lastPredictionLocation") == JFileChooser.APPROVE_OPTION) { // Time to copy the predictions autoweka.Util.copyFile(mOutputFile, mFileChooser.getSelectedFile()); } };
public boolean openTestingSet() { mFileChooser.setDialogTitle("Testing Set ARFF"); mFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); mFileChooser.setFileFilter(UIUtil.msArffFileFilter); if (UIUtil.runFileChooser(mFileChooser, this, mTestingSetText, "lastArffLocation") == JFileChooser.APPROVE_OPTION) { // Time to do the predictions return true; } return false; }
/** * @param exception * @return */ private String getRetryMessage(Throwable exception) { String retryMsg = context.getString(com.twapime.app.R.string.try_again); // if (getFailureStringId() != -1) { retryMsg = context.getString(getFailureStringId()) + " " + retryMsg; } else { retryMsg = context.getString(UIUtil.getMessageId(exception)) + " " + retryMsg; } // return retryMsg; }
@DoInBackground(indeterminateProgress = true, cancelable = false) public void makePredictions(BackgroundEvent evt) { // Go grab the experiment, and see what stuff we should end up loading try { // Get the model File modelFile = new File( mExperimentText.getText() + File.separator + "trained." + mSelectedSeedLabel.getText() + ".model"); if (!modelFile.exists()) { Properties props = new Properties(); String seed = mSelectedSeedLabel.getText(); File experimentDir = new File(mExperimentText.getText()); props.put("modelOutputFilePrefix", experimentDir.getAbsolutePath() + "/trained." + seed); SubProcessWrapper.getErrorAndTime( experimentDir, Experiment.createFromFolder(experimentDir), "default", mBest.rawArgs, seed, props); } File attribSelectFile = new File( mExperimentText.getText() + File.separator + "trained." + mSelectedSeedLabel.getText() + ".attributeselection"); String attribSelectPath = null; if (attribSelectFile.exists()) attribSelectPath = attribSelectFile.getAbsolutePath(); File tmpFile = File.createTempFile("predictions", ".tmp"); tmpFile.deleteOnExit(); TrainedModelPredictionMaker tmpm = new TrainedModelPredictionMaker( attribSelectPath, modelFile.getAbsolutePath(), mTestingSetText.getText(), "last", tmpFile.getAbsolutePath()); ResultsWindow resWindow = new ResultsWindow(tmpm.eval.toSummaryString(), tmpFile); resWindow.setVisible(true); } catch (Exception e) { UIUtil.showExceptionDialog(this, "Failed to get predictions", e); } }
@Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == android.R.id.home && fromPush) { Intent intent = new Intent(this, MessageListActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); finish(); return true; } return UIUtil.selectMenu(item, this); }
protected void buildOptions(JPanel searchOptions) { super.buildOptions(searchOptions); searchOptions.add( UIUtil.createOptionLine( shortenFQN = new JCheckBox(SSRBundle.message("shorten.fully.qualified.names.checkbox"), true))); searchOptions.add( UIUtil.createOptionLine( formatAccordingToStyle = new JCheckBox( CodeInsightBundle.message( "dialog.edit.template.checkbox.reformat.according.to.style"), true))); searchOptions.add( UIUtil.createOptionLine( useStaticImport = new JCheckBox( CodeInsightBundle.message("dialog.edit.template.checkbox.use.static.import"), true))); }
private static boolean isTableDecorationSupported() { return UIUtil.isUnderAlloyLookAndFeel() || UIUtil.isUnderNativeMacLookAndFeel() || UIUtil.isUnderQuaquaLookAndFeel() || UIUtil.isUnderMetalLookAndFeel() || UIUtil.isUnderNimbusLookAndFeel() || UIUtil.isUnderWindowsLookAndFeel(); }
/** @see android.os.AsyncTask#onPostExecute(java.lang.Object) */ protected final void onPostExecute(Throwable result) { if (progressDialog != null) { progressDialog.dismiss(); } // if (result != null) { if (!retryEnabled) { if (getFailureStringId() != -1) { UIUtil.showMessage(context, getFailureStringId()); } else { UIUtil.showMessage(context, result); } } // onFailedRun(result); } else { if (getSuccessStringId() != -1) { UIUtil.showMessage(context, getSuccessStringId()); } // onPostRun(resultRun); } };
public void setValuesFromConfig(Configuration configuration) { // replaceCriteriaEdit.putUserData(SubstitutionShortInfoHandler.CURRENT_CONFIGURATION_KEY, // configuration); if (configuration instanceof ReplaceConfiguration) { final ReplaceConfiguration config = (ReplaceConfiguration) configuration; final ReplaceOptions options = config.getOptions(); super.setValuesFromConfig(config); UIUtil.setContent( replaceCriteriaEdit, config.getOptions().getReplacement(), 0, replaceCriteriaEdit.getDocument().getTextLength(), searchContext.getProject()); shortenFQN.setSelected(options.isToShortenFQN()); formatAccordingToStyle.setSelected(options.isToReformatAccordingToStyle()); useStaticImport.setSelected(options.isToUseStaticImport()); ReplaceOptions newReplaceOptions = ((ReplaceConfiguration) model.getConfig()).getOptions(); newReplaceOptions.clearVariableDefinitions(); for (ReplacementVariableDefinition def : options.getReplacementVariableDefinitions()) { newReplaceOptions.addVariableDefinition((ReplacementVariableDefinition) def.clone()); } } else { super.setValuesFromConfig(configuration); UIUtil.setContent( replaceCriteriaEdit, configuration.getMatchOptions().getSearchPattern(), 0, replaceCriteriaEdit.getDocument().getTextLength(), searchContext.getProject()); } }
private static float calculateScaleFactor() { if (SystemInfo.isMac) { return 1.0f; } if (SystemProperties.has("hidpi") && !SystemProperties.is("hidpi")) { return 1.0f; } // On Linux: rely on DPI if (SystemInfo.isLinux) { final int dpi = getSystemDPI(); if (dpi < 120) return 1f; if (dpi < 144) return 1.25f; if (dpi < 168) return 1.5f; if (dpi < 192) return 1.75f; return 2f; } int size = -1; // On Windows: rely on default system font if (SystemInfo.isWindows) { UIUtil.initSystemFontData(); Pair<String, Integer> fdata = UIUtil.getSystemFontData(); if (fdata != null) size = fdata.getSecond(); } if (size == -1) { size = Fonts.label().getSize(); } if (size <= 13) return 1.0f; if (size <= 16) return 1.25f; if (size <= 18) return 1.5f; if (size < 24) return 1.75f; return 2.0f; }
private void handle(MouseEvent e) { if (UIUtil.isActionClick(e, MouseEvent.MOUSE_PRESSED)) { if (!myPopup.isShowing()) { openProcessPopup(true); } else { hideProcessPopup(); } } else if (e.isPopupTrigger()) { ActionGroup group = (ActionGroup) ActionManager.getInstance().getAction("BackgroundTasks"); ActionManager.getInstance() .createActionPopupMenu(ActionPlaces.UNKNOWN, group) .getComponent() .show(e.getComponent(), e.getX(), e.getY()); } }
/** * 往流程图编辑器中增加一个元素 * * @param ele */ public DefaultGraphCell insertFlowElement(FlowElementObject ele) { if (this.graph == null) return null; if (ele.getId() == 0) { int id = (new IDService()).getProcessID(); ele.setId(id); } DefaultGraphCell cell = new DefaultGraphCell(); cell.setUserObject(ele); if (ele.getImageResource() != null) { GraphConstants.setIcon(cell.getAttributes(), UIUtil.loadImageIcon(ele.getImageResource())); } // 自动设置大小 // GraphConstants.setAutoSize(cell.getAttributes(), true); GraphConstants.setOpaque(cell.getAttributes(), true); // GraphConstants.setBackground(cell.getAttributes(), Color.YELLOW); GraphConstants.setLineColor(cell.getAttributes(), Color.RED); GraphConstants.setLineWidth(cell.getAttributes(), 1.5f); GraphConstants.setLineStyle(cell.getAttributes(), GraphConstants.STYLE_SPLINE); // GraphConstants.setSizeable(cell.getAttributes(),false); GraphConstants.setBorder( cell.getAttributes(), BorderFactory.createLineBorder(Color.BLACK)); // 外框颜色 // GraphConstants.setBounds(cell.getAttributes(), new // Rectangle2D.Double( // 10, 10, 80, 40)); GraphConstants.setBounds( cell.getAttributes(), new Rectangle2D.Double( ele.getLeft().doubleValue(), ele.getTop().doubleValue(), ele.getWidth().doubleValue(), ele.getHeight().doubleValue())); GraphConstants.setEditable(cell.getAttributes(), false); cell.addPort(); this.graph.getGraphLayoutCache().insert(cell); // 向图形编辑器写入处理后的图片. return cell; }
public StatusText() { myClickListener = new ClickListener() { @Override public boolean onClick(@NotNull MouseEvent e, int clickCount) { if (e.getButton() == MouseEvent.BUTTON1 && clickCount == 1) { ActionListener actionListener = findActionListenerAt(e.getPoint()); if (actionListener != null) { actionListener.actionPerformed(new ActionEvent(this, 0, "")); return true; } } return false; } }; myMouseMotionListener = new MouseAdapter() { private Cursor myOriginalCursor; @Override public void mouseMoved(final MouseEvent e) { if (isStatusVisible()) { if (findActionListenerAt(e.getPoint()) != null) { if (myOriginalCursor == null) { myOriginalCursor = myMouseTarget.getCursor(); myMouseTarget.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); } } else if (myOriginalCursor != null) { myMouseTarget.setCursor(myOriginalCursor); myOriginalCursor = null; } } } }; myComponent.setOpaque(false); myComponent.setFont(UIUtil.getLabelFont()); setText(DEFAULT_EMPTY_TEXT, DEFAULT_ATTRIBUTES); myIsDefaultText = true; }
public void setRefreshVisible(final boolean visible) { UIUtil.invokeLaterIfNeeded( new Runnable() { @Override public void run() { myRefreshAlarm.cancelAllRequests(); myRefreshAlarm.addRequest( new Runnable() { @Override public void run() { if (visible) { myRefreshIcon.resume(); } else { myRefreshIcon.suspend(); } myRefreshIcon.revalidate(); myRefreshIcon.repaint(); } }, visible ? 100 : 300); } }); }
private void buildInProcessCount() { removeAll(); setLayout(new BorderLayout()); final JPanel progressCountPanel = new JPanel(new BorderLayout(0, 0)); progressCountPanel.setOpaque(false); String processWord = myOriginals.size() == 1 ? " process" : " processes"; final LinkLabel label = new LinkLabel( myOriginals.size() + processWord + " running...", null, new LinkListener() { @Override public void linkSelected(final LinkLabel aSource, final Object aLinkData) { triggerPopupShowing(); } }); if (SystemInfo.isMac) label.setFont(UIUtil.getLabelFont().deriveFont(11.0f)); label.setOpaque(false); final Wrapper labelComp = new Wrapper(label); labelComp.setOpaque(false); progressCountPanel.add(labelComp, BorderLayout.CENTER); // myProgressIcon.setBorder(new IdeStatusBarImpl.MacStatusBarWidgetBorder()); progressCountPanel.add(myProgressIcon, BorderLayout.WEST); add(myRefreshAndInfoPanel, BorderLayout.CENTER); progressCountPanel.setBorder(new EmptyBorder(0, 0, 0, 4)); add(progressCountPanel, BorderLayout.EAST); revalidate(); repaint(); }
/** * Creates a new AboutDialog object. The icon displayed in this dialog box is provided by the * parent shell. It should be either a unique image (Shell.getImage()), or the second image of a * list of (Shell.getImages()[1]). * * @param parent The parent shell (also carry the icon to display). * @param caption Caption text. * @param description Text for the application description line. * @param version Text for the application version line. */ public AboutDialog(Shell parent, String caption, String description, String version) { // Take the opportunity to do some clean up if possible Runtime rt = Runtime.getRuntime(); rt.runFinalization(); rt.gc(); shell = new Shell(parent, SWT.CLOSE | SWT.TITLE | SWT.RESIZE | SWT.APPLICATION_MODAL); shell.setText(caption); UIUtil.inheritIcon(shell, parent); shell.setLayout(new GridLayout()); Composite cmpTmp = new Composite(shell, SWT.BORDER); cmpTmp.setLayoutData(new GridData(GridData.FILL_BOTH)); GridLayout layTmp = new GridLayout(2, false); cmpTmp.setLayout(layTmp); // Application icon Label appIcon = new Label(cmpTmp, SWT.NONE); GridData gdTmp = new GridData(); gdTmp.verticalSpan = 2; appIcon.setLayoutData(gdTmp); Image[] list = parent.getImages(); // Gets the single icon if ((list == null) || (list.length < 2)) { appIcon.setImage(parent.getImage()); } else { // Or the second one if there are more than one. appIcon.setImage(list[1]); } Label label = new Label(cmpTmp, SWT.NONE); label.setText(description == null ? "TBD" : description); // $NON-NLS-1$ gdTmp = new GridData( GridData.HORIZONTAL_ALIGN_CENTER | GridData.GRAB_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER | GridData.GRAB_VERTICAL); label.setLayoutData(gdTmp); label = new Label(cmpTmp, SWT.NONE); label.setText( String.format( Res.getString("AboutDialog.versionLabel"), version == null ? "TBD" : version)); // $NON-NLS-1$ gdTmp = new GridData( GridData.HORIZONTAL_ALIGN_CENTER | GridData.GRAB_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER | GridData.GRAB_VERTICAL); label.setLayoutData(gdTmp); // Info cmpTmp = new Composite(shell, SWT.BORDER); cmpTmp.setLayoutData(new GridData(GridData.FILL_BOTH)); layTmp = new GridLayout(2, false); cmpTmp.setLayout(layTmp); label = new Label(cmpTmp, SWT.NONE); label.setText(Res.getString("AboutDialog.jvmVersion")); // $NON-NLS-1$ label = new Label(cmpTmp, SWT.NONE); label.setText(System.getProperty("java.version")); // $NON-NLS-1$ label = new Label(cmpTmp, SWT.NONE); label.setText(Res.getString("AboutDialog.platform")); // $NON-NLS-1$ label = new Label(cmpTmp, SWT.NONE); label.setText( String.format( "%s, %s, %s", //$NON-NLS-1$ System.getProperty("os.name"), // $NON-NLS-1$ System.getProperty("os.arch"), // $NON-NLS-1$ System.getProperty("os.version"))); // $NON-NLS-1$ label = new Label(cmpTmp, SWT.NONE); label.setText(Res.getString("AboutDialog.memoryLabel")); // $NON-NLS-1$ label = new Label(cmpTmp, SWT.NONE); NumberFormat nf = NumberFormat.getInstance(); label.setText( String.format( Res.getString("AboutDialog.memory"), // $NON-NLS-1$ nf.format(rt.freeMemory() / 1024), nf.format(rt.totalMemory() / 1024))); // --- Dialog-level buttons SelectionAdapter CloseActions = new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { shell.close(); }; }; ClosePanel pnlActions = new ClosePanel(shell, SWT.NONE, CloseActions, false); pnlActions.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); shell.setDefaultButton(pnlActions.btClose); shell.pack(); shell.setMinimumSize(shell.getSize()); Point startSize = shell.getMinimumSize(); if (startSize.x < 350) startSize.x = 350; shell.setSize(startSize); Dialogs.centerWindow(shell, parent); }
protected boolean isRetina() { return UIUtil.isRetina(); }
@PostConstruct protected void init() { // Button listeners: jb_add.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { add(); } }); jb_addAndClose.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { addAndClose(); } }); jb_cancel.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { cancel(); } }); jb_file.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { selectFile(); } }); // Default button: getRootPane().setDefaultButton(jb_add); // Layout: Container c = getContentPane(); c.setLayout(new BorderLayout()); { // Center JPanel jp = new JPanel(new BorderLayout()); JPanel jp_west = new JPanel(new GridLayout(3, 2)); jp_west.add(new JLabel(" Content type: ")); jp_west.add(new JLabel(" File name: ")); jp_west.add(new JLabel(" File: ")); jp.add(jp_west, BorderLayout.WEST); JPanel jp_center = new JPanel(new GridLayout(3, 2)); jp_center.add(jp_contentType.getComponent()); jp_center.add(UIUtil.getFlowLayoutPanelLeftAligned(jtf_fileName)); JPanel jp_file = new JPanel(new FlowLayout(FlowLayout.LEFT)); jp_file.add(jtf_file); jp_file.add(jb_file); jp_center.add(jp_file); jp.add(jp_center, BorderLayout.CENTER); c.add(jp, BorderLayout.CENTER); } { // South JPanel jp = new JPanel(); jp.setLayout(new FlowLayout(FlowLayout.RIGHT)); jp.add(jb_cancel); jp.add(jb_add); jp.add(jb_addAndClose); c.add(jp, BorderLayout.SOUTH); } pack(); }
/** 返回一个alpha动画 */ public static AlphaAnimation getAlphaAnimation() { return (AlphaAnimation) AnimationUtils.loadAnimation(UIUtil.getContext(), R.anim.alpha_animation); }
public void paintComponent(Graphics g) { if (getFrame() != null) { setState(getFrame().getExtendedState()); } JRootPane rootPane = getRootPane(); Window window = getWindow(); boolean leftToRight = (window == null) ? rootPane.getComponentOrientation().isLeftToRight() : window.getComponentOrientation().isLeftToRight(); boolean isSelected = (window == null) ? true : window.isActive(); int width = getWidth(); int height = getHeight(); Color background; Color foreground; Color darkShadow; if (isSelected) { background = UIUtil.getPanelBackground(); // myActiveBackground; foreground = myActiveForeground; darkShadow = Gray._73; // myActiveShadow; } else { background = UIUtil.getPanelBackground(); // myInactiveBackground; foreground = myInactiveForeground; darkShadow = myInactiveShadow; } g.setColor(background); g.fillRect(0, 0, width, height); // g.setColor(darkShadow); // g.drawLine(0, height - 1, width, height - 1); // g.drawLine(0, 0, 0, 0); // g.drawLine(width - 1, 0, width - 1, 0); int xOffset = leftToRight ? 5 : width - 5; if (getWindowDecorationStyle() == JRootPane.FRAME) { xOffset += leftToRight ? IMAGE_WIDTH + 5 : -IMAGE_WIDTH - 5; } String theTitle = getTitle(); if (theTitle != null) { FontMetrics fm = SwingUtilities2.getFontMetrics(rootPane, g); g.setColor(foreground); int yOffset = ((height - fm.getHeight()) / 2) + fm.getAscent(); Rectangle rect = new Rectangle(0, 0, 0, 0); if (myIconifyButton != null && myIconifyButton.getParent() != null) { rect = myIconifyButton.getBounds(); } int titleW; if (leftToRight) { if (rect.x == 0) { rect.x = window.getWidth() - window.getInsets().right - 2; } titleW = rect.x - xOffset - 4; theTitle = SwingUtilities2.clipStringIfNecessary(rootPane, fm, theTitle, titleW); } else { titleW = xOffset - rect.x - rect.width - 4; theTitle = SwingUtilities2.clipStringIfNecessary(rootPane, fm, theTitle, titleW); xOffset -= SwingUtilities2.stringWidth(rootPane, fm, theTitle); } int titleLength = SwingUtilities2.stringWidth(rootPane, fm, theTitle); if (myIdeMenu == null) { SwingUtilities2.drawString(rootPane, g, theTitle, xOffset, yOffset); xOffset += leftToRight ? titleLength + 5 : -5; } } int w = width; int h = height; h--; g.setColor(UIManager.getColor("MenuBar.darcula.borderColor")); g.drawLine(0, h, w, h); h--; g.setColor(UIManager.getColor("MenuBar.darcula.borderShadowColor")); g.drawLine(0, h, w, h); }
/** @author subwiz */ public class AddMultipartFileDialog extends AddMultipartBaseDialog { @Inject private ContentTypeCharsetComponent jp_contentType; private JTextField jtf_fileName = new JTextField(ContentTypeCharsetComponent.TEXT_FIELD_LENGTH); private JTextField jtf_file = new JTextField(ContentTypeCharsetComponent.TEXT_FIELD_LENGTH); private JButton jb_file = new JButton(UIUtil.getIconFromClasspath(RCFileView.iconBasePath + "load_from_file.png")); private JButton jb_add = new JButton("Add"); private JButton jb_addAndClose = new JButton("Add & close"); private JButton jb_cancel = new JButton("Cancel"); @Inject public AddMultipartFileDialog(RESTUserInterface rest_ui) { super(rest_ui); setTitle("Add Multipart File"); } @PostConstruct protected void init() { // Button listeners: jb_add.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { add(); } }); jb_addAndClose.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { addAndClose(); } }); jb_cancel.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { cancel(); } }); jb_file.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { selectFile(); } }); // Default button: getRootPane().setDefaultButton(jb_add); // Layout: Container c = getContentPane(); c.setLayout(new BorderLayout()); { // Center JPanel jp = new JPanel(new BorderLayout()); JPanel jp_west = new JPanel(new GridLayout(3, 2)); jp_west.add(new JLabel(" Content type: ")); jp_west.add(new JLabel(" File name: ")); jp_west.add(new JLabel(" File: ")); jp.add(jp_west, BorderLayout.WEST); JPanel jp_center = new JPanel(new GridLayout(3, 2)); jp_center.add(jp_contentType.getComponent()); jp_center.add(UIUtil.getFlowLayoutPanelLeftAligned(jtf_fileName)); JPanel jp_file = new JPanel(new FlowLayout(FlowLayout.LEFT)); jp_file.add(jtf_file); jp_file.add(jb_file); jp_center.add(jp_file); jp.add(jp_center, BorderLayout.CENTER); c.add(jp, BorderLayout.CENTER); } { // South JPanel jp = new JPanel(); jp.setLayout(new FlowLayout(FlowLayout.RIGHT)); jp.add(jb_cancel); jp.add(jb_add); jp.add(jb_addAndClose); c.add(jp, BorderLayout.SOUTH); } pack(); } private void selectFile() { File f = rest_ui.getOpenFile(FileChooserType.OPEN_REQUEST_BODY); if (f == null) { // Pressed cancel? return; } if (!f.canRead()) { JOptionPane.showMessageDialog( rest_ui.getFrame(), "File not readable: " + f.getAbsolutePath(), "IO Error", JOptionPane.ERROR_MESSAGE); return; } // Content type charset correction: ContentTypeSelectorOnFile.select(jp_contentType, f, this); // Set name: if (StringUtil.isEmpty(jtf_fileName.getText())) { jtf_fileName.setText(f.getName()); } // Set file: jtf_file.setText(f.getAbsolutePath()); } private boolean add() { // Validation: if (StringUtil.isEmpty(jtf_fileName.getText())) { JOptionPane.showMessageDialog( this, "Name must be present!", "Validation: name empty!", JOptionPane.ERROR_MESSAGE); jtf_fileName.requestFocus(); return false; } // Read values: final String fileName = jtf_fileName.getText(); final ContentType ct = jp_contentType.getContentType(); final File file = new File(jtf_file.getText()); final ReqEntityFilePart part = new ReqEntityFilePartBean(fileName, ct, file); // Trigger all listeners: for (AddMultipartPartListener l : listeners) { l.addPart(part); } // Clear: clear(); // Focus: jb_file.requestFocus(); return true; } private void addAndClose() { if (add()) { setVisible(false); } } private void cancel() { clear(); setVisible(false); } @Override public void clear() { jp_contentType.clear(); jtf_fileName.setText(""); jtf_file.setText(""); } @Override public void setVisible(boolean boo) { jp_contentType.requestFocus(); super.setVisible(boo); } }
public TrainedModelRunner() { SwingJavaBuilder.build(this); UIUtil.setNoBoldJLabels(mSelectedPanel); UIUtil.setNoBoldJLabels(mDetailsPanel); }
public void setTabText(final String text) { String tabDesc = UIUtil.shorten(text, 16, ".."); desc.setText(tabDesc); }
public void openExperiment(String experimentPath) { mFileChooser.setDialogTitle("Experiment"); if (experimentPath == null) { mFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); mFileChooser.setDialogTitle("Experiment to run"); mFileChooser.setFileFilter(null); if (UIUtil.runFileChooser(mFileChooser, this, mExperimentText, "lastExperimentDirLocation") == JFileChooser.CANCEL_OPTION) { return; } } else { mFileChooser.setSelectedFile(new File(experimentPath)); mExperimentText.setEnabled(false); mExperimentText.setEditable(false); mExperimentText.setText(experimentPath); mMakePredictionsButton.setEnabled(false); } try { File expFolder = mFileChooser.getSelectedFile(); File exp = new File( expFolder.getAbsolutePath() + File.separator + expFolder.getName() + ".experiment"); if (!exp.exists() || !exp.isFile()) { throw new RuntimeException( expFolder.getAbsolutePath() + " does not appear to contain a .experiment"); } TrajectoryGroup group = TrajectoryMerger.mergeExperimentFolder(expFolder.getAbsolutePath()); ArrayList<String> inProgressSeeds = new ArrayList<String>(); // Go through all the logs and see if we can parse any other partial trajectories File[] files = new File(expFolder.getAbsolutePath() + File.separator + "out" + File.separator + "logs") .listFiles(); for (File f : files) { String fName = f.getName(); if (fName.endsWith(".log")) { String seed = fName.substring(0, fName.length() - 4); if (!group.getSeeds().contains(seed)) { inProgressSeeds.add(seed); } } } // Do we want use these inprogress seeds if (!inProgressSeeds.isEmpty()) { Collections.sort(inProgressSeeds); StringBuilder msgSB = new StringBuilder("It looks like there are partial runs for the following seeds:\n"); for (String s : inProgressSeeds) { msgSB.append(s); msgSB.append("\n"); } msgSB.append( "Do you wish to use these experiments?\nYou may not be able to make predictions from\nthese experiments without training a model first."); // We want to use these partial runs if we're in force open mode if (experimentPath != null || JOptionPane.showConfirmDialog( this, msgSB.toString(), "Use Partial Runs", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { for (String s : inProgressSeeds) { group.addTrajectory( TrajectoryParser.getTrajectory( Experiment.createFromFolder(expFolder), expFolder, s)); } } } mBest = new GetBestFromTrajectoryGroup(group); // Set all the text blocks mExperimentText.setText(expFolder.getAbsolutePath()); mSelectedErrorLabel.setText(Float.toString(mBest.errorEstimate)); mSelectedSeedLabel.setText(mBest.seed); mNumEvaluationsLabel.setText(mBest.numEval == -1 ? "" : Integer.toString(mBest.numEval)); mNumTimeOutEvaluationsLabel.setText( mBest.numTimeOut == -1 ? "" : Integer.toString(mBest.numTimeOut)); mNumMemOutEvaluationsLabel.setText( mBest.numMemOut == -1 ? "" : Integer.toString(mBest.numMemOut)); setText(mClassifierText, mBest.classifierClass); setText(mClassifierParamsText, mBest.classifierArgs); setText(mAttributeSearchText, mBest.attributeSearchClass); setText(mAttributeSearchParamsText, mBest.attributeSearchArgs); setText(mAttributeEvalText, mBest.attributeEvalClass); setText(mAttributeEvalParamsText, mBest.attributeEvalArgs); // Enable the dataset button mMakePredictionsButton.setEnabled(true); } catch (Exception e) { UIUtil.showExceptionDialog(this, "Failed to open experiment", e); } }
public static JBFont smallFont() { return label().deriveFont(UIUtil.getFontSize(UIUtil.FontSize.SMALL)); }
public static JBFont miniFont() { return label().deriveFont(UIUtil.getFontSize(UIUtil.FontSize.MINI)); }