From c6cd81378149631f528b838b7920bd736833be71 Mon Sep 17 00:00:00 2001 From: We-unite <3205135446@qq.com> Date: Sat, 22 Feb 2025 17:17:43 +0800 Subject: Format all code, Fix bug report ensure. The bug report result table should enable people to ensure one by one menually, and there's 3 kinds of states: not sure, currect issure, or wrong report. However, in the old report it's a yes/no question. So it's changed, and the state for each row also works nolonger as intager but enum, to make it more readable. Besides, all codes of this project get formatted, to make it clean, and no more change caused by format in later commits. --- lib/example/GridBagVersusTable.java | 119 ++-- lib/example/GridVersusTable.java | 88 ++- lib/example/MyClass.java | 47 +- lib/example/Preferred.java | 127 ++--- lib/example/RadTool.java | 620 ++++++++++----------- lib/example/Simple.java | 54 +- lib/example/TypicalGui.java | 215 ++++--- src/control/images/agree_notsure.png | Bin 0 -> 572 bytes src/cppcheckplus/control/MyContentPanel.java | 16 +- src/cppcheckplus/control/MyHeader.java | 341 ++++++------ src/cppcheckplus/control/MyList.java | 104 ++-- src/cppcheckplus/control/MyListRenderer.java | 222 ++++---- src/cppcheckplus/control/MyListSplitListener.java | 71 ++- src/cppcheckplus/control/MySeparator.java | 58 +- src/cppcheckplus/control/MyTextField.java | 93 ++-- src/cppcheckplus/control/MyToolbarButton.java | 131 ++--- src/cppcheckplus/control/UIFrame.java | 10 +- .../control/XChartletFullScreenListenter.java | 6 +- src/cppcheckplus/menu/MyMenu.java | 104 ++-- src/cppcheckplus/menu/MyMenuBar.java | 82 +-- src/cppcheckplus/menu/MyMenuItem.java | 82 ++- src/cppcheckplus/menu/MyRootMenu.java | 91 ++- src/cppcheckplus/outlookpanel/MyOutlookBar.java | 393 +++++++------ src/cppcheckplus/outlookpanel/MyOutlookHeader.java | 179 +++--- src/cppcheckplus/outlookpanel/MyOutlookList.java | 41 +- .../outlookpanel/MyOutlookListPanel.java | 86 ++- .../outlookpanel/MyOutlookListRenderer.java | 81 ++- src/cppcheckplus/outlookpanel/MyOutlookPanel.java | 405 +++++++------- .../outlookpanel/MyOutlookPanelListItem.java | 83 ++- .../outlookpanel/MyOutlookSplitListener.java | 42 +- src/cppcheckplus/shortcut/MyShortcutItem.java | 21 +- .../shortcut/MyShortcutItemClickListenter.java | 6 +- src/cppcheckplus/shortcut/MyShortcutPanel.java | 194 +++---- src/cppcheckplus/shortcut/MyTree.java | 2 +- src/cppcheckplus/tab/MyTabComponent.java | 299 +++++----- src/cppcheckplus/tab/MyTabComponent1.java | 213 ++++--- src/cppcheckplus/tab/MyTabPage.java | 69 ++- src/cppcheckplus/tab/MyTabPage1.java | 39 +- src/cppcheckplus/tab/MyTabPanel.java | 145 +++-- src/cppcheckplus/tab/MyTabPanelUI.java | 85 ++- src/cppcheckplus/tab/MyTabPanelUI1.java | 85 ++- src/cppcheckplus/text/DeflectRow.java | 283 ++++++---- src/cppcheckplus/text/FileTools.java | 123 ++-- src/cppcheckplus/text/LineNumberHeaderView.java | 140 ++--- src/cppcheckplus/text/MyButtonEditor.java | 144 ++--- src/cppcheckplus/text/MyButtonRenderer.java | 65 ++- src/cppcheckplus/text/MyPanel.java | 35 +- src/cppcheckplus/text/MyTextArea.java | 92 +-- src/cppcheckplus/text/MyTextPanel.java | 108 ++-- src/cppcheckplus/text/MyTextPanel1.java | 94 ++-- src/cppcheckplus/text/ViewPanel.java | 354 ++++++------ src/cppcheckplus/text/creatTable.java | 597 ++++++++++---------- src/cppcheckplus/text/stdClangType.java | 10 +- src/cppcheckplus/toolbar/MyToolBar.java | 93 ++-- src/cppcheckplus/toolbar/MyToolBarButton.java | 133 ++--- src/cppcheckplus/toolbar/MyToolBarRoverButton.java | 46 +- src/toolsconfig/clangTidy.java | 2 - src/toolsconfig/flawfinder.java | 4 +- src/toolsconfig/settings.xml | 4 +- 59 files changed, 3619 insertions(+), 3857 deletions(-) create mode 100644 src/control/images/agree_notsure.png diff --git a/lib/example/GridBagVersusTable.java b/lib/example/GridBagVersusTable.java index 53e45d6..0ed367a 100644 --- a/lib/example/GridBagVersusTable.java +++ b/lib/example/GridBagVersusTable.java @@ -1,140 +1,133 @@ package example; - -import java.awt.*; -import java.awt.event.*; +import java.awt.Font; +import java.awt.Frame; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.awt.event.WindowListener; import javax.swing.JButton; import layout.TableLayout; -import layout.TableLayoutConstraints; +public class GridBagVersusTable { -public class GridBagVersusTable -{ - - protected static void makeButton - (Frame frame, String name, GridBagLayout gridbag, GridBagConstraints c) - { + (Frame frame, String name, GridBagLayout gridbag, + GridBagConstraints c) { JButton button = new JButton(name); gridbag.setConstraints(button, c); frame.add(button); } - - - protected static Frame showGridBagWindow () - { + + protected static Frame showGridBagWindow() { // Create layout and contraints object GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); - + // Create frame Frame frame = new Frame("GridBagLayout"); - frame.setFont (new Font("Helvetica", Font.PLAIN, 14)); - frame.setLayout (gridbag); - + frame.setFont(new Font("Helvetica", Font.PLAIN, 14)); + frame.setLayout(gridbag); + // Create buttons, add buttons, and apply constraints c.fill = GridBagConstraints.BOTH; c.weightx = 1.0; - makeButton (frame, "Button1", gridbag, c); - makeButton (frame, "Button2", gridbag, c); - makeButton (frame, "Button3", gridbag, c); + makeButton(frame, "Button1", gridbag, c); + makeButton(frame, "Button2", gridbag, c); + makeButton(frame, "Button3", gridbag, c); c.gridwidth = GridBagConstraints.REMAINDER; //end of row - makeButton (frame, "Button4", gridbag, c); + makeButton(frame, "Button4", gridbag, c); c.weightx = 0.0; //reset to the default - makeButton (frame, "Button5", gridbag, c); //another row + makeButton(frame, "Button5", gridbag, c); //another row c.gridwidth = GridBagConstraints.RELATIVE; //next-to-last in row - makeButton (frame, "Button6", gridbag, c); + makeButton(frame, "Button6", gridbag, c); c.gridwidth = GridBagConstraints.REMAINDER; //end of row - makeButton (frame, "Button7", gridbag, c); + makeButton(frame, "Button7", gridbag, c); c.gridwidth = 1; //reset to the default c.gridheight = 2; c.weighty = 1.0; - makeButton (frame, "Button8", gridbag, c); + makeButton(frame, "Button8", gridbag, c); c.weighty = 0.0; //reset to the default c.gridwidth = GridBagConstraints.REMAINDER; //end of row c.gridheight = 1; //reset to the default - makeButton (frame, "Button9", gridbag, c); - makeButton (frame, "Button10", gridbag, c); + makeButton(frame, "Button9", gridbag, c); + makeButton(frame, "Button10", gridbag, c); // Show frame frame.pack(); - frame.setLocation (0, 10); + frame.setLocation(0, 10); frame.show(); return frame; } - - - protected static Frame showTableWindow () - { + + protected static Frame showTableWindow() { // Create frame Frame frame = new Frame("TableLayout"); frame.setFont(new Font("Helvetica", Font.PLAIN, 14)); - + // Set layout double f = TableLayout.FILL; double p = TableLayout.PREFERRED; double size[][] = {{f, f, f, f}, {p, p, p, p, f}}; - + TableLayout layout = new TableLayout(size); - frame.setLayout (layout); - + frame.setLayout(layout); + // Create buttons labeled Button1 to Button10 int numButton = 10; JButton button[] = new JButton[numButton + 1]; - - for (int i = 1; i <= numButton; i++) + + for (int i = 1; i <= numButton; i++) { button[i] = new JButton("Button" + i); - + } + // Add buttons - frame.add (button[1], "0, 0"); - frame.add (button[2], "1, 0"); - frame.add (button[3], "2, 0"); - frame.add (button[4], "3, 0"); - frame.add (button[5], "0, 1, 3, 1"); - frame.add (button[6], "0, 2, 2, 2"); - frame.add (button[7], "3, 2, 3, 2"); - frame.add (button[8], "0, 3, 0, 4"); - frame.add (button[9], "1, 3, 3, 3"); - frame.add (button[10], "1, 4, 3, 4"); + frame.add(button[1], "0, 0"); + frame.add(button[2], "1, 0"); + frame.add(button[3], "2, 0"); + frame.add(button[4], "3, 0"); + frame.add(button[5], "0, 1, 3, 1"); + frame.add(button[6], "0, 2, 2, 2"); + frame.add(button[7], "3, 2, 3, 2"); + frame.add(button[8], "0, 3, 0, 4"); + frame.add(button[9], "1, 3, 3, 3"); + frame.add(button[10], "1, 4, 3, 4"); // Show frame frame.pack(); - frame.setLocation (400, 10); + frame.setLocation(400, 10); frame.show(); return frame; } - - public static void main (String args[]) - { + public static void main(String args[]) { WindowListener listener = - (new WindowAdapter() - { - public void windowClosing (WindowEvent e) - { - System.exit (0); - } + (new WindowAdapter() { + public void windowClosing(WindowEvent e) { + System.exit(0); } + } ); Frame frame = showGridBagWindow(); - frame.addWindowListener (listener); - + frame.addWindowListener(listener); + frame = showTableWindow(); - frame.addWindowListener (listener); + frame.addWindowListener(listener); } } diff --git a/lib/example/GridVersusTable.java b/lib/example/GridVersusTable.java index c5746c4..890d2e9 100644 --- a/lib/example/GridVersusTable.java +++ b/lib/example/GridVersusTable.java @@ -1,108 +1,100 @@ package example; - -import java.awt.*; -import java.awt.event.*; +import java.awt.Font; +import java.awt.Frame; +import java.awt.GridLayout; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.awt.event.WindowListener; import javax.swing.JButton; import layout.TableLayout; - public class GridVersusTable { - - - protected static Frame showGridWindow () - { + + protected static Frame showGridWindow() { // Create frame Frame frame = new Frame("GridLayout"); - frame.setFont (new Font("Helvetica", Font.PLAIN, 14)); - frame.setLayout (new GridLayout(2, 0)); - + frame.setFont(new Font("Helvetica", Font.PLAIN, 14)); + frame.setLayout(new GridLayout(2, 0)); + // Create and add buttons - frame.add (new JButton("One")); - frame.add (new JButton("Two")); - frame.add (new JButton("Three")); - frame.add (new JButton("Four")); + frame.add(new JButton("One")); + frame.add(new JButton("Two")); + frame.add(new JButton("Three")); + frame.add(new JButton("Four")); // Show frame frame.pack(); - frame.setLocation (0, 10); + frame.setLocation(0, 10); frame.show(); return frame; } - - protected static Frame showTableWindow () - { + protected static Frame showTableWindow() { // Create frame Frame frame = new Frame("TableLayout"); - frame.setFont (new Font("Helvetica", Font.PLAIN, 14)); - + frame.setFont(new Font("Helvetica", Font.PLAIN, 14)); + // Set layout double f = TableLayout.FILL; double size[][] = {{f, f}, {f, f}}; - frame.setLayout (new TableLayout(size)); - + frame.setLayout(new TableLayout(size)); + // Create and add buttons - frame.add (new JButton("One"), "0, 0"); - frame.add (new JButton("Two"), "1, 0"); - frame.add (new JButton("Three"), "0, 1"); - frame.add (new JButton("Four"), "1, 1"); + frame.add(new JButton("One"), "0, 0"); + frame.add(new JButton("Two"), "1, 0"); + frame.add(new JButton("Three"), "0, 1"); + frame.add(new JButton("Four"), "1, 1"); // Show frame frame.pack(); - frame.setLocation (200, 10); + frame.setLocation(200, 10); frame.show(); return frame; } - - protected static Frame showTableWindow2 () - { + protected static Frame showTableWindow2() { // Create frame Frame frame = new Frame("TableLayout"); - frame.setFont (new Font("Helvetica", Font.PLAIN, 14)); - + frame.setFont(new Font("Helvetica", Font.PLAIN, 14)); + // Set layout double f = TableLayout.FILL; double size[][] = {{f, f}, {f, f}}; - frame.setLayout (new TableLayout(size)); - + frame.setLayout(new TableLayout(size)); + // Create and add buttons - frame.add (new JButton("One"), "0, 0"); - frame.add (new JButton("Two"), "1, 1"); + frame.add(new JButton("One"), "0, 0"); + frame.add(new JButton("Two"), "1, 1"); // Show frame frame.pack(); - frame.setLocation (400, 10); + frame.setLocation(400, 10); frame.show(); return frame; } - - public static void main (String args[]) - { + public static void main(String args[]) { WindowListener listener = - (new WindowAdapter() - { - public void windowClosing (WindowEvent e) - { - System.exit (0); - } + (new WindowAdapter() { + public void windowClosing(WindowEvent e) { + System.exit(0); } + } ); Frame frame = showGridWindow(); frame.addWindowListener(listener); - + frame = showTableWindow(); frame.addWindowListener(listener); diff --git a/lib/example/MyClass.java b/lib/example/MyClass.java index 632e99a..ef47ace 100644 --- a/lib/example/MyClass.java +++ b/lib/example/MyClass.java @@ -1,47 +1,44 @@ package example; - -import java.awt.*; -import java.awt.event.*; +import java.awt.Button; +import java.awt.Frame; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; import layout.TableLayout; -public class MyClass -{ +public class MyClass { - public static void main (String args[]) - { + public static void main(String args[]) { Frame frame = new Frame("MyTitle"); - frame.setBounds (100, 100, 300, 300); + frame.setBounds(100, 100, 300, 300); - double size[][] = - {{-2.0, 10.0, 50.0, -1.0, 10.0}, // Columns - {-2.0, 10.0, 0.25, -1.0, 10.0}}; // Rows + double size[][] = + {{-2.0, 10.0, 50.0, -1.0, 10.0}, // Columns + {-2.0, 10.0, 0.25, -1.0, 10.0}}; // Rows - frame.setLayout (new TableLayout(size)); + frame.setLayout(new TableLayout(size)); Button button; button = new Button("3, 3, R, C"); - frame.add (button, "3, 3, R, C"); + frame.add(button, "3, 3, R, C"); button = new Button("3, 3, L, T"); - frame.add (button, "3, 3, L, T"); + frame.add(button, "3, 3, L, T"); button = new Button("2, 3, C, T"); - frame.add (button, "2, 3, C, T"); + frame.add(button, "2, 3, C, T"); button = new Button("3, 2, L, C"); - frame.add (button, "3, 2, L, C"); + frame.add(button, "3, 2, L, C"); button = new Button("2, 2, F, F"); - frame.add (button, "2, 2, F, F"); + frame.add(button, "2, 2, F, F"); button = new Button("3, 3, C, C"); - frame.add (button, "3, 3, C, C"); + frame.add(button, "3, 3, C, C"); frame.addWindowListener - (new WindowAdapter() - { - public void windowClosing (WindowEvent e) - { - System.exit (0); - } - } + (new WindowAdapter() { + public void windowClosing(WindowEvent e) { + System.exit(0); + } + } ); frame.show(); diff --git a/lib/example/Preferred.java b/lib/example/Preferred.java index aa1e8a6..f5fc54e 100644 --- a/lib/example/Preferred.java +++ b/lib/example/Preferred.java @@ -1,106 +1,97 @@ package example; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; +import java.awt.Container; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; import layout.TableLayout; +public class Preferred extends JFrame { + + + public Preferred() { + super("The Power of Preferred Sizes"); -public class Preferred extends JFrame -{ - - - - public static void main (String args[]) - { - new Preferred(); - } - - - - public Preferred () - { - super ("The Power of Preferred Sizes"); - Container pane = getContentPane(); - + // b - border // f - FILL // p - PREFERRED // vs - vertical space between labels and text fields // vg - vertical gap between form elements // hg - horizontal gap between form elements - + double b = 10; double f = TableLayout.FILL; double p = TableLayout.PREFERRED; double vs = 5; double vg = 10; double hg = 10; - + double size[][] = {{b, f, hg, p, hg, p, b}, - {b, p, vs, p, vg, p, vs, p, vg, p, vs, p, vg, p, b}}; - + {b, p, vs, p, vg, p, vs, p, vg, p, vs, p, vg, p, b}}; + TableLayout layout = new TableLayout(size); - pane.setLayout (layout); - + pane.setLayout(layout); + // Create all controls - JLabel labelName = new JLabel("Name"); + JLabel labelName = new JLabel("Name"); JLabel labelAddress = new JLabel("Address"); - JLabel labelCity = new JLabel("City"); - JLabel labelState = new JLabel("State"); - JLabel labelZip = new JLabel("Zip"); - - JTextField textfieldName = new JTextField(10); + JLabel labelCity = new JLabel("City"); + JLabel labelState = new JLabel("State"); + JLabel labelZip = new JLabel("Zip"); + + JTextField textfieldName = new JTextField(10); JTextField textfieldAddress = new JTextField(20); - JTextField textfieldCity = new JTextField(10); - JTextField textfieldState = new JTextField(2); - JTextField textfieldZip = new JTextField(5); - + JTextField textfieldCity = new JTextField(10); + JTextField textfieldState = new JTextField(2); + JTextField textfieldZip = new JTextField(5); + JButton buttonOk = new JButton("OK"); JButton buttonCancel = new JButton("Cancel"); JPanel panelButton = new JPanel(); - panelButton.add (buttonOk); - panelButton.add (buttonCancel); - + panelButton.add(buttonOk); + panelButton.add(buttonCancel); + // Add all controls - pane.add (labelName, "1, 1, 5, 1"); - pane.add (textfieldName, "1, 3, 5, 3"); - pane.add (labelAddress, "1, 5, 5, 5"); - pane.add (textfieldAddress, "1, 7, 5, 7"); - pane.add (labelCity, "1, 9"); - pane.add (textfieldCity, "1, 11"); - pane.add (labelState, "3, 9"); - pane.add (textfieldState, "3, 11"); - pane.add (labelZip, "5, 9"); - pane.add (textfieldZip, "5, 11"); - pane.add (panelButton, "1, 13, 5, 13"); - + pane.add(labelName, "1, 1, 5, 1"); + pane.add(textfieldName, "1, 3, 5, 3"); + pane.add(labelAddress, "1, 5, 5, 5"); + pane.add(textfieldAddress, "1, 7, 5, 7"); + pane.add(labelCity, "1, 9"); + pane.add(textfieldCity, "1, 11"); + pane.add(labelState, "3, 9"); + pane.add(textfieldState, "3, 11"); + pane.add(labelZip, "5, 9"); + pane.add(textfieldZip, "5, 11"); + pane.add(panelButton, "1, 13, 5, 13"); + allowClosing(); pack(); - setResizable (false); + setResizable(false); show(); } - - - - public void allowClosing () - { + + public static void main(String args[]) { + new Preferred(); + } + + public void allowClosing() { addWindowListener - (new WindowAdapter() - { - public void windowClosing (WindowEvent e) - { - System.exit (0); - } - } + (new WindowAdapter() { + public void windowClosing(WindowEvent e) { + System.exit(0); + } + } ); } - - - + + } diff --git a/lib/example/RadTool.java b/lib/example/RadTool.java index 8ef0c55..75e7635 100644 --- a/lib/example/RadTool.java +++ b/lib/example/RadTool.java @@ -1,22 +1,33 @@ package example; - -import java.awt.*; -import java.awt.event.*; -import java.util.*; -import javax.swing.*; +import java.awt.Choice; +import java.awt.Color; +import java.awt.Component; +import java.awt.Container; +import java.awt.Dimension; +import java.awt.Frame; +import java.awt.Graphics; +import java.awt.Panel; +import java.awt.TextArea; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseListener; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.util.ArrayList; +import javax.swing.JButton; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; import layout.TableLayout; import layout.TableLayoutConstraints; import support.GeneralDialog; +public class RadTool extends Frame implements ActionListener { -public class RadTool extends Frame implements ActionListener -{ - - private JTextField textfieldColumnNumber; private JTextField textfieldColumnSize; private JTextField textfieldRowNumber; @@ -37,20 +48,11 @@ public class RadTool extends Frame implements ActionListener private ArrayList boxList; - - public static void main (String args[]) - { - new RadTool(); - } - - - /** * Constructs the user interface. */ - - public RadTool() - { + + public RadTool() { // Create frame super("Example of Dynamic Rows and Columns"); @@ -61,9 +63,9 @@ public class RadTool extends Frame implements ActionListener double p = TableLayout.PREFERRED; double size[][] = {{b, p, s, p, s, p, s, p, s, p, s, p, s, p, f, b}, - {f, s, p, s, p, s, 100, s, p, b}}; + {f, s, p, s, p, s, 100, s, p, b}}; - setLayout (new TableLayout(size)); + setLayout(new TableLayout(size)); // Create static controls JLabel labelColumn = new JLabel("Column"); @@ -81,106 +83,105 @@ public class RadTool extends Frame implements ActionListener buttonAddRow = new JButton("Add"); buttonRemoveRow = new JButton("Remove"); buttonResizeRow = new JButton("Resize"); - + textArea = new TextArea(); columnHeader = new ArrayList(); rowHeader = new ArrayList(); boxList = new ArrayList(); buttonShowLayout = new JButton("Show Layout"); buttonGenerateCode = new JButton("Generate Code"); - + // Add static controls - add (labelColumn, " 1, 2"); - add (textfieldColumnNumber, " 3, 2"); - add (labelColumnSize, " 5, 2"); - add (textfieldColumnSize, " 7, 2"); - add (buttonAddColumn, " 9, 2"); - add (buttonRemoveColumn, "11, 2"); - add (buttonResizeColumn, "13, 2"); - - add (labelRow, " 1, 4"); - add (textfieldRowNumber, " 3, 4"); - add (labelRowSize, " 5, 4"); - add (textfieldRowSize, " 7, 4"); - add (buttonAddRow, " 9, 4"); - add (buttonRemoveRow, "11, 4"); - add (buttonResizeRow, "13, 4"); - - add (textArea, "1, 6, 14, 6"); - add (buttonShowLayout, "1, 8, 7, 6"); - add (buttonGenerateCode, "9, 8, 12, 8"); - + add(labelColumn, " 1, 2"); + add(textfieldColumnNumber, " 3, 2"); + add(labelColumnSize, " 5, 2"); + add(textfieldColumnSize, " 7, 2"); + add(buttonAddColumn, " 9, 2"); + add(buttonRemoveColumn, "11, 2"); + add(buttonResizeColumn, "13, 2"); + + add(labelRow, " 1, 4"); + add(textfieldRowNumber, " 3, 4"); + add(labelRowSize, " 5, 4"); + add(textfieldRowSize, " 7, 4"); + add(buttonAddRow, " 9, 4"); + add(buttonRemoveRow, "11, 4"); + add(buttonResizeRow, "13, 4"); + + add(textArea, "1, 6, 14, 6"); + add(buttonShowLayout, "1, 8, 7, 6"); + add(buttonGenerateCode, "9, 8, 12, 8"); + // Listen for button events - buttonAddColumn.addActionListener (this); - buttonRemoveColumn.addActionListener (this); - buttonResizeColumn.addActionListener (this); - buttonAddRow.addActionListener (this); - buttonRemoveRow.addActionListener (this); - buttonResizeRow.addActionListener (this); - buttonShowLayout.addActionListener (this); - buttonGenerateCode.addActionListener (this); - + buttonAddColumn.addActionListener(this); + buttonRemoveColumn.addActionListener(this); + buttonResizeColumn.addActionListener(this); + buttonAddRow.addActionListener(this); + buttonRemoveRow.addActionListener(this); + buttonResizeRow.addActionListener(this); + buttonShowLayout.addActionListener(this); + buttonGenerateCode.addActionListener(this); + // Add a panel for RadTool controls panel = new JPanel(); - panel.setBackground (Color.white); - add (panel, "0, 0, 15, 0"); - + panel.setBackground(Color.white); + add(panel, "0, 0, 15, 0"); + // Create the layout manager for the panel double size2[][] = {{p, -1}, {p, -1}}; layout = new TableLayout(size2); - panel.setLayout (layout); + panel.setLayout(layout); updateHeader(); updateBox(); // Allow user to close the window to terminate the program addWindowListener - (new WindowAdapter() - { - public void windowClosing (WindowEvent e) - { - System.exit (0); - } - } + (new WindowAdapter() { + public void windowClosing(WindowEvent e) { + System.exit(0); + } + } ); // Show frame - setBackground (Color.lightGray); - setBounds (100, 100, 500, 400); + setBackground(Color.lightGray); + setBounds(100, 100, 500, 400); show(); } - - + public static void main(String args[]) { + new RadTool(); + } + /** * Handles all action events. */ - - public void actionPerformed (ActionEvent e) - { + + public void actionPerformed(ActionEvent e) { // Get row and column information from text fields int row = getInt(textfieldRowNumber); int col = getInt(textfieldColumnNumber); double rowSize = getDouble(textfieldRowSize); double colSize = getDouble(textfieldColumnSize); - + // Get source of the event Object source = e.getSource(); - - try - { + + try { // Update layout - if (source == buttonAddColumn) - layout.insertColumn (col, colSize); - else if (source == buttonRemoveColumn) - layout.deleteColumn (col); - else if (source == buttonResizeColumn) - layout.setColumn (col, colSize); - else if (source == buttonAddRow) - layout.insertRow (row, rowSize); - else if (source == buttonRemoveRow) - layout.deleteRow (row); - else if (source == buttonResizeRow) - layout.setRow (row, rowSize); + if (source == buttonAddColumn) { + layout.insertColumn(col, colSize); + } else if (source == buttonRemoveColumn) { + layout.deleteColumn(col); + } else if (source == buttonResizeColumn) { + layout.setColumn(col, colSize); + } else if (source == buttonAddRow) { + layout.insertRow(row, rowSize); + } else if (source == buttonRemoveRow) { + layout.deleteRow(row); + } else if (source == buttonResizeRow) { + layout.setRow(row, rowSize); + } // Update headers, etc. to reflect layout's change updateHeader(); @@ -189,258 +190,242 @@ public class RadTool extends Frame implements ActionListener // Layout and repaint panel since the layout has changed panel.doLayout(); panel.repaint(); - + // Update layout's description textArea.setText(layout.toString()); - + // Generate code if desired - if (source == buttonGenerateCode) + if (source == buttonGenerateCode) { generateCode(); - } - catch (Throwable error) - { + } + } catch (Throwable error) { error.printStackTrace(); - textArea.setText (error.toString()); + textArea.setText(error.toString()); } } - - - + + /** * Converts the text in a text field to an integer. */ - - private int getInt (JTextField field) - { + + private int getInt(JTextField field) { int value = 0; - - try - { + + try { value = Integer.parseInt(field.getText()); + } catch (NumberFormatException e) { } - catch (NumberFormatException e) {} - + return value; } - - - + + /** * Converts the text in a text field to a double. */ - - private double getDouble (JTextField field) - { + + private double getDouble(JTextField field) { double value = -1.0; - - try - { + + try { value = Double.parseDouble(field.getText()); + } catch (NumberFormatException e) { } - catch (NumberFormatException e) {} - + return value; } - - + /** * Updates all the row and columns headers by bruce force. The headers * are removed and then recreated based on the current layout configuration. */ - - private void updateHeader () - { + + private void updateHeader() { TableLayoutConstraints c = new TableLayoutConstraints (0, 0, 0, 0, TableLayout.FULL, TableLayout.FULL); - + double size[] = layout.getColumn(); - for (int i = columnHeader.size() - 1; i >= 0; i--) - { + for (int i = columnHeader.size() - 1; i >= 0; i--) { JButton header = (JButton) columnHeader.remove(i); panel.remove(header); } - for (int i = 0; i < size.length; i++) - { + for (int i = 0; i < size.length; i++) { c.col1 = c.col2 = i; JButton header = new JButton("" + i + ": " + size[i]); columnHeader.add(i, header); - panel.add (header, c); + panel.add(header, c); } - + c.col1 = c.col2 = 0; size = layout.getRow(); - - for (int i = rowHeader.size() - 1; i >= 0; i--) - { + + for (int i = rowHeader.size() - 1; i >= 0; i--) { JButton header = (JButton) rowHeader.remove(i); panel.remove(header); } - for (int i = 0; i < size.length; i++) - { + for (int i = 0; i < size.length; i++) { c.row1 = c.row2 = i; JButton header = new JButton("" + i + ": " + size[i]); rowHeader.add(i, header); - panel.add (header, c); + panel.add(header, c); } } - - - + + /** * Updates the boxes used to illustrate cells. This is a brute force, * unoptimized method. */ - - private void updateBox () - { - for (int i = boxList.size() - 1; i >= 0; i--) - { + + private void updateBox() { + for (int i = boxList.size() - 1; i >= 0; i--) { Box box = (Box) boxList.remove(i); panel.remove(box); } TableLayoutConstraints constraint = new TableLayoutConstraints (0, 0, 0, 0, TableLayout.FULL, TableLayout.FULL); - + double col[] = layout.getColumn(); double row[] = layout.getRow(); - for (int c = 1; c < col.length; c++) - for (int r = 1; r < row.length; r++) - { + for (int c = 1; c < col.length; c++) { + for (int r = 1; r < row.length; r++) { constraint.col1 = constraint.col2 = c; constraint.row1 = constraint.row2 = r; Box box = new Box(); - panel.add (box, constraint); + panel.add(box, constraint); } + } } - - - + + /** * Generates code based on the current layout and Smiley controls. */ - - private void generateCode () - { + + private void generateCode() { String code = "import java.awt.*;\n" + - "import java.awt.event.*;\n" + - "import layout.TableLayout;\n\n" + + "import java.awt.event.*;\n" + + "import layout.TableLayout;\n\n" + - "public class MyClass\n" + - "{\n\n" + + "public class MyClass\n" + + "{\n\n" + - " public static void main (String args[])\n" + - " {\n" + - " Frame frame = new Frame(\"MyTitle\");\n" + - " frame.setBounds (100, 100, 300, 300);\n\n" + + " public static void main (String args[])\n" + + " {\n" + + " Frame frame = new Frame(\"MyTitle\");\n" + + " frame.setBounds (100, 100, 300, 300);\n\n" + + + " double size[][] =\n" + + " {{"; - " double size[][] =\n" + - " {{"; - double size[] = layout.getColumn(); - if (size.length > 0) + if (size.length > 0) { code += size[0]; + } - for (int i = 1; i < size.length; i++) + for (int i = 1; i < size.length; i++) { code += ", " + size[i]; + } code += "}, // Columns\n" + " {"; - + size = layout.getRow(); - if (size.length > 0) + if (size.length > 0) { code += size[0]; + } - for (int i = 1; i < size.length; i++) + for (int i = 1; i < size.length; i++) { code += ", " + size[i]; + } code += "}}; // Rows\n\n" + " frame.setLayout (new TableLayout(size));\n\n" + " Button button;\n"; Component component[] = panel.getComponents(); - - for (int i = 0; i < component.length; i++) - { - if (component[i] instanceof Smiley) - { + + for (int i = 0; i < component.length; i++) { + if (component[i] instanceof Smiley) { TableLayoutConstraints c = layout.getConstraints(component[i]); - String constraint = "" + c.col1 + ", " + c.row1 + ", "; - - if ((c.col1 == c.col2) && (c.row1 == c.row2)) - { + String constraint = "" + c.col1 + ", " + c.row1 + ", "; + + if ((c.col1 == c.col2) && (c.row1 == c.row2)) { String h[] = {"L", "C", "F", "R"}; String v[] = {"T", "C", "F", "B"}; constraint += h[c.hAlign] + ", " + v[c.vAlign]; - } - else + } else { constraint += c.col2 + ", " + c.row2; - + } + code += " button = new Button(\"" + constraint + "\");\n" + - " frame.add (button, \"" + constraint + "\");\n"; + " frame.add (button, \"" + constraint + "\");\n"; } } code += "\n" + - " frame.addWindowListener\n" + - " (new WindowAdapter()\n" + - " {\n" + - " public void windowClosing (WindowEvent e)\n" + - " {\n" + - " System.exit (0);\n" + - " }\n" + - " }\n" + - " );\n\n" + - " frame.show();\n" + - " }\n" + - "}\n"; - - textArea.setText (code); + " frame.addWindowListener\n" + + " (new WindowAdapter()\n" + + " {\n" + + " public void windowClosing (WindowEvent e)\n" + + " {\n" + + " System.exit (0);\n" + + " }\n" + + " }\n" + + " );\n\n" + + " frame.show();\n" + + " }\n" + + "}\n"; + + textArea.setText(code); } - - - + + /** * This inner class is a component that looks like a box. */ - - public class Box extends Component implements MouseListener - { - public Box () - { + + public class Box extends Component implements MouseListener { + public Box() { super(); addMouseListener(this); } - - public void update (Graphics g) - { - paint (g); + + public void update(Graphics g) { + paint(g); } - - public void paint (Graphics g) - { + + public void paint(Graphics g) { Dimension d = getSize(); - g.setColor (Color.black); - g.drawRect (0, 0, d.width - 1, d.height - 1); + g.setColor(Color.black); + g.drawRect(0, 0, d.width - 1, d.height - 1); + } + + public void mouseExited(java.awt.event.MouseEvent mouseEvent) { + } + + public void mousePressed(java.awt.event.MouseEvent mouseEvent) { + } + + public void mouseClicked(java.awt.event.MouseEvent mouseEvent) { } - - public void mouseExited(java.awt.event.MouseEvent mouseEvent) {} - public void mousePressed(java.awt.event.MouseEvent mouseEvent) {} - public void mouseClicked(java.awt.event.MouseEvent mouseEvent) {} - public void mouseEntered(java.awt.event.MouseEvent mouseEvent) {} - - public void mouseReleased(java.awt.event.MouseEvent mouseEvent) - { + + public void mouseEntered(java.awt.event.MouseEvent mouseEvent) { + } + + public void mouseReleased(java.awt.event.MouseEvent mouseEvent) { TableLayoutConstraints c = layout.getConstraints(this); Smiley smiley = new Smiley(); Container container = getParent(); @@ -449,32 +434,26 @@ public class RadTool extends Frame implements ActionListener } } - /** * This inner class is a component that looks like a smiley face. */ - - public class Smiley extends Component implements MouseListener - { - public Smiley () - { + + public class Smiley extends Component implements MouseListener { + public Smiley() { super(); - addMouseListener (this); + addMouseListener(this); } - - public Dimension getPreferredSize () - { + + public Dimension getPreferredSize() { return new Dimension(64, 64); } - - public void update (Graphics g) - { - paint (g); + + public void update(Graphics g) { + paint(g); } - - public void paint (Graphics g) - { + + public void paint(Graphics g) { Dimension d = getSize(); int width_1_8 = d.width >> 3; int width_7_8 = d.width - width_1_8; @@ -487,131 +466,132 @@ public class RadTool extends Frame implements ActionListener int height_1_4 = d.height >> 2; int height_3_4 = d.height - height_1_4; int height_5_8 = height_7_8 - height_1_4; - - g.setColor (Color.yellow); - g.fillArc (0, 0, d.width - 1, d.height - 1, 0, 360); - g.setColor (Color.blue); - g.fillArc (width_1_4, height_1_4, width_1_8, height_1_8, 0, 360); - g.fillArc (width_5_8, height_1_4, width_1_8, height_1_8, 0, 360); - g.setColor (Color.red); - g.fillArc (width_1_4, height_5_8, width_1_2, height_1_4, 180, 180); + + g.setColor(Color.yellow); + g.fillArc(0, 0, d.width - 1, d.height - 1, 0, 360); + g.setColor(Color.blue); + g.fillArc(width_1_4, height_1_4, width_1_8, height_1_8, 0, 360); + g.fillArc(width_5_8, height_1_4, width_1_8, height_1_8, 0, 360); + g.setColor(Color.red); + g.fillArc(width_1_4, height_5_8, width_1_2, height_1_4, 180, 180); + } + + public void mouseExited(java.awt.event.MouseEvent mouseEvent) { + } + + public void mousePressed(java.awt.event.MouseEvent mouseEvent) { + } + + public void mouseClicked(java.awt.event.MouseEvent mouseEvent) { + } + + public void mouseEntered(java.awt.event.MouseEvent mouseEvent) { } - - public void mouseExited(java.awt.event.MouseEvent mouseEvent) {} - public void mousePressed(java.awt.event.MouseEvent mouseEvent) {} - public void mouseClicked(java.awt.event.MouseEvent mouseEvent) {} - public void mouseEntered(java.awt.event.MouseEvent mouseEvent) {} - - public void mouseReleased(java.awt.event.MouseEvent mouseEvent) - { + + public void mouseReleased(java.awt.event.MouseEvent mouseEvent) { // Get constraints applied to this Smiley TableLayoutConstraints c = layout.getConstraints(this); - + // Create controls Panel panel = new Panel(); - + int numRow = layout.getNumRow(); int numColumn = layout.getNumColumn(); - + Choice choiceCol1 = new Choice(); Choice choiceCol2 = new Choice(); Choice choiceRow1 = new Choice(); Choice choiceRow2 = new Choice(); - - for (int i = 1; i < numColumn; i++) - { - choiceCol1.add ("" + i); - choiceCol2.add ("" + i); + + for (int i = 1; i < numColumn; i++) { + choiceCol1.add("" + i); + choiceCol2.add("" + i); } - - for (int i = 1; i < numRow; i++) - { - choiceRow1.add ("" + i); - choiceRow2.add ("" + i); + + for (int i = 1; i < numRow; i++) { + choiceRow1.add("" + i); + choiceRow2.add("" + i); } - - choiceCol1.select (c.col1 - 1); - choiceCol2.select (c.col2 - 1); - choiceRow1.select (c.row1 - 1); - choiceRow2.select (c.row2 - 1); - + + choiceCol1.select(c.col1 - 1); + choiceCol2.select(c.col2 - 1); + choiceRow1.select(c.row1 - 1); + choiceRow2.select(c.row2 - 1); + Choice choiceAlignH = new Choice(); - choiceAlignH.add ("Left"); - choiceAlignH.add ("Center"); - choiceAlignH.add ("Full"); - choiceAlignH.add ("Right"); - choiceAlignH.select (c.hAlign); + choiceAlignH.add("Left"); + choiceAlignH.add("Center"); + choiceAlignH.add("Full"); + choiceAlignH.add("Right"); + choiceAlignH.select(c.hAlign); Choice choiceAlignV = new Choice(); - choiceAlignV.add ("Top"); - choiceAlignV.add ("Center"); - choiceAlignV.add ("Full"); - choiceAlignV.add ("Bottom"); - choiceAlignV.select (c.vAlign); - + choiceAlignV.add("Top"); + choiceAlignV.add("Center"); + choiceAlignV.add("Full"); + choiceAlignV.add("Bottom"); + choiceAlignV.select(c.vAlign); + JLabel labelCol1 = new JLabel("Column 1"); JLabel labelCol2 = new JLabel("Column 2"); JLabel labelRow1 = new JLabel("Row 1"); JLabel labelRow2 = new JLabel("Row 2"); JLabel labelAlignH = new JLabel("Horizontal Justification"); JLabel labelAlignV = new JLabel("Vertical Justification"); - labelAlignH.setHorizontalAlignment (JLabel.RIGHT); - labelAlignV.setHorizontalAlignment (JLabel.RIGHT); - + labelAlignH.setHorizontalAlignment(JLabel.RIGHT); + labelAlignV.setHorizontalAlignment(JLabel.RIGHT); + // Create layout double f = TableLayout.FILL; double p = TableLayout.PREFERRED; double s = 10; - + double size[][] = {{f, p, s, p, s, p, s, p, f}, - {p, s, p, s, p, s, p, s, p, s, p}}; - + {p, s, p, s, p, s, p, s, p, s, p}}; + TableLayout panelLayout = new TableLayout(size); - panel.setLayout (panelLayout); - + panel.setLayout(panelLayout); + // Add controls - panel.add (labelCol1, "1, 0, R, B"); - panel.add (choiceCol1, "3, 0, L, B"); - panel.add (labelRow1, "5, 0, R, B"); - panel.add (choiceRow1, "7, 0, L, B"); - panel.add (labelCol2, "1, 2, R, B"); - panel.add (choiceCol2, "3, 2, L, B"); - panel.add (labelRow2, "5, 2, R, B"); - panel.add (choiceRow2, "7, 2, L, B"); - panel.add (labelAlignH, "0, 4, 3, 4"); - panel.add (choiceAlignH, "5, 4, 7, 4"); - panel.add (labelAlignV, "0, 6, 3, 6"); - panel.add (choiceAlignV, "5, 6, 7, 6"); + panel.add(labelCol1, "1, 0, R, B"); + panel.add(choiceCol1, "3, 0, L, B"); + panel.add(labelRow1, "5, 0, R, B"); + panel.add(choiceRow1, "7, 0, L, B"); + panel.add(labelCol2, "1, 2, R, B"); + panel.add(choiceCol2, "3, 2, L, B"); + panel.add(labelRow2, "5, 2, R, B"); + panel.add(choiceRow2, "7, 2, L, B"); + panel.add(labelAlignH, "0, 4, 3, 4"); + panel.add(choiceAlignH, "5, 4, 7, 4"); + panel.add(labelAlignV, "0, 6, 3, 6"); + panel.add(choiceAlignV, "5, 6, 7, 6"); // Prompt user String button[] = {"Update Smiley", "Remove Smiley", "Cancel"}; - + GeneralDialog dialog = new GeneralDialog (RadTool.this, "Update Smiley", "", button, null, panel); - + String answer = dialog.promptUser(); - + // Update constraints applied to this Smiley - if (answer.equals("Update Smiley")) - { + if (answer.equals("Update Smiley")) { // Get columns int col1 = choiceCol1.getSelectedIndex() + 1; int col2 = choiceCol2.getSelectedIndex() + 1; int row1 = choiceRow1.getSelectedIndex() + 1; int row2 = choiceRow2.getSelectedIndex() + 1; - + // Make sure col1 < col2 - if (col1 > col2) - { + if (col1 > col2) { int temp = col1; col1 = col2; col2 = temp; } // Make sure row1 < row2 - if (row1 > row2) - { + if (row1 > row2) { int temp = row1; row1 = row2; row2 = temp; @@ -624,7 +604,7 @@ public class RadTool extends Frame implements ActionListener c.row2 = row2; c.hAlign = choiceAlignH.getSelectedIndex(); c.vAlign = choiceAlignV.getSelectedIndex(); - layout.setConstraints (this, c); + layout.setConstraints(this, c); // Repaint and layout container since layout has changed Container container = getParent(); @@ -632,16 +612,14 @@ public class RadTool extends Frame implements ActionListener container.repaint(); } // Remove Smiley - else if (answer.equals("Remove Smiley")) - { + else if (answer.equals("Remove Smiley")) { Container container = getParent(); - container.remove (this); + container.remove(this); container.doLayout(); container.repaint(); } } } - - - + + } diff --git a/lib/example/Simple.java b/lib/example/Simple.java index 3ff9fb9..b49f8df 100644 --- a/lib/example/Simple.java +++ b/lib/example/Simple.java @@ -1,62 +1,58 @@ package example; - -import java.awt.*; -import java.awt.event.*; +import java.awt.Button; +import java.awt.Frame; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; import layout.TableLayout; - -public class Simple -{ +public class Simple { - - public static void main (String args[]) - { + public static void main(String args[]) { // Create a frame Frame frame = new Frame("Example of TableLayout"); - frame.setBounds (100, 100, 300, 300); + frame.setBounds(100, 100, 300, 300); // Create a TableLayout for the frame double border = 10; double size[][] = {{border, 0.10, 20, TableLayout.FILL, 20, 0.20, border}, // Columns - {border, 0.20, 20, TableLayout.FILL, 20, 0.20, border}}; // Rows + {border, 0.20, 20, TableLayout.FILL, 20, 0.20, border}}; // Rows - frame.setLayout (new TableLayout(size)); + frame.setLayout(new TableLayout(size)); // Create some buttons - String label[] = {"Top", "Bottom", "Left", "Right", "Center", "Overlap"}; + String label[] = + {"Top", "Bottom", "Left", "Right", "Center", "Overlap"}; Button button[] = new Button[label.length]; - for (int i = 0; i < label.length; i++) + for (int i = 0; i < label.length; i++) { button[i] = new Button(label[i]); + } // Add buttons - frame.add (button[0], "1, 1, 5, 1"); // Top - frame.add (button[1], "1, 5, 5, 5"); // Bottom - frame.add (button[2], "1, 3 "); // Left - frame.add (button[3], "5, 3 "); // Right - frame.add (button[4], "3, 3, c, c"); // Center - frame.add (button[5], "3, 3, 3, 5"); // Overlap + frame.add(button[0], "1, 1, 5, 1"); // Top + frame.add(button[1], "1, 5, 5, 5"); // Bottom + frame.add(button[2], "1, 3 "); // Left + frame.add(button[3], "5, 3 "); // Right + frame.add(button[4], "3, 3, c, c"); // Center + frame.add(button[5], "3, 3, 3, 5"); // Overlap // Allow user to close the window to terminate the program frame.addWindowListener - (new WindowAdapter() - { - public void windowClosing (WindowEvent e) - { - System.exit (0); - } - } + (new WindowAdapter() { + public void windowClosing(WindowEvent e) { + System.exit(0); + } + } ); // Show frame frame.show(); } - - + } \ No newline at end of file diff --git a/lib/example/TypicalGui.java b/lib/example/TypicalGui.java index ab80ff1..e44a371 100644 --- a/lib/example/TypicalGui.java +++ b/lib/example/TypicalGui.java @@ -1,179 +1,158 @@ package example; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; +import java.awt.Color; +import java.awt.Component; +import java.awt.Container; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JMenuItem; +import javax.swing.JPanel; +import javax.swing.JTextPane; import layout.TableLayout; +public class TypicalGui extends JFrame { + + + public TypicalGui() { + super("A Typical GUI"); -public class TypicalGui extends JFrame -{ - - - - public static void main (String args[]) - { - new TypicalGui(); - } - - - - public TypicalGui () - { - super ("A Typical GUI"); - Container pane = getContentPane(); - + double b = 10; double f = TableLayout.FILL; double p = TableLayout.PREFERRED; double size[][] = {{b, f, 5, p, 5, p, b}, {p, b, f, 10, p, b}}; TableLayout layout = new TableLayout(size); - pane.setLayout (layout); - + pane.setLayout(layout); + addMenu(pane); addCommandButtons(pane, layout); addColorBoxes(pane, layout); addTextArea(pane, layout); - + allowClosing(); - setSize (640, 480); + setSize(640, 480); show(); } - - - - public void addMenu (Container pane) - { + + public static void main(String args[]) { + new TypicalGui(); + } + + public void addMenu(Container pane) { JMenuBar menuBar = new JMenuBar(); - + String menuText[] = {"File", "Edit", "View", "Help"}; String itemText[][] = {{"New", "Open", "Save", "Print", "Exit"}, - {"Cut", "Copy", "Paste"}, - {"Zoom in", "Zoom out"}, - {"About", "Index", "Search"}}; + {"Cut", "Copy", "Paste"}, + {"Zoom in", "Zoom out"}, + {"About", "Index", "Search"}}; - for (int i = 0; i < menuText.length; i++) - { + for (int i = 0; i < menuText.length; i++) { JMenu menu = new JMenu(menuText[i]); - menuBar.add (menu); - - for (int j = 0; j < itemText[i].length; j++) - { + menuBar.add(menu); + + for (int j = 0; j < itemText[i].length; j++) { JMenuItem item = new JMenuItem(itemText[i][j]); - menu.add (item); + menu.add(item); } } - - pane.add (menuBar, "0, 0, 6, 0"); + + pane.add(menuBar, "0, 0, 6, 0"); } - - public void addCommandButtons (Container pane, TableLayout layout) - { + public void addCommandButtons(Container pane, TableLayout layout) { JPanel buttonPanel = new JPanel(); - pane.add (buttonPanel, "1, 4, 5, 4"); - - for (int i = 1; i <= 5; i++) - { + pane.add(buttonPanel, "1, 4, 5, 4"); + + for (int i = 1; i <= 5; i++) { JButton button = new JButton("Button " + i); - buttonPanel.add (button); + buttonPanel.add(button); } } - - - - public void addColorBoxes (Container pane, TableLayout layout) - { + + + public void addColorBoxes(Container pane, TableLayout layout) { Color color[][] = {{Color.white, Color.black}, - {Color.green, Color.blue}, - {Color.red, Color.yellow}, - {Color.pink, Color.orange}, - {Color.magenta, Color.cyan}}; - - for (int i = 0; i < color.length; i++) - { + {Color.green, Color.blue}, + {Color.red, Color.yellow}, + {Color.pink, Color.orange}, + {Color.magenta, Color.cyan}}; + + for (int i = 0; i < color.length; i++) { // Add a row for spacing and a row for the color boxes - layout.insertRow (2, TableLayout.PREFERRED); - layout.insertRow (2, 5); - + layout.insertRow(2, TableLayout.PREFERRED); + layout.insertRow(2, 5); + // Add color boxes - pane.add (new ColorBox(color[i][0]), "3, 3"); - pane.add (new ColorBox(color[i][1]), "5, 3"); + pane.add(new ColorBox(color[i][0]), "3, 3"); + pane.add(new ColorBox(color[i][1]), "5, 3"); } - + // Remove the unnecessary leading space - layout.deleteRow (2); + layout.deleteRow(2); } - - - - public void addTextArea (Container pane, TableLayout layout) - { + + + public void addTextArea(Container pane, TableLayout layout) { int numRow = layout.getRow().length; JTextPane textArea = new JTextPane(); - pane.add (textArea, "1, 2, 1, " + (numRow - 4)); + pane.add(textArea, "1, 2, 1, " + (numRow - 4)); } - - - - public void allowClosing () - { + + + public void allowClosing() { addWindowListener - (new WindowAdapter() - { - public void windowClosing (WindowEvent e) - { - System.exit (0); - } - } + (new WindowAdapter() { + public void windowClosing(WindowEvent e) { + System.exit(0); + } + } ); } - - - + + //************************************************************************** //*** Inner classes *** //************************************************************************** - - - - protected class ColorBox extends Component - { + + + protected class ColorBox extends Component { protected Color color; - - protected ColorBox (Color color) - { + + protected ColorBox(Color color) { this.color = color; } - - public void update (Graphics g) - { - paint (g); + + public void update(Graphics g) { + paint(g); } - - public void paint (Graphics g) - { + + public void paint(Graphics g) { Dimension d = getSize(); - g.setColor (Color.black); - g.drawRect (0, 0, d.width - 1, d.height - 1); - - g.setColor (color); - g.fillRect (1, 1, d.width - 1, d.height - 1); + g.setColor(Color.black); + g.drawRect(0, 0, d.width - 1, d.height - 1); + + g.setColor(color); + g.fillRect(1, 1, d.width - 1, d.height - 1); } - - public Dimension getPreferredSize () - { - return new Dimension(40, 20);; + + public Dimension getPreferredSize() { + return new Dimension(40, 20); + ; } } - - - + + } diff --git a/src/control/images/agree_notsure.png b/src/control/images/agree_notsure.png new file mode 100644 index 0000000..32dceb0 Binary files /dev/null and b/src/control/images/agree_notsure.png differ diff --git a/src/cppcheckplus/control/MyContentPanel.java b/src/cppcheckplus/control/MyContentPanel.java index 63d792a..f676cc8 100644 --- a/src/cppcheckplus/control/MyContentPanel.java +++ b/src/cppcheckplus/control/MyContentPanel.java @@ -1,16 +1,12 @@ - package cppcheckplus.control; import java.awt.BorderLayout; - import javax.swing.JPanel; -public class MyContentPanel extends JPanel -{ - public MyContentPanel() - { - super(); - setLayout(new BorderLayout()); - setBackground(MyContorlUtil.CONTENT_PANE_BACKGROUND); - } +public class MyContentPanel extends JPanel { + public MyContentPanel() { + super(); + setLayout(new BorderLayout()); + setBackground(MyContorlUtil.CONTENT_PANE_BACKGROUND); + } } diff --git a/src/cppcheckplus/control/MyHeader.java b/src/cppcheckplus/control/MyHeader.java index 1b71704..2cd11b8 100644 --- a/src/cppcheckplus/control/MyHeader.java +++ b/src/cppcheckplus/control/MyHeader.java @@ -1,4 +1,3 @@ - package cppcheckplus.control; import java.awt.BorderLayout; @@ -13,7 +12,6 @@ import java.awt.TexturePaint; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; - import javax.swing.BorderFactory; import javax.swing.ImageIcon; import javax.swing.JComponent; @@ -22,180 +20,167 @@ import javax.swing.JPanel; import javax.swing.border.Border; - -public class MyHeader extends JPanel -{ - public static final ImageIcon RIGHT_ARROW_ICON = MyContorlUtil.getImageIcon("control/images/shrink_handler_right.png"); - public static final ImageIcon LEFT_ARROW_ICON = MyContorlUtil.getImageIcon("control/images/shrink_handler_left.png"); - private Color titleColor; - private boolean shrinked; - private ImageIcon backgroundImageIcon; - private Image backgroundLeftImage; - private Image backgroundRightImage; - private TexturePaint paint; - private int preferredHeight; - private JLabel lbResizeHandler; - private JLabel lbShrinkHandler; - private JLabel lbTitle; - private int normalPreferredWidth; - private MyListSplitListener splitListener; - private MouseListener shrinkListener; - - public MyHeader() - { - super(); - titleColor = new Color(215, 215, 216); - shrinked = false; - backgroundImageIcon = MyContorlUtil.getImageIcon("control/images/header_background.png"); - backgroundLeftImage = MyContorlUtil.getImage("control/images/header_background_left.png"); - backgroundRightImage = MyContorlUtil.getImage("control/images/header_background_right.png"); - paint = MyContorlUtil.createTexturePaint("control/images/header_background.png"); - preferredHeight = backgroundImageIcon.getIconHeight(); - lbResizeHandler = new JLabel(MyContorlUtil.getImageIcon("control/images/resize_handler.png")); - lbShrinkHandler = new JLabel(getShrinkIcon(shrinked)); - lbTitle = new JLabel(); - normalPreferredWidth = 0; - splitListener = createSplitListener(); - shrinkListener = new MouseAdapter() { - public void mouseClicked(MouseEvent e) - { - changeShrink(); - } - }; - init(); - } - - protected MyListSplitListener createSplitListener() - { - return new MyListSplitListener(this); - } - - protected Border createBorder() - { - return BorderFactory.createEmptyBorder(4, 7, 0, 0); - } - - private void init() - { - setBorder(createBorder()); - setOpaque(false); - setLayout(new BorderLayout()); - add(lbResizeHandler, getResizeHandlerLayoutConstraint()); - add(lbShrinkHandler, getShrinkHandlerLayoutConstraint()); - JComponent centerComponent = getCenterComponent(); - if (centerComponent != null) - add(centerComponent, "Center"); - lbResizeHandler.addMouseMotionListener(splitListener); - lbResizeHandler.addMouseListener(splitListener); - lbShrinkHandler.addMouseListener(shrinkListener); - lbTitle.setFont(MyContorlUtil.FONT_14_BOLD); - lbTitle.setForeground(titleColor); - lbTitle.setBorder(BorderFactory.createEmptyBorder(2, 8, 0, 0)); - updateCursor(); - lbShrinkHandler.setBorder(BorderFactory.createEmptyBorder(0, 8, 2, 5)); - } - - protected JComponent getCenterComponent() - { - return lbTitle; - } - - protected Object getResizeHandlerLayoutConstraint() - { - return "West"; - } - - protected Object getShrinkHandlerLayoutConstraint() - { - return "East"; - } - - protected void paintComponent(Graphics g) - { - Graphics2D g2d = (Graphics2D)g; - g2d.setPaint(paint); - g2d.fillRect(0, 0, getWidth(), getHeight()); - g2d.drawImage(backgroundLeftImage, 0, 0, null); - int x = getWidth() - backgroundRightImage.getWidth(null); - int y = 0; - g2d.drawImage(backgroundRightImage, x, y, null); - } - - public Dimension getPreferredSize() - { - return new Dimension(super.getPreferredSize().width, preferredHeight); - } - - public void revalidateParent() - { - if (getParent() instanceof JComponent) - ((JComponent)getParent()).revalidate(); - } - - public void changeShrink() - { - setShrink(!isShrinked()); - } - - public void setShrink(boolean shrinked) - { - if (shrinked != this.shrinked) - { - Container parent = getParent(); - Dimension size = parent.getPreferredSize(); - if (shrinked) - { - normalPreferredWidth = size.width; - size = new Dimension(getShrinkedWidth(), size.height); - } else - { - int width = normalPreferredWidth; - int height = parent.getPreferredSize().height; - size = new Dimension(width, height); - } - parent.setPreferredSize(size); - lbShrinkHandler.setIcon(getShrinkIcon(shrinked)); - revalidateParent(); - this.shrinked = shrinked; - updateCursor(); - lbTitle.setVisible(!shrinked); - lbResizeHandler.setVisible(!shrinked); - } - } - - protected ImageIcon getShrinkIcon(boolean shrinked) - { - if (shrinked) - return LEFT_ARROW_ICON; - else - return RIGHT_ARROW_ICON; - } - - private void updateCursor() - { - if (shrinked) - lbResizeHandler.setCursor(Cursor.getDefaultCursor()); - else - lbResizeHandler.setCursor(Cursor.getPredefinedCursor(10)); - } - - public boolean isShrinked() - { - return shrinked; - } - - public void setTitle(String title) - { - lbTitle.setText(title); - } - - public String getTitle() - { - return lbTitle.getText(); - } - - protected int getShrinkedWidth() - { - return 37; - } +public class MyHeader extends JPanel { + public static final ImageIcon RIGHT_ARROW_ICON = + MyContorlUtil.getImageIcon("control/images/shrink_handler_right.png"); + public static final ImageIcon LEFT_ARROW_ICON = + MyContorlUtil.getImageIcon("control/images/shrink_handler_left.png"); + private Color titleColor; + private boolean shrinked; + private ImageIcon backgroundImageIcon; + private Image backgroundLeftImage; + private Image backgroundRightImage; + private TexturePaint paint; + private int preferredHeight; + private JLabel lbResizeHandler; + private JLabel lbShrinkHandler; + private JLabel lbTitle; + private int normalPreferredWidth; + private MyListSplitListener splitListener; + private MouseListener shrinkListener; + + public MyHeader() { + super(); + titleColor = new Color(215, 215, 216); + shrinked = false; + backgroundImageIcon = + MyContorlUtil.getImageIcon("control/images/header_background.png"); + backgroundLeftImage = + MyContorlUtil.getImage("control/images/header_background_left.png"); + backgroundRightImage = MyContorlUtil.getImage( + "control/images/header_background_right.png"); + paint = MyContorlUtil.createTexturePaint( + "control/images/header_background.png"); + preferredHeight = backgroundImageIcon.getIconHeight(); + lbResizeHandler = new JLabel( + MyContorlUtil.getImageIcon("control/images/resize_handler.png")); + lbShrinkHandler = new JLabel(getShrinkIcon(shrinked)); + lbTitle = new JLabel(); + normalPreferredWidth = 0; + splitListener = createSplitListener(); + shrinkListener = new MouseAdapter() { + public void mouseClicked(MouseEvent e) { + changeShrink(); + } + }; + init(); + } + + protected MyListSplitListener createSplitListener() { + return new MyListSplitListener(this); + } + + protected Border createBorder() { + return BorderFactory.createEmptyBorder(4, 7, 0, 0); + } + + private void init() { + setBorder(createBorder()); + setOpaque(false); + setLayout(new BorderLayout()); + add(lbResizeHandler, getResizeHandlerLayoutConstraint()); + add(lbShrinkHandler, getShrinkHandlerLayoutConstraint()); + JComponent centerComponent = getCenterComponent(); + if (centerComponent != null) { + add(centerComponent, "Center"); + } + lbResizeHandler.addMouseMotionListener(splitListener); + lbResizeHandler.addMouseListener(splitListener); + lbShrinkHandler.addMouseListener(shrinkListener); + lbTitle.setFont(MyContorlUtil.FONT_14_BOLD); + lbTitle.setForeground(titleColor); + lbTitle.setBorder(BorderFactory.createEmptyBorder(2, 8, 0, 0)); + updateCursor(); + lbShrinkHandler.setBorder(BorderFactory.createEmptyBorder(0, 8, 2, 5)); + } + + protected JComponent getCenterComponent() { + return lbTitle; + } + + protected Object getResizeHandlerLayoutConstraint() { + return "West"; + } + + protected Object getShrinkHandlerLayoutConstraint() { + return "East"; + } + + protected void paintComponent(Graphics g) { + Graphics2D g2d = (Graphics2D) g; + g2d.setPaint(paint); + g2d.fillRect(0, 0, getWidth(), getHeight()); + g2d.drawImage(backgroundLeftImage, 0, 0, null); + int x = getWidth() - backgroundRightImage.getWidth(null); + int y = 0; + g2d.drawImage(backgroundRightImage, x, y, null); + } + + public Dimension getPreferredSize() { + return new Dimension(super.getPreferredSize().width, preferredHeight); + } + + public void revalidateParent() { + if (getParent() instanceof JComponent) { + ((JComponent) getParent()).revalidate(); + } + } + + public void changeShrink() { + setShrink(!isShrinked()); + } + + public void setShrink(boolean shrinked) { + if (shrinked != this.shrinked) { + Container parent = getParent(); + Dimension size = parent.getPreferredSize(); + if (shrinked) { + normalPreferredWidth = size.width; + size = new Dimension(getShrinkedWidth(), size.height); + } else { + int width = normalPreferredWidth; + int height = parent.getPreferredSize().height; + size = new Dimension(width, height); + } + parent.setPreferredSize(size); + lbShrinkHandler.setIcon(getShrinkIcon(shrinked)); + revalidateParent(); + this.shrinked = shrinked; + updateCursor(); + lbTitle.setVisible(!shrinked); + lbResizeHandler.setVisible(!shrinked); + } + } + + protected ImageIcon getShrinkIcon(boolean shrinked) { + if (shrinked) { + return LEFT_ARROW_ICON; + } else { + return RIGHT_ARROW_ICON; + } + } + + private void updateCursor() { + if (shrinked) { + lbResizeHandler.setCursor(Cursor.getDefaultCursor()); + } else { + lbResizeHandler.setCursor(Cursor.getPredefinedCursor(10)); + } + } + + public boolean isShrinked() { + return shrinked; + } + + public String getTitle() { + return lbTitle.getText(); + } + + public void setTitle(String title) { + lbTitle.setText(title); + } + + protected int getShrinkedWidth() { + return 37; + } } diff --git a/src/cppcheckplus/control/MyList.java b/src/cppcheckplus/control/MyList.java index 2a577ff..084ee74 100644 --- a/src/cppcheckplus/control/MyList.java +++ b/src/cppcheckplus/control/MyList.java @@ -1,68 +1,58 @@ - package cppcheckplus.control; +import cppcheckplus.shortcut.MyShortcutItem; +import cppcheckplus.shortcut.MyShortcutItemClickListenter; import java.awt.event.MouseEvent; - import javax.swing.JList; import javax.swing.event.MouseInputAdapter; import javax.swing.event.MouseInputListener; -import cppcheckplus.shortcut.MyShortcutItem; -import cppcheckplus.shortcut.MyShortcutItemClickListenter; +public class MyList extends JList { + private MyShortcutItemClickListenter clickListenter; + + public MyList() { + init(); + } + + public void setListenter(MyShortcutItemClickListenter itemClickListenter) { + this.clickListenter = itemClickListenter; + MouseInputListener listener = new MouseInputAdapter() { + //通过Move设置Item为selected,从而触发渲染器处理,实现高亮 + @Override + public void mouseMoved(MouseEvent e) { + int moveIndex = locationToIndex(e.getPoint()); + setSelectedIndex(moveIndex); + } + + //移动出去之后,清除选中,从而触发渲染器 + @Override + public void mouseExited(MouseEvent e) { + getSelectionModel().clearSelection(); + } -public class MyList extends JList -{ - private MyShortcutItemClickListenter clickListenter; - - public MyList() - { - init(); - } - public void setListenter(MyShortcutItemClickListenter itemClickListenter) - { - this.clickListenter = itemClickListenter; - MouseInputListener listener = new MouseInputAdapter() - { - //通过Move设置Item为selected,从而触发渲染器处理,实现高亮 - @Override - public void mouseMoved(MouseEvent e) - { - int moveIndex = locationToIndex(e.getPoint()); - setSelectedIndex(moveIndex); - } - //移动出去之后,清除选中,从而触发渲染器 - @Override - public void mouseExited(MouseEvent e) - { - getSelectionModel().clearSelection(); - } + @Override + public void mouseClicked(MouseEvent e) { + //因为该JList是单选模式,所以取第一个选择的就可以了 + Object selObj = getSelectedValue(); + if (selObj != null) { + MyShortcutItem item = (MyShortcutItem) selObj; + if (!item.isGroup()) { + clickListenter.ItemClick(item.getActionCommand()); + } + } + //itemClick.ItemClick(actionCommand) + } + }; + addMouseMotionListener(listener); + addMouseListener(listener); + } - @Override - public void mouseClicked(MouseEvent e) - { - //因为该JList是单选模式,所以取第一个选择的就可以了 - Object selObj = getSelectedValue(); - if(selObj != null) - { - MyShortcutItem item = (MyShortcutItem)selObj; - if(!item.isGroup()) - { - clickListenter.ItemClick(item.getActionCommand()); - } - } - //itemClick.ItemClick(actionCommand) - } - }; - addMouseMotionListener(listener); - addMouseListener(listener); - } - private void init() - { - setFont(MyContorlUtil.FONT_12_BOLD); - setForeground(MyContorlUtil.DEFAULT_TEXT_COLOR); - setBackground(MyContorlUtil.LIST_BACKGROUND); - setCellRenderer(new MyListRenderer(this)); - setSelectionMode(0); - } + private void init() { + setFont(MyContorlUtil.FONT_12_BOLD); + setForeground(MyContorlUtil.DEFAULT_TEXT_COLOR); + setBackground(MyContorlUtil.LIST_BACKGROUND); + setCellRenderer(new MyListRenderer(this)); + setSelectionMode(0); + } } diff --git a/src/cppcheckplus/control/MyListRenderer.java b/src/cppcheckplus/control/MyListRenderer.java index 1495378..b407227 100644 --- a/src/cppcheckplus/control/MyListRenderer.java +++ b/src/cppcheckplus/control/MyListRenderer.java @@ -1,12 +1,12 @@ - package cppcheckplus.control; +import cppcheckplus.shortcut.MyShortcutItem; +import cppcheckplus.shortcut.MyShortcutPanel; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; import java.awt.Dimension; import java.awt.Font; - import javax.swing.BorderFactory; import javax.swing.DefaultListCellRenderer; import javax.swing.JLabel; @@ -14,125 +14,111 @@ import javax.swing.JList; import javax.swing.JPanel; import javax.swing.OverlayLayout; -import cppcheckplus.shortcut.MyShortcutItem; -import cppcheckplus.shortcut.MyShortcutPanel; - //快捷菜单 -public class MyListRenderer extends DefaultListCellRenderer -{ - private JPanel itemRender; - private int separatorHeight = 30; - //每组List的分割Group - private JPanel separatorPanel; - private JLabel separatorLabel; - private MySeparator separator; - private Color itemTextColor; - private Color separatorTextColor; - private Color itemSelectedBackground; - private Color itemSelectedBorder; - private Font separatorFont; - - public MyListRenderer(MyList list) - { - super(); - itemRender = new JPanel(new BorderLayout()); - separatorPanel = new JPanel() { +public class MyListRenderer extends DefaultListCellRenderer { + private JPanel itemRender; + private int separatorHeight = 30; + //每组List的分割Group + private JPanel separatorPanel; + private JLabel separatorLabel; + private MySeparator separator; + private Color itemTextColor; + private Color separatorTextColor; + private Color itemSelectedBackground; + private Color itemSelectedBorder; + private Font separatorFont; + + public MyListRenderer(MyList list) { + super(); + itemRender = new JPanel(new BorderLayout()); + separatorPanel = new JPanel() { + + public Dimension getPreferredSize() { + Dimension size = super.getPreferredSize(); + return new Dimension(size.width, separatorHeight); + } + + }; + //分割Group的样式 + separatorLabel = new JLabel(); + separator = new MySeparator(0); + separatorTextColor = Color.white; + separatorFont = MyContorlUtil.FONT_12_BOLD; + + itemTextColor = MyContorlUtil.LIST_TEXT_COLOR; + itemSelectedBackground = new Color(199, 198, 200); + itemSelectedBorder = new Color(163, 163, 163); + itemRender.setOpaque(false); + itemRender.add(this, "Center"); + separatorPanel.setLayout(new OverlayLayout(separatorPanel)); + JPanel separatorHelpPane = new JPanel(new BorderLayout()); + separatorHelpPane.setBorder( + BorderFactory.createEmptyBorder(12, 0, 0, 0)); + separatorHelpPane.add(separator); + separatorHelpPane.setOpaque(false); + separatorPanel.setOpaque(false); + separatorLabel.setOpaque(true); + separatorLabel.setBackground(MyContorlUtil.LIST_BACKGROUND); + separatorLabel.setForeground(separatorTextColor); + separatorLabel.setFont(separatorFont); + separatorLabel.setVerticalAlignment(1); + separatorLabel.setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 2)); + JPanel labelHelpPane = new JPanel(new BorderLayout()); + labelHelpPane.setBorder(BorderFactory.createEmptyBorder(6, 15, 0, 0)); + labelHelpPane.add(separatorLabel, "West"); + labelHelpPane.setOpaque(false); + separatorPanel.add(labelHelpPane); + separatorPanel.add(separatorHelpPane); + } - public Dimension getPreferredSize() - { - Dimension size = super.getPreferredSize(); - return new Dimension(size.width, separatorHeight); - } + public Component getListCellRendererComponent(JList list, Object value, + int index, boolean isSelected, + boolean cellHasFocus) { + MyShortcutItem shortcutItem = (MyShortcutItem) value; + //Group的渲染 + if (shortcutItem.isGroup()) { + String groupName = shortcutItem.getText(); + separatorLabel.setText(groupName); + separatorPanel.setToolTipText(groupName); + if (list.getParent() instanceof MyShortcutPanel) { + MyShortcutPanel pane = (MyShortcutPanel) list.getParent(); + if (pane.isShrinked()) { + separatorLabel.setText(" "); + separatorLabel.setOpaque(false); + } else { + separatorLabel.setOpaque(true); + } + } + return separatorPanel; + } + //普通Item的渲染 + else { + setText(shortcutItem.getText()); + setBackground(MyContorlUtil.LIST_BACKGROUND); + setToolTipText(shortcutItem.getToolTip()); + setIcon(shortcutItem.getIcon()); + } - }; - //分割Group的样式 - separatorLabel = new JLabel(); - separator = new MySeparator(0); - separatorTextColor = Color.white; - separatorFont = MyContorlUtil.FONT_12_BOLD; - - itemTextColor = MyContorlUtil.LIST_TEXT_COLOR; - itemSelectedBackground = new Color(199, 198, 200); - itemSelectedBorder = new Color(163, 163, 163); - itemRender.setOpaque(false); - itemRender.add(this, "Center"); - separatorPanel.setLayout(new OverlayLayout(separatorPanel)); - JPanel separatorHelpPane = new JPanel(new BorderLayout()); - separatorHelpPane.setBorder(BorderFactory.createEmptyBorder(12, 0, 0, 0)); - separatorHelpPane.add(separator); - separatorHelpPane.setOpaque(false); - separatorPanel.setOpaque(false); - separatorLabel.setOpaque(true); - separatorLabel.setBackground(MyContorlUtil.LIST_BACKGROUND); - separatorLabel.setForeground(separatorTextColor); - separatorLabel.setFont(separatorFont); - separatorLabel.setVerticalAlignment(1); - separatorLabel.setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 2)); - JPanel labelHelpPane = new JPanel(new BorderLayout()); - labelHelpPane.setBorder(BorderFactory.createEmptyBorder(6, 15, 0, 0)); - labelHelpPane.add(separatorLabel, "West"); - labelHelpPane.setOpaque(false); - separatorPanel.add(labelHelpPane); - separatorPanel.add(separatorHelpPane); - } + //判断List的父容器是否是快捷菜单面板,如果是,需要考虑收缩展开的处理 + if (list.getParent() instanceof MyShortcutPanel) { + MyShortcutPanel pane = (MyShortcutPanel) list.getParent(); + if (pane.isShrinked()) { + setBorder(BorderFactory.createEmptyBorder(2, 7, 1, 2)); + setText(""); + } else { + setBorder(BorderFactory.createEmptyBorder(2, 20, 1, 2)); + } + } + if (isSelected) { + setBackground(itemSelectedBackground); + itemRender.setBorder( + BorderFactory.createLineBorder(itemSelectedBorder)); + } else { + itemRender.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); + } + setForeground(itemTextColor); - public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) - { - MyShortcutItem shortcutItem = (MyShortcutItem)value; - //Group的渲染 - if(shortcutItem.isGroup()) - { - String groupName = shortcutItem.getText(); - separatorLabel.setText(groupName); - separatorPanel.setToolTipText(groupName); - if (list.getParent() instanceof MyShortcutPanel) - { - MyShortcutPanel pane = (MyShortcutPanel)list.getParent(); - if (pane.isShrinked()) - { - separatorLabel.setText(" "); - separatorLabel.setOpaque(false); - } else - { - separatorLabel.setOpaque(true); - } - } - return separatorPanel; - } - //普通Item的渲染 - else - { - setText(shortcutItem.getText()); - setBackground(MyContorlUtil.LIST_BACKGROUND); - setToolTipText(shortcutItem.getToolTip()); - setIcon(shortcutItem.getIcon()); - } - - //判断List的父容器是否是快捷菜单面板,如果是,需要考虑收缩展开的处理 - if (list.getParent() instanceof MyShortcutPanel) - { - MyShortcutPanel pane = (MyShortcutPanel)list.getParent(); - if (pane.isShrinked()) - { - setBorder(BorderFactory.createEmptyBorder(2, 7, 1, 2)); - setText(""); - } else - { - setBorder(BorderFactory.createEmptyBorder(2, 20, 1, 2)); - } - } - if (isSelected) - { - setBackground(itemSelectedBackground); - itemRender.setBorder(BorderFactory.createLineBorder(itemSelectedBorder)); - } - else - { - itemRender.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); - } - setForeground(itemTextColor); - - return itemRender; - } + return itemRender; + } } diff --git a/src/cppcheckplus/control/MyListSplitListener.java b/src/cppcheckplus/control/MyListSplitListener.java index 4ee8fea..b594f98 100644 --- a/src/cppcheckplus/control/MyListSplitListener.java +++ b/src/cppcheckplus/control/MyListSplitListener.java @@ -1,50 +1,43 @@ - package cppcheckplus.control; import java.awt.Dimension; import java.awt.Point; import java.awt.event.MouseEvent; - import javax.swing.JComponent; import javax.swing.event.MouseInputAdapter; -public class MyListSplitListener extends MouseInputAdapter -{ - protected Point lastPoint; - protected MyHeader header; - - public MyListSplitListener(MyHeader header) - { - lastPoint = null; - this.header = null; - this.header = header; - } - - public void mousePressed(MouseEvent e) - { - if (!header.isShrinked()) - lastPoint = e.getPoint(); - } - - public void mouseReleased(MouseEvent e) - { - lastPoint = null; - } - - public void mouseDragged(MouseEvent e) - { - if (!header.isShrinked() && lastPoint != null) - { - JComponent parent = (JComponent)header.getParent(); - Dimension size = parent.getPreferredSize(); - Point thisPoint = e.getPoint(); - int xMovement = thisPoint.x - lastPoint.x; - size.width -= xMovement; - size.width = Math.max(size.width, 37); - parent.setPreferredSize(size); - header.revalidateParent(); - } - } +public class MyListSplitListener extends MouseInputAdapter { + protected Point lastPoint; + protected MyHeader header; + + public MyListSplitListener(MyHeader header) { + lastPoint = null; + this.header = null; + this.header = header; + } + + public void mousePressed(MouseEvent e) { + if (!header.isShrinked()) { + lastPoint = e.getPoint(); + } + } + + public void mouseReleased(MouseEvent e) { + lastPoint = null; + } + + public void mouseDragged(MouseEvent e) { + if (!header.isShrinked() && lastPoint != null) { + JComponent parent = (JComponent) header.getParent(); + Dimension size = parent.getPreferredSize(); + Point thisPoint = e.getPoint(); + int xMovement = thisPoint.x - lastPoint.x; + size.width -= xMovement; + size.width = Math.max(size.width, 37); + parent.setPreferredSize(size); + header.revalidateParent(); + } + } } diff --git a/src/cppcheckplus/control/MySeparator.java b/src/cppcheckplus/control/MySeparator.java index f5ba4ad..a7769d7 100644 --- a/src/cppcheckplus/control/MySeparator.java +++ b/src/cppcheckplus/control/MySeparator.java @@ -1,40 +1,38 @@ - package cppcheckplus.control; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Image; import java.awt.TexturePaint; - import javax.swing.JSeparator; -public class MySeparator extends JSeparator -{ - private Image image; - private TexturePaint paint; - - public MySeparator() - { - image = MyContorlUtil.getImage("control/images/separator_background.png"); - paint = MyContorlUtil.createTexturePaint("control/images/separator_background.png"); - } - - public MySeparator(int direction) - { - super(direction); - image = MyContorlUtil.getImage("control/images/separator_background.png"); - paint = MyContorlUtil.createTexturePaint("control/images/separator_background.png"); - } - - public void paintComponent(Graphics g) - { - Graphics2D g2d = (Graphics2D)g; - g2d.setPaint(paint); - int x = 0; - int y = 0; - int width = getWidth(); - int height = image.getHeight(null); - g2d.fillRect(x, y, width, height); - } +public class MySeparator extends JSeparator { + private Image image; + private TexturePaint paint; + + public MySeparator() { + image = + MyContorlUtil.getImage("control/images/separator_background.png"); + paint = MyContorlUtil.createTexturePaint( + "control/images/separator_background.png"); + } + + public MySeparator(int direction) { + super(direction); + image = + MyContorlUtil.getImage("control/images/separator_background.png"); + paint = MyContorlUtil.createTexturePaint( + "control/images/separator_background.png"); + } + + public void paintComponent(Graphics g) { + Graphics2D g2d = (Graphics2D) g; + g2d.setPaint(paint); + int x = 0; + int y = 0; + int width = getWidth(); + int height = image.getHeight(null); + g2d.fillRect(x, y, width, height); + } } diff --git a/src/cppcheckplus/control/MyTextField.java b/src/cppcheckplus/control/MyTextField.java index d0ed080..1edae1e 100644 --- a/src/cppcheckplus/control/MyTextField.java +++ b/src/cppcheckplus/control/MyTextField.java @@ -1,4 +1,3 @@ - package cppcheckplus.control; import java.awt.Dimension; @@ -6,7 +5,6 @@ import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Image; import java.awt.TexturePaint; - import javax.swing.BorderFactory; import javax.swing.ImageIcon; import javax.swing.JTextField; @@ -14,49 +12,50 @@ import javax.swing.border.Border; import javax.swing.plaf.metal.MetalTextFieldUI; -public class MyTextField extends JTextField -{ - private Image backgroundLeftImage; - private Image backgroundRightImage; - private ImageIcon backgroundImageIcon; - private TexturePaint paint; - private Border border; - - public MyTextField() - { - backgroundLeftImage = MyContorlUtil.getImage("control/images/textfield_background_left.png"); - backgroundRightImage = MyContorlUtil.getImage("control/images/textfield_background_right.png"); - backgroundImageIcon = MyContorlUtil.getImageIcon("control/images/textfield_background.png"); - paint = MyContorlUtil.createTexturePaint("control/images/textfield_background.png"); - border = BorderFactory.createEmptyBorder(1, 3, 1, 3); - init(); - } - public MyTextField(String text) - { - this(); - setText(text); - } - - private void init() - { - setBorder(border); - setUI(new MetalTextFieldUI() { - - protected void paintBackground(Graphics g) - { - Graphics2D g2d = (Graphics2D)g; - g2d.setPaint(paint); - g2d.fillRect(0, 0, getWidth(), getHeight()); - g2d.drawImage(backgroundLeftImage, 0, 0, null); - g2d.drawImage(backgroundRightImage, getWidth() - backgroundRightImage.getWidth(null), 0, null); - } - - }); - } - - public Dimension getPreferredSize() - { - return new Dimension(super.getPreferredSize().width, backgroundImageIcon.getIconHeight()); - } - +public class MyTextField extends JTextField { + private Image backgroundLeftImage; + private Image backgroundRightImage; + private ImageIcon backgroundImageIcon; + private TexturePaint paint; + private Border border; + + public MyTextField() { + backgroundLeftImage = MyContorlUtil.getImage( + "control/images/textfield_background_left.png"); + backgroundRightImage = MyContorlUtil.getImage( + "control/images/textfield_background_right.png"); + backgroundImageIcon = MyContorlUtil.getImageIcon( + "control/images/textfield_background.png"); + paint = MyContorlUtil.createTexturePaint( + "control/images/textfield_background.png"); + border = BorderFactory.createEmptyBorder(1, 3, 1, 3); + init(); + } + + public MyTextField(String text) { + this(); + setText(text); + } + + private void init() { + setBorder(border); + setUI(new MetalTextFieldUI() { + + protected void paintBackground(Graphics g) { + Graphics2D g2d = (Graphics2D) g; + g2d.setPaint(paint); + g2d.fillRect(0, 0, getWidth(), getHeight()); + g2d.drawImage(backgroundLeftImage, 0, 0, null); + g2d.drawImage(backgroundRightImage, + getWidth() - backgroundRightImage.getWidth(null), 0, null); + } + + }); + } + + public Dimension getPreferredSize() { + return new Dimension(super.getPreferredSize().width, + backgroundImageIcon.getIconHeight()); + } + } diff --git a/src/cppcheckplus/control/MyToolbarButton.java b/src/cppcheckplus/control/MyToolbarButton.java index e709296..dff78cd 100644 --- a/src/cppcheckplus/control/MyToolbarButton.java +++ b/src/cppcheckplus/control/MyToolbarButton.java @@ -1,4 +1,3 @@ - package cppcheckplus.control; import java.awt.Color; @@ -8,89 +7,77 @@ import java.awt.Graphics; import java.awt.Insets; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; - import javax.swing.BorderFactory; import javax.swing.Icon; import javax.swing.JButton; import javax.swing.border.Border; -public class MyToolbarButton extends JButton -{ - private int buttonSize; - private Color roverBorderColor; - private Border roverBorder; - private Border emptyBorder; +public class MyToolbarButton extends JButton { + private int buttonSize; + private Color roverBorderColor; + private Border roverBorder; + private Border emptyBorder; - public MyToolbarButton() - { - super(); - buttonSize = 20; - roverBorderColor = MyContorlUtil.BUTTON_ROVER_COLOR; - roverBorder = new Border() { + public MyToolbarButton() { + super(); + buttonSize = 20; + roverBorderColor = MyContorlUtil.BUTTON_ROVER_COLOR; + roverBorder = new Border() { - public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) - { - g.setColor(roverBorderColor); - g.drawRect(x, y, width - 1, height - 1); - } + public void paintBorder(Component c, Graphics g, int x, int y, + int width, int height) { + g.setColor(roverBorderColor); + g.drawRect(x, y, width - 1, height - 1); + } - public Insets getBorderInsets(Component c) - { - return new Insets(1, 1, 1, 1); - } + public Insets getBorderInsets(Component c) { + return new Insets(1, 1, 1, 1); + } - public boolean isBorderOpaque() - { - return true; - } - }; - emptyBorder = BorderFactory.createEmptyBorder(1, 1, 1, 1); - init(); - } + public boolean isBorderOpaque() { + return true; + } + }; + emptyBorder = BorderFactory.createEmptyBorder(1, 1, 1, 1); + init(); + } - private void init() - { - setVerticalAlignment(0); - setFont(MyContorlUtil.FONT_12_BOLD); - setOpaque(false); - setBorder(emptyBorder); - setContentAreaFilled(false); - setFocusPainted(false); - addMouseListener(new MouseAdapter() { - public void mouseEntered(MouseEvent e) - { - setBorder(roverBorder); - } + private void init() { + setVerticalAlignment(0); + setFont(MyContorlUtil.FONT_12_BOLD); + setOpaque(false); + setBorder(emptyBorder); + setContentAreaFilled(false); + setFocusPainted(false); + addMouseListener(new MouseAdapter() { + public void mouseEntered(MouseEvent e) { + setBorder(roverBorder); + } - public void mouseExited(MouseEvent e) - { - setBorder(emptyBorder); - } - }); - } + public void mouseExited(MouseEvent e) { + setBorder(emptyBorder); + } + }); + } - @Override - public void setIcon(Icon icon) - { - super.setIcon(icon); - if (icon == null) - { - setPressedIcon(null); - setRolloverIcon(null); - } else - { - Icon pressedIcon = MyContorlUtil.createMovedIcon(icon); - setPressedIcon(pressedIcon); - } - } + @Override + public void setIcon(Icon icon) { + super.setIcon(icon); + if (icon == null) { + setPressedIcon(null); + setRolloverIcon(null); + } else { + Icon pressedIcon = MyContorlUtil.createMovedIcon(icon); + setPressedIcon(pressedIcon); + } + } - @Override - public Dimension getPreferredSize() - { - int width = super.getPreferredSize().width; - width = Math.max(width, buttonSize); - int height = buttonSize; - return new Dimension(width, height); - } + @Override + public Dimension getPreferredSize() { + int width = super.getPreferredSize().width; + width = Math.max(width, buttonSize); + int height = buttonSize; + return new Dimension(width, height); + } } diff --git a/src/cppcheckplus/control/UIFrame.java b/src/cppcheckplus/control/UIFrame.java index a2a04ab..bb15707 100644 --- a/src/cppcheckplus/control/UIFrame.java +++ b/src/cppcheckplus/control/UIFrame.java @@ -21,16 +21,9 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -import java.io.BufferedReader; import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; import javax.swing.BorderFactory; import javax.swing.JComponent; import javax.swing.JFileChooser; @@ -193,7 +186,8 @@ public class UIFrame extends JFrame { if (src != null && src.length() != 0) { new Thread() { public void run() { - ToolsRegistry.executeTool("flawfinder", src); + ToolsRegistry.executeTool("flawfinder", + src); viewResult("flawfinder"); } }.start(); diff --git a/src/cppcheckplus/control/XChartletFullScreenListenter.java b/src/cppcheckplus/control/XChartletFullScreenListenter.java index c7eca34..8890357 100644 --- a/src/cppcheckplus/control/XChartletFullScreenListenter.java +++ b/src/cppcheckplus/control/XChartletFullScreenListenter.java @@ -1,10 +1,8 @@ - package cppcheckplus.control; import javax.swing.JPanel; -public interface XChartletFullScreenListenter -{ - public void fullScreen(JPanel chartPanellet); +public interface XChartletFullScreenListenter { + public void fullScreen(JPanel chartPanellet); } diff --git a/src/cppcheckplus/menu/MyMenu.java b/src/cppcheckplus/menu/MyMenu.java index 3570408..73cf5ab 100644 --- a/src/cppcheckplus/menu/MyMenu.java +++ b/src/cppcheckplus/menu/MyMenu.java @@ -1,6 +1,6 @@ - package cppcheckplus.menu; +import cppcheckplus.control.MyContorlUtil; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; @@ -9,63 +9,57 @@ import javax.swing.BorderFactory; import javax.swing.JMenu; import javax.swing.border.Border; -import cppcheckplus.control.MyContorlUtil; +public class MyMenu extends JMenu { + private Color backgroundColor; + private Color foregroundColor; + private int borderThickness; + private Border border; + private int preferredHeight; + + public MyMenu() { + backgroundColor = MyContorlUtil.MENUITEM_BACKGROUND; + foregroundColor = MyContorlUtil.DEFAULT_TEXT_COLOR; + borderThickness = 1; + border = + BorderFactory.createLineBorder(backgroundColor, borderThickness); + preferredHeight = 25; + init(); + } -public class MyMenu extends JMenu -{ - private Color backgroundColor; - private Color foregroundColor; - private int borderThickness; - private Border border; - private int preferredHeight; + public MyMenu(String text) { + super(text); + backgroundColor = MyContorlUtil.MENUITEM_BACKGROUND; + foregroundColor = MyContorlUtil.DEFAULT_TEXT_COLOR; + borderThickness = 1; + border = + BorderFactory.createLineBorder(backgroundColor, borderThickness); + preferredHeight = 25; + init(); + } - public MyMenu() - { - backgroundColor = MyContorlUtil.MENUITEM_BACKGROUND; - foregroundColor = MyContorlUtil.DEFAULT_TEXT_COLOR; - borderThickness = 1; - border = BorderFactory.createLineBorder(backgroundColor, borderThickness); - preferredHeight = 25; - init(); - } + private void init() { + setForeground(foregroundColor); + setFont(MyContorlUtil.FONT_14_BOLD); + setOpaque(true); + setBackground(backgroundColor); + setBorder(border); + } - public MyMenu(String text) - { - super(text); - backgroundColor = MyContorlUtil.MENUITEM_BACKGROUND; - foregroundColor = MyContorlUtil.DEFAULT_TEXT_COLOR; - borderThickness = 1; - border = BorderFactory.createLineBorder(backgroundColor, borderThickness); - preferredHeight = 25; - init(); - } + @Override + protected void paintComponent(Graphics g) { + if (isSelected()) { + Graphics2D g2d = (Graphics2D) g; + g2d.setColor(MyContorlUtil.MENUITEM_SELECTED_BACKGROUND); + g2d.fillRect(0, 0, getWidth(), getHeight()); + super.paintComponent(g); + } else { + super.paintComponent(g); + } + } - private void init() - { - setForeground(foregroundColor); - setFont(MyContorlUtil.FONT_14_BOLD); - setOpaque(true); - setBackground(backgroundColor); - setBorder(border); - } - @Override - protected void paintComponent(Graphics g) - { - if (isSelected()) - { - Graphics2D g2d = (Graphics2D)g; - g2d.setColor(MyContorlUtil.MENUITEM_SELECTED_BACKGROUND); - g2d.fillRect(0, 0, getWidth(), getHeight()); - super.paintComponent(g); - } else - { - super.paintComponent(g); - } - } - @Override - public Dimension getPreferredSize() - { - return new Dimension(super.getPreferredSize().width, preferredHeight); - } + @Override + public Dimension getPreferredSize() { + return new Dimension(super.getPreferredSize().width, preferredHeight); + } } diff --git a/src/cppcheckplus/menu/MyMenuBar.java b/src/cppcheckplus/menu/MyMenuBar.java index 7d5d102..d1fd952 100644 --- a/src/cppcheckplus/menu/MyMenuBar.java +++ b/src/cppcheckplus/menu/MyMenuBar.java @@ -1,6 +1,6 @@ - package cppcheckplus.menu; +import cppcheckplus.control.MyContorlUtil; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; @@ -11,46 +11,48 @@ import javax.swing.ImageIcon; import javax.swing.JMenuBar; import javax.swing.border.Border; -import cppcheckplus.control.MyContorlUtil; +public class MyMenuBar extends JMenuBar { + + private Image backgroundLeftImage; + private Image backgroundRightImage; + private ImageIcon backgroundImageIcon; + private TexturePaint paint; + private Border border; + + public MyMenuBar() { + backgroundLeftImage = MyContorlUtil.getImage( + "control/images/menubar_background_left.png"); + backgroundRightImage = MyContorlUtil.getImage( + "control/images/menubar_background_right.png"); + backgroundImageIcon = + MyContorlUtil.getImageIcon("control/images/menubar_background.png"); + paint = MyContorlUtil.createTexturePaint( + "control/images/menubar_background.png"); + border = BorderFactory.createEmptyBorder(); + init(); + } + + private void init() { + setBorder(border); + } + + @Override + protected void paintComponent(Graphics g) { + super.paintComponent(g); + Graphics2D g2d = (Graphics2D) g; + g2d.setPaint(paint); + g2d.fillRect(0, 0, getWidth(), getHeight()); + g2d.drawImage(backgroundLeftImage, 0, 0, null); + g2d.drawImage(backgroundRightImage, + getWidth() - backgroundRightImage.getWidth(null), 0, null); + } + + @Override + public Dimension getPreferredSize() { + return new Dimension(super.getPreferredSize().width, + backgroundImageIcon.getIconHeight()); + } -public class MyMenuBar extends JMenuBar -{ - - private Image backgroundLeftImage; - private Image backgroundRightImage; - private ImageIcon backgroundImageIcon; - private TexturePaint paint; - private Border border; - - public MyMenuBar() - { - backgroundLeftImage = MyContorlUtil.getImage("control/images/menubar_background_left.png"); - backgroundRightImage = MyContorlUtil.getImage("control/images/menubar_background_right.png"); - backgroundImageIcon = MyContorlUtil.getImageIcon("control/images/menubar_background.png"); - paint = MyContorlUtil.createTexturePaint("control/images/menubar_background.png"); - border = BorderFactory.createEmptyBorder(); - init(); - } - private void init() - { - setBorder(border); - } - @Override - protected void paintComponent(Graphics g) - { - super.paintComponent(g); - Graphics2D g2d = (Graphics2D)g; - g2d.setPaint(paint); - g2d.fillRect(0, 0, getWidth(), getHeight()); - g2d.drawImage(backgroundLeftImage, 0, 0, null); - g2d.drawImage(backgroundRightImage, getWidth() - backgroundRightImage.getWidth(null), 0, null); - } - @Override - public Dimension getPreferredSize() - { - return new Dimension(super.getPreferredSize().width, backgroundImageIcon.getIconHeight()); - } - } diff --git a/src/cppcheckplus/menu/MyMenuItem.java b/src/cppcheckplus/menu/MyMenuItem.java index 6ac46e9..5b71233 100644 --- a/src/cppcheckplus/menu/MyMenuItem.java +++ b/src/cppcheckplus/menu/MyMenuItem.java @@ -1,52 +1,50 @@ - package cppcheckplus.menu; +import cppcheckplus.control.MyContorlUtil; import java.awt.Color; import java.awt.Dimension; import javax.swing.BorderFactory; import javax.swing.JMenuItem; import javax.swing.border.Border; -import cppcheckplus.control.MyContorlUtil; +public class MyMenuItem extends JMenuItem { + private static final long serialVersionUID = 1L; + private Color backgroundColor; + private Color foregroundColor; + private int borderThickness; + private Border border; + private int preferredHeight; + + public MyMenuItem() { + backgroundColor = MyContorlUtil.MENUITEM_BACKGROUND; + foregroundColor = MyContorlUtil.DEFAULT_TEXT_COLOR; + borderThickness = 1; + border = + BorderFactory.createLineBorder(backgroundColor, borderThickness); + preferredHeight = 23; + init(); + } + + public MyMenuItem(String text) { + super(text); + backgroundColor = MyContorlUtil.MENUITEM_BACKGROUND; + foregroundColor = MyContorlUtil.DEFAULT_TEXT_COLOR; + borderThickness = 1; + border = + BorderFactory.createLineBorder(backgroundColor, borderThickness); + preferredHeight = 23; + init(); + } + + private void init() { + setForeground(foregroundColor); + setFont(MyContorlUtil.FONT_14_BOLD); + setBackground(backgroundColor); + setBorder(border); + } -public class MyMenuItem extends JMenuItem -{ - private static final long serialVersionUID = 1L; - private Color backgroundColor; - private Color foregroundColor; - private int borderThickness; - private Border border; - private int preferredHeight; - - public MyMenuItem() - { - backgroundColor = MyContorlUtil.MENUITEM_BACKGROUND; - foregroundColor = MyContorlUtil.DEFAULT_TEXT_COLOR; - borderThickness = 1; - border = BorderFactory.createLineBorder(backgroundColor, borderThickness); - preferredHeight = 23; - init(); - } - public MyMenuItem(String text) - { - super(text); - backgroundColor = MyContorlUtil.MENUITEM_BACKGROUND; - foregroundColor = MyContorlUtil.DEFAULT_TEXT_COLOR; - borderThickness = 1; - border = BorderFactory.createLineBorder(backgroundColor, borderThickness); - preferredHeight = 23; - init(); - } - private void init() - { - setForeground(foregroundColor); - setFont(MyContorlUtil.FONT_14_BOLD); - setBackground(backgroundColor); - setBorder(border); - } - @Override - public Dimension getPreferredSize() - { - return new Dimension(super.getPreferredSize().width, preferredHeight); - } + @Override + public Dimension getPreferredSize() { + return new Dimension(super.getPreferredSize().width, preferredHeight); + } } diff --git a/src/cppcheckplus/menu/MyRootMenu.java b/src/cppcheckplus/menu/MyRootMenu.java index b5d442d..55a06d6 100644 --- a/src/cppcheckplus/menu/MyRootMenu.java +++ b/src/cppcheckplus/menu/MyRootMenu.java @@ -1,62 +1,53 @@ - - package cppcheckplus.menu; +import cppcheckplus.control.MyContorlUtil; import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.TexturePaint; - import javax.swing.BorderFactory; import javax.swing.JMenu; import javax.swing.border.Border; -import cppcheckplus.control.MyContorlUtil; - -public class MyRootMenu extends JMenu -{ - private Color foregroundColor; - private String selectedBackgroundImageURL; - private TexturePaint paint; - private Border border; - - public MyRootMenu() - { - foregroundColor = MyContorlUtil.DEFAULT_TEXT_COLOR; - paint = MyContorlUtil.createTexturePaint("control/images/menubar_background_selected.png"); - border = BorderFactory.createEmptyBorder(0, 5, 0, 4); - init(); - - } - - public MyRootMenu(String text) - { - super(text); - foregroundColor = MyContorlUtil.DEFAULT_TEXT_COLOR; - paint = MyContorlUtil.createTexturePaint("control/images/menubar_background_selected.png"); - border = BorderFactory.createEmptyBorder(0, 5, 0, 4); - init(); - } - - private void init() - { - setFont(MyContorlUtil.FONT_14_BOLD); - setBorder(border); - setForeground(foregroundColor); - } - - protected void paintComponent(Graphics g) - { - if (isSelected()) - { - Graphics2D g2d = (Graphics2D)g; - g2d.setPaint(paint); - g2d.fillRect(0, 0, getWidth(), getHeight()); - super.paintComponent(g); - } else - { - super.paintComponent(g); - } - } +public class MyRootMenu extends JMenu { + private Color foregroundColor; + private String selectedBackgroundImageURL; + private TexturePaint paint; + private Border border; + + public MyRootMenu() { + foregroundColor = MyContorlUtil.DEFAULT_TEXT_COLOR; + paint = MyContorlUtil.createTexturePaint( + "control/images/menubar_background_selected.png"); + border = BorderFactory.createEmptyBorder(0, 5, 0, 4); + init(); + + } + + public MyRootMenu(String text) { + super(text); + foregroundColor = MyContorlUtil.DEFAULT_TEXT_COLOR; + paint = MyContorlUtil.createTexturePaint( + "control/images/menubar_background_selected.png"); + border = BorderFactory.createEmptyBorder(0, 5, 0, 4); + init(); + } + + private void init() { + setFont(MyContorlUtil.FONT_14_BOLD); + setBorder(border); + setForeground(foregroundColor); + } + + protected void paintComponent(Graphics g) { + if (isSelected()) { + Graphics2D g2d = (Graphics2D) g; + g2d.setPaint(paint); + g2d.fillRect(0, 0, getWidth(), getHeight()); + super.paintComponent(g); + } else { + super.paintComponent(g); + } + } } diff --git a/src/cppcheckplus/outlookpanel/MyOutlookBar.java b/src/cppcheckplus/outlookpanel/MyOutlookBar.java index d74345d..ce61489 100644 --- a/src/cppcheckplus/outlookpanel/MyOutlookBar.java +++ b/src/cppcheckplus/outlookpanel/MyOutlookBar.java @@ -1,14 +1,12 @@ - package cppcheckplus.outlookpanel; +import cppcheckplus.control.MyContorlUtil; import java.awt.BorderLayout; import java.awt.Color; -import java.awt.Component; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Image; -import java.awt.Insets; import java.awt.TexturePaint; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; @@ -19,205 +17,202 @@ import javax.swing.ImageIcon; import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JPanel; -import javax.swing.JScrollPane; import javax.swing.border.Border; -import cppcheckplus.control.MyContorlUtil; +public class MyOutlookBar extends JPanel { + private Image backgroundSelectedLeft; + private Image backgroundSelectedRight; + private Image backgroundImage; + private ImageIcon handlerIcon; + private ImageIcon handlerSelectedIcon; + private TexturePaint paint; + private TexturePaint selectedPaint; + private JLabel lbHandler; + private Border handlerBorder; + private Border handlerShrinkedBorder; + private JLabel lbIcon; + private JLabel lbTitle; + private boolean selected; + private Color titleColor; + private Color selectedTitleColor; + private MouseListener mouseListener; + + private Icon icon = null; + private Icon selectedIcon = null; + private MyOutlookPanel outlookPanel; + private MyOutlookListPanel outlookListPanel; + + public MyOutlookBar(MyOutlookPanel panel) { + super(); + backgroundSelectedLeft = MyContorlUtil.getImage( + "control/images/outlook_bar_background_selected_left.png"); + backgroundSelectedRight = MyContorlUtil.getImage( + "control/images/outlook_bar_background_selected_right.png"); + backgroundImage = + MyContorlUtil.getImage("control/images/outlook_bar_background.png"); + handlerIcon = MyContorlUtil.getImageIcon( + "control/images/outlook_bar_handler.png"); + handlerSelectedIcon = MyContorlUtil.getImageIcon( + "control/images/outlook_bar_handler_selected.png"); + paint = MyContorlUtil.createTexturePaint( + "control/images/outlook_bar_background.png"); + selectedPaint = MyContorlUtil.createTexturePaint( + "control/images/outlook_bar_background_selected.png"); + lbHandler = new JLabel(); + handlerBorder = BorderFactory.createEmptyBorder(0, 0, 0, 16); + handlerShrinkedBorder = BorderFactory.createEmptyBorder(0, 0, 0, 22); + lbIcon = new JLabel(); + lbTitle = new JLabel(); + selected = false; + titleColor = MyContorlUtil.OUTLOOK_TEXT_COLOR; + selectedTitleColor = Color.white; + mouseListener = new MouseAdapter() { + public void mouseReleased(MouseEvent e) { + if (((JComponent) e.getSource()).contains(e.getPoint())) { + changeStatus(); + } + } + }; + this.outlookPanel = panel; + + init(); + } + + public void setOutlookListPanel(MyOutlookListPanel listPanel) { + this.outlookListPanel = listPanel; + } + + private void init() { + setLayout(new BorderLayout()); + lbHandler.setVerticalAlignment(0); + lbHandler.setIcon(handlerIcon); + lbHandler.setBorder(handlerBorder); + add(lbHandler, "East"); + lbIcon.setVerticalAlignment(0); + lbIcon.setBorder(BorderFactory.createEmptyBorder(0, 16, 0, 0)); + add(lbIcon, "West"); + lbTitle.setVerticalAlignment(0); + lbTitle.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 0)); + lbTitle.setFont(MyContorlUtil.FONT_14_BOLD); + lbTitle.setForeground(titleColor); + add(lbTitle, "Center"); + lbHandler.addMouseListener(mouseListener); + lbTitle.addMouseListener(mouseListener); + lbIcon.addMouseListener(mouseListener); + } + + protected void paintComponent(Graphics g) { + super.paintComponent(g); + Graphics2D g2d = (Graphics2D) g; + if (isSelected()) { + g2d.setPaint(selectedPaint); + if (getSelectedIcon() != null) { + lbIcon.setIcon(getSelectedIcon()); + } else { + lbIcon.setIcon(getIcon()); + } + } else { + g2d.setPaint(paint); + lbIcon.setIcon(getIcon()); + } + g2d.fillRect(0, 0, getWidth(), getHeight()); + if (isSelected()) { + g2d.drawImage(backgroundSelectedLeft, 0, 0, null); + g2d.drawImage(backgroundSelectedRight, getWidth() + - backgroundSelectedRight.getWidth(null), 0, null); + } + } + + public Dimension getPreferredSize() { + return new Dimension(super.getPreferredSize().width, backgroundImage + .getHeight(null)); + } + + public void changeStatus() { + setSelected(!isSelected()); + } + + public boolean isSelected() { + return selected; + } + + public void setSelected(boolean selected) { + if (selected != this.selected) { + if (!isSelected()) { + outlookPanel.closeAllBars(); + } + this.selected = selected; + if (selected) { + lbHandler.setIcon(handlerSelectedIcon); + lbTitle.setForeground(selectedTitleColor); + } else { + lbHandler.setIcon(handlerIcon); + lbTitle.setForeground(titleColor); + } + + outlookPanel.updateLayoutConstraint(getContentComponent(), + selected); + outlookPanel.setAdditionalPaneVisible(!selected); + outlookPanel.revalidate(); + } + } + + public Icon getIcon() { + return icon; + } + + public void setIcon(Icon icon) { + this.icon = icon; + updateIcon(); + } + + public Icon getSelectedIcon() { + return selectedIcon; + } + + public void setSelectedIcon(Icon selectedIcon) { + this.selectedIcon = selectedIcon; + updateIcon(); + } + + private void updateIcon() { + if (selected) { + lbIcon.setIcon(selectedIcon); + } else { + lbIcon.setIcon(icon); + } + } + + public String getTitle() { + return lbTitle.getText(); + } + + public void setTitle(String title) { + lbTitle.setText(title); + lbTitle.setToolTipText(title); + lbHandler.setToolTipText(title); + lbIcon.setToolTipText(title); + } + + public MyOutlookListPanel getContentComponent() { + return outlookListPanel; + } + + public MyOutlookList getList() { + return this.outlookListPanel.getOutlookList(); + } + + public MyOutlookPanel getOutlookPanel() { + return this.outlookPanel; + } -public class MyOutlookBar extends JPanel -{ - private Image backgroundSelectedLeft; - private Image backgroundSelectedRight; - private Image backgroundImage; - private ImageIcon handlerIcon; - private ImageIcon handlerSelectedIcon; - private TexturePaint paint; - private TexturePaint selectedPaint; - private JLabel lbHandler; - private Border handlerBorder; - private Border handlerShrinkedBorder; - private JLabel lbIcon; - private JLabel lbTitle; - private boolean selected; - private Color titleColor; - private Color selectedTitleColor; - private MouseListener mouseListener; - - private Icon icon = null; - private Icon selectedIcon = null; - private MyOutlookPanel outlookPanel; - private MyOutlookListPanel outlookListPanel; - - public MyOutlookBar(MyOutlookPanel panel) - { - super(); - backgroundSelectedLeft = MyContorlUtil.getImage("control/images/outlook_bar_background_selected_left.png"); - backgroundSelectedRight = MyContorlUtil.getImage("control/images/outlook_bar_background_selected_right.png"); - backgroundImage = MyContorlUtil.getImage("control/images/outlook_bar_background.png"); - handlerIcon = MyContorlUtil.getImageIcon("control/images/outlook_bar_handler.png"); - handlerSelectedIcon = MyContorlUtil.getImageIcon("control/images/outlook_bar_handler_selected.png"); - paint = MyContorlUtil.createTexturePaint("control/images/outlook_bar_background.png"); - selectedPaint = MyContorlUtil.createTexturePaint("control/images/outlook_bar_background_selected.png"); - lbHandler = new JLabel(); - handlerBorder = BorderFactory.createEmptyBorder(0, 0, 0, 16); - handlerShrinkedBorder = BorderFactory.createEmptyBorder(0, 0, 0, 22); - lbIcon = new JLabel(); - lbTitle = new JLabel(); - selected = false; - titleColor = MyContorlUtil.OUTLOOK_TEXT_COLOR; - selectedTitleColor = Color.white; - mouseListener = new MouseAdapter() - { - public void mouseReleased(MouseEvent e) - { - if (((JComponent) e.getSource()).contains(e.getPoint())) - changeStatus(); - } - }; - this.outlookPanel = panel; - - init(); - } - public void setOutlookListPanel(MyOutlookListPanel listPanel) - { - this.outlookListPanel=listPanel; - } - private void init() - { - setLayout(new BorderLayout()); - lbHandler.setVerticalAlignment(0); - lbHandler.setIcon(handlerIcon); - lbHandler.setBorder(handlerBorder); - add(lbHandler, "East"); - lbIcon.setVerticalAlignment(0); - lbIcon.setBorder(BorderFactory.createEmptyBorder(0, 16, 0, 0)); - add(lbIcon, "West"); - lbTitle.setVerticalAlignment(0); - lbTitle.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 0)); - lbTitle.setFont(MyContorlUtil.FONT_14_BOLD); - lbTitle.setForeground(titleColor); - add(lbTitle, "Center"); - lbHandler.addMouseListener(mouseListener); - lbTitle.addMouseListener(mouseListener); - lbIcon.addMouseListener(mouseListener); - } - protected void paintComponent(Graphics g) - { - super.paintComponent(g); - Graphics2D g2d = (Graphics2D) g; - if (isSelected()) - { - g2d.setPaint(selectedPaint); - if (getSelectedIcon() != null) - lbIcon.setIcon(getSelectedIcon()); - else - lbIcon.setIcon(getIcon()); - } - else - { - g2d.setPaint(paint); - lbIcon.setIcon(getIcon()); - } - g2d.fillRect(0, 0, getWidth(), getHeight()); - if (isSelected()) - { - g2d.drawImage(backgroundSelectedLeft, 0, 0, null); - g2d.drawImage(backgroundSelectedRight, getWidth() - - backgroundSelectedRight.getWidth(null), 0, null); - } - } - public Dimension getPreferredSize() - { - return new Dimension(super.getPreferredSize().width, backgroundImage - .getHeight(null)); - } - public void setSelected(boolean selected) - { - if (selected != this.selected) - { - if (!isSelected()) - outlookPanel.closeAllBars(); - this.selected = selected; - if (selected) - { - lbHandler.setIcon(handlerSelectedIcon); - lbTitle.setForeground(selectedTitleColor); - } - else - { - lbHandler.setIcon(handlerIcon); - lbTitle.setForeground(titleColor); - } - - outlookPanel.updateLayoutConstraint(getContentComponent(), selected); - outlookPanel.setAdditionalPaneVisible(!selected); - outlookPanel.revalidate(); - } - } - public void changeStatus() - { - setSelected(!isSelected()); - } - public boolean isSelected() - { - return selected; - } - public Icon getIcon() - { - return icon; - } - public void setIcon(Icon icon) - { - this.icon = icon; - updateIcon(); - } - public Icon getSelectedIcon() - { - return selectedIcon; - } - public void setSelectedIcon(Icon selectedIcon) - { - this.selectedIcon = selectedIcon; - updateIcon(); - } - private void updateIcon() - { - if (selected) - lbIcon.setIcon(selectedIcon); - else - lbIcon.setIcon(icon); - } - public void setTitle(String title) - { - lbTitle.setText(title); - lbTitle.setToolTipText(title); - lbHandler.setToolTipText(title); - lbIcon.setToolTipText(title); - } - public String getTitle() - { - return lbTitle.getText(); - } - - public MyOutlookListPanel getContentComponent() - { - return outlookListPanel; - } - public MyOutlookList getList() - { - return this.outlookListPanel.getOutlookList(); - } - public MyOutlookPanel getOutlookPanel() - { - return this.outlookPanel; - } - public void headerShrinkChanged(boolean headShrinked) - { - if (headShrinked) - lbHandler.setBorder(handlerShrinkedBorder); - else - lbHandler.setBorder(handlerBorder); - } + public void headerShrinkChanged(boolean headShrinked) { + if (headShrinked) { + lbHandler.setBorder(handlerShrinkedBorder); + } else { + lbHandler.setBorder(handlerBorder); + } + } } diff --git a/src/cppcheckplus/outlookpanel/MyOutlookHeader.java b/src/cppcheckplus/outlookpanel/MyOutlookHeader.java index c7ba589..9cd4026 100644 --- a/src/cppcheckplus/outlookpanel/MyOutlookHeader.java +++ b/src/cppcheckplus/outlookpanel/MyOutlookHeader.java @@ -1,9 +1,11 @@ - package cppcheckplus.outlookpanel; +import cppcheckplus.control.MyContorlUtil; +import cppcheckplus.control.MyHeader; +import cppcheckplus.control.MyListSplitListener; +import cppcheckplus.toolbar.MyToolBarButton; import java.awt.FlowLayout; import java.awt.LayoutManager; -import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.BorderFactory; import javax.swing.Icon; @@ -13,97 +15,84 @@ import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.border.Border; -import cppcheckplus.control.MyContorlUtil; -import cppcheckplus.control.MyHeader; -import cppcheckplus.control.MyListSplitListener; -import cppcheckplus.toolbar.MyToolBarButton; - -public class MyOutlookHeader extends MyHeader -{ - private LayoutManager toolbarLayout; - private JPanel toolbar; - private ImageIcon separatorIcon; - - public MyOutlookHeader(ActionListener listener) - { - toolbarLayout = new FlowLayout(FlowLayout.LEFT,2,1); - toolbar = new JPanel(toolbarLayout); - separatorIcon = MyContorlUtil.getImageIcon("control/images/toolbar_separator.png"); - init(); - //加载工具栏 - MyContorlUtil.loadOutlookToolBar("cppcheckplus/control/toolbar.xml", this,listener); - } - - private void init() - { - toolbar.setOpaque(false); - toolbar.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5)); - add(toolbar, "Center"); - } - //在Header上添加工具按钮 - public MyToolBarButton addButton(Icon icon, String tooltip, ActionListener action, String command) - { - MyToolBarButton button = new MyToolBarButton(); - button.setIcon(icon); - button.setToolTipText(tooltip); - if (action != null) - button.addActionListener(action); - button.setActionCommand(command); - toolbar.add(button); - return button; - } - - public void addSeparator() - { - toolbar.add(new JLabel(separatorIcon)); - } - - protected Object getResizeHandlerLayoutConstraint() - { - return "East"; - } - - protected Object getShrinkHandlerLayoutConstraint() - { - return "West"; - } - - protected MyListSplitListener createSplitListener() - { - return new MyOutlookSplitListener(this); - } - - protected Border createBorder() - { - return BorderFactory.createEmptyBorder(4, 0, 0, 7); - } - - protected ImageIcon getShrinkIcon(boolean shrinked) - { - if (shrinked) - return RIGHT_ARROW_ICON; - else - return LEFT_ARROW_ICON; - } - - protected JComponent getCenterComponent() - { - return null; - } - - public void setShrink(boolean shrinked) - { - super.setShrink(shrinked); - toolbar.setVisible(!shrinked); - } - - protected int getShrinkedWidth() - { - return 37; - } - - public JPanel getToolBar() - { - return toolbar; - } +public class MyOutlookHeader extends MyHeader { + private LayoutManager toolbarLayout; + private JPanel toolbar; + private ImageIcon separatorIcon; + + public MyOutlookHeader(ActionListener listener) { + toolbarLayout = new FlowLayout(FlowLayout.LEFT, 2, 1); + toolbar = new JPanel(toolbarLayout); + separatorIcon = + MyContorlUtil.getImageIcon("control/images/toolbar_separator.png"); + init(); + //加载工具栏 + MyContorlUtil.loadOutlookToolBar("cppcheckplus/control/toolbar.xml", + this, listener); + } + + private void init() { + toolbar.setOpaque(false); + toolbar.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5)); + add(toolbar, "Center"); + } + + //在Header上添加工具按钮 + public MyToolBarButton addButton(Icon icon, String tooltip, + ActionListener action, String command) { + MyToolBarButton button = new MyToolBarButton(); + button.setIcon(icon); + button.setToolTipText(tooltip); + if (action != null) { + button.addActionListener(action); + } + button.setActionCommand(command); + toolbar.add(button); + return button; + } + + public void addSeparator() { + toolbar.add(new JLabel(separatorIcon)); + } + + protected Object getResizeHandlerLayoutConstraint() { + return "East"; + } + + protected Object getShrinkHandlerLayoutConstraint() { + return "West"; + } + + protected MyListSplitListener createSplitListener() { + return new MyOutlookSplitListener(this); + } + + protected Border createBorder() { + return BorderFactory.createEmptyBorder(4, 0, 0, 7); + } + + protected ImageIcon getShrinkIcon(boolean shrinked) { + if (shrinked) { + return RIGHT_ARROW_ICON; + } else { + return LEFT_ARROW_ICON; + } + } + + protected JComponent getCenterComponent() { + return null; + } + + public void setShrink(boolean shrinked) { + super.setShrink(shrinked); + toolbar.setVisible(!shrinked); + } + + protected int getShrinkedWidth() { + return 37; + } + + public JPanel getToolBar() { + return toolbar; + } } diff --git a/src/cppcheckplus/outlookpanel/MyOutlookList.java b/src/cppcheckplus/outlookpanel/MyOutlookList.java index d5c04d5..9af3c24 100644 --- a/src/cppcheckplus/outlookpanel/MyOutlookList.java +++ b/src/cppcheckplus/outlookpanel/MyOutlookList.java @@ -1,31 +1,26 @@ - package cppcheckplus.outlookpanel; +import cppcheckplus.control.MyContorlUtil; import javax.swing.JList; -import cppcheckplus.control.MyContorlUtil; +public class MyOutlookList extends JList { + //通过MyOutlookBar获得MyOutlookPanel是否sh + private MyOutlookBar bar; -public class MyOutlookList extends JList -{ - //通过MyOutlookBar获得MyOutlookPanel是否sh - private MyOutlookBar bar; - public MyOutlookList(MyOutlookPanelListItem[] listItems,MyOutlookBar bar) - { - this.bar = bar; - setListData(listItems); - init(); - } + public MyOutlookList(MyOutlookPanelListItem[] listItems, MyOutlookBar bar) { + this.bar = bar; + setListData(listItems); + init(); + } - private void init() - { - setCellRenderer(new MyOutlookListRenderer()); - setFont(MyContorlUtil.FONT_12_BOLD); - setForeground(MyContorlUtil.OUTLOOK_TEXT_COLOR); - setSelectionMode(0); - } + private void init() { + setCellRenderer(new MyOutlookListRenderer()); + setFont(MyContorlUtil.FONT_12_BOLD); + setForeground(MyContorlUtil.OUTLOOK_TEXT_COLOR); + setSelectionMode(0); + } - public MyOutlookBar getOutlookBar() - { - return this.bar; - } + public MyOutlookBar getOutlookBar() { + return this.bar; + } } diff --git a/src/cppcheckplus/outlookpanel/MyOutlookListPanel.java b/src/cppcheckplus/outlookpanel/MyOutlookListPanel.java index 2b43866..6195b4c 100644 --- a/src/cppcheckplus/outlookpanel/MyOutlookListPanel.java +++ b/src/cppcheckplus/outlookpanel/MyOutlookListPanel.java @@ -1,4 +1,3 @@ - package cppcheckplus.outlookpanel; @@ -14,48 +13,45 @@ import javax.swing.ScrollPaneConstants; import javax.swing.border.Border; -public class MyOutlookListPanel extends JPanel -{ - private MyOutlookList list; - - //MyOutlookBar对应的MyOutlookList封装的Panel - private JScrollPane listScrollPane; - private Border scrollBorder; - - public MyOutlookListPanel(MyOutlookList list) - { - this.list = list; - listScrollPane = new JScrollPane(list); - // listScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER); - listScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); - scrollBorder = new Border() - { - public void paintBorder(Component c, Graphics g, int x, int y, - int width, int height) - { - g.setColor(new Color(233, 223, 207)); - g.drawLine(0, height, x, height); - } - public Insets getBorderInsets(Component c) - { - return new Insets(0, 0, 1, 0); - } - public boolean isBorderOpaque() - { - return true; - } - }; - init(); - } - private void init() - { - listScrollPane.setMinimumSize(new Dimension(0, 0)); - listScrollPane.setBorder(scrollBorder); - this.setLayout(new BorderLayout()); - add(listScrollPane,BorderLayout.CENTER); - } - public MyOutlookList getOutlookList() - { - return list; - } +public class MyOutlookListPanel extends JPanel { + private MyOutlookList list; + + //MyOutlookBar对应的MyOutlookList封装的Panel + private JScrollPane listScrollPane; + private Border scrollBorder; + + public MyOutlookListPanel(MyOutlookList list) { + this.list = list; + listScrollPane = new JScrollPane(list); + // listScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER); + listScrollPane.setHorizontalScrollBarPolicy( + ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); + scrollBorder = new Border() { + public void paintBorder(Component c, Graphics g, int x, int y, + int width, int height) { + g.setColor(new Color(233, 223, 207)); + g.drawLine(0, height, x, height); + } + + public Insets getBorderInsets(Component c) { + return new Insets(0, 0, 1, 0); + } + + public boolean isBorderOpaque() { + return true; + } + }; + init(); + } + + private void init() { + listScrollPane.setMinimumSize(new Dimension(0, 0)); + listScrollPane.setBorder(scrollBorder); + this.setLayout(new BorderLayout()); + add(listScrollPane, BorderLayout.CENTER); + } + + public MyOutlookList getOutlookList() { + return list; + } } diff --git a/src/cppcheckplus/outlookpanel/MyOutlookListRenderer.java b/src/cppcheckplus/outlookpanel/MyOutlookListRenderer.java index 9c71301..1b29f68 100644 --- a/src/cppcheckplus/outlookpanel/MyOutlookListRenderer.java +++ b/src/cppcheckplus/outlookpanel/MyOutlookListRenderer.java @@ -1,4 +1,3 @@ - package cppcheckplus.outlookpanel; import java.awt.Color; @@ -9,46 +8,44 @@ import javax.swing.JList; import javax.swing.SwingConstants; import javax.swing.border.Border; -import cppcheckplus.control.MyContorlUtil; +public class MyOutlookListRenderer extends DefaultListCellRenderer { + private Color selectedColor; + private Border normalBorder; + private Border shrinkedBorder; + + public MyOutlookListRenderer() { + super(); + selectedColor = new Color(253, 192, 47); + normalBorder = BorderFactory.createEmptyBorder(3, 19, 3, 2); + shrinkedBorder = BorderFactory.createEmptyBorder(2, 7, 1, 2); + } + + @Override + public Component getListCellRendererComponent(JList list, Object value, + int index, boolean isSelected, + boolean cellHasFocus) { + super.getListCellRendererComponent(list, value, index, isSelected, + cellHasFocus); -public class MyOutlookListRenderer extends DefaultListCellRenderer -{ - private Color selectedColor; - private Border normalBorder; - private Border shrinkedBorder; - - public MyOutlookListRenderer() - { - super(); - selectedColor = new Color(253, 192, 47); - normalBorder = BorderFactory.createEmptyBorder(3, 19, 3, 2); - shrinkedBorder = BorderFactory.createEmptyBorder(2, 7, 1, 2); - } - @Override - public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) - { - super.getListCellRendererComponent(list, value, index, isSelected,cellHasFocus); - - MyOutlookPanelListItem listItem = (MyOutlookPanelListItem)value; - MyOutlookList outlookList = (MyOutlookList)list; - setToolTipText(listItem.getToolTip()); - setIcon(listItem.getIcon()); - //收缩样式 - if (outlookList.getOutlookBar().getOutlookPanel().isShrinked()) - { - setBorder(shrinkedBorder); - setText(null); - } - //普通样式 - else - { - setBorder(normalBorder); - setText(listItem.getText()); - setHorizontalAlignment(SwingConstants.LEADING); - setIconTextGap(5); - } - if (isSelected) - setBackground(selectedColor); - return this; - } + MyOutlookPanelListItem listItem = (MyOutlookPanelListItem) value; + MyOutlookList outlookList = (MyOutlookList) list; + setToolTipText(listItem.getToolTip()); + setIcon(listItem.getIcon()); + //收缩样式 + if (outlookList.getOutlookBar().getOutlookPanel().isShrinked()) { + setBorder(shrinkedBorder); + setText(null); + } + //普通样式 + else { + setBorder(normalBorder); + setText(listItem.getText()); + setHorizontalAlignment(SwingConstants.LEADING); + setIconTextGap(5); + } + if (isSelected) { + setBackground(selectedColor); + } + return this; + } } diff --git a/src/cppcheckplus/outlookpanel/MyOutlookPanel.java b/src/cppcheckplus/outlookpanel/MyOutlookPanel.java index 139f62a..afa7392 100644 --- a/src/cppcheckplus/outlookpanel/MyOutlookPanel.java +++ b/src/cppcheckplus/outlookpanel/MyOutlookPanel.java @@ -1,6 +1,6 @@ - package cppcheckplus.outlookpanel; +import cppcheckplus.control.MyContorlUtil; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; @@ -9,214 +9,213 @@ import java.awt.Dimension; import java.awt.Graphics; import java.awt.Insets; import java.awt.event.ActionListener; -import java.util.ArrayList; import java.util.Hashtable; -import java.util.List; import javax.swing.Icon; -import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JPanel; import javax.swing.border.Border; import javax.swing.event.ListSelectionListener; - -import cppcheckplus.control.MyContorlUtil; import layout.TableLayout; -public class MyOutlookPanel extends JPanel -{ - //Header - private MyOutlookHeader header; - //容器Panel - private JPanel barPane;; - //右边的分割滑动线条 - private JPanel split; - private int splitWidth; - private Color splitColor; - private JPanel additionalPane; - private Hashtable componentLayoutRows; - private JPanel centerPane; - private TableLayout barPaneLayout; - private MyOutlookSplitListener splitListener; - private ListSelectionListener listSelectionListener; - - /** - * 构造MyOutlookPanel - * @param headerListener Header的监听器 - * @param listSelectionListener ListItemSelection的监听器 - */ - public MyOutlookPanel(ActionListener headerListener,ListSelectionListener listSelectionListener) - { - super(); - //注册Header事件 - this.header = new MyOutlookHeader(headerListener){ - public void setShrink(boolean shrinked) - { - super.setShrink(shrinked); - shrinkChanged(shrinked); - } - - }; - this.listSelectionListener = listSelectionListener; - barPaneLayout = new TableLayout(); - barPane = new JPanel(barPaneLayout); - - additionalPane = new JPanel(new BorderLayout()); - componentLayoutRows = new Hashtable(); - centerPane = new JPanel(new BorderLayout()); - - //分割条 - split = new JPanel(); - splitWidth = 1; - splitColor = new Color(166, 172, 174); - splitListener = new MyOutlookSplitListener(header); - - init(); - } - private void init() - { - split.setPreferredSize(new Dimension(splitWidth, 0)); - split.setOpaque(true); - split.setBackground(splitColor); - split.setCursor(Cursor.getPredefinedCursor(10)); - split.addMouseListener(splitListener); - split.addMouseMotionListener(splitListener); - additionalPane.setBackground(MyContorlUtil.OUTLOOK_CONTAINER_COLOR); - additionalPane.setPreferredSize(new Dimension(0, 0)); - additionalPane.setBorder(new Border() { - - public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) - { - g.setColor(MyContorlUtil.OUTLOOK_SPLIT_COLOR); - g.drawLine(0, 0, width, 0); - } - - public Insets getBorderInsets(Component c) - { - return new Insets(1, 0, 0, 0); - } - - public boolean isBorderOpaque() - { - return true; - } - - }); - - centerPane.add(barPane, "North"); - centerPane.add(additionalPane, "Center"); - barPaneLayout.insertColumn(0, -1D); - setLayout(new BorderLayout()); - add(header, "North"); - add(centerPane, "Center"); - add(split, "East"); - } - public MyOutlookBar addBar(String title, Icon icon, Icon selectedIcon,MyOutlookPanelListItem[] listItems) - { - MyOutlookBar bar = new MyOutlookBar(this); - MyOutlookListPanel listPanel = getListPanel(listItems, bar); - //注册JList事件 - listPanel.getOutlookList().addListSelectionListener(listSelectionListener); - bar.setOutlookListPanel(listPanel); - bar.setSelected(false); - bar.setTitle(title); - bar.setIcon(icon); - bar.setSelectedIcon(selectedIcon); - int rowCount = barPaneLayout.getRow().length; - barPaneLayout.insertRow(rowCount, -2D); - barPane.add(bar, (new StringBuilder()).append("0,").append(rowCount).toString()); - componentLayoutRows.put(bar, Integer.valueOf(rowCount)); - rowCount++; - barPaneLayout.insertRow(rowCount, -3D); - //加载列表 - barPane.add(listPanel,(new StringBuilder()).append("0,").append(rowCount).toString()); - componentLayoutRows.put(bar.getContentComponent(), Integer.valueOf(rowCount)); - return bar; - } - private MyOutlookListPanel getListPanel(MyOutlookPanelListItem[] listItems,MyOutlookBar bar) - { - MyOutlookList list = new MyOutlookList(listItems,bar); - MyOutlookListPanel listPanel = new MyOutlookListPanel(list); - return listPanel; - } - public void updateLayoutConstraint(Component component, boolean selected) - { - int rowIndex = ((Integer)componentLayoutRows.get(component)).intValue(); - double constraint = -1D; - if (!selected) - constraint = -3D; - barPaneLayout.setRow(rowIndex, constraint); - } - public JComponent getAdditionalPane() - { - return additionalPane; - } - public void setAdditionalPaneVisible(boolean visible) - { - centerPane.remove(barPane); - centerPane.remove(additionalPane); - if (visible) - { - centerPane.add(barPane, "North"); - centerPane.add(additionalPane, "Center"); - } else - { - centerPane.add(barPane, "Center"); - } - } - public void closeAllBars() - { - for (int i = 0; i < barPane.getComponentCount(); i++) - { - Component c = barPane.getComponent(i); - if (!(c instanceof MyOutlookBar)) - continue; - MyOutlookBar bar = (MyOutlookBar)c; - if (bar.isSelected()) - bar.setSelected(false); - } - } - public MyOutlookBar getSelectedBar() - { - for (int i = 0; i < barPane.getComponentCount(); i++) - { - Component c = barPane.getComponent(i); - if (!(c instanceof MyOutlookBar)) - continue; - MyOutlookBar bar = (MyOutlookBar)c; - if (bar.isSelected()) - return bar; - } - - return null; - } - public void setShrink(boolean shrinked) - { - header.setShrink(shrinked); - } - - public boolean isShrinked() - { - return header.isShrinked(); - } - private void shrinkChanged(boolean shrinked) - { - if (shrinked) - split.setCursor(Cursor.getDefaultCursor()); - else - split.setCursor(Cursor.getPredefinedCursor(10)); - for (int i = 0; i < barPane.getComponentCount(); i++) - { - Component c = barPane.getComponent(i); - if (c instanceof MyOutlookBar) - { - MyOutlookBar bar = (MyOutlookBar)c; - bar.headerShrinkChanged(shrinked); - - - //XOutlookList list = bar.getList(); - - //list.firePropertyChange("layoutOrientation", true, false); - } - } - } +public class MyOutlookPanel extends JPanel { + //Header + private MyOutlookHeader header; + //容器Panel + private JPanel barPane; + ; + //右边的分割滑动线条 + private JPanel split; + private int splitWidth; + private Color splitColor; + private JPanel additionalPane; + private Hashtable componentLayoutRows; + private JPanel centerPane; + private TableLayout barPaneLayout; + private MyOutlookSplitListener splitListener; + private ListSelectionListener listSelectionListener; + + /** + * 构造MyOutlookPanel + * + * @param headerListener Header的监听器 + * @param listSelectionListener ListItemSelection的监听器 + */ + public MyOutlookPanel(ActionListener headerListener, + ListSelectionListener listSelectionListener) { + super(); + //注册Header事件 + this.header = new MyOutlookHeader(headerListener) { + public void setShrink(boolean shrinked) { + super.setShrink(shrinked); + shrinkChanged(shrinked); + } + + }; + this.listSelectionListener = listSelectionListener; + barPaneLayout = new TableLayout(); + barPane = new JPanel(barPaneLayout); + + additionalPane = new JPanel(new BorderLayout()); + componentLayoutRows = new Hashtable(); + centerPane = new JPanel(new BorderLayout()); + + //分割条 + split = new JPanel(); + splitWidth = 1; + splitColor = new Color(166, 172, 174); + splitListener = new MyOutlookSplitListener(header); + + init(); + } + + private void init() { + split.setPreferredSize(new Dimension(splitWidth, 0)); + split.setOpaque(true); + split.setBackground(splitColor); + split.setCursor(Cursor.getPredefinedCursor(10)); + split.addMouseListener(splitListener); + split.addMouseMotionListener(splitListener); + additionalPane.setBackground(MyContorlUtil.OUTLOOK_CONTAINER_COLOR); + additionalPane.setPreferredSize(new Dimension(0, 0)); + additionalPane.setBorder(new Border() { + + public void paintBorder(Component c, Graphics g, int x, int y, + int width, int height) { + g.setColor(MyContorlUtil.OUTLOOK_SPLIT_COLOR); + g.drawLine(0, 0, width, 0); + } + + public Insets getBorderInsets(Component c) { + return new Insets(1, 0, 0, 0); + } + + public boolean isBorderOpaque() { + return true; + } + + }); + + centerPane.add(barPane, "North"); + centerPane.add(additionalPane, "Center"); + barPaneLayout.insertColumn(0, -1D); + setLayout(new BorderLayout()); + add(header, "North"); + add(centerPane, "Center"); + add(split, "East"); + } + + public MyOutlookBar addBar(String title, Icon icon, Icon selectedIcon, + MyOutlookPanelListItem[] listItems) { + MyOutlookBar bar = new MyOutlookBar(this); + MyOutlookListPanel listPanel = getListPanel(listItems, bar); + //注册JList事件 + listPanel.getOutlookList() + .addListSelectionListener(listSelectionListener); + bar.setOutlookListPanel(listPanel); + bar.setSelected(false); + bar.setTitle(title); + bar.setIcon(icon); + bar.setSelectedIcon(selectedIcon); + int rowCount = barPaneLayout.getRow().length; + barPaneLayout.insertRow(rowCount, -2D); + barPane.add(bar, + (new StringBuilder()).append("0,").append(rowCount).toString()); + componentLayoutRows.put(bar, Integer.valueOf(rowCount)); + rowCount++; + barPaneLayout.insertRow(rowCount, -3D); + //加载列表 + barPane.add(listPanel, + (new StringBuilder()).append("0,").append(rowCount).toString()); + componentLayoutRows.put(bar.getContentComponent(), + Integer.valueOf(rowCount)); + return bar; + } + + private MyOutlookListPanel getListPanel(MyOutlookPanelListItem[] listItems, + MyOutlookBar bar) { + MyOutlookList list = new MyOutlookList(listItems, bar); + MyOutlookListPanel listPanel = new MyOutlookListPanel(list); + return listPanel; + } + + public void updateLayoutConstraint(Component component, boolean selected) { + int rowIndex = + ((Integer) componentLayoutRows.get(component)).intValue(); + double constraint = -1D; + if (!selected) { + constraint = -3D; + } + barPaneLayout.setRow(rowIndex, constraint); + } + + public JComponent getAdditionalPane() { + return additionalPane; + } + + public void setAdditionalPaneVisible(boolean visible) { + centerPane.remove(barPane); + centerPane.remove(additionalPane); + if (visible) { + centerPane.add(barPane, "North"); + centerPane.add(additionalPane, "Center"); + } else { + centerPane.add(barPane, "Center"); + } + } + + public void closeAllBars() { + for (int i = 0; i < barPane.getComponentCount(); i++) { + Component c = barPane.getComponent(i); + if (!(c instanceof MyOutlookBar)) { + continue; + } + MyOutlookBar bar = (MyOutlookBar) c; + if (bar.isSelected()) { + bar.setSelected(false); + } + } + } + + public MyOutlookBar getSelectedBar() { + for (int i = 0; i < barPane.getComponentCount(); i++) { + Component c = barPane.getComponent(i); + if (!(c instanceof MyOutlookBar)) { + continue; + } + MyOutlookBar bar = (MyOutlookBar) c; + if (bar.isSelected()) { + return bar; + } + } + + return null; + } + + public void setShrink(boolean shrinked) { + header.setShrink(shrinked); + } + + public boolean isShrinked() { + return header.isShrinked(); + } + + private void shrinkChanged(boolean shrinked) { + if (shrinked) { + split.setCursor(Cursor.getDefaultCursor()); + } else { + split.setCursor(Cursor.getPredefinedCursor(10)); + } + for (int i = 0; i < barPane.getComponentCount(); i++) { + Component c = barPane.getComponent(i); + if (c instanceof MyOutlookBar) { + MyOutlookBar bar = (MyOutlookBar) c; + bar.headerShrinkChanged(shrinked); + + + //XOutlookList list = bar.getList(); + + //list.firePropertyChange("layoutOrientation", true, false); + } + } + } } diff --git a/src/cppcheckplus/outlookpanel/MyOutlookPanelListItem.java b/src/cppcheckplus/outlookpanel/MyOutlookPanelListItem.java index 92fd09e..421ff09 100644 --- a/src/cppcheckplus/outlookpanel/MyOutlookPanelListItem.java +++ b/src/cppcheckplus/outlookpanel/MyOutlookPanelListItem.java @@ -2,50 +2,41 @@ package cppcheckplus.outlookpanel; import javax.swing.Icon; -public class MyOutlookPanelListItem -{ - private Icon icon; - private String text; - private String toolTip; - private String actionCommand; - - public void setIcon(Icon icon) - { - this.icon = icon; - } - - public Icon getIcon() - { - return icon; - } - - public void setText(String value) - { - this.text = value; - } - - public String getText() - { - return text; - } - - public void setToolTip(String toolTip) - { - this.toolTip = toolTip; - } - - public String getToolTip() - { - return toolTip; - } - - public void setActionCommand(String actionCommand) - { - this.actionCommand = actionCommand; - } - - public String getActionCommand() - { - return actionCommand; - } +public class MyOutlookPanelListItem { + private Icon icon; + private String text; + private String toolTip; + private String actionCommand; + + public Icon getIcon() { + return icon; + } + + public void setIcon(Icon icon) { + this.icon = icon; + } + + public String getText() { + return text; + } + + public void setText(String value) { + this.text = value; + } + + public String getToolTip() { + return toolTip; + } + + public void setToolTip(String toolTip) { + this.toolTip = toolTip; + } + + public String getActionCommand() { + return actionCommand; + } + + public void setActionCommand(String actionCommand) { + this.actionCommand = actionCommand; + } } diff --git a/src/cppcheckplus/outlookpanel/MyOutlookSplitListener.java b/src/cppcheckplus/outlookpanel/MyOutlookSplitListener.java index b65e706..c78b1c5 100644 --- a/src/cppcheckplus/outlookpanel/MyOutlookSplitListener.java +++ b/src/cppcheckplus/outlookpanel/MyOutlookSplitListener.java @@ -1,33 +1,27 @@ - package cppcheckplus.outlookpanel; +import cppcheckplus.control.MyHeader; +import cppcheckplus.control.MyListSplitListener; import java.awt.Dimension; import java.awt.Point; import java.awt.event.MouseEvent; import javax.swing.JComponent; -import cppcheckplus.control.MyHeader; -import cppcheckplus.control.MyListSplitListener; - -public class MyOutlookSplitListener extends MyListSplitListener -{ - public MyOutlookSplitListener(MyHeader header) - { - super(header); - } +public class MyOutlookSplitListener extends MyListSplitListener { + public MyOutlookSplitListener(MyHeader header) { + super(header); + } - public void mouseDragged(MouseEvent e) - { - if (!header.isShrinked() && lastPoint != null) - { - JComponent parent = (JComponent)header.getParent(); - Dimension size = parent.getPreferredSize(); - Point thisPoint = e.getPoint(); - int xMovement = thisPoint.x - lastPoint.x; - size.width += xMovement; - size.width = Math.max(size.width, 37); - parent.setPreferredSize(size); - header.revalidateParent(); - } - } + public void mouseDragged(MouseEvent e) { + if (!header.isShrinked() && lastPoint != null) { + JComponent parent = (JComponent) header.getParent(); + Dimension size = parent.getPreferredSize(); + Point thisPoint = e.getPoint(); + int xMovement = thisPoint.x - lastPoint.x; + size.width += xMovement; + size.width = Math.max(size.width, 37); + parent.setPreferredSize(size); + header.revalidateParent(); + } + } } diff --git a/src/cppcheckplus/shortcut/MyShortcutItem.java b/src/cppcheckplus/shortcut/MyShortcutItem.java index 7461690..1baf836 100644 --- a/src/cppcheckplus/shortcut/MyShortcutItem.java +++ b/src/cppcheckplus/shortcut/MyShortcutItem.java @@ -1,20 +1,15 @@ - package cppcheckplus.shortcut; import cppcheckplus.outlookpanel.MyOutlookPanelListItem; -public class MyShortcutItem extends MyOutlookPanelListItem -{ - private boolean isGroup; - +public class MyShortcutItem extends MyOutlookPanelListItem { + private boolean isGroup; - public void setGroup(boolean isGroup) - { - this.isGroup = isGroup; - } + public boolean isGroup() { + return isGroup; + } - public boolean isGroup() - { - return isGroup; - } + public void setGroup(boolean isGroup) { + this.isGroup = isGroup; + } } diff --git a/src/cppcheckplus/shortcut/MyShortcutItemClickListenter.java b/src/cppcheckplus/shortcut/MyShortcutItemClickListenter.java index b2ea232..47b61fa 100644 --- a/src/cppcheckplus/shortcut/MyShortcutItemClickListenter.java +++ b/src/cppcheckplus/shortcut/MyShortcutItemClickListenter.java @@ -1,7 +1,5 @@ - package cppcheckplus.shortcut; -public interface MyShortcutItemClickListenter -{ - public void ItemClick(String actionCommand); +public interface MyShortcutItemClickListenter { + public void ItemClick(String actionCommand); } diff --git a/src/cppcheckplus/shortcut/MyShortcutPanel.java b/src/cppcheckplus/shortcut/MyShortcutPanel.java index 5d97b08..c1e6a72 100644 --- a/src/cppcheckplus/shortcut/MyShortcutPanel.java +++ b/src/cppcheckplus/shortcut/MyShortcutPanel.java @@ -1,6 +1,9 @@ - package cppcheckplus.shortcut; +import cppcheckplus.control.MyContorlUtil; +import cppcheckplus.control.MyHeader; +import cppcheckplus.control.MyList; +import cppcheckplus.control.MyListSplitListener; import java.awt.BorderLayout; import java.awt.Component; import java.awt.Cursor; @@ -10,105 +13,92 @@ import java.awt.Insets; import javax.swing.JPanel; import javax.swing.border.Border; -import cppcheckplus.control.MyContorlUtil; -import cppcheckplus.control.MyHeader; -import cppcheckplus.control.MyList; -import cppcheckplus.control.MyListSplitListener; -import cppcheckplus.outlookpanel.MyOutlookList; -import cppcheckplus.outlookpanel.MyOutlookPanelListItem; - -public class MyShortcutPanel extends JPanel{ - private MyList list; - private JPanel split; - private MyHeader header; - private MyListSplitListener splitListener; - public MyTree mytree; - public MyShortcutPanel() - { - super(); - //list = new MyList(); - split = new JPanel(new BorderLayout()); - - header = new MyHeader() { - - public void setShrink(boolean shrinked) - { - super.setShrink(shrinked); - if (shrinked) - split.setCursor(Cursor.getDefaultCursor()); - else - split.setCursor(Cursor.getPredefinedCursor(10)); - } - }; - splitListener = new MyListSplitListener(header); - mytree = new MyTree(); - init(); - } - public void setData(MyShortcutItem[] items,MyShortcutItemClickListenter listenter) - { - //list.setListData(items); - list.setListenter(listenter); - } - private void init() - { - setLayout(new BorderLayout()); - JPanel rightInsetPane = new JPanel(); - rightInsetPane.setPreferredSize(new Dimension(2, 0)); - rightInsetPane.setBackground(MyContorlUtil.LIST_BACKGROUND); - add(rightInsetPane, "East"); - add(header, "North"); - - split.setBorder(new Border() { - public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) - { - g.setColor(MyContorlUtil.LIST_SPLIT_COLOR); - g.drawLine(x, y, x, y + height); - } - - public Insets getBorderInsets(Component c) - { - return new Insets(0, 1, 0, 0); - } - - public boolean isBorderOpaque() - { - return true; - } - - }); - split.setOpaque(true); - split.setPreferredSize(new Dimension(4, 0)); - split.setBackground(MyContorlUtil.LIST_BACKGROUND); - split.setCursor(Cursor.getPredefinedCursor(10)); - split.addMouseListener(splitListener); - split.addMouseMotionListener(splitListener); - add(split, "West"); - add(mytree, "Center"); - //add(list, "Center"); - } - - public MyList getList() - { - return list; - } - - public void setTitle(String title) - { - header.setTitle(title); - } - - public String getTitle() - { - return header.getTitle(); - } - - public void setShrink(boolean shrinked) - { - header.setShrink(shrinked); - } - - public boolean isShrinked() - { - return header.isShrinked(); - } +public class MyShortcutPanel extends JPanel { + public MyTree mytree; + private MyList list; + private JPanel split; + private MyHeader header; + private MyListSplitListener splitListener; + + public MyShortcutPanel() { + super(); + //list = new MyList(); + split = new JPanel(new BorderLayout()); + + header = new MyHeader() { + + public void setShrink(boolean shrinked) { + super.setShrink(shrinked); + if (shrinked) { + split.setCursor(Cursor.getDefaultCursor()); + } else { + split.setCursor(Cursor.getPredefinedCursor(10)); + } + } + }; + splitListener = new MyListSplitListener(header); + mytree = new MyTree(); + init(); + } + + public void setData(MyShortcutItem[] items, + MyShortcutItemClickListenter listenter) { + //list.setListData(items); + list.setListenter(listenter); + } + + private void init() { + setLayout(new BorderLayout()); + JPanel rightInsetPane = new JPanel(); + rightInsetPane.setPreferredSize(new Dimension(2, 0)); + rightInsetPane.setBackground(MyContorlUtil.LIST_BACKGROUND); + add(rightInsetPane, "East"); + add(header, "North"); + + split.setBorder(new Border() { + public void paintBorder(Component c, Graphics g, int x, int y, + int width, int height) { + g.setColor(MyContorlUtil.LIST_SPLIT_COLOR); + g.drawLine(x, y, x, y + height); + } + + public Insets getBorderInsets(Component c) { + return new Insets(0, 1, 0, 0); + } + + public boolean isBorderOpaque() { + return true; + } + + }); + split.setOpaque(true); + split.setPreferredSize(new Dimension(4, 0)); + split.setBackground(MyContorlUtil.LIST_BACKGROUND); + split.setCursor(Cursor.getPredefinedCursor(10)); + split.addMouseListener(splitListener); + split.addMouseMotionListener(splitListener); + add(split, "West"); + add(mytree, "Center"); + //add(list, "Center"); + } + + public MyList getList() { + return list; + } + + public String getTitle() { + return header.getTitle(); + } + + public void setTitle(String title) { + header.setTitle(title); + } + + public void setShrink(boolean shrinked) { + header.setShrink(shrinked); + } + + public boolean isShrinked() { + return header.isShrinked(); + } } diff --git a/src/cppcheckplus/shortcut/MyTree.java b/src/cppcheckplus/shortcut/MyTree.java index 5286dde..e13fc1a 100644 --- a/src/cppcheckplus/shortcut/MyTree.java +++ b/src/cppcheckplus/shortcut/MyTree.java @@ -16,9 +16,9 @@ import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.MutableTreeNode; public class MyTree extends JPanel { + private final JTree tree; public File result; public String src; - private final JTree tree; private UIFrame jf; private JTextArea textCode; diff --git a/src/cppcheckplus/tab/MyTabComponent.java b/src/cppcheckplus/tab/MyTabComponent.java index 5a1d2a6..4ed4b1d 100644 --- a/src/cppcheckplus/tab/MyTabComponent.java +++ b/src/cppcheckplus/tab/MyTabComponent.java @@ -1,6 +1,6 @@ - package cppcheckplus.tab; +import cppcheckplus.control.MyContorlUtil; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; @@ -17,157 +17,150 @@ import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.border.Border; -import cppcheckplus.control.MyContorlUtil; - -public class MyTabComponent extends JPanel -{ - - private String backgroundUnselectedImageURL; - private TexturePaint selectedPaint; - private TexturePaint unselectedPaint; - private ImageIcon icon; - private ImageIcon pressedIcon; - private Image unselectedLeftImage; - private Image unselectedRightImage; - private Image selectedLeftImage; - private Image selectedRightImage; - private JButton btnClose; - private JLabel lbTitle; - private MyTabPanel tab; - private Color selectedTitleColor; - private Color unselectedTitleColor; - private Border border; - private String oId; - - public MyTabComponent(String oId,MyTabPanel tab) - { - super(); - this.oId = oId; - selectedPaint = MyContorlUtil.createTexturePaint("control/images/tab_header_background.png"); - unselectedPaint = MyContorlUtil.createTexturePaint("control/images/tab_header_unselected_background.png"); - icon = MyContorlUtil.getImageIcon("control/images/tab_close.png"); - pressedIcon = MyContorlUtil.getImageIcon("control/images/tab_close_pressed.png"); - unselectedLeftImage = MyContorlUtil.getImage("control/images/tab_header_unselected_background_left.png"); - unselectedRightImage = MyContorlUtil.getImage("control/images/tab_header_unselected_background_right.png"); - selectedLeftImage = MyContorlUtil.getImage("control/images/tab_header_selected_background_left.png"); - selectedRightImage = MyContorlUtil.getImage("control/images/tab_header_selected_background_right.png"); - btnClose = new JButton(); - lbTitle = new JLabel(); - this.tab = null; - selectedTitleColor = new Color(120, 120, 125); - unselectedTitleColor = Color.white; - border = BorderFactory.createEmptyBorder(0, 5, 0, 5); - this.tab = tab; - init(); - } - - private void init() - { - btnClose.setIcon(icon); - btnClose.setPressedIcon(pressedIcon); - btnClose.setToolTipText("Close this tab"); - btnClose.setMargin(MyContorlUtil.ZERO_INSETS); - btnClose.setFocusPainted(false); - btnClose.setBorder(BorderFactory.createEmptyBorder(0, 3, 1, 3)); - btnClose.setContentAreaFilled(false); - btnClose.addActionListener(new ActionListener() { - - public void actionPerformed(ActionEvent e) - { - closeTab(); - } - - }); - lbTitle.setOpaque(false); - lbTitle.setBorder(BorderFactory.createEmptyBorder(0, 3, 0, 3)); - lbTitle.setVerticalAlignment(0); - lbTitle.setFont(MyContorlUtil.FONT_12_BOLD); - setLayout(new BorderLayout()); - add(btnClose, "East"); - add(lbTitle, "Center"); - setBorder(border); - setOpaque(false); - } - - public void paintComponent(Graphics g) - { - Graphics2D g2d = (Graphics2D)g; - if (isTabSelected()) - { - g2d.drawImage(selectedLeftImage, 0, 0, null); - g2d.setPaint(selectedPaint); - int x = selectedLeftImage.getWidth(null); - int y = 0; - int width = getWidth() - x - selectedRightImage.getWidth(null); - int height = getHeight(); - g2d.fillRect(x, y, width, height); - g2d.drawImage(selectedRightImage, x + width, 0, null); - } else - { - g2d.drawImage(unselectedLeftImage, 0, 0, null); - g2d.setPaint(unselectedPaint); - int x = unselectedLeftImage.getWidth(null); - int y = 0; - int width = getWidth() - x - selectedRightImage.getWidth(null); - int height = getHeight(); - g2d.fillRect(x, y, width, height); - g2d.drawImage(unselectedRightImage, x + width, 0, null); - g2d.setColor(MyContorlUtil.TAB_BOTTOM_LINE_COLOR); - int lineY = getHeight() - 1; - g2d.drawLine(0, lineY, getWidth(), lineY); - } - } - - public Dimension getPreferredSize() - { - int width = super.getPreferredSize().width; - if (!isTabSelected()) - width = Math.min(width, tab.getPreferredUnselectedTabWidth()); - int height = tab.getPreferredTabHeight(); - return new Dimension(width, height); - } - - public boolean isTabSelected() - { - int index = tab.indexOfTabComponent(this); - int selectedIndex = tab.getSelectedIndex(); - return selectedIndex == index; - } - - public void setTitle(String title) - { - lbTitle.setText(title); - } - - public void updateSelection(boolean selected) - { - if (selected) - lbTitle.setForeground(selectedTitleColor); - else - lbTitle.setForeground(unselectedTitleColor); - btnClose.setVisible(selected); - } - - private void closeTab() - { - int index = tab.indexOfTabComponent(this); - tab.removeTabAt(index); - } - - /** - * @param oId the oId to set - */ - public void setOId(String oId) - { - this.oId = oId; - } - - /** - * @return the oId - */ - public String getOId() - { - return oId; - } +public class MyTabComponent extends JPanel { + + private String backgroundUnselectedImageURL; + private TexturePaint selectedPaint; + private TexturePaint unselectedPaint; + private ImageIcon icon; + private ImageIcon pressedIcon; + private Image unselectedLeftImage; + private Image unselectedRightImage; + private Image selectedLeftImage; + private Image selectedRightImage; + private JButton btnClose; + private JLabel lbTitle; + private MyTabPanel tab; + private Color selectedTitleColor; + private Color unselectedTitleColor; + private Border border; + private String oId; + + public MyTabComponent(String oId, MyTabPanel tab) { + super(); + this.oId = oId; + selectedPaint = MyContorlUtil.createTexturePaint( + "control/images/tab_header_background.png"); + unselectedPaint = MyContorlUtil.createTexturePaint( + "control/images/tab_header_unselected_background.png"); + icon = MyContorlUtil.getImageIcon("control/images/tab_close.png"); + pressedIcon = + MyContorlUtil.getImageIcon("control/images/tab_close_pressed.png"); + unselectedLeftImage = MyContorlUtil.getImage( + "control/images/tab_header_unselected_background_left.png"); + unselectedRightImage = MyContorlUtil.getImage( + "control/images/tab_header_unselected_background_right.png"); + selectedLeftImage = MyContorlUtil.getImage( + "control/images/tab_header_selected_background_left.png"); + selectedRightImage = MyContorlUtil.getImage( + "control/images/tab_header_selected_background_right.png"); + btnClose = new JButton(); + lbTitle = new JLabel(); + this.tab = null; + selectedTitleColor = new Color(120, 120, 125); + unselectedTitleColor = Color.white; + border = BorderFactory.createEmptyBorder(0, 5, 0, 5); + this.tab = tab; + init(); + } + + private void init() { + btnClose.setIcon(icon); + btnClose.setPressedIcon(pressedIcon); + btnClose.setToolTipText("Close this tab"); + btnClose.setMargin(MyContorlUtil.ZERO_INSETS); + btnClose.setFocusPainted(false); + btnClose.setBorder(BorderFactory.createEmptyBorder(0, 3, 1, 3)); + btnClose.setContentAreaFilled(false); + btnClose.addActionListener(new ActionListener() { + + public void actionPerformed(ActionEvent e) { + closeTab(); + } + + }); + lbTitle.setOpaque(false); + lbTitle.setBorder(BorderFactory.createEmptyBorder(0, 3, 0, 3)); + lbTitle.setVerticalAlignment(0); + lbTitle.setFont(MyContorlUtil.FONT_12_BOLD); + setLayout(new BorderLayout()); + add(btnClose, "East"); + add(lbTitle, "Center"); + setBorder(border); + setOpaque(false); + } + + public void paintComponent(Graphics g) { + Graphics2D g2d = (Graphics2D) g; + if (isTabSelected()) { + g2d.drawImage(selectedLeftImage, 0, 0, null); + g2d.setPaint(selectedPaint); + int x = selectedLeftImage.getWidth(null); + int y = 0; + int width = getWidth() - x - selectedRightImage.getWidth(null); + int height = getHeight(); + g2d.fillRect(x, y, width, height); + g2d.drawImage(selectedRightImage, x + width, 0, null); + } else { + g2d.drawImage(unselectedLeftImage, 0, 0, null); + g2d.setPaint(unselectedPaint); + int x = unselectedLeftImage.getWidth(null); + int y = 0; + int width = getWidth() - x - selectedRightImage.getWidth(null); + int height = getHeight(); + g2d.fillRect(x, y, width, height); + g2d.drawImage(unselectedRightImage, x + width, 0, null); + g2d.setColor(MyContorlUtil.TAB_BOTTOM_LINE_COLOR); + int lineY = getHeight() - 1; + g2d.drawLine(0, lineY, getWidth(), lineY); + } + } + + public Dimension getPreferredSize() { + int width = super.getPreferredSize().width; + if (!isTabSelected()) { + width = Math.min(width, tab.getPreferredUnselectedTabWidth()); + } + int height = tab.getPreferredTabHeight(); + return new Dimension(width, height); + } + + public boolean isTabSelected() { + int index = tab.indexOfTabComponent(this); + int selectedIndex = tab.getSelectedIndex(); + return selectedIndex == index; + } + + public void setTitle(String title) { + lbTitle.setText(title); + } + + public void updateSelection(boolean selected) { + if (selected) { + lbTitle.setForeground(selectedTitleColor); + } else { + lbTitle.setForeground(unselectedTitleColor); + } + btnClose.setVisible(selected); + } + + private void closeTab() { + int index = tab.indexOfTabComponent(this); + tab.removeTabAt(index); + } + + /** + * @return the oId + */ + public String getOId() { + return oId; + } + + /** + * @param oId the oId to set + */ + public void setOId(String oId) { + this.oId = oId; + } } diff --git a/src/cppcheckplus/tab/MyTabComponent1.java b/src/cppcheckplus/tab/MyTabComponent1.java index 9901441..5ca0dfb 100644 --- a/src/cppcheckplus/tab/MyTabComponent1.java +++ b/src/cppcheckplus/tab/MyTabComponent1.java @@ -1,5 +1,6 @@ package cppcheckplus.tab; +import cppcheckplus.control.MyContorlUtil; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; @@ -7,130 +8,122 @@ import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Image; import java.awt.TexturePaint; - import javax.swing.BorderFactory; import javax.swing.ImageIcon; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.border.Border; -import cppcheckplus.control.MyContorlUtil; - -public class MyTabComponent1 extends JPanel{ - - private String backgroundUnselectedImageURL; - private TexturePaint selectedPaint; - private TexturePaint unselectedPaint; - private ImageIcon pressedIcon; - private Image unselectedLeftImage; - private Image unselectedRightImage; - private Image selectedLeftImage; - private Image selectedRightImage; - private JLabel lbTitle; - private MyTabPanel1 tab; - private Color selectedTitleColor; - private Color unselectedTitleColor; - private Border border; - private String oId; - - public MyTabComponent1(String oId,MyTabPanel1 tab) - { - super(); - this.oId = oId; - selectedPaint = MyContorlUtil.createTexturePaint("control/images/tab_header_background.png"); - unselectedPaint = MyContorlUtil.createTexturePaint("control/images/tab_header_unselected_background.png"); - unselectedLeftImage = MyContorlUtil.getImage("control/images/tab_header_unselected_background_left.png"); - unselectedRightImage = MyContorlUtil.getImage("control/images/tab_header_unselected_background_right.png"); - selectedLeftImage = MyContorlUtil.getImage("control/images/tab_header_selected_background_left.png"); - selectedRightImage = MyContorlUtil.getImage("control/images/tab_header_selected_background_right.png"); - lbTitle = new JLabel(); - this.tab = null; - selectedTitleColor = new Color(120, 120, 125); - unselectedTitleColor = Color.white; - border = BorderFactory.createEmptyBorder(0, 5, 0, 5); - this.tab = tab; - init(); - } +public class MyTabComponent1 extends JPanel { - private void init() - { - lbTitle.setOpaque(false); - lbTitle.setBorder(BorderFactory.createEmptyBorder(0, 3, 0, 3)); - lbTitle.setVerticalAlignment(0); - lbTitle.setFont(MyContorlUtil.FONT_12_BOLD); - setLayout(new BorderLayout()); - add(lbTitle, "Center"); - setBorder(border); - setOpaque(false); - } + private String backgroundUnselectedImageURL; + private TexturePaint selectedPaint; + private TexturePaint unselectedPaint; + private ImageIcon pressedIcon; + private Image unselectedLeftImage; + private Image unselectedRightImage; + private Image selectedLeftImage; + private Image selectedRightImage; + private JLabel lbTitle; + private MyTabPanel1 tab; + private Color selectedTitleColor; + private Color unselectedTitleColor; + private Border border; + private String oId; - public void paintComponent(Graphics g) - { - Graphics2D g2d = (Graphics2D)g; - if (isTabSelected()) - { - g2d.drawImage(selectedLeftImage, 0, 0, null); - g2d.setPaint(selectedPaint); - int x = selectedLeftImage.getWidth(null); - int y = 0; - int width = getWidth() - x - selectedRightImage.getWidth(null); - int height = getHeight(); - g2d.fillRect(x, y, width, height); - g2d.drawImage(selectedRightImage, x + width, 0, null); - } else - { - g2d.drawImage(unselectedLeftImage, 0, 0, null); - g2d.setPaint(unselectedPaint); - int x = unselectedLeftImage.getWidth(null); - int y = 0; - int width = getWidth() - x - selectedRightImage.getWidth(null); - int height = getHeight(); - g2d.fillRect(x, y, width, height); - g2d.drawImage(unselectedRightImage, x + width, 0, null); - g2d.setColor(MyContorlUtil.TAB_BOTTOM_LINE_COLOR); - int lineY = getHeight() - 1; - g2d.drawLine(0, lineY, getWidth(), lineY); - } - } + public MyTabComponent1(String oId, MyTabPanel1 tab) { + super(); + this.oId = oId; + selectedPaint = MyContorlUtil.createTexturePaint( + "control/images/tab_header_background.png"); + unselectedPaint = MyContorlUtil.createTexturePaint( + "control/images/tab_header_unselected_background.png"); + unselectedLeftImage = MyContorlUtil.getImage( + "control/images/tab_header_unselected_background_left.png"); + unselectedRightImage = MyContorlUtil.getImage( + "control/images/tab_header_unselected_background_right.png"); + selectedLeftImage = MyContorlUtil.getImage( + "control/images/tab_header_selected_background_left.png"); + selectedRightImage = MyContorlUtil.getImage( + "control/images/tab_header_selected_background_right.png"); + lbTitle = new JLabel(); + this.tab = null; + selectedTitleColor = new Color(120, 120, 125); + unselectedTitleColor = Color.white; + border = BorderFactory.createEmptyBorder(0, 5, 0, 5); + this.tab = tab; + init(); + } - public Dimension getPreferredSize() - { - int width = super.getPreferredSize().width; - if (!isTabSelected()) - width = Math.min(width, tab.getPreferredUnselectedTabWidth()); - int height = tab.getPreferredTabHeight(); - return new Dimension(width, height); - } + private void init() { + lbTitle.setOpaque(false); + lbTitle.setBorder(BorderFactory.createEmptyBorder(0, 3, 0, 3)); + lbTitle.setVerticalAlignment(0); + lbTitle.setFont(MyContorlUtil.FONT_12_BOLD); + setLayout(new BorderLayout()); + add(lbTitle, "Center"); + setBorder(border); + setOpaque(false); + } - public boolean isTabSelected() - { - int index = tab.indexOfTabComponent(this); - int selectedIndex = tab.getSelectedIndex(); - return selectedIndex == index; - } + public void paintComponent(Graphics g) { + Graphics2D g2d = (Graphics2D) g; + if (isTabSelected()) { + g2d.drawImage(selectedLeftImage, 0, 0, null); + g2d.setPaint(selectedPaint); + int x = selectedLeftImage.getWidth(null); + int y = 0; + int width = getWidth() - x - selectedRightImage.getWidth(null); + int height = getHeight(); + g2d.fillRect(x, y, width, height); + g2d.drawImage(selectedRightImage, x + width, 0, null); + } else { + g2d.drawImage(unselectedLeftImage, 0, 0, null); + g2d.setPaint(unselectedPaint); + int x = unselectedLeftImage.getWidth(null); + int y = 0; + int width = getWidth() - x - selectedRightImage.getWidth(null); + int height = getHeight(); + g2d.fillRect(x, y, width, height); + g2d.drawImage(unselectedRightImage, x + width, 0, null); + g2d.setColor(MyContorlUtil.TAB_BOTTOM_LINE_COLOR); + int lineY = getHeight() - 1; + g2d.drawLine(0, lineY, getWidth(), lineY); + } + } - public void setTitle(String title) - { - lbTitle.setText(title); - } + public Dimension getPreferredSize() { + int width = super.getPreferredSize().width; + if (!isTabSelected()) { + width = Math.min(width, tab.getPreferredUnselectedTabWidth()); + } + int height = tab.getPreferredTabHeight(); + return new Dimension(width, height); + } - public void updateSelection(boolean selected) - { - if (selected) - lbTitle.setForeground(selectedTitleColor); - else - lbTitle.setForeground(unselectedTitleColor); - } + public boolean isTabSelected() { + int index = tab.indexOfTabComponent(this); + int selectedIndex = tab.getSelectedIndex(); + return selectedIndex == index; + } + public void setTitle(String title) { + lbTitle.setText(title); + } + public void updateSelection(boolean selected) { + if (selected) { + lbTitle.setForeground(selectedTitleColor); + } else { + lbTitle.setForeground(unselectedTitleColor); + } + } - public void setOId(String oId) - { - this.oId = oId; - } + public String getOId() { + return oId; + } - public String getOId() - { - return oId; - } + public void setOId(String oId) { + this.oId = oId; + } } diff --git a/src/cppcheckplus/tab/MyTabPage.java b/src/cppcheckplus/tab/MyTabPage.java index ef26580..a240b58 100644 --- a/src/cppcheckplus/tab/MyTabPage.java +++ b/src/cppcheckplus/tab/MyTabPage.java @@ -1,46 +1,39 @@ - package cppcheckplus.tab; +import cppcheckplus.toolbar.MyToolBar; import java.awt.BorderLayout; import javax.swing.JComponent; import javax.swing.JPanel; -import cppcheckplus.toolbar.MyToolBar; - -public class MyTabPage extends JPanel -{ - private MyToolBar toolbar; - private JPanel centerPane; - - public MyTabPage() - { - this(null); - } - - public MyTabPage(JComponent contentComponent) - { - toolbar = new MyToolBar(); - centerPane = new JPanel(new BorderLayout()); - init(contentComponent); - } - - private void init(JComponent contentComponent) - { - setLayout(new BorderLayout()); - add(toolbar, "North"); - add(centerPane, "Center"); - if (contentComponent != null) - centerPane.add(contentComponent, "Center"); - } - - public JPanel getCenterPane() - { - return centerPane; - } - - public MyToolBar getToolBar() - { - return toolbar; - } +public class MyTabPage extends JPanel { + private MyToolBar toolbar; + private JPanel centerPane; + + public MyTabPage() { + this(null); + } + + public MyTabPage(JComponent contentComponent) { + toolbar = new MyToolBar(); + centerPane = new JPanel(new BorderLayout()); + init(contentComponent); + } + + private void init(JComponent contentComponent) { + setLayout(new BorderLayout()); + add(toolbar, "North"); + add(centerPane, "Center"); + if (contentComponent != null) { + centerPane.add(contentComponent, "Center"); + } + } + + public JPanel getCenterPane() { + return centerPane; + } + + public MyToolBar getToolBar() { + return toolbar; + } } diff --git a/src/cppcheckplus/tab/MyTabPage1.java b/src/cppcheckplus/tab/MyTabPage1.java index e851b3a..d20b78c 100644 --- a/src/cppcheckplus/tab/MyTabPage1.java +++ b/src/cppcheckplus/tab/MyTabPage1.java @@ -1,30 +1,31 @@ package cppcheckplus.tab; import java.awt.BorderLayout; - import javax.swing.JComponent; import javax.swing.JPanel; -public class MyTabPage1 extends JPanel{ - private JPanel centerPane; - public MyTabPage1(){ - this(null); - } +public class MyTabPage1 extends JPanel { + private JPanel centerPane; + + public MyTabPage1() { + this(null); + } - public MyTabPage1(JComponent contentComponent){ - centerPane = new JPanel(new BorderLayout()); - init(contentComponent); - } + public MyTabPage1(JComponent contentComponent) { + centerPane = new JPanel(new BorderLayout()); + init(contentComponent); + } - private void init(JComponent contentComponent){ - setLayout(new BorderLayout()); - add(centerPane, "Center"); - if (contentComponent != null) - centerPane.add(contentComponent, "Center"); - } + private void init(JComponent contentComponent) { + setLayout(new BorderLayout()); + add(centerPane, "Center"); + if (contentComponent != null) { + centerPane.add(contentComponent, "Center"); + } + } - public JPanel getCenterPane(){ - return centerPane; - } + public JPanel getCenterPane() { + return centerPane; + } } diff --git a/src/cppcheckplus/tab/MyTabPanel.java b/src/cppcheckplus/tab/MyTabPanel.java index cda8c3a..3dff0f4 100644 --- a/src/cppcheckplus/tab/MyTabPanel.java +++ b/src/cppcheckplus/tab/MyTabPanel.java @@ -1,97 +1,82 @@ - package cppcheckplus.tab; +import cppcheckplus.control.MyContorlUtil; import java.awt.Component; import javax.swing.JTabbedPane; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; -import cppcheckplus.control.MyContorlUtil; +public class MyTabPanel extends JTabbedPane { + private int preferredUnselectedTabWidth; + private int preferredTabHeight; + + public MyTabPanel() { + preferredUnselectedTabWidth = 80; + preferredTabHeight = MyContorlUtil.getImageIcon( + "control/images/tab_header_background.png").getIconHeight(); + init(); + } -public class MyTabPanel extends JTabbedPane -{ - private int preferredUnselectedTabWidth; - private int preferredTabHeight; + private void init() { + setFont(MyContorlUtil.FONT_12_BOLD); + setForeground(MyContorlUtil.DEFAULT_TEXT_COLOR); + setBorder(null); + setFocusable(false); + setTabLayoutPolicy(1); + setOpaque(false); + setUI(new MyTabPanelUI(this)); + addChangeListener(new ChangeListener() { + public void stateChanged(ChangeEvent e) { + updateTabComponents(); + } + }); + } - public MyTabPanel() - { - preferredUnselectedTabWidth = 80; - preferredTabHeight = MyContorlUtil.getImageIcon("control/images/tab_header_background.png").getIconHeight(); - init(); - } - private void init() - { - setFont(MyContorlUtil.FONT_12_BOLD); - setForeground(MyContorlUtil.DEFAULT_TEXT_COLOR); - setBorder(null); - setFocusable(false); - setTabLayoutPolicy(1); - setOpaque(false); - setUI(new MyTabPanelUI(this)); - addChangeListener(new ChangeListener() { - public void stateChanged(ChangeEvent e) - { - updateTabComponents(); - } - }); - } + @Override + public void addTab(String title, Component component) { + super.addTab(title, component); + int index = getTabCount() - 1; + MyTabComponent tabComponent = new MyTabComponent(title, this); + tabComponent.setTitle(title); + setTabComponentAt(index, tabComponent); + setToolTipTextAt(index, title); + updateTabComponents(); + } - - @Override - public void addTab(String title, Component component) - { - super.addTab(title, component); - int index = getTabCount() - 1; - MyTabComponent tabComponent = new MyTabComponent(title, this); - tabComponent.setTitle(title); - setTabComponentAt(index, tabComponent); - setToolTipTextAt(index, title); - updateTabComponents(); - } - - public boolean isSelectTabComponents(String oId) - { - for(int i=0;i= values().length) { + return NOTSURE_ISSURE; // 传入非法数据,默认为待定 + } + return values()[i]; + } + } } \ No newline at end of file diff --git a/src/cppcheckplus/text/FileTools.java b/src/cppcheckplus/text/FileTools.java index 95dd4fb..9da0c75 100644 --- a/src/cppcheckplus/text/FileTools.java +++ b/src/cppcheckplus/text/FileTools.java @@ -7,7 +7,6 @@ import java.io.FileOutputStream; import java.io.FileReader; import java.io.FileWriter; import java.util.Vector; - import org.dom4j.Document; import org.dom4j.DocumentHelper; import org.dom4j.Element; @@ -16,69 +15,71 @@ import org.dom4j.io.XMLWriter; public class FileTools { - public static String readFile(File file) { - StringBuilder resultStr = new StringBuilder(); - try { - BufferedReader bReader = new BufferedReader(new FileReader(file)); - String line = bReader.readLine(); - while (line != null) { - resultStr.append(line + "\r\n"); - line = bReader.readLine(); - } - bReader.close(); - } catch (Exception e) { - e.printStackTrace(); - } - return resultStr.toString(); - } + public static String readFile(File file) { + StringBuilder resultStr = new StringBuilder(); + try { + BufferedReader bReader = new BufferedReader(new FileReader(file)); + String line = bReader.readLine(); + while (line != null) { + resultStr.append(line + "\r\n"); + line = bReader.readLine(); + } + bReader.close(); + } catch (Exception e) { + e.printStackTrace(); + } + return resultStr.toString(); + } - public static void writeFile(File file, String str) { - try { - BufferedWriter bWriter = new BufferedWriter(new FileWriter(file)); - bWriter.write(str); - bWriter.close(); - } catch (Exception e) { - e.printStackTrace(); - } - } + public static void writeFile(File file, String str) { + try { + BufferedWriter bWriter = new BufferedWriter(new FileWriter(file)); + bWriter.write(str); + bWriter.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } - public static void writeFile(File file, Vector rows) {// xml - try { - Document doc = DocumentHelper.createDocument(); - Element root = doc.addElement("缺陷报告"); - int n = 0; - if (rows != null && rows.size() > 0) { - for (DeflectRow row : rows) { - if (row.getIssure() == 0 || row.getIssure() == 2) - continue; - n++; - Element empEle = root.addElement("item"); + public static void writeFile(File file, Vector rows) {// xml + try { + Document doc = DocumentHelper.createDocument(); + Element root = doc.addElement("缺陷报告"); + int n = 0; + if (rows != null && rows.size() > 0) { + for (DeflectRow row : rows) { + if (row.getIssure() == DeflectRow.Issure.WRONG_ISSURE) { + continue; + } + n++; + Element empEle = root.addElement("item"); - Element untilEle = empEle.addElement("工具"); - untilEle.addText(row.getUntil()); - Element fileEle = empEle.addElement("文件路径"); - fileEle.addText(row.getFile()); - Element lineEle = empEle.addElement("行号"); - lineEle.addText(row.getLine()); - Element levelEle = empEle.addElement("级别"); - levelEle.addText(row.getLevel()); - Element typeEle = empEle.addElement("类型"); - typeEle.addText(row.getType()); - Element descEle = empEle.addElement("描述"); - descEle.addText(row.getDescription()); - empEle.addAttribute("id", n + ""); - } - XMLWriter writer = new XMLWriter(OutputFormat.createPrettyPrint()); - FileOutputStream fos = new FileOutputStream(file); - writer.setOutputStream(fos); - writer.write(doc); - System.out.println("写出完毕!"); - writer.close(); + Element untilEle = empEle.addElement("工具"); + untilEle.addText(row.getUntil()); + Element fileEle = empEle.addElement("文件路径"); + fileEle.addText(row.getFile()); + Element lineEle = empEle.addElement("行号"); + lineEle.addText(row.getLine()); + Element levelEle = empEle.addElement("级别"); + levelEle.addText(row.getLevel()); + Element typeEle = empEle.addElement("类型"); + typeEle.addText(row.getType()); + Element descEle = empEle.addElement("描述"); + descEle.addText(row.getDescription()); + empEle.addAttribute("id", n + ""); + } + XMLWriter writer = + new XMLWriter(OutputFormat.createPrettyPrint()); + FileOutputStream fos = new FileOutputStream(file); + writer.setOutputStream(fos); + writer.write(doc); + System.out.println("写出完毕!"); + writer.close(); - } - } catch (Exception e) { - e.printStackTrace(); - } - } + } + } catch (Exception e) { + e.printStackTrace(); + } + } } \ No newline at end of file diff --git a/src/cppcheckplus/text/LineNumberHeaderView.java b/src/cppcheckplus/text/LineNumberHeaderView.java index 85819fa..af837fa 100644 --- a/src/cppcheckplus/text/LineNumberHeaderView.java +++ b/src/cppcheckplus/text/LineNumberHeaderView.java @@ -7,74 +7,76 @@ import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.Rectangle; -public class LineNumberHeaderView extends javax.swing.JComponent { +public class LineNumberHeaderView extends javax.swing.JComponent { - private final Font DEFAULT_FONT = new Font("Serif", 0, 16); - public final Color DEFAULT_BACKGROUD = new Color(228, 228, 228); - public final Color DEFAULT_FOREGROUD = Color.BLACK; - public final int nHEIGHT = Integer.MAX_VALUE - 1000000; - public final int MARGIN = 2; - private int lineHeight; - private int fontLineHeight; - private int currentRowWidth; - private FontMetrics fontMetrics; - - public LineNumberHeaderView() { - setFont(DEFAULT_FONT); - setForeground(DEFAULT_FOREGROUD); - setBackground(DEFAULT_BACKGROUD); - setPreferredSize(9999); - } - - public void setPreferredSize(int row) { - int width = fontMetrics.stringWidth(String.valueOf(row)); - if (currentRowWidth < width) { - currentRowWidth = width; - setPreferredSize(new Dimension(2 * MARGIN + width, nHEIGHT)); - } - } - - @Override - public void setFont(Font font) { - super.setFont(font); - fontMetrics = getFontMetrics(getFont()); - fontLineHeight = fontMetrics.getHeight(); - } - - public int getLineHeight() { - if (lineHeight == 0) { - return fontLineHeight; - } - return lineHeight; - } - - public void setLineHeight(int lineHeight) { - if (lineHeight > 0) { - this.lineHeight = lineHeight; - } - } - - public int getStartOffset() { - return 0; - } - - @Override - protected void paintComponent(Graphics g) { - int nlineHeight = getLineHeight(); - int startOffset = getStartOffset(); - Rectangle drawHere = g.getClipBounds(); - g.setColor(getBackground()); - g.fillRect(drawHere.x, drawHere.y, drawHere.width, drawHere.height); - g.setColor(getForeground()); - int startLineNum = (drawHere.y / nlineHeight) + 1; - int endLineNum = startLineNum + (drawHere.height / nlineHeight); - int start = (drawHere.y / nlineHeight) * nlineHeight + nlineHeight - startOffset; - for (int i = startLineNum; i <= endLineNum; ++i) { - String lineNum = String.valueOf(i); - int width = fontMetrics.stringWidth(lineNum); - g.drawString(lineNum + " ", MARGIN + currentRowWidth - width - 1, start); - start += nlineHeight; - } - setPreferredSize(endLineNum); - } + public final Color DEFAULT_BACKGROUD = new Color(228, 228, 228); + public final Color DEFAULT_FOREGROUD = Color.BLACK; + public final int nHEIGHT = Integer.MAX_VALUE - 1000000; + public final int MARGIN = 2; + private final Font DEFAULT_FONT = new Font("Serif", 0, 16); + private int lineHeight; + private int fontLineHeight; + private int currentRowWidth; + private FontMetrics fontMetrics; + + public LineNumberHeaderView() { + setFont(DEFAULT_FONT); + setForeground(DEFAULT_FOREGROUD); + setBackground(DEFAULT_BACKGROUD); + setPreferredSize(9999); + } + + public void setPreferredSize(int row) { + int width = fontMetrics.stringWidth(String.valueOf(row)); + if (currentRowWidth < width) { + currentRowWidth = width; + setPreferredSize(new Dimension(2 * MARGIN + width, nHEIGHT)); + } + } + + @Override + public void setFont(Font font) { + super.setFont(font); + fontMetrics = getFontMetrics(getFont()); + fontLineHeight = fontMetrics.getHeight(); + } + + public int getLineHeight() { + if (lineHeight == 0) { + return fontLineHeight; + } + return lineHeight; + } + + public void setLineHeight(int lineHeight) { + if (lineHeight > 0) { + this.lineHeight = lineHeight; + } + } + + public int getStartOffset() { + return 0; + } + + @Override + protected void paintComponent(Graphics g) { + int nlineHeight = getLineHeight(); + int startOffset = getStartOffset(); + Rectangle drawHere = g.getClipBounds(); + g.setColor(getBackground()); + g.fillRect(drawHere.x, drawHere.y, drawHere.width, drawHere.height); + g.setColor(getForeground()); + int startLineNum = (drawHere.y / nlineHeight) + 1; + int endLineNum = startLineNum + (drawHere.height / nlineHeight); + int start = (drawHere.y / nlineHeight) * nlineHeight + nlineHeight - + startOffset; + for (int i = startLineNum; i <= endLineNum; ++i) { + String lineNum = String.valueOf(i); + int width = fontMetrics.stringWidth(lineNum); + g.drawString(lineNum + " ", MARGIN + currentRowWidth - width - 1, + start); + start += nlineHeight; + } + setPreferredSize(endLineNum); + } } diff --git a/src/cppcheckplus/text/MyButtonEditor.java b/src/cppcheckplus/text/MyButtonEditor.java index 6ce0007..22345e3 100644 --- a/src/cppcheckplus/text/MyButtonEditor.java +++ b/src/cppcheckplus/text/MyButtonEditor.java @@ -1,10 +1,10 @@ package cppcheckplus.text; +import cppcheckplus.control.MyContorlUtil; import java.awt.BorderLayout; import java.awt.Component; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; - import javax.swing.AbstractCellEditor; import javax.swing.Icon; import javax.swing.JButton; @@ -13,76 +13,76 @@ import javax.swing.JPanel; import javax.swing.JTable; import javax.swing.table.TableCellEditor; -import cppcheckplus.control.MyContorlUtil; - -public class MyButtonEditor extends AbstractCellEditor implements TableCellEditor { - - /** - * serialVersionUID - */ - private static final long serialVersionUID = -6546334664166791132L; - - private JPanel panel; - - private JButton button; - - private int state; - public static Icon icon0; - public static Icon icon1; - public static Icon icon2; - public MyButtonEditor() { - - initButton(); - - initPanel(); - - panel.add(this.button, BorderLayout.CENTER); - } - - private void initButton() { - button = new JButton(); - - icon0 = MyContorlUtil.getImageIcon("control/images/onError.gif"); - icon1 = MyContorlUtil.getImageIcon("control/images/agree_ok.gif"); - icon2 = MyContorlUtil.getImageIcon("control/images/agree_no.gif"); - button.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - int res = JOptionPane.showConfirmDialog(null, "你想确认报告吗?", "choose one", - JOptionPane.YES_NO_OPTION); - - if (res == JOptionPane.YES_OPTION) { - state=(state+1)%3; - } - // stopped!!!! - fireEditingStopped(); - - } - }); - - } - - private void initPanel() { - panel = new JPanel(); - - panel.setLayout(new BorderLayout()); - } - - @Override - public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { - state = (Integer) value; - - if(state==0) - button.setIcon(icon0); - else if(state==1) - button.setIcon(icon1); - else if(state==2) - button.setIcon(icon2); - return panel; - } - - @Override - public Object getCellEditorValue() { - return state; - } +public class MyButtonEditor extends AbstractCellEditor + implements TableCellEditor { + + /** + * serialVersionUID + */ + private static final long serialVersionUID = -6546334664166791132L; + public static Icon[] icon = new Icon[3]; + // public static Icon icon[1]; +// public static Icon icon[2]; + private JPanel panel; + private JButton button; + private DeflectRow.Issure state = DeflectRow.Issure.NOTSURE_ISSURE; + + public MyButtonEditor() { + initButton(); + initPanel(); + panel.add(this.button, BorderLayout.CENTER); + } + + private void initButton() { + button = new JButton(); + + icon[0] = + MyContorlUtil.getImageIcon("control/images/agree_notsure.png"); + icon[1] = MyContorlUtil.getImageIcon("control/images/agree_ok.gif"); + icon[2] = MyContorlUtil.getImageIcon("control/images/agree_no.gif"); + button.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + Object[] options = {"待定", "确认", "误报"}; + int res = JOptionPane.showOptionDialog(null, "请确认报告状态", + "选择状态", JOptionPane.DEFAULT_OPTION, + JOptionPane.QUESTION_MESSAGE, null, options, options[0]); + state = DeflectRow.Issure.values()[res]; + fireEditingStopped(); + } + }); + } + + private void initPanel() { + panel = new JPanel(); + + panel.setLayout(new BorderLayout()); + } + + @Override + public Component getTableCellEditorComponent(JTable table, Object value, + boolean isSelected, int row, + int column) { + state = (DeflectRow.Issure) value; + switch (state) { + case NOTSURE_ISSURE: + button.setIcon(icon[0]); + break; + case CURRECT_ISSURE: + button.setIcon(icon[1]); + break; + case WRONG_ISSURE: + button.setIcon(icon[2]); + break; + default: + button.setIcon(icon[0]); + break; + } + return panel; + } + + @Override + public Object getCellEditorValue() { + return state; + } } \ No newline at end of file diff --git a/src/cppcheckplus/text/MyButtonRenderer.java b/src/cppcheckplus/text/MyButtonRenderer.java index e030620..0ff148b 100644 --- a/src/cppcheckplus/text/MyButtonRenderer.java +++ b/src/cppcheckplus/text/MyButtonRenderer.java @@ -1,26 +1,20 @@ package cppcheckplus.text; +import cppcheckplus.control.MyContorlUtil; import java.awt.BorderLayout; import java.awt.Component; - import javax.swing.Icon; import javax.swing.JButton; import javax.swing.JPanel; import javax.swing.JTable; import javax.swing.table.TableCellRenderer; -import cppcheckplus.control.MyContorlUtil; - public class MyButtonRenderer implements TableCellRenderer { + public static Icon[] icon = new Icon[3]; private JPanel panel; - private JButton button; + private DeflectRow.Issure state = DeflectRow.Issure.NOTSURE_ISSURE; - public static Icon icon0; - public static Icon icon1; - public static Icon icon2; - private int state;//0是未确认, 1是确认正确, 2是确认误报 - public MyButtonRenderer() { initButton(); @@ -31,15 +25,24 @@ public class MyButtonRenderer implements TableCellRenderer { private void initButton() { button = new JButton(); - icon0 = MyContorlUtil.getImageIcon("control/images/onError.gif"); - icon1 = MyContorlUtil.getImageIcon("control/images/agree_ok.gif"); - icon2 = MyContorlUtil.getImageIcon("control/images/agree_no.gif"); - if(state==0) - button.setIcon(icon0); - else if(state==1) - button.setIcon(icon1); - else if(state==2) - button.setIcon(icon2); + icon[0] = + MyContorlUtil.getImageIcon("control/images/agree_notsure.png"); + icon[1] = MyContorlUtil.getImageIcon("control/images/agree_ok.gif"); + icon[2] = MyContorlUtil.getImageIcon("control/images/agree_no.gif"); + switch (state) { + case NOTSURE_ISSURE: + button.setIcon(icon[0]); + break; + case CURRECT_ISSURE: + button.setIcon(icon[1]); + break; + case WRONG_ISSURE: + button.setIcon(icon[2]); + break; + default: + button.setIcon(icon[0]); + break; + } } private void initPanel() { @@ -48,14 +51,24 @@ public class MyButtonRenderer implements TableCellRenderer { } public Component getTableCellRendererComponent(JTable table, Object value, - boolean isSelected, boolean hasFocus, int row, int column) { - state = (Integer) value; - if(state==0) - button.setIcon(icon0); - else if(state==1) - button.setIcon(icon1); - else if(state==2) - button.setIcon(icon2); + boolean isSelected, + boolean hasFocus, int row, + int column) { + state = (DeflectRow.Issure) value; + switch (state) { + case NOTSURE_ISSURE: + button.setIcon(icon[0]); + break; + case CURRECT_ISSURE: + button.setIcon(icon[1]); + break; + case WRONG_ISSURE: + button.setIcon(icon[2]); + break; + default: + button.setIcon(icon[0]); + break; + } return panel; } diff --git a/src/cppcheckplus/text/MyPanel.java b/src/cppcheckplus/text/MyPanel.java index cec59ac..89aae3a 100644 --- a/src/cppcheckplus/text/MyPanel.java +++ b/src/cppcheckplus/text/MyPanel.java @@ -1,31 +1,34 @@ package cppcheckplus.text; +import cppcheckplus.control.MyContorlUtil; import java.awt.BorderLayout; import java.awt.Graphics; import java.awt.Image; - import javax.swing.ImageIcon; import javax.swing.JPanel; -import cppcheckplus.control.MyContorlUtil; +public class MyPanel extends JPanel { + ImageIcon icon; + Image img; -public class MyPanel extends JPanel{ - ImageIcon icon; - Image img; - public MyPanel(){ - // /img/HomeImg.jpg 是存放在你正在编写的项目的bin文件夹下的img文件夹下的一个图片 - icon=new ImageIcon(MyContorlUtil.getImage("control/images/back2.jpg")); - img=icon.getImage(); + public MyPanel() { + // /img/HomeImg.jpg 是存放在你正在编写的项目的bin文件夹下的img文件夹下的一个图片 + icon = + new ImageIcon(MyContorlUtil.getImage("control/images/back2.jpg")); + img = icon.getImage(); } + public MyPanel(BorderLayout borderLayout) { - icon=new ImageIcon(MyContorlUtil.getImage("control/images/back2.jpg")); - img=icon.getImage(); + icon = + new ImageIcon(MyContorlUtil.getImage("control/images/back2.jpg")); + img = icon.getImage(); setLayout(borderLayout); - } - public void paintComponent(Graphics g) { - super.paintComponent(g); + } + + public void paintComponent(Graphics g) { + super.paintComponent(g); //下面这行是为了背景图片可以跟随窗口自行调整大小,可以自己设置成固定大小 - g.drawImage(img, 0, 0,this.getWidth(), this.getHeight(), this); - } + g.drawImage(img, 0, 0, this.getWidth(), this.getHeight(), this); + } } diff --git a/src/cppcheckplus/text/MyTextArea.java b/src/cppcheckplus/text/MyTextArea.java index 9860093..9c6c101 100644 --- a/src/cppcheckplus/text/MyTextArea.java +++ b/src/cppcheckplus/text/MyTextArea.java @@ -1,60 +1,60 @@ package cppcheckplus.text; +import cppcheckplus.control.MyContorlUtil; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Image; import java.awt.TexturePaint; - import javax.swing.BorderFactory; import javax.swing.ImageIcon; import javax.swing.JTextArea; import javax.swing.border.Border; import javax.swing.plaf.metal.MetalTextFieldUI; -import cppcheckplus.control.MyContorlUtil; - -public class MyTextArea extends JTextArea{ - private Image backgroundLeftImage; - private Image backgroundRightImage; - private ImageIcon backgroundImageIcon; - private TexturePaint paint; - private Border border; - - public MyTextArea () - { - backgroundLeftImage = MyContorlUtil.getImage("xujun/control/images/textfield_background_left.png"); - backgroundRightImage = MyContorlUtil.getImage("xujun/control/images/textfield_background_right.png"); - backgroundImageIcon = MyContorlUtil.getImageIcon("xujun/control/images/textfield_background.png"); - paint = MyContorlUtil.createTexturePaint("xujun/control/images/textfield_background.png"); - border = BorderFactory.createEmptyBorder(1, 3, 1, 3); - init(); - } - public MyTextArea (String text) - { - this(); - setText(text); - } - - private void init() - { - setBorder(border); - setUI(new MetalTextFieldUI() { - - protected void paintBackground(Graphics g) - { - Graphics2D g2d = (Graphics2D)g; - g2d.setPaint(paint); - g2d.fillRect(0, 0, getWidth(), getHeight()); - g2d.drawImage(backgroundLeftImage, 0, 0, null); - g2d.drawImage(backgroundRightImage, getWidth() - backgroundRightImage.getWidth(null), 0, null); - } - - }); - } - - public Dimension getPreferredSize() - { - return new Dimension(super.getPreferredSize().width, backgroundImageIcon.getIconHeight()); - } +public class MyTextArea extends JTextArea { + private Image backgroundLeftImage; + private Image backgroundRightImage; + private ImageIcon backgroundImageIcon; + private TexturePaint paint; + private Border border; + + public MyTextArea() { + backgroundLeftImage = MyContorlUtil.getImage( + "xujun/control/images/textfield_background_left.png"); + backgroundRightImage = MyContorlUtil.getImage( + "xujun/control/images/textfield_background_right.png"); + backgroundImageIcon = MyContorlUtil.getImageIcon( + "xujun/control/images/textfield_background.png"); + paint = MyContorlUtil.createTexturePaint( + "xujun/control/images/textfield_background.png"); + border = BorderFactory.createEmptyBorder(1, 3, 1, 3); + init(); + } + + public MyTextArea(String text) { + this(); + setText(text); + } + + private void init() { + setBorder(border); + setUI(new MetalTextFieldUI() { + + protected void paintBackground(Graphics g) { + Graphics2D g2d = (Graphics2D) g; + g2d.setPaint(paint); + g2d.fillRect(0, 0, getWidth(), getHeight()); + g2d.drawImage(backgroundLeftImage, 0, 0, null); + g2d.drawImage(backgroundRightImage, + getWidth() - backgroundRightImage.getWidth(null), 0, null); + } + + }); + } + + public Dimension getPreferredSize() { + return new Dimension(super.getPreferredSize().width, + backgroundImageIcon.getIconHeight()); + } } diff --git a/src/cppcheckplus/text/MyTextPanel.java b/src/cppcheckplus/text/MyTextPanel.java index 8ef60c4..d2f29ee 100644 --- a/src/cppcheckplus/text/MyTextPanel.java +++ b/src/cppcheckplus/text/MyTextPanel.java @@ -1,72 +1,64 @@ - package cppcheckplus.text; +import cppcheckplus.control.XChartletFullScreenListenter; import java.awt.BorderLayout; import java.awt.Font; - import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextArea; -import cppcheckplus.control.XChartletFullScreenListenter; +public class MyTextPanel extends JPanel + implements XChartletFullScreenListenter { + public static final int LINEHEIGHT = 16; + private BorderLayout layout; + private boolean isFullScreen; + private JTextArea textArea; + private JScrollPane scroll; + private LineNumberHeaderView lineNumberHeader = null; + + public MyTextPanel() { + layout = new BorderLayout(); + setLayout(layout); + textArea = new JTextArea(""); + Font x = new Font("Serif", 0, LINEHEIGHT); + textArea.setFont(x); + scroll = new JScrollPane(textArea); + //scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); + //scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); + //scroll.setPreferredSize(new Dimension(300, 200)); + + if (lineNumberHeader == null) { + lineNumberHeader = new LineNumberHeaderView(); + //设置行号的高度,如果和textarea的行高不匹配,可以修改此值 + lineNumberHeader.setLineHeight(LINEHEIGHT + 4); + } + scroll.setRowHeaderView(lineNumberHeader); + add(scroll); + } + + public JTextArea getTextArea() { + return textArea; + } -public class MyTextPanel extends JPanel implements XChartletFullScreenListenter -{ - private BorderLayout layout; - private boolean isFullScreen; - private JTextArea textArea; - private JScrollPane scroll; - private LineNumberHeaderView lineNumberHeader=null; - public static final int LINEHEIGHT =16; - public JTextArea getTextArea() { - return textArea; - } - - - public MyTextPanel() - { - layout = new BorderLayout(); - setLayout(layout); - textArea=new JTextArea(""); - Font x = new Font("Serif",0,LINEHEIGHT); - textArea.setFont(x); - scroll = new JScrollPane(textArea); - //scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); - //scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); - //scroll.setPreferredSize(new Dimension(300, 200)); - - if (lineNumberHeader == null) { - lineNumberHeader = new LineNumberHeaderView(); - //设置行号的高度,如果和textarea的行高不匹配,可以修改此值 - lineNumberHeader.setLineHeight(LINEHEIGHT+4); - } - scroll.setRowHeaderView(lineNumberHeader); - add(scroll); - } - - public void initialize() - { - setLayout(layout); - add(scroll); - } + public void initialize() { + setLayout(layout); + add(scroll); + } - @Override - public void fullScreen(JPanel chartPanellet) - { - removeAll(); - isFullScreen = !isFullScreen; - if (isFullScreen) - { - setLayout(new BorderLayout()); - add(chartPanellet, "Center"); - } else - { - initialize(); - } - repaint(); - revalidate(); - } + @Override + public void fullScreen(JPanel chartPanellet) { + removeAll(); + isFullScreen = !isFullScreen; + if (isFullScreen) { + setLayout(new BorderLayout()); + add(chartPanellet, "Center"); + } else { + initialize(); + } + repaint(); + revalidate(); + } } diff --git a/src/cppcheckplus/text/MyTextPanel1.java b/src/cppcheckplus/text/MyTextPanel1.java index fb07c7d..5553995 100644 --- a/src/cppcheckplus/text/MyTextPanel1.java +++ b/src/cppcheckplus/text/MyTextPanel1.java @@ -1,59 +1,53 @@ package cppcheckplus.text; +import cppcheckplus.control.XChartletFullScreenListenter; import java.awt.BorderLayout; -import java.awt.TextArea; import java.awt.Font; +import java.awt.TextArea; import javax.swing.JPanel; -import cppcheckplus.control.XChartletFullScreenListenter; - - -public class MyTextPanel1 extends JPanel implements XChartletFullScreenListenter -{ - private BorderLayout layout; - private boolean isFullScreen; - private TextArea textArea; - - public TextArea getTextArea() { - return textArea; - } - public void setTextArea(TextArea textArea) { - this.textArea = textArea; - } - - public MyTextPanel1() - { - layout = new BorderLayout(); - setLayout(layout); - textArea=new TextArea(""); - textArea.setFont(new Font("MonoSpaced", Font.PLAIN, 12)); - - add(textArea); - } - - public void initialize() - { - setLayout(layout); - add(textArea); - } - - - @Override - public void fullScreen(JPanel chartPanellet) - { - removeAll(); - isFullScreen = !isFullScreen; - if (isFullScreen) - { - setLayout(new BorderLayout()); - add(chartPanellet, "Center"); - } else - { - initialize(); - } - repaint(); - revalidate(); - } +public class MyTextPanel1 extends JPanel + implements XChartletFullScreenListenter { + private BorderLayout layout; + private boolean isFullScreen; + private TextArea textArea; + + public MyTextPanel1() { + layout = new BorderLayout(); + setLayout(layout); + textArea = new TextArea(""); + textArea.setFont(new Font("MonoSpaced", Font.PLAIN, 12)); + + add(textArea); + } + + public TextArea getTextArea() { + return textArea; + } + + public void setTextArea(TextArea textArea) { + this.textArea = textArea; + } + + public void initialize() { + setLayout(layout); + add(textArea); + } + + + @Override + public void fullScreen(JPanel chartPanellet) { + removeAll(); + isFullScreen = !isFullScreen; + if (isFullScreen) { + setLayout(new BorderLayout()); + add(chartPanellet, "Center"); + } else { + initialize(); + } + repaint(); + revalidate(); + } } diff --git a/src/cppcheckplus/text/ViewPanel.java b/src/cppcheckplus/text/ViewPanel.java index c5b79d9..6c1a765 100644 --- a/src/cppcheckplus/text/ViewPanel.java +++ b/src/cppcheckplus/text/ViewPanel.java @@ -1,72 +1,65 @@ package cppcheckplus.text; +import cppcheckplus.control.XChartletFullScreenListenter; import java.awt.BorderLayout; import java.util.Vector; - import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.table.DefaultTableModel; import javax.swing.table.TableColumn; -import cppcheckplus.control.XChartletFullScreenListenter; - public class ViewPanel extends JPanel implements XChartletFullScreenListenter { - private static final long serialVersionUID = 1L; - private DefaultTableModel model; - private JScrollPane jsp; - private JTable table; - private Vector results=new Vector(); - private BorderLayout layout; - private boolean isFullScreen; - - public JTable getTable() { - return table; - } - - public void setTable(JTable table) { - this.table = table; - } - - public ViewPanel() { - - layout = new BorderLayout(); - setLayout(layout); - - String[] colnames = { "序号", "工具", "文件", "行号", "级别", "类型", "描述", "人工确认" }; - // 填充数据 - model = new DefaultTableModel(colnames, 0){ - @Override - public Object getValueAt(int row, int column) { - if(results!=null && row results = new Vector(); + private BorderLayout layout; + private boolean isFullScreen; + + public ViewPanel() { + + layout = new BorderLayout(); + setLayout(layout); + + String[] colnames = + {"序号", "工具", "文件", "行号", "级别", "类型", "描述", + "人工确认"}; + // 填充数据 + model = new DefaultTableModel(colnames, 0) { + @Override + public Object getValueAt(int row, int column) { + if (results != null && row < results.size()) { + switch (column) { + case 1: + return results.elementAt(row).getUntil(); + case 2: + return results.elementAt(row).getFile(); + case 3: + return results.elementAt(row).getLine(); + case 4: + return results.elementAt(row).getLevel(); + case 5: + return results.elementAt(row).getType(); + case 6: + return results.elementAt(row).getDescription(); + case 7: + return results.elementAt(row).getIssure(); + case 0: + return row + 1; + } + } + return null; + } + @Override public boolean isCellEditable(int row, int column) { - if (column == 7 || column == 2 || column == 5) + if (column == 7 || column == 2 || column == 5) { return true; + } return false; } /* @@ -79,135 +72,146 @@ public class ViewPanel extends JPanel implements XChartletFullScreenListenter { public int getColumnCount() { return 8; } - + @Override - public void setValueAt(Object aValue, int row, int column){ - if(results!=null && row rows) { - this(); - results = rows; - fillTable(results); - } - - public void clearTable() { - model.setRowCount(0);// 清除原有行 - results.clear(); - table.invalidate(); - } - - public void update(Vector rows) { - results = rows; - fillTable(results); - } - - public void initialize() { - setLayout(layout); - add(jsp); - } - - public void fillTable(Vector rows) { - - model.setRowCount(0);// 清除原有行 - int n = 0; - if (rows != null && rows.size() > 0) { - for (DeflectRow row : rows) { - n++; - Object[] arr = new Object[8]; - arr[0] = String.valueOf(n); - arr[1] = row.getUntil(); - arr[2] = row.getFile(); - arr[3] = row.getLine(); - arr[4] = row.getLevel(); - arr[5] = row.getType(); - arr[6] = row.getDescription(); - arr[7] = row.getIssure(); - // 添加数据到表格 - model.addRow(arr); - } - } - table.invalidate(); - } - - @Override - public void fullScreen(JPanel chartPanellet) { - removeAll(); - isFullScreen = !isFullScreen; - if (isFullScreen) { - setLayout(new BorderLayout()); - add(chartPanellet, "Center"); - } else { - initialize(); - } - repaint(); - revalidate(); - } + jsp = new JScrollPane(table); + add(jsp, BorderLayout.CENTER); + } + + public ViewPanel(Vector rows) { + this(); + results = rows; + fillTable(results); + } + + public JTable getTable() { + return table; + } + + public void setTable(JTable table) { + this.table = table; + } + + public void clearTable() { + model.setRowCount(0);// 清除原有行 + results.clear(); + table.invalidate(); + } + + public void update(Vector rows) { + results = rows; + fillTable(results); + } + + public void initialize() { + setLayout(layout); + add(jsp); + } + + public void fillTable(Vector rows) { + + model.setRowCount(0);// 清除原有行 + int n = 0; + if (rows != null && rows.size() > 0) { + for (DeflectRow row : rows) { + n++; + Object[] arr = new Object[8]; + arr[0] = String.valueOf(n); + arr[1] = row.getUntil(); + arr[2] = row.getFile(); + arr[3] = row.getLine(); + arr[4] = row.getLevel(); + arr[5] = row.getType(); + arr[6] = row.getDescription(); + arr[7] = row.getIssure(); + // 添加数据到表格 + model.addRow(arr); + } + } + table.invalidate(); + } + + @Override + public void fullScreen(JPanel chartPanellet) { + removeAll(); + isFullScreen = !isFullScreen; + if (isFullScreen) { + setLayout(new BorderLayout()); + add(chartPanellet, "Center"); + } else { + initialize(); + } + repaint(); + revalidate(); + } } diff --git a/src/cppcheckplus/text/creatTable.java b/src/cppcheckplus/text/creatTable.java index 0295eb6..f261e3a 100644 --- a/src/cppcheckplus/text/creatTable.java +++ b/src/cppcheckplus/text/creatTable.java @@ -1,321 +1,328 @@ package cppcheckplus.text; +import cppcheckplus.control.MyContorlUtil; import java.util.Vector; import java.util.regex.Pattern; - import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; - import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; -import cppcheckplus.control.MyContorlUtil; - public class creatTable { - public String tableNameTemp = ""; - public Vector cppcheckplusResults = new Vector(); - public Vector flawfinderResults = new Vector(); - public Vector clangResults = new Vector(); - public Vector results = new Vector(); + public String tableNameTemp = ""; + public Vector cppcheckplusResults = new Vector(); + public Vector flawfinderResults = new Vector(); + public Vector clangResults = new Vector(); + public Vector results = new Vector(); public Vector stdclang = new Vector(); - - public void initSTDClang(String xml){ - try - { - DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - DocumentBuilder db = dbf.newDocumentBuilder(); - Document doc = db.parse(MyContorlUtil.getXMLFile(xml)); - Element root = doc.getDocumentElement(); - NodeList stdlist = root.getChildNodes(); - if (stdlist != null) - { - for (int i = 0; i < stdlist.getLength(); i++) - { - org.w3c.dom.Node menu = stdlist.item(i); - if (menu.getNodeType() == Node.ELEMENT_NODE) - { - if (menu.getNodeName().equalsIgnoreCase("clangNode")) - { - stdClangType node = new stdClangType(); - node.cwe=MyContorlUtil.getStringAttribute(menu, "cwe"); - node.level=MyContorlUtil.getStringAttribute(menu, "level"); - node.target=MyContorlUtil.getStringAttribute(menu, "target"); - node.len=Integer.valueOf(MyContorlUtil.getStringAttribute(menu, "len")); - node.type=MyContorlUtil.getStringAttribute(menu, "type"); - stdclang.add(node); - } - } - } - } - } - catch (Exception ex) - { - ex.printStackTrace(); - } + + public static void addObject(Vector nodes, DeflectRow node) { + if (!nodes.contains(node)) { + nodes.add(node); + } else {//重复检测的缺陷需要标注 + int nodesNum = nodes.size(); + for (int i = 0; i < nodesNum; i++) { + if (nodes.elementAt(i).equals(node)) + // FIXME: 这里作用不明 + { + nodes.elementAt(i) + .setIssure(DeflectRow.Issure.CURRECT_ISSURE); + } + } + } + } + + public void initSTDClang(String xml) { + try { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + DocumentBuilder db = dbf.newDocumentBuilder(); + Document doc = db.parse(MyContorlUtil.getXMLFile(xml)); + Element root = doc.getDocumentElement(); + NodeList stdlist = root.getChildNodes(); + if (stdlist != null) { + for (int i = 0; i < stdlist.getLength(); i++) { + org.w3c.dom.Node menu = stdlist.item(i); + if (menu.getNodeType() == Node.ELEMENT_NODE) { + if (menu.getNodeName().equalsIgnoreCase("clangNode")) { + stdClangType node = new stdClangType(); + node.cwe = + MyContorlUtil.getStringAttribute(menu, "cwe"); + node.level = + MyContorlUtil.getStringAttribute(menu, "level"); + node.target = MyContorlUtil.getStringAttribute(menu, + "target"); + node.len = Integer.valueOf( + MyContorlUtil.getStringAttribute(menu, "len")); + node.type = + MyContorlUtil.getStringAttribute(menu, "type"); + stdclang.add(node); + } + } + } + } + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + public void makeTable() {// 统一并输出 + results.clear(); + for (int i = 0; i < cppcheckplusResults.size(); i++) { + addObject(results, cppcheckplusResults.elementAt(i)); + } + for (int i = 0; i < clangResults.size(); i++) { + addObject(results, clangResults.elementAt(i)); + } + for (int i = 0; i < flawfinderResults.size(); i++) { + addObject(results, flawfinderResults.elementAt(i)); + } } - - public void makeTable() {// 统一并输出 - results.clear(); - for (int i = 0; i < cppcheckplusResults.size(); i++) { - addObject(results,cppcheckplusResults.elementAt(i)); - } - for (int i = 0; i < clangResults.size(); i++) { - addObject(results,clangResults.elementAt(i)); - } - for (int i = 0; i < flawfinderResults.size(); i++) { - addObject(results,flawfinderResults.elementAt(i)); - } - } - - public void clearall() {// 清除 - results.clear(); - clangResults.clear(); - flawfinderResults.clear(); - cppcheckplusResults.clear(); - } - public static void addObject(Vector nodes, DeflectRow node) { - if (!nodes.contains(node)) { - nodes.add(node); - } - else{//重复检测的缺陷需要标注 - int nodesNum = nodes.size(); - for(int i=0; i other = new Vector(); - if(ordType==1){//按照文件排序 - int memNum = results.size(); - for(int i=0; i results.elementAt(j+1).getFile().hashCode()){ - DeflectRow temp=results.elementAt(j); - results.set(j, results.elementAt(j+1)); - results.set(j+1, temp); - } - } - } - } - else if(ordType==2){//按照类型排序 - int memNum = results.size(); - for(int i=0; i results.elementAt(j+1).getType().hashCode()){ - DeflectRow temp=results.elementAt(j); - results.set(j, results.elementAt(j+1)); - results.set(j+1, temp); - } - } - } - } - else if(ordType==3){//按照级别筛选 - int memNum = results.size(); - for(int i=0; i results.elementAt(j+1).getLevel().hashCode()){ - DeflectRow temp=results.elementAt(j); - results.set(j, results.elementAt(j+1)); - results.set(j+1, temp); - } - } - } - } - } + public void clearall() {// 清除 + results.clear(); + clangResults.clear(); + flawfinderResults.clear(); + cppcheckplusResults.clear(); + } - public void toRowsOfCppcheckResult(String input) {// - String[] temp = input.split("\\$"); - int size = temp.length; - String until = null; - String file = null; - String line = null; - String level = null; - String type = null; - String cwe = null; - String description = null; - if (size > 6) { - if (temp[1].length() == 0) - return; - until = temp[0]; - file = temp[1]; - line = temp[2]; - level = temp[3]; - if (temp[3].equals("error")) - level = "4"; - else if (temp[3].equals("warning")) - level = "3"; - else if (temp[2].equals("style")) - level = "1"; - else if (temp[2].equals("information")) - level = "0"; - else - level = "2"; - type = temp[4]; - description = temp[5]; - cwe = temp[6]; - DeflectRow node = new DeflectRow(until, file, line, level, type, cwe, description, 0); - stdCppcheck(node); - cppcheckplusResults.add(node); - } - } + //按文件、类型和级别排序 + public void ord(int ordType) {//1文件,2类型,3级别 + //final int prime = 31; + //Vector other = new Vector(); + if (ordType == 1) {//按照文件排序 + int memNum = results.size(); + for (int i = 0; i < memNum - 1; i++) { + for (int j = 0; j < memNum - i - 1; j++) { + if (results.elementAt(j).getFile().hashCode() + > results.elementAt(j + 1).getFile().hashCode()) { + DeflectRow temp = results.elementAt(j); + results.set(j, results.elementAt(j + 1)); + results.set(j + 1, temp); + } + } + } + } else if (ordType == 2) {//按照类型排序 + int memNum = results.size(); + for (int i = 0; i < memNum - 1; i++) { + for (int j = 0; j < memNum - i - 1; j++) { + if (results.elementAt(j).getType().hashCode() + > results.elementAt(j + 1).getType().hashCode()) { + DeflectRow temp = results.elementAt(j); + results.set(j, results.elementAt(j + 1)); + results.set(j + 1, temp); + } + } + } + } else if (ordType == 3) {//按照级别筛选 + int memNum = results.size(); + for (int i = 0; i < memNum - 1; i++) { + for (int j = 0; j < memNum - i - 1; j++) { + if (results.elementAt(j).getLevel().hashCode() + > results.elementAt(j + 1).getLevel().hashCode()) { + DeflectRow temp = results.elementAt(j); + results.set(j, results.elementAt(j + 1)); + results.set(j + 1, temp); + } + } + } + } + } - public void stdCppcheck(DeflectRow node) { - String cwe = node.getCwe(); - int cwenum = Integer.parseInt(cwe); - switch(cwenum){ //cppcheck向flawfinder看齐 - case 134: - node.setLevel("4"); - node.setType("format"); - break; - case 367: - node.setLevel("4"); - node.setType("race"); - break; - case 120: - node.setLevel("4"); - node.setType("buff"); - break; - case 78: - node.setLevel("4"); - node.setType("shell"); - break; - case 327: - node.setLevel("3"); - node.setType("random"); - break; - case 119: - node.setLevel("4"); - node.setType("buffer"); - break; - case 362: - node.setLevel("2"); - node.setType("misc"); - break; - case 190: - node.setLevel("2"); - node.setType("integer"); - break; - default: - ; - } - } + public void toRowsOfCppcheckResult(String input) {// + String[] temp = input.split("\\$"); + int size = temp.length; + String until = null; + String file = null; + String line = null; + String level = null; + String type = null; + String cwe = null; + String description = null; + if (size > 6) { + if (temp[1].length() == 0) { + return; + } + until = temp[0]; + file = temp[1]; + line = temp[2]; + level = temp[3]; + if (temp[3].equals("error")) { + level = "4"; + } else if (temp[3].equals("warning")) { + level = "3"; + } else if (temp[2].equals("style")) { + level = "1"; + } else if (temp[2].equals("information")) { + level = "0"; + } else { + level = "2"; + } + type = temp[4]; + description = temp[5]; + cwe = temp[6]; + DeflectRow node = + new DeflectRow(until, file, line, level, type, cwe, description, + 0); + stdCppcheck(node); + cppcheckplusResults.add(node); + } + } + + public void stdCppcheck(DeflectRow node) { + String cwe = node.getCwe(); + int cwenum = Integer.parseInt(cwe); + switch (cwenum) { //cppcheck向flawfinder看齐 + case 134: + node.setLevel("4"); + node.setType("format"); + break; + case 367: + node.setLevel("4"); + node.setType("race"); + break; + case 120: + node.setLevel("4"); + node.setType("buff"); + break; + case 78: + node.setLevel("4"); + node.setType("shell"); + break; + case 327: + node.setLevel("3"); + node.setType("random"); + break; + case 119: + node.setLevel("4"); + node.setType("buffer"); + break; + case 362: + node.setLevel("2"); + node.setType("misc"); + break; + case 190: + node.setLevel("2"); + node.setType("integer"); + break; + default: + ; + } + } - public void toRowsOfClang(String input) { - String[] temp = input.split(":"); - int size = temp.length; - String until = null; - String file = null; - String line = null; - String column = null; - String level = null; - String type = null; - String cwe = null; - String description = null; - if (size > 5) { - until = "clang-tidy"; - file = temp[0] + ":" + temp[1]; - line = temp[2]; - column = temp[3]; - level = temp[4];// warning,note, error - type = ""; - description = temp[5]; - cwe = "0"; - // 标准化 - DeflectRow node = new DeflectRow(until, file, line, level, type, cwe, description, 0); - stdClang(node); - clangResults.add(node); - } - } + public void toRowsOfClang(String input) { + String[] temp = input.split(":"); + int size = temp.length; + String until = null; + String file = null; + String line = null; + String column = null; + String level = null; + String type = null; + String cwe = null; + String description = null; + if (size > 5) { + until = "clang-tidy"; + file = temp[0] + ":" + temp[1]; + line = temp[2]; + column = temp[3]; + level = temp[4];// warning,note, error + type = ""; + description = temp[5]; + cwe = "0"; + // 标准化 + DeflectRow node = + new DeflectRow(until, file, line, level, type, cwe, description, + 0); + stdClang(node); + clangResults.add(node); + } + } - public void stdClang(DeflectRow node) { - String describ = node.getDescription(); - int len = describ.length(); - boolean isFound = false; - for (int i = 0; i < stdclang.size(); i++) { - if(len>stdclang.elementAt(i).len){ - if (describ.substring(1, stdclang.elementAt(i).len).equals(stdclang.elementAt(i).target)) { - node.setCwe(stdclang.elementAt(i).cwe); - node.setLevel(stdclang.elementAt(i).level); - node.setType(stdclang.elementAt(i).type); - isFound=true; - return; - } - } - } - if(!isFound){ - node.setCwe("未知"); - node.setLevel("2"); - node.setType("other"); - } - } + public void stdClang(DeflectRow node) { + String describ = node.getDescription(); + int len = describ.length(); + boolean isFound = false; + for (int i = 0; i < stdclang.size(); i++) { + if (len > stdclang.elementAt(i).len) { + if (describ.substring(1, stdclang.elementAt(i).len) + .equals(stdclang.elementAt(i).target)) { + node.setCwe(stdclang.elementAt(i).cwe); + node.setLevel(stdclang.elementAt(i).level); + node.setType(stdclang.elementAt(i).type); + isFound = true; + return; + } + } + } + if (!isFound) { + node.setCwe("未知"); + node.setLevel("2"); + node.setType("other"); + } + } - public void toRowsOfFlawfinder(String csvFileName) {// csv + public void toRowsOfFlawfinder(String csvFileName) {// csv - String until = null; - // public String defObject = null; - String file = null; - String location = null; - String level = null; - String type = null; - String function = null; - String description = null; - DeflectRow node = new DeflectRow(until, file, location, level, type, function, description, 0); - } + String until = null; + // public String defObject = null; + String file = null; + String location = null; + String level = null; + String type = null; + String function = null; + String description = null; + DeflectRow node = + new DeflectRow(until, file, location, level, type, function, + description, 0); + } - public boolean isInteger(String str){ - Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$"); - return pattern.matcher(str).matches(); - } - - public void toRowsOfflawfinder(String input) { - // File,Line,Column,Level,Category,Name,Warning,Suggestion,Note,CWEs,Context,Fingerprint - String[] temp = input.split(","); - int size = temp.length; - String until = null; - String file = null; - String line = null; - String column = null; - String level = null; - String category = null; - String name = null; - String warning = null; - String suggestion = null; - String note = null; - String cwe = null; - String context = null; - String fingerprint = null; - if (size > 11) { - if(!isInteger(temp[1])) - return; - until = "flawfinder"; - file = temp[0]; - line = temp[1]; - column = temp[2]; - level = temp[3]; - category = temp[4]; - name = temp[5]; - warning = temp[6]; - suggestion = temp[7]; - note = temp[8]; - cwe = temp[9]; - context = temp[10]; - fingerprint = temp[11]; - DeflectRow node = new DeflectRow(until, file, line, level, category, cwe, warning, 0); - flawfinderResults.add(node); - } - } + public boolean isInteger(String str) { + Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$"); + return pattern.matcher(str).matches(); + } + public void toRowsOfflawfinder(String input) { + // File,Line,Column,Level,Category,Name,Warning,Suggestion,Note,CWEs,Context,Fingerprint + String[] temp = input.split(","); + int size = temp.length; + String until = null; + String file = null; + String line = null; + String column = null; + String level = null; + String category = null; + String name = null; + String warning = null; + String suggestion = null; + String note = null; + String cwe = null; + String context = null; + String fingerprint = null; + if (size > 11) { + if (!isInteger(temp[1])) { + return; + } + until = "flawfinder"; + file = temp[0]; + line = temp[1]; + column = temp[2]; + level = temp[3]; + category = temp[4]; + name = temp[5]; + warning = temp[6]; + suggestion = temp[7]; + note = temp[8]; + cwe = temp[9]; + context = temp[10]; + fingerprint = temp[11]; + DeflectRow node = + new DeflectRow(until, file, line, level, category, cwe, warning, + 0); + flawfinderResults.add(node); + } + } } diff --git a/src/cppcheckplus/text/stdClangType.java b/src/cppcheckplus/text/stdClangType.java index 42e9c37..ccbe3f7 100644 --- a/src/cppcheckplus/text/stdClangType.java +++ b/src/cppcheckplus/text/stdClangType.java @@ -1,9 +1,9 @@ package cppcheckplus.text; public class stdClangType { - public int len; - public String cwe; - public String type; - public String level; - public String target; + public int len; + public String cwe; + public String type; + public String level; + public String target; } diff --git a/src/cppcheckplus/toolbar/MyToolBar.java b/src/cppcheckplus/toolbar/MyToolBar.java index e0473a6..26f14d2 100644 --- a/src/cppcheckplus/toolbar/MyToolBar.java +++ b/src/cppcheckplus/toolbar/MyToolBar.java @@ -1,6 +1,6 @@ - package cppcheckplus.toolbar; +import cppcheckplus.control.MyContorlUtil; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Graphics; @@ -10,51 +10,50 @@ import javax.swing.BorderFactory; import javax.swing.Icon; import javax.swing.JPanel; -import cppcheckplus.control.MyContorlUtil; - -public class MyToolBar extends JPanel -{ - private String backgroundImageURL; - private int preferredHeight; - private TexturePaint paint; - private int buttonGap; - - public MyToolBar() - { - preferredHeight = MyContorlUtil.getImageIcon("control/images/toolbar_background.png").getIconHeight(); - paint = MyContorlUtil.createTexturePaint("control/images/toolbar_background.png"); - buttonGap = 2; - init(); - } - - private void init() - { - setLayout(new FlowLayout(3, buttonGap, 0)); - setBorder(BorderFactory.createEmptyBorder(2, 5, 0, 5)); - } - public void addButton(Icon icon, String tooltip,String actionCommand,boolean rover) - { - MyToolBarButton barButton; - if (rover) - barButton = new MyToolBarRoverButton(); - else - barButton = new MyToolBarButton(); - barButton.setIcon(icon); - barButton.setToolTipText(tooltip); - barButton.setActionCommand(actionCommand); - add(barButton); - } - protected void paintComponent(Graphics g) - { - super.paintComponent(g); - Graphics2D g2d = (Graphics2D)g; - g2d.setPaint(paint); - g2d.fillRect(0, 0, getWidth(), getHeight()); - } - - public Dimension getPreferredSize() - { - return new Dimension(super.getPreferredSize().width, preferredHeight); - } +public class MyToolBar extends JPanel { + private String backgroundImageURL; + private int preferredHeight; + private TexturePaint paint; + private int buttonGap; + + public MyToolBar() { + preferredHeight = + MyContorlUtil.getImageIcon("control/images/toolbar_background.png") + .getIconHeight(); + paint = MyContorlUtil.createTexturePaint( + "control/images/toolbar_background.png"); + buttonGap = 2; + init(); + } + + private void init() { + setLayout(new FlowLayout(3, buttonGap, 0)); + setBorder(BorderFactory.createEmptyBorder(2, 5, 0, 5)); + } + + public void addButton(Icon icon, String tooltip, String actionCommand, + boolean rover) { + MyToolBarButton barButton; + if (rover) { + barButton = new MyToolBarRoverButton(); + } else { + barButton = new MyToolBarButton(); + } + barButton.setIcon(icon); + barButton.setToolTipText(tooltip); + barButton.setActionCommand(actionCommand); + add(barButton); + } + + protected void paintComponent(Graphics g) { + super.paintComponent(g); + Graphics2D g2d = (Graphics2D) g; + g2d.setPaint(paint); + g2d.fillRect(0, 0, getWidth(), getHeight()); + } + + public Dimension getPreferredSize() { + return new Dimension(super.getPreferredSize().width, preferredHeight); + } } diff --git a/src/cppcheckplus/toolbar/MyToolBarButton.java b/src/cppcheckplus/toolbar/MyToolBarButton.java index d6fa386..32f5056 100644 --- a/src/cppcheckplus/toolbar/MyToolBarButton.java +++ b/src/cppcheckplus/toolbar/MyToolBarButton.java @@ -1,6 +1,6 @@ - package cppcheckplus.toolbar; +import cppcheckplus.control.MyContorlUtil; import java.awt.Color; import java.awt.Component; import java.awt.Dimension; @@ -13,85 +13,72 @@ import javax.swing.Icon; import javax.swing.JButton; import javax.swing.border.Border; -import cppcheckplus.control.MyContorlUtil; - -public class MyToolBarButton extends JButton -{ - private int buttonSize; - private Color roverBorderColor; - private Border roverBorder; - private Border emptyBorder; +public class MyToolBarButton extends JButton { + private int buttonSize; + private Color roverBorderColor; + private Border roverBorder; + private Border emptyBorder; - public MyToolBarButton() - { - super(); - buttonSize = 20; - roverBorderColor = MyContorlUtil.BUTTON_ROVER_COLOR; - roverBorder = new Border() { + public MyToolBarButton() { + super(); + buttonSize = 20; + roverBorderColor = MyContorlUtil.BUTTON_ROVER_COLOR; + roverBorder = new Border() { - public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) - { - g.setColor(roverBorderColor); - g.drawRect(x, y, width - 1, height - 1); - } + public void paintBorder(Component c, Graphics g, int x, int y, + int width, int height) { + g.setColor(roverBorderColor); + g.drawRect(x, y, width - 1, height - 1); + } - public Insets getBorderInsets(Component c) - { - return new Insets(1, 1, 1, 1); - } + public Insets getBorderInsets(Component c) { + return new Insets(1, 1, 1, 1); + } - public boolean isBorderOpaque() - { - return true; - } - }; - emptyBorder = BorderFactory.createEmptyBorder(1, 1, 1, 1); - init(); - } + public boolean isBorderOpaque() { + return true; + } + }; + emptyBorder = BorderFactory.createEmptyBorder(1, 1, 1, 1); + init(); + } - private void init() - { - setVerticalAlignment(0); - setFont(MyContorlUtil.FONT_12_BOLD); - setOpaque(false); - setBorder(emptyBorder); - setContentAreaFilled(false); - setFocusPainted(false); - addMouseListener(new MouseAdapter() { - public void mouseEntered(MouseEvent e) - { - setBorder(roverBorder); - } + private void init() { + setVerticalAlignment(0); + setFont(MyContorlUtil.FONT_12_BOLD); + setOpaque(false); + setBorder(emptyBorder); + setContentAreaFilled(false); + setFocusPainted(false); + addMouseListener(new MouseAdapter() { + public void mouseEntered(MouseEvent e) { + setBorder(roverBorder); + } - public void mouseExited(MouseEvent e) - { - setBorder(emptyBorder); - } - }); - } + public void mouseExited(MouseEvent e) { + setBorder(emptyBorder); + } + }); + } - @Override - public void setIcon(Icon icon) - { - super.setIcon(icon); - if (icon == null) - { - setPressedIcon(null); - setRolloverIcon(null); - } else - { - Icon pressedIcon = MyContorlUtil.createMovedIcon(icon); - setPressedIcon(pressedIcon); - } - } + @Override + public void setIcon(Icon icon) { + super.setIcon(icon); + if (icon == null) { + setPressedIcon(null); + setRolloverIcon(null); + } else { + Icon pressedIcon = MyContorlUtil.createMovedIcon(icon); + setPressedIcon(pressedIcon); + } + } - @Override - public Dimension getPreferredSize() - { - int width = super.getPreferredSize().width; - width = Math.max(width, buttonSize); - int height = buttonSize; - return new Dimension(width, height); - } + @Override + public Dimension getPreferredSize() { + int width = super.getPreferredSize().width; + width = Math.max(width, buttonSize); + int height = buttonSize; + return new Dimension(width, height); + } } diff --git a/src/cppcheckplus/toolbar/MyToolBarRoverButton.java b/src/cppcheckplus/toolbar/MyToolBarRoverButton.java index 9ab1dc8..79069f5 100644 --- a/src/cppcheckplus/toolbar/MyToolBarRoverButton.java +++ b/src/cppcheckplus/toolbar/MyToolBarRoverButton.java @@ -1,36 +1,30 @@ - package cppcheckplus.toolbar; +import cppcheckplus.control.MyContorlUtil; import java.awt.Color; import javax.swing.Icon; import javax.swing.ImageIcon; -import cppcheckplus.control.MyContorlUtil; - -public class MyToolBarRoverButton extends MyToolBarButton -{ - private Color roverDyeColor; +public class MyToolBarRoverButton extends MyToolBarButton { + private Color roverDyeColor; - public MyToolBarRoverButton() - { - roverDyeColor = new Color(86, 146, 61); - } + public MyToolBarRoverButton() { + roverDyeColor = new Color(86, 146, 61); + } - public void setIcon(Icon icon) - { - super.setIcon(icon); - if (icon == null) - { - setPressedIcon(null); - setRolloverIcon(null); - } else - { - java.awt.Image image = MyContorlUtil.iconToImage(icon); - Icon roverIcon = MyContorlUtil.createDyedIcon(new ImageIcon(image), roverDyeColor); - Icon pressedIcon = MyContorlUtil.createMovedIcon(roverIcon); - setRolloverIcon(roverIcon); - setPressedIcon(pressedIcon); - } - } + public void setIcon(Icon icon) { + super.setIcon(icon); + if (icon == null) { + setPressedIcon(null); + setRolloverIcon(null); + } else { + java.awt.Image image = MyContorlUtil.iconToImage(icon); + Icon roverIcon = MyContorlUtil.createDyedIcon(new ImageIcon(image), + roverDyeColor); + Icon pressedIcon = MyContorlUtil.createMovedIcon(roverIcon); + setRolloverIcon(roverIcon); + setPressedIcon(pressedIcon); + } + } } diff --git a/src/toolsconfig/clangTidy.java b/src/toolsconfig/clangTidy.java index d197393..8186603 100644 --- a/src/toolsconfig/clangTidy.java +++ b/src/toolsconfig/clangTidy.java @@ -1,7 +1,5 @@ package toolsconfig; -import cppcheckplus.control.UIFrame; -import cppcheckplus.text.ViewPanel; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; diff --git a/src/toolsconfig/flawfinder.java b/src/toolsconfig/flawfinder.java index 4ed19c2..0528eb6 100644 --- a/src/toolsconfig/flawfinder.java +++ b/src/toolsconfig/flawfinder.java @@ -1,13 +1,11 @@ package toolsconfig; -import cppcheckplus.control.MyContorlUtil; -import cppcheckplus.text.ViewPanel; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; -public class flawfinder extends ToolsConfig{ +public class flawfinder extends ToolsConfig { public flawfinder() { this.name = "flawfinder"; ToolsRegistry.registerTool(this.name, this); diff --git a/src/toolsconfig/settings.xml b/src/toolsconfig/settings.xml index c0664d9..77dd785 100644 --- a/src/toolsconfig/settings.xml +++ b/src/toolsconfig/settings.xml @@ -1,7 +1,7 @@ - + - + -- cgit v1.2.3-70-g09d2